@junobuild/core 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/README.md +1 -1
- package/declarations/cmc/cmc.did +122 -0
- package/declarations/cmc/cmc.did.d.ts +48 -0
- package/declarations/cmc/cmc.factory.did.js +65 -0
- package/declarations/cmc/index.d.ts +45 -0
- package/declarations/cmc/index.js +32 -0
- package/declarations/console/console.did.d.ts +60 -0
- package/declarations/console/console.factory.did.js +62 -0
- package/declarations/console/console.factory.did.mjs +62 -0
- package/declarations/console/index.d.ts +45 -0
- package/declarations/console/index.js +32 -0
- package/declarations/frontend/frontend.did +188 -0
- package/declarations/frontend/frontend.did.d.ts +172 -0
- package/declarations/frontend/frontend.factory.did.js +208 -0
- package/declarations/frontend/index.d.ts +45 -0
- package/declarations/frontend/index.js +32 -0
- package/declarations/ic/ic.did +82 -0
- package/declarations/ic/ic.did.d.ts +77 -0
- package/declarations/ic/ic.factory.did.js +128 -0
- package/declarations/internet_identity/index.d.ts +45 -0
- package/declarations/internet_identity/index.js +32 -0
- package/declarations/internet_identity/internet_identity.did +330 -0
- package/declarations/internet_identity/internet_identity.did.d.ts +204 -0
- package/declarations/internet_identity/internet_identity.factory.did.js +233 -0
- package/declarations/ledger/index.d.ts +45 -0
- package/declarations/ledger/index.js +32 -0
- package/declarations/ledger/ledger.did +249 -0
- package/declarations/ledger/ledger.did.d.ts +100 -0
- package/declarations/ledger/ledger.factory.did.js +98 -0
- package/declarations/mission_control/index.d.ts +45 -0
- package/declarations/mission_control/index.js +32 -0
- package/declarations/mission_control/mission_control.did.d.ts +41 -0
- package/declarations/mission_control/mission_control.factory.did.js +50 -0
- package/declarations/satellite/index.d.ts +45 -0
- package/declarations/satellite/index.js +32 -0
- package/declarations/satellite/satellite.did.d.ts +183 -0
- package/declarations/satellite/satellite.factory.did.js +194 -0
- package/declarations/satellite/satellite.factory.did.mjs +192 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +2 -2
- package/dist/node/index.mjs +7 -7
- package/dist/node/index.mjs.map +3 -3
- package/dist/workers/auth.worker.js.map +2 -2
- package/package.json +3 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {Actor, HttpAgent} from '@dfinity/agent';
|
|
2
|
+
|
|
3
|
+
// Imports and re-exports candid interface
|
|
4
|
+
import {idlFactory} from './satellite.did.js';
|
|
5
|
+
export {idlFactory} from './satellite.did.js';
|
|
6
|
+
|
|
7
|
+
// CANISTER_ID is replaced by webpack based on node environment
|
|
8
|
+
|
|
9
|
+
export const createActor = (canisterId, options = {}) => {
|
|
10
|
+
const agent = options.agent || new HttpAgent({...options.agentOptions});
|
|
11
|
+
|
|
12
|
+
if (options.agent && options.agentOptions) {
|
|
13
|
+
console.warn(
|
|
14
|
+
'Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent.'
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Fetch root key for certificate validation during development
|
|
19
|
+
if (process.env.DFX_NETWORK !== 'ic') {
|
|
20
|
+
agent.fetchRootKey().catch((err) => {
|
|
21
|
+
console.warn('Unable to fetch root key. Check to ensure that your local replica is running');
|
|
22
|
+
console.error(err);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Creates an actor with using the candid interface and the HttpAgent
|
|
27
|
+
return Actor.createActor(idlFactory, {
|
|
28
|
+
agent,
|
|
29
|
+
canisterId,
|
|
30
|
+
...options.actorOptions
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type {ActorMethod} from '@dfinity/agent';
|
|
2
|
+
import type {Principal} from '@dfinity/principal';
|
|
3
|
+
|
|
4
|
+
export interface AssetEncodingNoContent {
|
|
5
|
+
modified: bigint;
|
|
6
|
+
sha256: Uint8Array | number[];
|
|
7
|
+
total_length: bigint;
|
|
8
|
+
}
|
|
9
|
+
export interface AssetKey {
|
|
10
|
+
token: [] | [string];
|
|
11
|
+
collection: string;
|
|
12
|
+
owner: Principal;
|
|
13
|
+
name: string;
|
|
14
|
+
full_path: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AssetNoContent {
|
|
17
|
+
key: AssetKey;
|
|
18
|
+
updated_at: bigint;
|
|
19
|
+
encodings: Array<[string, AssetEncodingNoContent]>;
|
|
20
|
+
headers: Array<[string, string]>;
|
|
21
|
+
created_at: bigint;
|
|
22
|
+
}
|
|
23
|
+
export interface Chunk {
|
|
24
|
+
content: Uint8Array | number[];
|
|
25
|
+
batch_id: bigint;
|
|
26
|
+
}
|
|
27
|
+
export interface CommitBatch {
|
|
28
|
+
batch_id: bigint;
|
|
29
|
+
headers: Array<[string, string]>;
|
|
30
|
+
chunk_ids: Array<bigint>;
|
|
31
|
+
}
|
|
32
|
+
export interface Config {
|
|
33
|
+
storage: StorageConfig;
|
|
34
|
+
}
|
|
35
|
+
export interface Controller {
|
|
36
|
+
updated_at: bigint;
|
|
37
|
+
metadata: Array<[string, string]>;
|
|
38
|
+
created_at: bigint;
|
|
39
|
+
expires_at: [] | [bigint];
|
|
40
|
+
}
|
|
41
|
+
export interface CustomDomain {
|
|
42
|
+
updated_at: bigint;
|
|
43
|
+
created_at: bigint;
|
|
44
|
+
bn_id: [] | [string];
|
|
45
|
+
}
|
|
46
|
+
export interface DelDoc {
|
|
47
|
+
updated_at: [] | [bigint];
|
|
48
|
+
}
|
|
49
|
+
export interface DeleteControllersArgs {
|
|
50
|
+
controllers: Array<Principal>;
|
|
51
|
+
}
|
|
52
|
+
export interface Doc {
|
|
53
|
+
updated_at: bigint;
|
|
54
|
+
owner: Principal;
|
|
55
|
+
data: Uint8Array | number[];
|
|
56
|
+
created_at: bigint;
|
|
57
|
+
}
|
|
58
|
+
export interface HttpRequest {
|
|
59
|
+
url: string;
|
|
60
|
+
method: string;
|
|
61
|
+
body: Uint8Array | number[];
|
|
62
|
+
headers: Array<[string, string]>;
|
|
63
|
+
}
|
|
64
|
+
export interface HttpResponse {
|
|
65
|
+
body: Uint8Array | number[];
|
|
66
|
+
headers: Array<[string, string]>;
|
|
67
|
+
streaming_strategy: [] | [StreamingStrategy];
|
|
68
|
+
status_code: number;
|
|
69
|
+
}
|
|
70
|
+
export interface InitAssetKey {
|
|
71
|
+
token: [] | [string];
|
|
72
|
+
collection: string;
|
|
73
|
+
name: string;
|
|
74
|
+
encoding_type: [] | [string];
|
|
75
|
+
full_path: string;
|
|
76
|
+
}
|
|
77
|
+
export interface InitUploadResult {
|
|
78
|
+
batch_id: bigint;
|
|
79
|
+
}
|
|
80
|
+
export interface ListOrder {
|
|
81
|
+
field: ListOrderField;
|
|
82
|
+
desc: boolean;
|
|
83
|
+
}
|
|
84
|
+
export type ListOrderField = {UpdatedAt: null} | {Keys: null} | {CreatedAt: null};
|
|
85
|
+
export interface ListPaginate {
|
|
86
|
+
start_after: [] | [string];
|
|
87
|
+
limit: [] | [bigint];
|
|
88
|
+
}
|
|
89
|
+
export interface ListParams {
|
|
90
|
+
order: [] | [ListOrder];
|
|
91
|
+
owner: [] | [Principal];
|
|
92
|
+
matcher: [] | [string];
|
|
93
|
+
paginate: [] | [ListPaginate];
|
|
94
|
+
}
|
|
95
|
+
export interface ListResults {
|
|
96
|
+
matches_length: bigint;
|
|
97
|
+
length: bigint;
|
|
98
|
+
items: Array<[string, AssetNoContent]>;
|
|
99
|
+
}
|
|
100
|
+
export interface ListResults_1 {
|
|
101
|
+
matches_length: bigint;
|
|
102
|
+
length: bigint;
|
|
103
|
+
items: Array<[string, Doc]>;
|
|
104
|
+
}
|
|
105
|
+
export type Permission = {Controllers: null} | {Private: null} | {Public: null} | {Managed: null};
|
|
106
|
+
export interface Rule {
|
|
107
|
+
updated_at: bigint;
|
|
108
|
+
max_size: [] | [bigint];
|
|
109
|
+
read: Permission;
|
|
110
|
+
created_at: bigint;
|
|
111
|
+
write: Permission;
|
|
112
|
+
}
|
|
113
|
+
export type RulesType = {Db: null} | {Storage: null};
|
|
114
|
+
export interface SetController {
|
|
115
|
+
metadata: Array<[string, string]>;
|
|
116
|
+
expires_at: [] | [bigint];
|
|
117
|
+
}
|
|
118
|
+
export interface SetControllersArgs {
|
|
119
|
+
controller: SetController;
|
|
120
|
+
controllers: Array<Principal>;
|
|
121
|
+
}
|
|
122
|
+
export interface SetDoc {
|
|
123
|
+
updated_at: [] | [bigint];
|
|
124
|
+
data: Uint8Array | number[];
|
|
125
|
+
}
|
|
126
|
+
export interface SetRule {
|
|
127
|
+
updated_at: [] | [bigint];
|
|
128
|
+
max_size: [] | [bigint];
|
|
129
|
+
read: Permission;
|
|
130
|
+
write: Permission;
|
|
131
|
+
}
|
|
132
|
+
export interface StorageConfig {
|
|
133
|
+
headers: Array<[string, Array<[string, string]>]>;
|
|
134
|
+
}
|
|
135
|
+
export interface StreamingCallbackHttpResponse {
|
|
136
|
+
token: [] | [StreamingCallbackToken];
|
|
137
|
+
body: Uint8Array | number[];
|
|
138
|
+
}
|
|
139
|
+
export interface StreamingCallbackToken {
|
|
140
|
+
token: [] | [string];
|
|
141
|
+
sha256: [] | [Uint8Array | number[]];
|
|
142
|
+
headers: Array<[string, string]>;
|
|
143
|
+
index: bigint;
|
|
144
|
+
encoding_type: string;
|
|
145
|
+
full_path: string;
|
|
146
|
+
}
|
|
147
|
+
export type StreamingStrategy = {
|
|
148
|
+
Callback: {
|
|
149
|
+
token: StreamingCallbackToken;
|
|
150
|
+
callback: [Principal, string];
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
export interface UploadChunk {
|
|
154
|
+
chunk_id: bigint;
|
|
155
|
+
}
|
|
156
|
+
export interface _SERVICE {
|
|
157
|
+
commit_asset_upload: ActorMethod<[CommitBatch], undefined>;
|
|
158
|
+
del_asset: ActorMethod<[string, string], undefined>;
|
|
159
|
+
del_assets: ActorMethod<[[] | [string]], undefined>;
|
|
160
|
+
del_controllers: ActorMethod<[DeleteControllersArgs], Array<[Principal, Controller]>>;
|
|
161
|
+
del_custom_domain: ActorMethod<[string], undefined>;
|
|
162
|
+
del_doc: ActorMethod<[string, string, DelDoc], undefined>;
|
|
163
|
+
get_config: ActorMethod<[], Config>;
|
|
164
|
+
get_doc: ActorMethod<[string, string], [] | [Doc]>;
|
|
165
|
+
http_request: ActorMethod<[HttpRequest], HttpResponse>;
|
|
166
|
+
http_request_streaming_callback: ActorMethod<
|
|
167
|
+
[StreamingCallbackToken],
|
|
168
|
+
StreamingCallbackHttpResponse
|
|
169
|
+
>;
|
|
170
|
+
init_asset_upload: ActorMethod<[InitAssetKey], InitUploadResult>;
|
|
171
|
+
list_assets: ActorMethod<[[] | [string], ListParams], ListResults>;
|
|
172
|
+
list_controllers: ActorMethod<[], Array<[Principal, Controller]>>;
|
|
173
|
+
list_custom_domains: ActorMethod<[], Array<[string, CustomDomain]>>;
|
|
174
|
+
list_docs: ActorMethod<[string, ListParams], ListResults_1>;
|
|
175
|
+
list_rules: ActorMethod<[RulesType], Array<[string, Rule]>>;
|
|
176
|
+
set_config: ActorMethod<[Config], undefined>;
|
|
177
|
+
set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
|
|
178
|
+
set_custom_domain: ActorMethod<[string, [] | [string]], undefined>;
|
|
179
|
+
set_doc: ActorMethod<[string, string, SetDoc], Doc>;
|
|
180
|
+
set_rule: ActorMethod<[RulesType, string, SetRule], undefined>;
|
|
181
|
+
upload_asset_chunk: ActorMethod<[Chunk], UploadChunk>;
|
|
182
|
+
version: ActorMethod<[], string>;
|
|
183
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
export const idlFactory = ({IDL}) => {
|
|
3
|
+
const CommitBatch = IDL.Record({
|
|
4
|
+
batch_id: IDL.Nat,
|
|
5
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
6
|
+
chunk_ids: IDL.Vec(IDL.Nat)
|
|
7
|
+
});
|
|
8
|
+
const DeleteControllersArgs = IDL.Record({
|
|
9
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
10
|
+
});
|
|
11
|
+
const Controller = IDL.Record({
|
|
12
|
+
updated_at: IDL.Nat64,
|
|
13
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
14
|
+
created_at: IDL.Nat64,
|
|
15
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
16
|
+
});
|
|
17
|
+
const DelDoc = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
|
|
18
|
+
const StorageConfig = IDL.Record({
|
|
19
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))))
|
|
20
|
+
});
|
|
21
|
+
const Config = IDL.Record({storage: StorageConfig});
|
|
22
|
+
const Doc = IDL.Record({
|
|
23
|
+
updated_at: IDL.Nat64,
|
|
24
|
+
owner: IDL.Principal,
|
|
25
|
+
data: IDL.Vec(IDL.Nat8),
|
|
26
|
+
created_at: IDL.Nat64
|
|
27
|
+
});
|
|
28
|
+
const HttpRequest = IDL.Record({
|
|
29
|
+
url: IDL.Text,
|
|
30
|
+
method: IDL.Text,
|
|
31
|
+
body: IDL.Vec(IDL.Nat8),
|
|
32
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))
|
|
33
|
+
});
|
|
34
|
+
const StreamingCallbackToken = IDL.Record({
|
|
35
|
+
token: IDL.Opt(IDL.Text),
|
|
36
|
+
sha256: IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
37
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
38
|
+
index: IDL.Nat64,
|
|
39
|
+
encoding_type: IDL.Text,
|
|
40
|
+
full_path: IDL.Text
|
|
41
|
+
});
|
|
42
|
+
const StreamingStrategy = IDL.Variant({
|
|
43
|
+
Callback: IDL.Record({
|
|
44
|
+
token: StreamingCallbackToken,
|
|
45
|
+
callback: IDL.Func([], [], [])
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
const HttpResponse = IDL.Record({
|
|
49
|
+
body: IDL.Vec(IDL.Nat8),
|
|
50
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
51
|
+
streaming_strategy: IDL.Opt(StreamingStrategy),
|
|
52
|
+
status_code: IDL.Nat16
|
|
53
|
+
});
|
|
54
|
+
const StreamingCallbackHttpResponse = IDL.Record({
|
|
55
|
+
token: IDL.Opt(StreamingCallbackToken),
|
|
56
|
+
body: IDL.Vec(IDL.Nat8)
|
|
57
|
+
});
|
|
58
|
+
const InitAssetKey = IDL.Record({
|
|
59
|
+
token: IDL.Opt(IDL.Text),
|
|
60
|
+
collection: IDL.Text,
|
|
61
|
+
name: IDL.Text,
|
|
62
|
+
encoding_type: IDL.Opt(IDL.Text),
|
|
63
|
+
full_path: IDL.Text
|
|
64
|
+
});
|
|
65
|
+
const InitUploadResult = IDL.Record({batch_id: IDL.Nat});
|
|
66
|
+
const ListOrderField = IDL.Variant({
|
|
67
|
+
UpdatedAt: IDL.Null,
|
|
68
|
+
Keys: IDL.Null,
|
|
69
|
+
CreatedAt: IDL.Null
|
|
70
|
+
});
|
|
71
|
+
const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});
|
|
72
|
+
const ListPaginate = IDL.Record({
|
|
73
|
+
start_after: IDL.Opt(IDL.Text),
|
|
74
|
+
limit: IDL.Opt(IDL.Nat64)
|
|
75
|
+
});
|
|
76
|
+
const ListParams = IDL.Record({
|
|
77
|
+
order: IDL.Opt(ListOrder),
|
|
78
|
+
owner: IDL.Opt(IDL.Principal),
|
|
79
|
+
matcher: IDL.Opt(IDL.Text),
|
|
80
|
+
paginate: IDL.Opt(ListPaginate)
|
|
81
|
+
});
|
|
82
|
+
const AssetKey = IDL.Record({
|
|
83
|
+
token: IDL.Opt(IDL.Text),
|
|
84
|
+
collection: IDL.Text,
|
|
85
|
+
owner: IDL.Principal,
|
|
86
|
+
name: IDL.Text,
|
|
87
|
+
full_path: IDL.Text
|
|
88
|
+
});
|
|
89
|
+
const AssetEncodingNoContent = IDL.Record({
|
|
90
|
+
modified: IDL.Nat64,
|
|
91
|
+
sha256: IDL.Vec(IDL.Nat8),
|
|
92
|
+
total_length: IDL.Nat
|
|
93
|
+
});
|
|
94
|
+
const AssetNoContent = IDL.Record({
|
|
95
|
+
key: AssetKey,
|
|
96
|
+
updated_at: IDL.Nat64,
|
|
97
|
+
encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
|
|
98
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
99
|
+
created_at: IDL.Nat64
|
|
100
|
+
});
|
|
101
|
+
const ListResults = IDL.Record({
|
|
102
|
+
matches_length: IDL.Nat64,
|
|
103
|
+
length: IDL.Nat64,
|
|
104
|
+
items: IDL.Vec(IDL.Tuple(IDL.Text, AssetNoContent))
|
|
105
|
+
});
|
|
106
|
+
const CustomDomain = IDL.Record({
|
|
107
|
+
updated_at: IDL.Nat64,
|
|
108
|
+
created_at: IDL.Nat64,
|
|
109
|
+
bn_id: IDL.Opt(IDL.Text)
|
|
110
|
+
});
|
|
111
|
+
const ListResults_1 = IDL.Record({
|
|
112
|
+
matches_length: IDL.Nat64,
|
|
113
|
+
length: IDL.Nat64,
|
|
114
|
+
items: IDL.Vec(IDL.Tuple(IDL.Text, Doc))
|
|
115
|
+
});
|
|
116
|
+
const RulesType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});
|
|
117
|
+
const Permission = IDL.Variant({
|
|
118
|
+
Controllers: IDL.Null,
|
|
119
|
+
Private: IDL.Null,
|
|
120
|
+
Public: IDL.Null,
|
|
121
|
+
Managed: IDL.Null
|
|
122
|
+
});
|
|
123
|
+
const Rule = IDL.Record({
|
|
124
|
+
updated_at: IDL.Nat64,
|
|
125
|
+
max_size: IDL.Opt(IDL.Nat),
|
|
126
|
+
read: Permission,
|
|
127
|
+
created_at: IDL.Nat64,
|
|
128
|
+
write: Permission
|
|
129
|
+
});
|
|
130
|
+
const SetController = IDL.Record({
|
|
131
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
132
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
133
|
+
});
|
|
134
|
+
const SetControllersArgs = IDL.Record({
|
|
135
|
+
controller: SetController,
|
|
136
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
137
|
+
});
|
|
138
|
+
const SetDoc = IDL.Record({
|
|
139
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
140
|
+
data: IDL.Vec(IDL.Nat8)
|
|
141
|
+
});
|
|
142
|
+
const SetRule = IDL.Record({
|
|
143
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
144
|
+
max_size: IDL.Opt(IDL.Nat),
|
|
145
|
+
read: Permission,
|
|
146
|
+
write: Permission
|
|
147
|
+
});
|
|
148
|
+
const Chunk = IDL.Record({
|
|
149
|
+
content: IDL.Vec(IDL.Nat8),
|
|
150
|
+
batch_id: IDL.Nat
|
|
151
|
+
});
|
|
152
|
+
const UploadChunk = IDL.Record({chunk_id: IDL.Nat});
|
|
153
|
+
return IDL.Service({
|
|
154
|
+
commit_asset_upload: IDL.Func([CommitBatch], [], []),
|
|
155
|
+
del_asset: IDL.Func([IDL.Text, IDL.Text], [], []),
|
|
156
|
+
del_assets: IDL.Func([IDL.Opt(IDL.Text)], [], []),
|
|
157
|
+
del_controllers: IDL.Func(
|
|
158
|
+
[DeleteControllersArgs],
|
|
159
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, Controller))],
|
|
160
|
+
[]
|
|
161
|
+
),
|
|
162
|
+
del_custom_domain: IDL.Func([IDL.Text], [], []),
|
|
163
|
+
del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []),
|
|
164
|
+
get_config: IDL.Func([], [Config], []),
|
|
165
|
+
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
166
|
+
http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
|
|
167
|
+
http_request_streaming_callback: IDL.Func(
|
|
168
|
+
[StreamingCallbackToken],
|
|
169
|
+
[StreamingCallbackHttpResponse],
|
|
170
|
+
['query']
|
|
171
|
+
),
|
|
172
|
+
init_asset_upload: IDL.Func([InitAssetKey], [InitUploadResult], []),
|
|
173
|
+
list_assets: IDL.Func([IDL.Opt(IDL.Text), ListParams], [ListResults], ['query']),
|
|
174
|
+
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
175
|
+
list_custom_domains: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Text, CustomDomain))], ['query']),
|
|
176
|
+
list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
|
|
177
|
+
list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
|
|
178
|
+
set_config: IDL.Func([Config], [], []),
|
|
179
|
+
set_controllers: IDL.Func(
|
|
180
|
+
[SetControllersArgs],
|
|
181
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, Controller))],
|
|
182
|
+
[]
|
|
183
|
+
),
|
|
184
|
+
set_custom_domain: IDL.Func([IDL.Text, IDL.Opt(IDL.Text)], [], []),
|
|
185
|
+
set_doc: IDL.Func([IDL.Text, IDL.Text, SetDoc], [Doc], []),
|
|
186
|
+
set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []),
|
|
187
|
+
upload_asset_chunk: IDL.Func([Chunk], [UploadChunk], []),
|
|
188
|
+
version: IDL.Func([], [IDL.Text], ['query'])
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
export const init = ({IDL}) => {
|
|
193
|
+
return [];
|
|
194
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export const idlFactory = ({IDL}) => {
|
|
2
|
+
const CommitBatch = IDL.Record({
|
|
3
|
+
batch_id: IDL.Nat,
|
|
4
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
5
|
+
chunk_ids: IDL.Vec(IDL.Nat)
|
|
6
|
+
});
|
|
7
|
+
const DeleteControllersArgs = IDL.Record({
|
|
8
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
9
|
+
});
|
|
10
|
+
const Controller = IDL.Record({
|
|
11
|
+
updated_at: IDL.Nat64,
|
|
12
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
13
|
+
created_at: IDL.Nat64,
|
|
14
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
15
|
+
});
|
|
16
|
+
const DelDoc = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
|
|
17
|
+
const StorageConfig = IDL.Record({
|
|
18
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))))
|
|
19
|
+
});
|
|
20
|
+
const Config = IDL.Record({storage: StorageConfig});
|
|
21
|
+
const Doc = IDL.Record({
|
|
22
|
+
updated_at: IDL.Nat64,
|
|
23
|
+
owner: IDL.Principal,
|
|
24
|
+
data: IDL.Vec(IDL.Nat8),
|
|
25
|
+
created_at: IDL.Nat64
|
|
26
|
+
});
|
|
27
|
+
const HttpRequest = IDL.Record({
|
|
28
|
+
url: IDL.Text,
|
|
29
|
+
method: IDL.Text,
|
|
30
|
+
body: IDL.Vec(IDL.Nat8),
|
|
31
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))
|
|
32
|
+
});
|
|
33
|
+
const StreamingCallbackToken = IDL.Record({
|
|
34
|
+
token: IDL.Opt(IDL.Text),
|
|
35
|
+
sha256: IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
36
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
37
|
+
index: IDL.Nat64,
|
|
38
|
+
encoding_type: IDL.Text,
|
|
39
|
+
full_path: IDL.Text
|
|
40
|
+
});
|
|
41
|
+
const StreamingStrategy = IDL.Variant({
|
|
42
|
+
Callback: IDL.Record({
|
|
43
|
+
token: StreamingCallbackToken,
|
|
44
|
+
callback: IDL.Func([], [], [])
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
const HttpResponse = IDL.Record({
|
|
48
|
+
body: IDL.Vec(IDL.Nat8),
|
|
49
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
50
|
+
streaming_strategy: IDL.Opt(StreamingStrategy),
|
|
51
|
+
status_code: IDL.Nat16
|
|
52
|
+
});
|
|
53
|
+
const StreamingCallbackHttpResponse = IDL.Record({
|
|
54
|
+
token: IDL.Opt(StreamingCallbackToken),
|
|
55
|
+
body: IDL.Vec(IDL.Nat8)
|
|
56
|
+
});
|
|
57
|
+
const InitAssetKey = IDL.Record({
|
|
58
|
+
token: IDL.Opt(IDL.Text),
|
|
59
|
+
collection: IDL.Text,
|
|
60
|
+
name: IDL.Text,
|
|
61
|
+
encoding_type: IDL.Opt(IDL.Text),
|
|
62
|
+
full_path: IDL.Text
|
|
63
|
+
});
|
|
64
|
+
const InitUploadResult = IDL.Record({batch_id: IDL.Nat});
|
|
65
|
+
const ListOrderField = IDL.Variant({
|
|
66
|
+
UpdatedAt: IDL.Null,
|
|
67
|
+
Keys: IDL.Null,
|
|
68
|
+
CreatedAt: IDL.Null
|
|
69
|
+
});
|
|
70
|
+
const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});
|
|
71
|
+
const ListPaginate = IDL.Record({
|
|
72
|
+
start_after: IDL.Opt(IDL.Text),
|
|
73
|
+
limit: IDL.Opt(IDL.Nat64)
|
|
74
|
+
});
|
|
75
|
+
const ListParams = IDL.Record({
|
|
76
|
+
order: IDL.Opt(ListOrder),
|
|
77
|
+
owner: IDL.Opt(IDL.Principal),
|
|
78
|
+
matcher: IDL.Opt(IDL.Text),
|
|
79
|
+
paginate: IDL.Opt(ListPaginate)
|
|
80
|
+
});
|
|
81
|
+
const AssetKey = IDL.Record({
|
|
82
|
+
token: IDL.Opt(IDL.Text),
|
|
83
|
+
collection: IDL.Text,
|
|
84
|
+
owner: IDL.Principal,
|
|
85
|
+
name: IDL.Text,
|
|
86
|
+
full_path: IDL.Text
|
|
87
|
+
});
|
|
88
|
+
const AssetEncodingNoContent = IDL.Record({
|
|
89
|
+
modified: IDL.Nat64,
|
|
90
|
+
sha256: IDL.Vec(IDL.Nat8),
|
|
91
|
+
total_length: IDL.Nat
|
|
92
|
+
});
|
|
93
|
+
const AssetNoContent = IDL.Record({
|
|
94
|
+
key: AssetKey,
|
|
95
|
+
updated_at: IDL.Nat64,
|
|
96
|
+
encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
|
|
97
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
98
|
+
created_at: IDL.Nat64
|
|
99
|
+
});
|
|
100
|
+
const ListResults = IDL.Record({
|
|
101
|
+
matches_length: IDL.Nat64,
|
|
102
|
+
length: IDL.Nat64,
|
|
103
|
+
items: IDL.Vec(IDL.Tuple(IDL.Text, AssetNoContent))
|
|
104
|
+
});
|
|
105
|
+
const CustomDomain = IDL.Record({
|
|
106
|
+
updated_at: IDL.Nat64,
|
|
107
|
+
created_at: IDL.Nat64,
|
|
108
|
+
bn_id: IDL.Opt(IDL.Text)
|
|
109
|
+
});
|
|
110
|
+
const ListResults_1 = IDL.Record({
|
|
111
|
+
matches_length: IDL.Nat64,
|
|
112
|
+
length: IDL.Nat64,
|
|
113
|
+
items: IDL.Vec(IDL.Tuple(IDL.Text, Doc))
|
|
114
|
+
});
|
|
115
|
+
const RulesType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});
|
|
116
|
+
const Permission = IDL.Variant({
|
|
117
|
+
Controllers: IDL.Null,
|
|
118
|
+
Private: IDL.Null,
|
|
119
|
+
Public: IDL.Null,
|
|
120
|
+
Managed: IDL.Null
|
|
121
|
+
});
|
|
122
|
+
const Rule = IDL.Record({
|
|
123
|
+
updated_at: IDL.Nat64,
|
|
124
|
+
max_size: IDL.Opt(IDL.Nat),
|
|
125
|
+
read: Permission,
|
|
126
|
+
created_at: IDL.Nat64,
|
|
127
|
+
write: Permission
|
|
128
|
+
});
|
|
129
|
+
const SetController = IDL.Record({
|
|
130
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
131
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
132
|
+
});
|
|
133
|
+
const SetControllersArgs = IDL.Record({
|
|
134
|
+
controller: SetController,
|
|
135
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
136
|
+
});
|
|
137
|
+
const SetDoc = IDL.Record({
|
|
138
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
139
|
+
data: IDL.Vec(IDL.Nat8)
|
|
140
|
+
});
|
|
141
|
+
const SetRule = IDL.Record({
|
|
142
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
143
|
+
max_size: IDL.Opt(IDL.Nat),
|
|
144
|
+
read: Permission,
|
|
145
|
+
write: Permission
|
|
146
|
+
});
|
|
147
|
+
const Chunk = IDL.Record({
|
|
148
|
+
content: IDL.Vec(IDL.Nat8),
|
|
149
|
+
batch_id: IDL.Nat
|
|
150
|
+
});
|
|
151
|
+
const UploadChunk = IDL.Record({chunk_id: IDL.Nat});
|
|
152
|
+
return IDL.Service({
|
|
153
|
+
commit_asset_upload: IDL.Func([CommitBatch], [], []),
|
|
154
|
+
del_asset: IDL.Func([IDL.Text, IDL.Text], [], []),
|
|
155
|
+
del_assets: IDL.Func([IDL.Opt(IDL.Text)], [], []),
|
|
156
|
+
del_controllers: IDL.Func(
|
|
157
|
+
[DeleteControllersArgs],
|
|
158
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, Controller))],
|
|
159
|
+
[]
|
|
160
|
+
),
|
|
161
|
+
del_custom_domain: IDL.Func([IDL.Text], [], []),
|
|
162
|
+
del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []),
|
|
163
|
+
get_config: IDL.Func([], [Config], []),
|
|
164
|
+
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
165
|
+
http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
|
|
166
|
+
http_request_streaming_callback: IDL.Func(
|
|
167
|
+
[StreamingCallbackToken],
|
|
168
|
+
[StreamingCallbackHttpResponse],
|
|
169
|
+
['query']
|
|
170
|
+
),
|
|
171
|
+
init_asset_upload: IDL.Func([InitAssetKey], [InitUploadResult], []),
|
|
172
|
+
list_assets: IDL.Func([IDL.Opt(IDL.Text), ListParams], [ListResults], ['query']),
|
|
173
|
+
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
174
|
+
list_custom_domains: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Text, CustomDomain))], ['query']),
|
|
175
|
+
list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
|
|
176
|
+
list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
|
|
177
|
+
set_config: IDL.Func([Config], [], []),
|
|
178
|
+
set_controllers: IDL.Func(
|
|
179
|
+
[SetControllersArgs],
|
|
180
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, Controller))],
|
|
181
|
+
[]
|
|
182
|
+
),
|
|
183
|
+
set_custom_domain: IDL.Func([IDL.Text, IDL.Opt(IDL.Text)], [], []),
|
|
184
|
+
set_doc: IDL.Func([IDL.Text, IDL.Text, SetDoc], [Doc], []),
|
|
185
|
+
set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []),
|
|
186
|
+
upload_asset_chunk: IDL.Func([Chunk], [UploadChunk], []),
|
|
187
|
+
version: IDL.Func([], [IDL.Text], ['query'])
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
export const init = ({IDL}) => {
|
|
191
|
+
return [];
|
|
192
|
+
};
|
package/dist/browser/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import{a as Bn,b as co,c as nr,d as Nn,e as me,f as uo,g as ir,h as lo,i as ot,j
|
|
|
2
2
|
ic-request`),Xt=class{getPrincipal(){return this._principal||(this._principal=ot.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(t){let{body:r}=t,i=Io(t,["body"]),a=await ie(r);return Object.assign(Object.assign({},i),{body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(Cn(Wo,a))}})}},Zt=class{getPrincipal(){return ot.anonymous()}async transformRequest(t){return Object.assign(Object.assign({},t),{body:{content:t.body}})}};var oi=me(kn());var hr;(function(e){e.Call="call"})(hr||(hr={}));function Ke(){let e=new ArrayBuffer(16),t=new DataView(e),r=BigInt(+Date.now()),i=Math.floor(Math.random()*4294967295),a=Math.floor(Math.random()*4294967295);if(typeof t.setBigUint64=="function")t.setBigUint64(0,r);else{let u=BigInt(1)<<BigInt(32);t.setUint32(0,Number(r>>BigInt(32))),t.setUint32(4,Number(r%u))}return t.setUint32(8,i),t.setUint32(12,a),e}var zo=BigInt(1e6),Go=BigInt(60*1e3),se=class{constructor(t){this._value=(BigInt(Date.now())+BigInt(t)-Go)*zo}toCBOR(){return oi.value.u64(this._value.toString(16),16)}toHash(){return Pn(this._value)}};function ai(e=Ke){return async t=>{let r=e(),i=t.request.headers?new Headers(t.request.headers):new Headers;t.request.headers=i,t.endpoint==="call"&&(t.body.nonce=e())}}var Kt;(function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"})(Kt||(Kt={}));var pr=5*60*1e3,Xo="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",Zo="ic0.app",Qo=".ic0.app",Do="icp0.io",Lo=".icp0.io",ta="icp-api.io",ea=".icp-api.io",Me=class extends ke{constructor(t){super(t),this.message=t}},Ee=class extends ke{constructor(t){super(t),this.message=t}};function ra(){let e;if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw new Me("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present.");else if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw new Me("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available.");else typeof self<"u"&&self.fetch&&(e=self.fetch.bind(self));if(e)return e;throw new Me("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}var fe=class{constructor(t={}){if(this.rootKey=Fn(Xo),this._pipeline=[],this._timeDiffMsecs=0,this._rootKeyFetched=!1,this._retryTimes=3,this._isAgent=!0,t.source){if(!(t.source instanceof fe))throw new Error("An Agent's source can only be another HttpAgent");this._pipeline=[...t.source._pipeline],this._identity=t.source._identity,this._fetch=t.source._fetch,this._host=t.source._host,this._credentials=t.source._credentials}else this._fetch=t.fetch||ra()||fetch.bind(window),this._fetchOptions=t.fetchOptions,this._callOptions=t.callOptions;if(t.host!==void 0)!t.host.match(/^[a-z]+:/)&&typeof window<"u"?this._host=new URL(window.location.protocol+"//"+t.host):this._host=new URL(t.host);else if(t.source!==void 0)this._host=t.source._host;else{let r=typeof window<"u"?window.location:void 0;if(!r)throw new Error("Must specify a host to connect to.");this._host=new URL(r+"")}if(t.retryTimes!==void 0&&(this._retryTimes=t.retryTimes),this._host.hostname.endsWith(Qo)?this._host.hostname=Zo:this._host.hostname.endsWith(Lo)?this._host.hostname=Do:this._host.hostname.endsWith(ea)&&(this._host.hostname=ta),t.credentials){let{name:r,password:i}=t.credentials;this._credentials=`${r}${i?":"+i:""}`}this._identity=Promise.resolve(t.identity||new Zt),t.disableNonce||this.addTransform(ai(Ke))}isLocal(){let t=this._host.hostname;return t==="127.0.0.1"||t.endsWith("localhost")}addTransform(t,r=t.priority||0){let i=this._pipeline.findIndex(a=>(a.priority||0)<r);this._pipeline.splice(i>=0?i:this._pipeline.length,0,Object.assign(t,{priority:r}))}async getPrincipal(){if(!this._identity)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");return(await this._identity).getPrincipal()}async call(t,r,i){let a=await(i!==void 0?await i:await this._identity);if(!a)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let u=ot.from(t),d=r.effectiveCanisterId?ot.from(r.effectiveCanisterId):u,m=a.getPrincipal()||ot.anonymous(),w=new se(pr);Math.abs(this._timeDiffMsecs)>1e3*30&&(w=new se(pr+this._timeDiffMsecs));let A={request_type:hr.Call,canister_id:u,method_name:r.methodName,arg:r.arg,sender:m,ingress_expiry:w},C=await this._transform({request:{body:null,method:"POST",headers:new Headers(Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{}))},endpoint:"call",body:A});C=await a.transformRequest(C);let O=or(C.body),Q=this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${d.toText()}/call`,this._host),Object.assign(Object.assign(Object.assign({},this._callOptions),C.request),{body:O}))),[st,it]=await Promise.all([Q,ie(A)]);return{requestId:it,response:{ok:st.ok,status:st.status,statusText:st.statusText}}}async _requestAndRetry(t,r=0){if(r>this._retryTimes&&this._retryTimes!==0)throw new Error(`AgentError: Exceeded configured limit of ${this._retryTimes} retry attempts. Please check your network connection or try again in a few moments`);let i=await t();if(!i.ok){let a=await i.clone().text(),u=`Server returned an error:
|
|
3
3
|
Code: ${i.status} (${i.statusText})
|
|
4
4
|
Body: ${a}
|
|
5
|
-
`;if(this._retryTimes>r)return console.warn(u+" Retrying request."),await this._requestAndRetry(t,r+1);throw new Error(u)}return i}async query(t,r,i){let a=await(i!==void 0?await i:await this._identity);if(!a)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let u=typeof t=="string"?ot.fromText(t):t,d=a?.getPrincipal()||ot.anonymous(),m={request_type:"query",canister_id:u,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:new se(pr)},w=await this._transform({request:{method:"POST",headers:new Headers(Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{}))},endpoint:"read",body:m});w=await a?.transformRequest(w);let A=or(w.body),C=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${u.toText()}/query`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),w.request),{body:A})));return ar(await C.arrayBuffer())}async createReadStateRequest(t,r){let i=await(r!==void 0?await r:await this._identity);if(!i)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let a=i?.getPrincipal()||ot.anonymous(),u=await this._transform({request:{method:"POST",headers:new Headers(Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{}))},endpoint:"read_state",body:{request_type:"read_state",paths:t.paths,sender:a,ingress_expiry:new se(pr)}});return i?.transformRequest(u)}async readState(t,r,i,a){let u=typeof t=="string"?ot.fromText(t):t,d=a??await this.createReadStateRequest(r,i),m=or(d.body),w=await this._fetch(""+new URL(`/api/v2/canister/${u}/read_state`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),d.request),{body:m}));if(!w.ok)throw new Error(`Server returned an error:
|
|
5
|
+
`;if(this._retryTimes>r)return console.warn(u+" Retrying request."),await this._requestAndRetry(t,r+1);throw new Error(u)}return i}async query(t,r,i){let a=await(i!==void 0?await i:await this._identity);if(!a)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let u=typeof t=="string"?ot.fromText(t):t,d=a?.getPrincipal()||ot.anonymous(),m={request_type:"query",canister_id:u,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:new se(pr)},w=await this._transform({request:{method:"POST",headers:new Headers(Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{}))},endpoint:"read",body:m});w=await a?.transformRequest(w);let A=or(w.body),C=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${u.toText()}/query`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),w.request),{body:A})));return ar(await C.arrayBuffer())}async createReadStateRequest(t,r){let i=await(r!==void 0?await r:await this._identity);if(!i)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let a=i?.getPrincipal()||ot.anonymous(),u=await this._transform({request:{method:"POST",headers:new Headers(Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{}))},endpoint:"read_state",body:{request_type:"read_state",paths:t.paths,sender:a,ingress_expiry:new se(pr)}});return i?.transformRequest(u)}async readState(t,r,i,a){let u=typeof t=="string"?ot.fromText(t):t,d=a??await this.createReadStateRequest(r,i),m=or(d.body),w=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${u}/read_state`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),d.request),{body:m})));if(!w.ok)throw new Error(`Server returned an error:
|
|
6
6
|
Code: ${w.status} (${w.statusText})
|
|
7
7
|
Body: ${await w.text()}
|
|
8
8
|
`);return ar(await w.arrayBuffer())}async syncTime(t){let r=await import("./canisterStatus-CMO3J52U.js"),i=Date.now();try{t||console.log("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let u=(await r.request({canisterId:t??ot.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:this,paths:["time"]})).get("time");u&&(this._timeDiffMsecs=Number(u)-Number(i))}catch(a){console.error("Caught exception while attempting to sync time:",a)}}async status(){let t=this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{},r=await this._requestAndRetry(()=>this._fetch(""+new URL("/api/v2/status",this._host),Object.assign({headers:t},this._fetchOptions)));return ar(await r.arrayBuffer())}async fetchRootKey(){return this._rootKeyFetched||(this.rootKey=(await this.status()).root_key,this._rootKeyFetched=!0),this.rootKey}invalidateIdentity(){this._identity=null}replaceIdentity(t){this._identity=Promise.resolve(t)}_transform(t){let r=Promise.resolve(t);for(let i of this._pipeline)r=r.then(a=>i(a).then(u=>u||a));return r}};var si;(function(e){e.Error="err",e.GetPrincipal="gp",e.GetPrincipalResponse="gpr",e.Query="q",e.QueryResponse="qr",e.Call="c",e.CallResponse="cr",e.ReadState="rs",e.ReadStateResponse="rsr",e.Status="s",e.StatusResponse="sr"})(si||(si={}));function Jr(){let e=typeof window>"u"&&typeof window>"u"?typeof self>"u"?void 0:self.ic.agent:window.ic.agent;if(!e)throw new Error("No Agent could be found.");return e}var xr={};Nn(xr,{backoff:()=>di,chain:()=>hi,conditionalDelay:()=>ui,defaultStrategy:()=>fi,maxAttempts:()=>ia,once:()=>ci,throttle:()=>oa,timeout:()=>li});var na=5*60*1e3;function fi(){return hi(ui(ci(),1e3),di(1e3,1.2),li(na))}function ci(){let e=!0;return async()=>e?(e=!1,!0):!1}function ui(e,t){return async(r,i,a)=>{if(await e(r,i,a))return new Promise(u=>setTimeout(u,t))}}function ia(e){let t=e;return async(r,i,a)=>{if(--t<=0)throw new Error(`Failed to retrieve a reply for request after ${e} attempts:
|