@junobuild/analytics 0.0.1
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/LICENSE +21 -0
- package/README.md +17 -0
- package/declarations/cmc/cmc.did +122 -0
- package/declarations/cmc/cmc.did.d.ts +48 -0
- package/declarations/cmc/cmc.factory.did.js +67 -0
- package/declarations/cmc/index.d.ts +45 -0
- package/declarations/cmc/index.js +37 -0
- package/declarations/console/console.did.d.ts +71 -0
- package/declarations/console/console.factory.did.js +79 -0
- package/declarations/console/console.factory.did.mjs +79 -0
- package/declarations/console/index.d.ts +45 -0
- package/declarations/console/index.js +37 -0
- package/declarations/ic/ic.did +195 -0
- package/declarations/ic/ic.did.d.ts +208 -0
- package/declarations/ic/ic.factory.did.js +274 -0
- package/declarations/mission_control/index.d.ts +45 -0
- package/declarations/mission_control/index.js +38 -0
- package/declarations/mission_control/mission_control.did.d.ts +101 -0
- package/declarations/mission_control/mission_control.factory.did.js +136 -0
- package/declarations/observatory/index.d.ts +45 -0
- package/declarations/observatory/index.js +38 -0
- package/declarations/observatory/observatory.did.d.ts +86 -0
- package/declarations/observatory/observatory.factory.did.js +95 -0
- package/declarations/observatory/observatory.factory.did.mjs +95 -0
- package/declarations/orbiter/index.d.ts +45 -0
- package/declarations/orbiter/index.js +37 -0
- package/declarations/orbiter/orbiter.did.d.ts +103 -0
- package/declarations/orbiter/orbiter.factory.did.js +124 -0
- package/declarations/satellite/index.d.ts +45 -0
- package/declarations/satellite/index.js +37 -0
- package/declarations/satellite/satellite.did.d.ts +201 -0
- package/declarations/satellite/satellite.factory.did.js +215 -0
- package/declarations/satellite/satellite.factory.did.mjs +215 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/declarations/cmc/cmc.did +122 -0
- package/dist/declarations/cmc/cmc.did.d.ts +48 -0
- package/dist/declarations/cmc/cmc.factory.did.js +67 -0
- package/dist/declarations/cmc/index.d.ts +45 -0
- package/dist/declarations/cmc/index.js +37 -0
- package/dist/declarations/console/console.did.d.ts +71 -0
- package/dist/declarations/console/console.factory.did.js +79 -0
- package/dist/declarations/console/console.factory.did.mjs +79 -0
- package/dist/declarations/console/index.d.ts +45 -0
- package/dist/declarations/console/index.js +37 -0
- package/dist/declarations/ic/ic.did +195 -0
- package/dist/declarations/ic/ic.did.d.ts +208 -0
- package/dist/declarations/ic/ic.factory.did.js +274 -0
- package/dist/declarations/mission_control/index.d.ts +45 -0
- package/dist/declarations/mission_control/index.js +38 -0
- package/dist/declarations/mission_control/mission_control.did.d.ts +101 -0
- package/dist/declarations/mission_control/mission_control.factory.did.js +136 -0
- package/dist/declarations/observatory/index.d.ts +45 -0
- package/dist/declarations/observatory/index.js +38 -0
- package/dist/declarations/observatory/observatory.did.d.ts +86 -0
- package/dist/declarations/observatory/observatory.factory.did.js +95 -0
- package/dist/declarations/observatory/observatory.factory.did.mjs +95 -0
- package/dist/declarations/orbiter/index.d.ts +45 -0
- package/dist/declarations/orbiter/index.js +37 -0
- package/dist/declarations/orbiter/orbiter.did.d.ts +103 -0
- package/dist/declarations/orbiter/orbiter.factory.did.js +124 -0
- package/dist/declarations/satellite/index.d.ts +45 -0
- package/dist/declarations/satellite/index.js +37 -0
- package/dist/declarations/satellite/satellite.did.d.ts +201 -0
- package/dist/declarations/satellite/satellite.factory.did.js +215 -0
- package/dist/declarations/satellite/satellite.factory.did.mjs +215 -0
- package/dist/index.js +1 -0
- package/dist/node/index.mjs +4 -0
- package/dist/node/index.mjs.map +7 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/services/analytics.services.d.ts +10 -0
- package/dist/types/services/proxy.services.d.ts +4 -0
- package/dist/types/types/env.d.ts +15 -0
- package/dist/types/types/post-message.d.ts +11 -0
- package/dist/types/types/proxy.d.ts +11 -0
- package/dist/types/types/track.d.ts +4 -0
- package/dist/types/utils/date.utils.d.ts +1 -0
- package/dist/types/utils/json.utils.d.ts +8 -0
- package/dist/types/workers/analytics.worker.d.ts +1 -0
- package/dist/workers/analytics.worker.js +6 -0
- package/dist/workers/analytics.worker.js.map +7 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 David Dal Busco
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[![npm][npm-badge]][npm-badge-url]
|
|
2
|
+
[![license][npm-license]][npm-license-url]
|
|
3
|
+
|
|
4
|
+
[npm-badge]: https://img.shields.io/npm/v/@junobuild/analytics
|
|
5
|
+
[npm-badge-url]: https://www.npmjs.com/package/@junobuild/analytics
|
|
6
|
+
[npm-license]: https://img.shields.io/npm/l/@junobuild/analytics
|
|
7
|
+
[npm-license-url]: https://github.com/buildwithjuno/juno-js/blob/main/LICENSE
|
|
8
|
+
|
|
9
|
+
# Juno JavaScript analytics
|
|
10
|
+
|
|
11
|
+
A tracker for [Juno] analytics.
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT © [David Dal Busco](mailto:david.dalbusco@outlook.com)
|
|
16
|
+
|
|
17
|
+
[juno]: https://juno.build
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
type Cycles = nat;
|
|
2
|
+
type BlockIndex = nat64;
|
|
3
|
+
|
|
4
|
+
// The argument of the [notify_top_up] method.
|
|
5
|
+
type NotifyTopUpArg = record {
|
|
6
|
+
// Index of the block on the ICP ledger that contains the payment.
|
|
7
|
+
block_index : BlockIndex;
|
|
8
|
+
|
|
9
|
+
// The canister to top up.
|
|
10
|
+
canister_id : principal;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// The argument of the [notify_create_canister] method.
|
|
14
|
+
type NotifyCreateCanisterArg = record {
|
|
15
|
+
// Index of the block on the ICP ledger that contains the payment.
|
|
16
|
+
block_index : BlockIndex;
|
|
17
|
+
|
|
18
|
+
// The controller of canister to create.
|
|
19
|
+
controller : principal;
|
|
20
|
+
|
|
21
|
+
// An optional subnet type that, if set, determines what type of subnet
|
|
22
|
+
// the new canister will be created on.
|
|
23
|
+
subnet_type: opt text;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type NotifyError = variant {
|
|
27
|
+
// The payment processing failed and the payment was returned the caller.
|
|
28
|
+
// This is a non-retriable error.
|
|
29
|
+
Refunded : record {
|
|
30
|
+
// The reason for the refund.
|
|
31
|
+
reason : text;
|
|
32
|
+
// The index of the block containing the refund.
|
|
33
|
+
block_index : opt BlockIndex;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// The same payment is already being processed by a concurrent request.
|
|
37
|
+
// This is a retriable error.
|
|
38
|
+
Processing;
|
|
39
|
+
|
|
40
|
+
// The payment was too old to be processed.
|
|
41
|
+
// The value of the variant is the oldest block index that can still be processed.
|
|
42
|
+
// This a non-retriable error.
|
|
43
|
+
TransactionTooOld : BlockIndex;
|
|
44
|
+
|
|
45
|
+
// The transaction does not satisfy the cycle minting canister payment protocol.
|
|
46
|
+
// The text contains the description of the problem.
|
|
47
|
+
// This is a non-retriable error.
|
|
48
|
+
InvalidTransaction : text;
|
|
49
|
+
|
|
50
|
+
// Other error.
|
|
51
|
+
Other : record { error_code : nat64; error_message : text };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type NotifyTopUpResult = variant {
|
|
55
|
+
// The amount of cycles sent to the specified canister.
|
|
56
|
+
Ok : Cycles;
|
|
57
|
+
Err : NotifyError;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type NotifyCreateCanisterResult = variant {
|
|
61
|
+
// The principal of the newly created canister.
|
|
62
|
+
Ok : principal;
|
|
63
|
+
Err : NotifyError;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type IcpXdrConversionRate = record {
|
|
67
|
+
// The time for which the market data was queried, expressed in UNIX epoch
|
|
68
|
+
// time in seconds.
|
|
69
|
+
timestamp_seconds : nat64;
|
|
70
|
+
|
|
71
|
+
// The number of 10,000ths of IMF SDR (currency code XDR) that corresponds
|
|
72
|
+
// to 1 ICP. This value reflects the current market price of one ICP token.
|
|
73
|
+
xdr_permyriad_per_icp : nat64;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
type IcpXdrConversionRateResponse = record {
|
|
78
|
+
// The latest ICP/XDR conversion rate.
|
|
79
|
+
data : IcpXdrConversionRate;
|
|
80
|
+
|
|
81
|
+
// CBOR-serialized hash tree as specified in
|
|
82
|
+
// https://smartcontracts.org/docs/interface-spec/index.html#certification-encoding.
|
|
83
|
+
// The hash tree is used for certification and hash the following structure:
|
|
84
|
+
// ```
|
|
85
|
+
// *
|
|
86
|
+
// |
|
|
87
|
+
// +-- ICP_XDR_CONVERSION_RATE -- [ Candid encoded IcpXdrConversionRate ]
|
|
88
|
+
// |
|
|
89
|
+
// `-- AVERAGE_ICP_XDR_CONVERSION_RATE -- [ Candid encoded IcpXdrConversionRate ]
|
|
90
|
+
// ```
|
|
91
|
+
hash_tree : blob;
|
|
92
|
+
|
|
93
|
+
// System certificate as specified in
|
|
94
|
+
// https://smartcontracts.org/docs/interface-spec/index.html#certification-encoding
|
|
95
|
+
certificate : blob;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
type SubnetTypesToSubnetsResponse = record {
|
|
99
|
+
data: vec record { text; vec principal };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type CyclesCanisterInitPayload = record {
|
|
103
|
+
governance_canister_id : principal;
|
|
104
|
+
minting_account_id : opt text;
|
|
105
|
+
ledger_canister_id : principal;
|
|
106
|
+
last_purged_notification: opt BlockIndex;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
service: (CyclesCanisterInitPayload) -> {
|
|
110
|
+
// Propmts the cycles minting canister to process a payment by converting ICP
|
|
111
|
+
// into cycles and sending the cycles the specified canister.
|
|
112
|
+
notify_top_up : (NotifyTopUpArg) -> (NotifyTopUpResult);
|
|
113
|
+
|
|
114
|
+
// Prompts the cycles minting canister to process a payment for canister creation.
|
|
115
|
+
notify_create_canister : (NotifyCreateCanisterArg) -> (NotifyCreateCanisterResult);
|
|
116
|
+
|
|
117
|
+
// Returns the ICP/XDR conversion rate.
|
|
118
|
+
get_icp_xdr_conversion_rate : () -> (IcpXdrConversionRateResponse) query;
|
|
119
|
+
|
|
120
|
+
// Returns the current mapping of subnet types to subnets.
|
|
121
|
+
get_subnet_types_to_subnets : () -> (SubnetTypesToSubnetsResponse) query;
|
|
122
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type {ActorMethod} from '@dfinity/agent';
|
|
2
|
+
import type {Principal} from '@dfinity/principal';
|
|
3
|
+
|
|
4
|
+
export type BlockIndex = bigint;
|
|
5
|
+
export type Cycles = bigint;
|
|
6
|
+
export interface CyclesCanisterInitPayload {
|
|
7
|
+
last_purged_notification: [] | [BlockIndex];
|
|
8
|
+
governance_canister_id: Principal;
|
|
9
|
+
minting_account_id: [] | [string];
|
|
10
|
+
ledger_canister_id: Principal;
|
|
11
|
+
}
|
|
12
|
+
export interface IcpXdrConversionRate {
|
|
13
|
+
xdr_permyriad_per_icp: bigint;
|
|
14
|
+
timestamp_seconds: bigint;
|
|
15
|
+
}
|
|
16
|
+
export interface IcpXdrConversionRateResponse {
|
|
17
|
+
certificate: Uint8Array | number[];
|
|
18
|
+
data: IcpXdrConversionRate;
|
|
19
|
+
hash_tree: Uint8Array | number[];
|
|
20
|
+
}
|
|
21
|
+
export interface NotifyCreateCanisterArg {
|
|
22
|
+
controller: Principal;
|
|
23
|
+
block_index: BlockIndex;
|
|
24
|
+
subnet_type: [] | [string];
|
|
25
|
+
}
|
|
26
|
+
export type NotifyCreateCanisterResult = {Ok: Principal} | {Err: NotifyError};
|
|
27
|
+
export type NotifyError =
|
|
28
|
+
| {
|
|
29
|
+
Refunded: {block_index: [] | [BlockIndex]; reason: string};
|
|
30
|
+
}
|
|
31
|
+
| {InvalidTransaction: string}
|
|
32
|
+
| {Other: {error_message: string; error_code: bigint}}
|
|
33
|
+
| {Processing: null}
|
|
34
|
+
| {TransactionTooOld: BlockIndex};
|
|
35
|
+
export interface NotifyTopUpArg {
|
|
36
|
+
block_index: BlockIndex;
|
|
37
|
+
canister_id: Principal;
|
|
38
|
+
}
|
|
39
|
+
export type NotifyTopUpResult = {Ok: Cycles} | {Err: NotifyError};
|
|
40
|
+
export interface SubnetTypesToSubnetsResponse {
|
|
41
|
+
data: Array<[string, Array<Principal>]>;
|
|
42
|
+
}
|
|
43
|
+
export interface _SERVICE {
|
|
44
|
+
get_icp_xdr_conversion_rate: ActorMethod<[], IcpXdrConversionRateResponse>;
|
|
45
|
+
get_subnet_types_to_subnets: ActorMethod<[], SubnetTypesToSubnetsResponse>;
|
|
46
|
+
notify_create_canister: ActorMethod<[NotifyCreateCanisterArg], NotifyCreateCanisterResult>;
|
|
47
|
+
notify_top_up: ActorMethod<[NotifyTopUpArg], NotifyTopUpResult>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
export const idlFactory = ({IDL}) => {
|
|
3
|
+
const BlockIndex = IDL.Nat64;
|
|
4
|
+
const CyclesCanisterInitPayload = IDL.Record({
|
|
5
|
+
last_purged_notification: IDL.Opt(BlockIndex),
|
|
6
|
+
governance_canister_id: IDL.Principal,
|
|
7
|
+
minting_account_id: IDL.Opt(IDL.Text),
|
|
8
|
+
ledger_canister_id: IDL.Principal
|
|
9
|
+
});
|
|
10
|
+
const IcpXdrConversionRate = IDL.Record({
|
|
11
|
+
xdr_permyriad_per_icp: IDL.Nat64,
|
|
12
|
+
timestamp_seconds: IDL.Nat64
|
|
13
|
+
});
|
|
14
|
+
const IcpXdrConversionRateResponse = IDL.Record({
|
|
15
|
+
certificate: IDL.Vec(IDL.Nat8),
|
|
16
|
+
data: IcpXdrConversionRate,
|
|
17
|
+
hash_tree: IDL.Vec(IDL.Nat8)
|
|
18
|
+
});
|
|
19
|
+
const SubnetTypesToSubnetsResponse = IDL.Record({
|
|
20
|
+
data: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Principal)))
|
|
21
|
+
});
|
|
22
|
+
const NotifyCreateCanisterArg = IDL.Record({
|
|
23
|
+
controller: IDL.Principal,
|
|
24
|
+
block_index: BlockIndex,
|
|
25
|
+
subnet_type: IDL.Opt(IDL.Text)
|
|
26
|
+
});
|
|
27
|
+
const NotifyError = IDL.Variant({
|
|
28
|
+
Refunded: IDL.Record({
|
|
29
|
+
block_index: IDL.Opt(BlockIndex),
|
|
30
|
+
reason: IDL.Text
|
|
31
|
+
}),
|
|
32
|
+
InvalidTransaction: IDL.Text,
|
|
33
|
+
Other: IDL.Record({
|
|
34
|
+
error_message: IDL.Text,
|
|
35
|
+
error_code: IDL.Nat64
|
|
36
|
+
}),
|
|
37
|
+
Processing: IDL.Null,
|
|
38
|
+
TransactionTooOld: BlockIndex
|
|
39
|
+
});
|
|
40
|
+
const NotifyCreateCanisterResult = IDL.Variant({
|
|
41
|
+
Ok: IDL.Principal,
|
|
42
|
+
Err: NotifyError
|
|
43
|
+
});
|
|
44
|
+
const NotifyTopUpArg = IDL.Record({
|
|
45
|
+
block_index: BlockIndex,
|
|
46
|
+
canister_id: IDL.Principal
|
|
47
|
+
});
|
|
48
|
+
const Cycles = IDL.Nat;
|
|
49
|
+
const NotifyTopUpResult = IDL.Variant({Ok: Cycles, Err: NotifyError});
|
|
50
|
+
return IDL.Service({
|
|
51
|
+
get_icp_xdr_conversion_rate: IDL.Func([], [IcpXdrConversionRateResponse], ['query']),
|
|
52
|
+
get_subnet_types_to_subnets: IDL.Func([], [SubnetTypesToSubnetsResponse], ['query']),
|
|
53
|
+
notify_create_canister: IDL.Func([NotifyCreateCanisterArg], [NotifyCreateCanisterResult], []),
|
|
54
|
+
notify_top_up: IDL.Func([NotifyTopUpArg], [NotifyTopUpResult], [])
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
export const init = ({IDL}) => {
|
|
59
|
+
const BlockIndex = IDL.Nat64;
|
|
60
|
+
const CyclesCanisterInitPayload = IDL.Record({
|
|
61
|
+
last_purged_notification: IDL.Opt(BlockIndex),
|
|
62
|
+
governance_canister_id: IDL.Principal,
|
|
63
|
+
minting_account_id: IDL.Opt(IDL.Text),
|
|
64
|
+
ledger_canister_id: IDL.Principal
|
|
65
|
+
});
|
|
66
|
+
return [CyclesCanisterInitPayload];
|
|
67
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {ActorConfig, ActorSubclass, Agent, HttpAgentOptions} from '@dfinity/agent';
|
|
2
|
+
import type {IDL} from '@dfinity/candid';
|
|
3
|
+
import type {Principal} from '@dfinity/principal';
|
|
4
|
+
|
|
5
|
+
import {_SERVICE} from './cmc.did';
|
|
6
|
+
|
|
7
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
8
|
+
export declare const canisterId: string;
|
|
9
|
+
|
|
10
|
+
export declare interface CreateActorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link Agent}
|
|
13
|
+
*/
|
|
14
|
+
agent?: Agent;
|
|
15
|
+
/**
|
|
16
|
+
* @see {@link HttpAgentOptions}
|
|
17
|
+
*/
|
|
18
|
+
agentOptions?: HttpAgentOptions;
|
|
19
|
+
/**
|
|
20
|
+
* @see {@link ActorConfig}
|
|
21
|
+
*/
|
|
22
|
+
actorOptions?: ActorConfig;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
|
|
27
|
+
* @constructs {@link ActorSubClass}
|
|
28
|
+
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
|
|
29
|
+
* @param {CreateActorOptions} options - see {@link CreateActorOptions}
|
|
30
|
+
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
|
|
31
|
+
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
|
|
32
|
+
* @see {@link HttpAgentOptions}
|
|
33
|
+
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
|
|
34
|
+
* @see {@link ActorConfig}
|
|
35
|
+
*/
|
|
36
|
+
export declare const createActor: (
|
|
37
|
+
canisterId: string | Principal,
|
|
38
|
+
options?: CreateActorOptions
|
|
39
|
+
) => ActorSubclass<_SERVICE>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Intialized Actor using default settings, ready to talk to a canister using its candid interface
|
|
43
|
+
* @constructs {@link ActorSubClass}
|
|
44
|
+
*/
|
|
45
|
+
export declare const cmc: ActorSubclass<_SERVICE>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {Actor, HttpAgent} from '@dfinity/agent';
|
|
2
|
+
|
|
3
|
+
// Imports and re-exports candid interface
|
|
4
|
+
import {idlFactory} from './cmc.did.js';
|
|
5
|
+
export {idlFactory} from './cmc.did.js';
|
|
6
|
+
|
|
7
|
+
/* CANISTER_ID is replaced by webpack based on node environment
|
|
8
|
+
* Note: canister environment variable will be standardized as
|
|
9
|
+
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
|
|
10
|
+
* beginning in dfx 0.15.0
|
|
11
|
+
*/
|
|
12
|
+
export const canisterId = process.env.CANISTER_ID_CMC || process.env.CMC_CANISTER_ID;
|
|
13
|
+
|
|
14
|
+
export const createActor = (canisterId, options = {}) => {
|
|
15
|
+
const agent = options.agent || new HttpAgent({...options.agentOptions});
|
|
16
|
+
|
|
17
|
+
if (options.agent && options.agentOptions) {
|
|
18
|
+
console.warn(
|
|
19
|
+
'Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent.'
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Fetch root key for certificate validation during development
|
|
24
|
+
if (process.env.DFX_NETWORK !== 'ic') {
|
|
25
|
+
agent.fetchRootKey().catch((err) => {
|
|
26
|
+
console.warn('Unable to fetch root key. Check to ensure that your local replica is running');
|
|
27
|
+
console.error(err);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Creates an actor with using the candid interface and the HttpAgent
|
|
32
|
+
return Actor.createActor(idlFactory, {
|
|
33
|
+
agent,
|
|
34
|
+
canisterId,
|
|
35
|
+
...options.actorOptions
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type {ActorMethod} from '@dfinity/agent';
|
|
2
|
+
import type {Principal} from '@dfinity/principal';
|
|
3
|
+
|
|
4
|
+
export interface AddCreditsArgs {
|
|
5
|
+
user: Principal;
|
|
6
|
+
}
|
|
7
|
+
export interface AssertMissionControlCenterArgs {
|
|
8
|
+
mission_control_id: Principal;
|
|
9
|
+
user: Principal;
|
|
10
|
+
}
|
|
11
|
+
export type ControllerScope = {Write: null} | {Admin: null};
|
|
12
|
+
export interface CreateCanisterArgs {
|
|
13
|
+
block_index: [] | [bigint];
|
|
14
|
+
user: Principal;
|
|
15
|
+
}
|
|
16
|
+
export interface DeleteControllersArgs {
|
|
17
|
+
controllers: Array<Principal>;
|
|
18
|
+
}
|
|
19
|
+
export interface LoadRelease {
|
|
20
|
+
total: bigint;
|
|
21
|
+
chunks: bigint;
|
|
22
|
+
}
|
|
23
|
+
export interface MissionControl {
|
|
24
|
+
updated_at: bigint;
|
|
25
|
+
credits: Tokens;
|
|
26
|
+
mission_control_id: [] | [Principal];
|
|
27
|
+
owner: Principal;
|
|
28
|
+
created_at: bigint;
|
|
29
|
+
}
|
|
30
|
+
export interface RateConfig {
|
|
31
|
+
max_tokens: bigint;
|
|
32
|
+
time_per_token_ns: bigint;
|
|
33
|
+
}
|
|
34
|
+
export interface ReleasesVersion {
|
|
35
|
+
satellite: [] | [string];
|
|
36
|
+
orbiter: [] | [string];
|
|
37
|
+
mission_control: [] | [string];
|
|
38
|
+
}
|
|
39
|
+
export type Segment = {Orbiter: null} | {MissionControl: null} | {Satellite: null};
|
|
40
|
+
export interface SetController {
|
|
41
|
+
metadata: Array<[string, string]>;
|
|
42
|
+
scope: ControllerScope;
|
|
43
|
+
expires_at: [] | [bigint];
|
|
44
|
+
}
|
|
45
|
+
export interface SetControllersArgs {
|
|
46
|
+
controller: SetController;
|
|
47
|
+
controllers: Array<Principal>;
|
|
48
|
+
}
|
|
49
|
+
export interface Tokens {
|
|
50
|
+
e8s: bigint;
|
|
51
|
+
}
|
|
52
|
+
export interface _SERVICE {
|
|
53
|
+
add_credits: ActorMethod<[AddCreditsArgs], undefined>;
|
|
54
|
+
add_invitation_code: ActorMethod<[string], undefined>;
|
|
55
|
+
assert_mission_control_center: ActorMethod<[AssertMissionControlCenterArgs], undefined>;
|
|
56
|
+
create_orbiter: ActorMethod<[CreateCanisterArgs], Principal>;
|
|
57
|
+
create_satellite: ActorMethod<[CreateCanisterArgs], Principal>;
|
|
58
|
+
del_controllers: ActorMethod<[DeleteControllersArgs], undefined>;
|
|
59
|
+
get_create_orbiter_fee: ActorMethod<[AddCreditsArgs], [] | [Tokens]>;
|
|
60
|
+
get_create_satellite_fee: ActorMethod<[AddCreditsArgs], [] | [Tokens]>;
|
|
61
|
+
get_credits: ActorMethod<[], Tokens>;
|
|
62
|
+
get_releases_version: ActorMethod<[], ReleasesVersion>;
|
|
63
|
+
get_user_mission_control_center: ActorMethod<[], [] | [MissionControl]>;
|
|
64
|
+
init_user_mission_control_center: ActorMethod<[], MissionControl>;
|
|
65
|
+
list_user_mission_control_centers: ActorMethod<[], Array<[Principal, MissionControl]>>;
|
|
66
|
+
load_release: ActorMethod<[Segment, Uint8Array | number[], string], LoadRelease>;
|
|
67
|
+
reset_release: ActorMethod<[Segment], undefined>;
|
|
68
|
+
set_controllers: ActorMethod<[SetControllersArgs], undefined>;
|
|
69
|
+
update_rate_config: ActorMethod<[Segment, RateConfig], undefined>;
|
|
70
|
+
version: ActorMethod<[], string>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
export const idlFactory = ({IDL}) => {
|
|
3
|
+
const AddCreditsArgs = IDL.Record({user: IDL.Principal});
|
|
4
|
+
const AssertMissionControlCenterArgs = IDL.Record({
|
|
5
|
+
mission_control_id: IDL.Principal,
|
|
6
|
+
user: IDL.Principal
|
|
7
|
+
});
|
|
8
|
+
const CreateCanisterArgs = IDL.Record({
|
|
9
|
+
block_index: IDL.Opt(IDL.Nat64),
|
|
10
|
+
user: IDL.Principal
|
|
11
|
+
});
|
|
12
|
+
const DeleteControllersArgs = IDL.Record({
|
|
13
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
14
|
+
});
|
|
15
|
+
const Tokens = IDL.Record({e8s: IDL.Nat64});
|
|
16
|
+
const ReleasesVersion = IDL.Record({
|
|
17
|
+
satellite: IDL.Opt(IDL.Text),
|
|
18
|
+
orbiter: IDL.Opt(IDL.Text),
|
|
19
|
+
mission_control: IDL.Opt(IDL.Text)
|
|
20
|
+
});
|
|
21
|
+
const MissionControl = IDL.Record({
|
|
22
|
+
updated_at: IDL.Nat64,
|
|
23
|
+
credits: Tokens,
|
|
24
|
+
mission_control_id: IDL.Opt(IDL.Principal),
|
|
25
|
+
owner: IDL.Principal,
|
|
26
|
+
created_at: IDL.Nat64
|
|
27
|
+
});
|
|
28
|
+
const Segment = IDL.Variant({
|
|
29
|
+
Orbiter: IDL.Null,
|
|
30
|
+
MissionControl: IDL.Null,
|
|
31
|
+
Satellite: IDL.Null
|
|
32
|
+
});
|
|
33
|
+
const LoadRelease = IDL.Record({total: IDL.Nat64, chunks: IDL.Nat64});
|
|
34
|
+
const ControllerScope = IDL.Variant({
|
|
35
|
+
Write: IDL.Null,
|
|
36
|
+
Admin: IDL.Null
|
|
37
|
+
});
|
|
38
|
+
const SetController = IDL.Record({
|
|
39
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
40
|
+
scope: ControllerScope,
|
|
41
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
42
|
+
});
|
|
43
|
+
const SetControllersArgs = IDL.Record({
|
|
44
|
+
controller: SetController,
|
|
45
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
46
|
+
});
|
|
47
|
+
const RateConfig = IDL.Record({
|
|
48
|
+
max_tokens: IDL.Nat64,
|
|
49
|
+
time_per_token_ns: IDL.Nat64
|
|
50
|
+
});
|
|
51
|
+
return IDL.Service({
|
|
52
|
+
add_credits: IDL.Func([AddCreditsArgs], [], []),
|
|
53
|
+
add_invitation_code: IDL.Func([IDL.Text], [], []),
|
|
54
|
+
assert_mission_control_center: IDL.Func([AssertMissionControlCenterArgs], [], ['query']),
|
|
55
|
+
create_orbiter: IDL.Func([CreateCanisterArgs], [IDL.Principal], []),
|
|
56
|
+
create_satellite: IDL.Func([CreateCanisterArgs], [IDL.Principal], []),
|
|
57
|
+
del_controllers: IDL.Func([DeleteControllersArgs], [], []),
|
|
58
|
+
get_create_orbiter_fee: IDL.Func([AddCreditsArgs], [IDL.Opt(Tokens)], ['query']),
|
|
59
|
+
get_create_satellite_fee: IDL.Func([AddCreditsArgs], [IDL.Opt(Tokens)], ['query']),
|
|
60
|
+
get_credits: IDL.Func([], [Tokens], ['query']),
|
|
61
|
+
get_releases_version: IDL.Func([], [ReleasesVersion], ['query']),
|
|
62
|
+
get_user_mission_control_center: IDL.Func([], [IDL.Opt(MissionControl)], ['query']),
|
|
63
|
+
init_user_mission_control_center: IDL.Func([], [MissionControl], []),
|
|
64
|
+
list_user_mission_control_centers: IDL.Func(
|
|
65
|
+
[],
|
|
66
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, MissionControl))],
|
|
67
|
+
['query']
|
|
68
|
+
),
|
|
69
|
+
load_release: IDL.Func([Segment, IDL.Vec(IDL.Nat8), IDL.Text], [LoadRelease], []),
|
|
70
|
+
reset_release: IDL.Func([Segment], [], []),
|
|
71
|
+
set_controllers: IDL.Func([SetControllersArgs], [], []),
|
|
72
|
+
update_rate_config: IDL.Func([Segment, RateConfig], [], []),
|
|
73
|
+
version: IDL.Func([], [IDL.Text], ['query'])
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
export const init = ({IDL}) => {
|
|
78
|
+
return [];
|
|
79
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
export const idlFactory = ({IDL}) => {
|
|
3
|
+
const AddCreditsArgs = IDL.Record({user: IDL.Principal});
|
|
4
|
+
const AssertMissionControlCenterArgs = IDL.Record({
|
|
5
|
+
mission_control_id: IDL.Principal,
|
|
6
|
+
user: IDL.Principal
|
|
7
|
+
});
|
|
8
|
+
const CreateCanisterArgs = IDL.Record({
|
|
9
|
+
block_index: IDL.Opt(IDL.Nat64),
|
|
10
|
+
user: IDL.Principal
|
|
11
|
+
});
|
|
12
|
+
const DeleteControllersArgs = IDL.Record({
|
|
13
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
14
|
+
});
|
|
15
|
+
const Tokens = IDL.Record({e8s: IDL.Nat64});
|
|
16
|
+
const ReleasesVersion = IDL.Record({
|
|
17
|
+
satellite: IDL.Opt(IDL.Text),
|
|
18
|
+
orbiter: IDL.Opt(IDL.Text),
|
|
19
|
+
mission_control: IDL.Opt(IDL.Text)
|
|
20
|
+
});
|
|
21
|
+
const MissionControl = IDL.Record({
|
|
22
|
+
updated_at: IDL.Nat64,
|
|
23
|
+
credits: Tokens,
|
|
24
|
+
mission_control_id: IDL.Opt(IDL.Principal),
|
|
25
|
+
owner: IDL.Principal,
|
|
26
|
+
created_at: IDL.Nat64
|
|
27
|
+
});
|
|
28
|
+
const Segment = IDL.Variant({
|
|
29
|
+
Orbiter: IDL.Null,
|
|
30
|
+
MissionControl: IDL.Null,
|
|
31
|
+
Satellite: IDL.Null
|
|
32
|
+
});
|
|
33
|
+
const LoadRelease = IDL.Record({total: IDL.Nat64, chunks: IDL.Nat64});
|
|
34
|
+
const ControllerScope = IDL.Variant({
|
|
35
|
+
Write: IDL.Null,
|
|
36
|
+
Admin: IDL.Null
|
|
37
|
+
});
|
|
38
|
+
const SetController = IDL.Record({
|
|
39
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
40
|
+
scope: ControllerScope,
|
|
41
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
42
|
+
});
|
|
43
|
+
const SetControllersArgs = IDL.Record({
|
|
44
|
+
controller: SetController,
|
|
45
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
46
|
+
});
|
|
47
|
+
const RateConfig = IDL.Record({
|
|
48
|
+
max_tokens: IDL.Nat64,
|
|
49
|
+
time_per_token_ns: IDL.Nat64
|
|
50
|
+
});
|
|
51
|
+
return IDL.Service({
|
|
52
|
+
add_credits: IDL.Func([AddCreditsArgs], [], []),
|
|
53
|
+
add_invitation_code: IDL.Func([IDL.Text], [], []),
|
|
54
|
+
assert_mission_control_center: IDL.Func([AssertMissionControlCenterArgs], [], ['query']),
|
|
55
|
+
create_orbiter: IDL.Func([CreateCanisterArgs], [IDL.Principal], []),
|
|
56
|
+
create_satellite: IDL.Func([CreateCanisterArgs], [IDL.Principal], []),
|
|
57
|
+
del_controllers: IDL.Func([DeleteControllersArgs], [], []),
|
|
58
|
+
get_create_orbiter_fee: IDL.Func([AddCreditsArgs], [IDL.Opt(Tokens)], ['query']),
|
|
59
|
+
get_create_satellite_fee: IDL.Func([AddCreditsArgs], [IDL.Opt(Tokens)], ['query']),
|
|
60
|
+
get_credits: IDL.Func([], [Tokens], ['query']),
|
|
61
|
+
get_releases_version: IDL.Func([], [ReleasesVersion], ['query']),
|
|
62
|
+
get_user_mission_control_center: IDL.Func([], [IDL.Opt(MissionControl)], ['query']),
|
|
63
|
+
init_user_mission_control_center: IDL.Func([], [MissionControl], []),
|
|
64
|
+
list_user_mission_control_centers: IDL.Func(
|
|
65
|
+
[],
|
|
66
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, MissionControl))],
|
|
67
|
+
['query']
|
|
68
|
+
),
|
|
69
|
+
load_release: IDL.Func([Segment, IDL.Vec(IDL.Nat8), IDL.Text], [LoadRelease], []),
|
|
70
|
+
reset_release: IDL.Func([Segment], [], []),
|
|
71
|
+
set_controllers: IDL.Func([SetControllersArgs], [], []),
|
|
72
|
+
update_rate_config: IDL.Func([Segment, RateConfig], [], []),
|
|
73
|
+
version: IDL.Func([], [IDL.Text], ['query'])
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
export const init = ({IDL}) => {
|
|
78
|
+
return [];
|
|
79
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {ActorConfig, ActorSubclass, Agent, HttpAgentOptions} from '@dfinity/agent';
|
|
2
|
+
import type {IDL} from '@dfinity/candid';
|
|
3
|
+
import type {Principal} from '@dfinity/principal';
|
|
4
|
+
|
|
5
|
+
import {_SERVICE} from './console.did';
|
|
6
|
+
|
|
7
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
8
|
+
export declare const canisterId: string;
|
|
9
|
+
|
|
10
|
+
export declare interface CreateActorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link Agent}
|
|
13
|
+
*/
|
|
14
|
+
agent?: Agent;
|
|
15
|
+
/**
|
|
16
|
+
* @see {@link HttpAgentOptions}
|
|
17
|
+
*/
|
|
18
|
+
agentOptions?: HttpAgentOptions;
|
|
19
|
+
/**
|
|
20
|
+
* @see {@link ActorConfig}
|
|
21
|
+
*/
|
|
22
|
+
actorOptions?: ActorConfig;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
|
|
27
|
+
* @constructs {@link ActorSubClass}
|
|
28
|
+
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
|
|
29
|
+
* @param {CreateActorOptions} options - see {@link CreateActorOptions}
|
|
30
|
+
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
|
|
31
|
+
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
|
|
32
|
+
* @see {@link HttpAgentOptions}
|
|
33
|
+
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
|
|
34
|
+
* @see {@link ActorConfig}
|
|
35
|
+
*/
|
|
36
|
+
export declare const createActor: (
|
|
37
|
+
canisterId: string | Principal,
|
|
38
|
+
options?: CreateActorOptions
|
|
39
|
+
) => ActorSubclass<_SERVICE>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Intialized Actor using default settings, ready to talk to a canister using its candid interface
|
|
43
|
+
* @constructs {@link ActorSubClass}
|
|
44
|
+
*/
|
|
45
|
+
export declare const console: ActorSubclass<_SERVICE>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {Actor, HttpAgent} from '@dfinity/agent';
|
|
2
|
+
|
|
3
|
+
// Imports and re-exports candid interface
|
|
4
|
+
import {idlFactory} from './console.did.js';
|
|
5
|
+
export {idlFactory} from './console.did.js';
|
|
6
|
+
|
|
7
|
+
/* CANISTER_ID is replaced by webpack based on node environment
|
|
8
|
+
* Note: canister environment variable will be standardized as
|
|
9
|
+
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
|
|
10
|
+
* beginning in dfx 0.15.0
|
|
11
|
+
*/
|
|
12
|
+
export const canisterId = process.env.CANISTER_ID_CONSOLE || process.env.CONSOLE_CANISTER_ID;
|
|
13
|
+
|
|
14
|
+
export const createActor = (canisterId, options = {}) => {
|
|
15
|
+
const agent = options.agent || new HttpAgent({...options.agentOptions});
|
|
16
|
+
|
|
17
|
+
if (options.agent && options.agentOptions) {
|
|
18
|
+
console.warn(
|
|
19
|
+
'Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent.'
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Fetch root key for certificate validation during development
|
|
24
|
+
if (process.env.DFX_NETWORK !== 'ic') {
|
|
25
|
+
agent.fetchRootKey().catch((err) => {
|
|
26
|
+
console.warn('Unable to fetch root key. Check to ensure that your local replica is running');
|
|
27
|
+
console.error(err);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Creates an actor with using the candid interface and the HttpAgent
|
|
32
|
+
return Actor.createActor(idlFactory, {
|
|
33
|
+
agent,
|
|
34
|
+
canisterId,
|
|
35
|
+
...options.actorOptions
|
|
36
|
+
});
|
|
37
|
+
};
|