@junobuild/core-peer 0.0.13 → 0.0.14
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 +17 -3
- package/declarations/satellite/satellite.factory.did.js +23 -6
- package/declarations/satellite/satellite.factory.did.mjs +23 -6
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/declarations/satellite/satellite.did.d.ts +17 -3
- package/dist/declarations/satellite/satellite.factory.did.js +23 -6
- package/dist/declarations/satellite/satellite.factory.did.mjs +23 -6
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +3 -3
- package/dist/types/api/doc.api.d.ts +1 -1
- package/dist/types/api/storage.api.d.ts +3 -3
- package/dist/types/services/doc.services.d.ts +9 -9
- package/dist/types/services/storage.services.d.ts +9 -9
- package/dist/types/types/doc.types.d.ts +1 -0
- package/dist/types/utils/actor.utils.d.ts +1 -1
- package/dist/workers/auth.worker.js +17 -12
- package/dist/workers/auth.worker.js.map +4 -4
- package/package.json +5 -5
- 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
|
@@ -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
|
-
|
|
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;
|
|
@@ -130,6 +139,7 @@ export interface Rule {
|
|
|
130
139
|
max_size: [] | [bigint];
|
|
131
140
|
read: Permission;
|
|
132
141
|
created_at: bigint;
|
|
142
|
+
version: [] | [bigint];
|
|
133
143
|
mutable_permissions: [] | [boolean];
|
|
134
144
|
write: Permission;
|
|
135
145
|
}
|
|
@@ -144,16 +154,16 @@ export interface SetControllersArgs {
|
|
|
144
154
|
controllers: Array<Principal>;
|
|
145
155
|
}
|
|
146
156
|
export interface SetDoc {
|
|
147
|
-
updated_at: [] | [bigint];
|
|
148
157
|
data: Uint8Array | number[];
|
|
149
158
|
description: [] | [string];
|
|
159
|
+
version: [] | [bigint];
|
|
150
160
|
}
|
|
151
161
|
export interface SetRule {
|
|
152
162
|
max_capacity: [] | [number];
|
|
153
163
|
memory: [] | [Memory];
|
|
154
|
-
updated_at: [] | [bigint];
|
|
155
164
|
max_size: [] | [bigint];
|
|
156
165
|
read: Permission;
|
|
166
|
+
version: [] | [bigint];
|
|
157
167
|
mutable_permissions: [] | [boolean];
|
|
158
168
|
write: Permission;
|
|
159
169
|
}
|
|
@@ -161,9 +171,11 @@ export interface StorageConfig {
|
|
|
161
171
|
iframe: [] | [StorageConfigIFrame];
|
|
162
172
|
rewrites: Array<[string, string]>;
|
|
163
173
|
headers: Array<[string, Array<[string, string]>]>;
|
|
174
|
+
raw_access: [] | [StorageConfigRawAccess];
|
|
164
175
|
redirects: [] | [Array<[string, StorageConfigRedirect]>];
|
|
165
176
|
}
|
|
166
177
|
export type StorageConfigIFrame = {Deny: null} | {AllowAny: null} | {SameOrigin: null};
|
|
178
|
+
export type StorageConfigRawAccess = {Deny: null} | {Allow: null};
|
|
167
179
|
export interface StorageConfigRedirect {
|
|
168
180
|
status_code: number;
|
|
169
181
|
location: string;
|
|
@@ -211,6 +223,7 @@ export interface _SERVICE {
|
|
|
211
223
|
del_rule: ActorMethod<[RulesType, string, DelDoc], undefined>;
|
|
212
224
|
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
213
225
|
get_asset: ActorMethod<[string, string], [] | [AssetNoContent]>;
|
|
226
|
+
get_auth_config: ActorMethod<[], [] | [AuthenticationConfig]>;
|
|
214
227
|
get_config: ActorMethod<[], Config>;
|
|
215
228
|
get_doc: ActorMethod<[string, string], [] | [Doc]>;
|
|
216
229
|
get_many_assets: ActorMethod<[Array<[string, string]>], Array<[string, [] | [AssetNoContent]]>>;
|
|
@@ -227,6 +240,7 @@ export interface _SERVICE {
|
|
|
227
240
|
list_docs: ActorMethod<[string, ListParams], ListResults_1>;
|
|
228
241
|
list_rules: ActorMethod<[RulesType], Array<[string, Rule]>>;
|
|
229
242
|
memory_size: ActorMethod<[], MemorySize>;
|
|
243
|
+
set_auth_config: ActorMethod<[AuthenticationConfig], undefined>;
|
|
230
244
|
set_config: ActorMethod<[Config], undefined>;
|
|
231
245
|
set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
|
|
232
246
|
set_custom_domain: ActorMethod<[string, [] | [string]], undefined>;
|
|
@@ -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({
|
|
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,13 +43,24 @@ 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,
|
|
50
57
|
AllowAny: IDL.Null,
|
|
51
58
|
SameOrigin: IDL.Null
|
|
52
59
|
});
|
|
60
|
+
const StorageConfigRawAccess = IDL.Variant({
|
|
61
|
+
Deny: IDL.Null,
|
|
62
|
+
Allow: IDL.Null
|
|
63
|
+
});
|
|
53
64
|
const StorageConfigRedirect = IDL.Record({
|
|
54
65
|
status_code: IDL.Nat16,
|
|
55
66
|
location: IDL.Text
|
|
@@ -58,6 +69,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
58
69
|
iframe: IDL.Opt(StorageConfigIFrame),
|
|
59
70
|
rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
60
71
|
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))),
|
|
72
|
+
raw_access: IDL.Opt(StorageConfigRawAccess),
|
|
61
73
|
redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect)))
|
|
62
74
|
});
|
|
63
75
|
const Config = IDL.Record({storage: StorageConfig});
|
|
@@ -66,7 +78,8 @@ export const idlFactory = ({IDL}) => {
|
|
|
66
78
|
owner: IDL.Principal,
|
|
67
79
|
data: IDL.Vec(IDL.Nat8),
|
|
68
80
|
description: IDL.Opt(IDL.Text),
|
|
69
|
-
created_at: IDL.Nat64
|
|
81
|
+
created_at: IDL.Nat64,
|
|
82
|
+
version: IDL.Opt(IDL.Nat64)
|
|
70
83
|
});
|
|
71
84
|
const HttpRequest = IDL.Record({
|
|
72
85
|
url: IDL.Text,
|
|
@@ -140,6 +153,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
140
153
|
const CustomDomain = IDL.Record({
|
|
141
154
|
updated_at: IDL.Nat64,
|
|
142
155
|
created_at: IDL.Nat64,
|
|
156
|
+
version: IDL.Opt(IDL.Nat64),
|
|
143
157
|
bn_id: IDL.Opt(IDL.Text)
|
|
144
158
|
});
|
|
145
159
|
const ListResults_1 = IDL.Record({
|
|
@@ -162,6 +176,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
162
176
|
max_size: IDL.Opt(IDL.Nat),
|
|
163
177
|
read: Permission,
|
|
164
178
|
created_at: IDL.Nat64,
|
|
179
|
+
version: IDL.Opt(IDL.Nat64),
|
|
165
180
|
mutable_permissions: IDL.Opt(IDL.Bool),
|
|
166
181
|
write: Permission
|
|
167
182
|
});
|
|
@@ -176,16 +191,16 @@ export const idlFactory = ({IDL}) => {
|
|
|
176
191
|
controllers: IDL.Vec(IDL.Principal)
|
|
177
192
|
});
|
|
178
193
|
const SetDoc = IDL.Record({
|
|
179
|
-
updated_at: IDL.Opt(IDL.Nat64),
|
|
180
194
|
data: IDL.Vec(IDL.Nat8),
|
|
181
|
-
description: IDL.Opt(IDL.Text)
|
|
195
|
+
description: IDL.Opt(IDL.Text),
|
|
196
|
+
version: IDL.Opt(IDL.Nat64)
|
|
182
197
|
});
|
|
183
198
|
const SetRule = IDL.Record({
|
|
184
199
|
max_capacity: IDL.Opt(IDL.Nat32),
|
|
185
200
|
memory: IDL.Opt(Memory),
|
|
186
|
-
updated_at: IDL.Opt(IDL.Nat64),
|
|
187
201
|
max_size: IDL.Opt(IDL.Nat),
|
|
188
202
|
read: Permission,
|
|
203
|
+
version: IDL.Opt(IDL.Nat64),
|
|
189
204
|
mutable_permissions: IDL.Opt(IDL.Bool),
|
|
190
205
|
write: Permission
|
|
191
206
|
});
|
|
@@ -215,6 +230,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
215
230
|
del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
|
|
216
231
|
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
217
232
|
get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
|
|
233
|
+
get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']),
|
|
218
234
|
get_config: IDL.Func([], [Config], []),
|
|
219
235
|
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
220
236
|
get_many_assets: IDL.Func(
|
|
@@ -240,6 +256,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
240
256
|
list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
|
|
241
257
|
list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
|
|
242
258
|
memory_size: IDL.Func([], [MemorySize], ['query']),
|
|
259
|
+
set_auth_config: IDL.Func([AuthenticationConfig], [], []),
|
|
243
260
|
set_config: IDL.Func([Config], [], []),
|
|
244
261
|
set_controllers: IDL.Func(
|
|
245
262
|
[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({
|
|
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,13 +43,24 @@ 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,
|
|
50
57
|
AllowAny: IDL.Null,
|
|
51
58
|
SameOrigin: IDL.Null
|
|
52
59
|
});
|
|
60
|
+
const StorageConfigRawAccess = IDL.Variant({
|
|
61
|
+
Deny: IDL.Null,
|
|
62
|
+
Allow: IDL.Null
|
|
63
|
+
});
|
|
53
64
|
const StorageConfigRedirect = IDL.Record({
|
|
54
65
|
status_code: IDL.Nat16,
|
|
55
66
|
location: IDL.Text
|
|
@@ -58,6 +69,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
58
69
|
iframe: IDL.Opt(StorageConfigIFrame),
|
|
59
70
|
rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
60
71
|
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))),
|
|
72
|
+
raw_access: IDL.Opt(StorageConfigRawAccess),
|
|
61
73
|
redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect)))
|
|
62
74
|
});
|
|
63
75
|
const Config = IDL.Record({storage: StorageConfig});
|
|
@@ -66,7 +78,8 @@ export const idlFactory = ({IDL}) => {
|
|
|
66
78
|
owner: IDL.Principal,
|
|
67
79
|
data: IDL.Vec(IDL.Nat8),
|
|
68
80
|
description: IDL.Opt(IDL.Text),
|
|
69
|
-
created_at: IDL.Nat64
|
|
81
|
+
created_at: IDL.Nat64,
|
|
82
|
+
version: IDL.Opt(IDL.Nat64)
|
|
70
83
|
});
|
|
71
84
|
const HttpRequest = IDL.Record({
|
|
72
85
|
url: IDL.Text,
|
|
@@ -140,6 +153,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
140
153
|
const CustomDomain = IDL.Record({
|
|
141
154
|
updated_at: IDL.Nat64,
|
|
142
155
|
created_at: IDL.Nat64,
|
|
156
|
+
version: IDL.Opt(IDL.Nat64),
|
|
143
157
|
bn_id: IDL.Opt(IDL.Text)
|
|
144
158
|
});
|
|
145
159
|
const ListResults_1 = IDL.Record({
|
|
@@ -162,6 +176,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
162
176
|
max_size: IDL.Opt(IDL.Nat),
|
|
163
177
|
read: Permission,
|
|
164
178
|
created_at: IDL.Nat64,
|
|
179
|
+
version: IDL.Opt(IDL.Nat64),
|
|
165
180
|
mutable_permissions: IDL.Opt(IDL.Bool),
|
|
166
181
|
write: Permission
|
|
167
182
|
});
|
|
@@ -176,16 +191,16 @@ export const idlFactory = ({IDL}) => {
|
|
|
176
191
|
controllers: IDL.Vec(IDL.Principal)
|
|
177
192
|
});
|
|
178
193
|
const SetDoc = IDL.Record({
|
|
179
|
-
updated_at: IDL.Opt(IDL.Nat64),
|
|
180
194
|
data: IDL.Vec(IDL.Nat8),
|
|
181
|
-
description: IDL.Opt(IDL.Text)
|
|
195
|
+
description: IDL.Opt(IDL.Text),
|
|
196
|
+
version: IDL.Opt(IDL.Nat64)
|
|
182
197
|
});
|
|
183
198
|
const SetRule = IDL.Record({
|
|
184
199
|
max_capacity: IDL.Opt(IDL.Nat32),
|
|
185
200
|
memory: IDL.Opt(Memory),
|
|
186
|
-
updated_at: IDL.Opt(IDL.Nat64),
|
|
187
201
|
max_size: IDL.Opt(IDL.Nat),
|
|
188
202
|
read: Permission,
|
|
203
|
+
version: IDL.Opt(IDL.Nat64),
|
|
189
204
|
mutable_permissions: IDL.Opt(IDL.Bool),
|
|
190
205
|
write: Permission
|
|
191
206
|
});
|
|
@@ -215,6 +230,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
215
230
|
del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
|
|
216
231
|
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
217
232
|
get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
|
|
233
|
+
get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']),
|
|
218
234
|
get_config: IDL.Func([], [Config], []),
|
|
219
235
|
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
220
236
|
get_many_assets: IDL.Func(
|
|
@@ -240,6 +256,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
240
256
|
list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
|
|
241
257
|
list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
|
|
242
258
|
memory_size: IDL.Func([], [MemorySize], ['query']),
|
|
259
|
+
set_auth_config: IDL.Func([AuthenticationConfig], [], []),
|
|
243
260
|
set_config: IDL.Func([Config], [], []),
|
|
244
261
|
set_controllers: IDL.Func(
|
|
245
262
|
[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),Qt=class extends Error{},st=(t,e)=>{if(c(t))throw new Qt(e)},j="__bigint__",H="__principal__",z="__uint8array__",Zt=(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,Dt=(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,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(),Dt)},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 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 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 G=({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??ct}`;let i=A.getInstance().get(),n=l(i)&&l(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 It}from"@dfinity/auth-client";var V=()=>It.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var dt=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 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 U(i),...n}};import{Principal as Lt}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"?Lt.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}),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}),O=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:O}),_=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)}),m=t.Variant({Heap:t.Null,Stable:t.Null}),S=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:S,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(S),body:t.Vec(t.Nat8)}),Et=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}),Ft=t.Record({batch_id:t.Nat}),Vt=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),Mt=t.Record({field:Vt,desc:t.Bool}),$t=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),Kt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),L=t.Record({order:t.Opt(Mt),owner:t.Opt(t.Principal),matcher:t.Opt($t),paginate:t.Opt(Kt)}),qt=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}),Bt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),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,_)),items_length:t.Nat64}),C=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Ht=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(m),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:C,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:C}),zt=t.Record({stable:t.Nat64,heap:t.Nat64}),Wt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),Gt=t.Record({controller:Wt,controllers:t.Vec(t.Principal)}),tt=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),Yt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(m),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:C,mutable_permissions:t.Opt(t.Bool),write:C}),Jt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Xt=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([b],[q],["query"]),http_request_streaming_callback:t.Func([S],[B],["query"]),init_asset_upload:t.Func([Et],[Ft],[]),list_assets:t.Func([t.Text,L],[qt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Bt))],["query"]),list_docs:t.Func([t.Text,L],[jt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Ht))],["query"]),memory_size:t.Func([],[zt],["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,Yt],[],[]),upload_asset_chunk:t.Func([Jt],[Xt],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as te,HttpAgent as ee}from"@dfinity/agent";var mt=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 ee({identity:s,host:r,...o&&{fetch:o}});return l(i)&&await a.fetchRootKey(),te.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 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 v({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 d=y(a);n.push(l(d)?await v({key:r,doc:d}):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 v({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: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},_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:d}=await o.list_docs(t,M(e)),h=[];for(let[u,T]of i){let{data:x,owner:O,description:N,..._}=T;h.push({key:u,description:y(N),owner:O.toText(),data:await dt({data:x}),..._})}return{items:h,items_length:r,items_page:y(n),matches_length:a,matches_pages:y(d)}};import{AnonymousIdentity as se}from"@dfinity/agent";var g=t=>t!==void 0?t:$()??new se;var At=async({satellite:t,...e})=>{let s=g(t?.identity);return yt({...e,satellite:{...t,identity:s}})},as=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}})},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,...e})=>{let s=g(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},ds=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=$();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 oe({userId:s,provider:t}):o},oe=async({userId:t,...e})=>Pt({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 Nt(t);w.getInstance().set(s)},ie=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,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()},$=()=>P?.getIdentity(),ne=async()=>(P??await V()).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: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=[],O=E()?new Blob([await t.arrayBuffer()]):t,N=0n;for(let m=0;m<O.size;m+=T){let S=O.slice(m,m+T);x.push({batchId:u,chunk:S,actor:h,orderId:N}),N++}let _=[];for await(let m of re({uploadChunks:x}))_=[..._,...m];let b=o.find(([m,S])=>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,...b||[]]})};async function*re({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=>ae(n)))}}var ae=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),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 Ks=async t=>Ut(t),qs=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 Ot({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}},Bs=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:O,created_at:N,updated_at:_})=>{let b=y(d);return{fullPath:a,description:y(T),name:h,downloadUrl:`${r}${a}${b!==void 0?`?token=${b}`:""}`,token:b,headers:x,encodings:O.reduce((m,[S,{modified:K,sha256:q,total_length:B}])=>({...m,[S]:{modified:K,sha256:Ct(q),total_length:B}}),{}),owner:u.toText(),created_at:N,updated_at:_}}),...n}},js=async({collection:t,fullPath:e,satellite:s})=>St({collection:t,fullPath:e,satellite:{...s,identity:g(s?.identity)}}),Hs=async({assets:t,satellite:e})=>Rt({assets:t,satellite:{...e,identity:g(e?.identity)}}),zs=async({satellite:t,...e})=>{let s=g(t?.identity);return kt({...e,satellite:{...t,identity:s}})},Ws=async({satellite:t,...e})=>{let s=g(t?.identity);return vt({...e,satellite:{...t,identity:s}})};var Zs=async t=>{A.getInstance().set(t),await D();let e=t.workers?.auth!==void 0?wt(t.workers.auth):void 0;return[...e?[e]:[]]},Ds=t=>w.getInstance().subscribe(t);export{F as InternetIdentityProvider,pt as NFIDProvider,Ds as authSubscribe,js as deleteAsset,ls as deleteDoc,Hs as deleteManyAssets,ps as deleteManyDocs,zs as getAsset,At as getDoc,Ws as getManyAssets,as as getManyDocs,Zs as initJuno,Bs as listAssets,ds as listDocs,Pt as setDoc,cs as setManyDocs,ie as signIn,I as signOut,ne as unsafeIdentity,Ks as uploadBlob,qs as uploadFile};
|
|
1
|
+
import{Principal as et}from"@dfinity/principal";var c=t=>t==null,l=t=>!c(t),It=class extends Error{},st=(t,e)=>{if(c(t))throw new It(e)},j="__bigint__",H="__principal__",z="__uint8array__",Lt=(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,te=(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},d=t=>l(t)?[t]:[],p=t=>t?.[0],ot=async t=>{let e=new Blob([JSON.stringify(t,Lt)],{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(),te)},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 O=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 P=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=P.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??ct}`;let i=P.getInstance().get(),n=l(i)&&l(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 ee}from"@dfinity/auth-client";var $=()=>ee.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:d(o),data:await ot(e),version:d(s)}},J=t=>{let{version:e}=t;return{version:d(e)}},U=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:p(i),owner:s.toText(),data:await F(n),version:p(o),...r}};import{Principal as se}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"?se.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}),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,version:t.Opt(t.Nat64)}),_=t.Record({derivation_origin:t.Opt(t.Text)}),T=t.Record({internet_identity:t.Opt(_)}),S=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),b=t.Variant({Deny:t.Null,Allow:t.Null}),w=t.Record({status_code:t.Nat16,location:t.Text}),x=t.Record({iframe:t.Opt(S),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),raw_access:t.Opt(b),redirects:t.Opt(t.Vec(t.Tuple(t.Text,w)))}),y=t.Record({storage:x}),A=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)}),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)}),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}),Et=t.Variant({Callback:t.Record({token:C,callback:t.Func([],[],["query"])})}),Ft=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Et),status_code:t.Nat16}),Vt=t.Record({token:t.Opt(C),body:t.Vec(t.Nat8)}),Mt=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=t.Record({batch_id:t.Nat}),Kt=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),qt=t.Record({field:Kt,desc:t.Bool}),Bt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),jt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),L=t.Record({order:t.Opt(qt),owner:t.Opt(t.Principal),matcher:t.Opt(Bt),paginate:t.Opt(jt)}),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,m)),items_length:t.Nat64}),zt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),Wt=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}),E=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Gt=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}),Yt=t.Record({stable:t.Nat64,heap:t.Nat64}),Jt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),Xt=t.Record({controller:Jt,controllers:t.Vec(t.Principal)}),tt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),Qt=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}),Zt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Dt=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([],[y],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(A)],["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(A)))],["query"]),http_request:t.Func([B],[Ft],["query"]),http_request_streaming_callback:t.Func([C],[Vt],["query"]),init_asset_upload:t.Func([Mt],[$t],[]),list_assets:t.Func([t.Text,L],[Ht],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,zt))],["query"]),list_docs:t.Func([t.Text,L],[Wt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Gt))],["query"]),memory_size:t.Func([],[Yt],["query"]),set_auth_config:t.Func([T],[],[]),set_config:t.Func([y],[],[]),set_controllers:t.Func([Xt],[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],[A],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,tt))],[t.Vec(t.Tuple(t.Text,A))],[]),set_rule:t.Func([r,t.Text,Qt],[],[]),upload_asset_chunk:t.Func([Zt],[Dt],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as oe,HttpAgent as ie}from"@dfinity/agent";var mt=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=l(i)&&i!==!1?i===!0?R:i:"https://icp-api.io",a=new ie({identity:s,host:r,...o&&{fetch:o}});return l(i)&&await a.fetchRootKey(),oe.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?R: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}:P.getInstance().get()??{satelliteId:void 0},Z=({container:t})=>l(t)?{container:t}:P.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=p(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=p(a);n.push(l(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:S,description:b,version:w,...x}=_;h.push({key:m,description:p(b),owner:S.toText(),data:await dt({data:T}),version:p(w),...x})}return{items:h,items_length:r,items_page:p(n),matches_length:a,matches_pages:p(u)}};import{AnonymousIdentity as ne}from"@dfinity/agent";var g=t=>t!==void 0?t:q()??new ne;var At=async({satellite:t,...e})=>{let s=g(t?.identity);return yt({...e,satellite:{...t,identity:s}})},ps=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}})},ds=async({satellite:t,...e})=>{let s=g(t?.identity);return ht({...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,...e})=>{let s=g(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},ys=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 re({userId:s,provider:t}):o},re=async({userId:t,...e})=>Pt({collection:"#user",doc:{key:t,data:e}});var N,D=async t=>{if(N=N??await $(),!(await N?.isAuthenticated()??!1))return;let s=await Nt(t);O.getInstance().set(s)},ae=async t=>new Promise(async(e,s)=>{N=N??await $();let o=t?.provider??new M({});await N.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 N?.logout(),N=void 0,O.getInstance().reset()},q=()=>N?.getIdentity(),ce=async()=>(N??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}},O.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=[],S=V()?new Blob([await t.arrayBuffer()]):t,b=0n;for(let y=0;y<S.size;y+=_){let A=S.slice(y,y+_);T.push({batchId:m,chunk:A,actor:h,orderId:b}),b++}let w=[];for await(let y of le({uploadChunks:T}))w=[...w,...y];let x=o.find(([y,A])=>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:w.map(({chunk_id:y})=>y),headers:[...o,...x||[]]})};async function*le({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=>pe(n)))}}var pe=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)}),St=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:p(r),matches_length:a,matches_pages:p(u)}},bt=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 p(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])=>p(r))};var Ct=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var js=async t=>Ut(t),Hs=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}},zs=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:g(e?.identity)},{items:i,...n}=await St({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:S,created_at:b,updated_at:w})=>{let x=p(u);return{fullPath:a,description:p(_),name:h,downloadUrl:`${r}${a}${x!==void 0?`?token=${x}`:""}`,token:x,headers:T,encodings:S.reduce((y,[A,{modified:B,sha256:k,total_length:C}])=>({...y,[A]:{modified:B,sha256:Ct(k),total_length:C}}),{}),owner:m.toText(),created_at:b,updated_at:w}}),...n}},Ws=async({collection:t,fullPath:e,satellite:s})=>bt({collection:t,fullPath:e,satellite:{...s,identity:g(s?.identity)}}),Gs=async({assets:t,satellite:e})=>vt({assets:t,satellite:{...e,identity:g(e?.identity)}}),Ys=async({satellite:t,...e})=>{let s=g(t?.identity);return Rt({...e,satellite:{...t,identity:s}})},Js=async({satellite:t,...e})=>{let s=g(t?.identity);return kt({...e,satellite:{...t,identity:s}})};var Ls=async t=>{P.getInstance().set(t),await D();let e=t.workers?.auth!==void 0?wt(t.workers.auth):void 0;return[...e?[e]:[]]},to=t=>O.getInstance().subscribe(t);export{M as InternetIdentityProvider,pt as NFIDProvider,to as authSubscribe,Ws as deleteAsset,us as deleteDoc,Gs as deleteManyAssets,ms as deleteManyDocs,Ys as getAsset,At as getDoc,Js as getManyAssets,ps as getManyDocs,Ls as initJuno,zs as listAssets,ys as listDocs,Pt as setDoc,ds as setManyDocs,ae as signIn,I as signOut,ce as unsafeIdentity,js as uploadBlob,Hs as uploadFile};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|