@ic-reactor/core 1.5.3 → 1.5.4-beta.0
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/dist/classes/actor/index.js +1 -2
- package/dist/classes/agent/index.d.ts +2 -0
- package/dist/classes/agent/index.js +31 -12
- package/dist/classes/agent/types.d.ts +1 -0
- package/dist/createReactorStore.js +1 -6
- package/dist/types.d.ts +0 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +2 -1
- package/dist/utils/helper.d.ts +1 -0
- package/dist/utils/helper.js +9 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ yarn add @ic-reactor/core
|
|
|
19
19
|
or you can use the UMD version:
|
|
20
20
|
|
|
21
21
|
```html
|
|
22
|
-
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.5.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.5.3/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -75,8 +75,7 @@ class ActorManager {
|
|
|
75
75
|
}, {});
|
|
76
76
|
};
|
|
77
77
|
this.initializeActor = (agent) => {
|
|
78
|
-
|
|
79
|
-
console.info(`Initializing actor ${this.canisterId} on ${((_a = agent.isLocal) === null || _a === void 0 ? void 0 : _a.call(agent)) === true ? "local" : "ic"} network`);
|
|
78
|
+
console.info(`Initializing actor ${this.canisterId} on ${this._agentManager.getNetwork()} network`);
|
|
80
79
|
const { _idlFactory, canisterId } = this;
|
|
81
80
|
this.updateState({
|
|
82
81
|
initializing: true,
|
|
@@ -24,7 +24,9 @@ export declare class AgentManager {
|
|
|
24
24
|
returnTo?: string;
|
|
25
25
|
}) => Promise<void>;
|
|
26
26
|
getAgent: () => HttpAgent;
|
|
27
|
+
getAgentHost: () => URL;
|
|
27
28
|
getIsLocal: () => boolean;
|
|
29
|
+
getNetwork: () => "ic" | "local" | "remote";
|
|
28
30
|
getAgentState: AgentStore["getState"];
|
|
29
31
|
subscribeAgentState: AgentStore["subscribe"];
|
|
30
32
|
getAuthState: AuthStore["getState"];
|
|
@@ -49,13 +49,13 @@ class AgentManager {
|
|
|
49
49
|
this.authStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
|
|
50
50
|
};
|
|
51
51
|
this.initializeAgent = () => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const
|
|
52
|
+
const network = this.getNetwork();
|
|
53
53
|
this.updateAgentState({
|
|
54
54
|
initializing: true,
|
|
55
55
|
error: undefined,
|
|
56
|
-
network
|
|
56
|
+
network,
|
|
57
57
|
}, "initializing");
|
|
58
|
-
if (
|
|
58
|
+
if (network !== "ic") {
|
|
59
59
|
try {
|
|
60
60
|
yield this._agent.fetchRootKey();
|
|
61
61
|
}
|
|
@@ -90,7 +90,7 @@ class AgentManager {
|
|
|
90
90
|
yield this.notifySubscribers();
|
|
91
91
|
});
|
|
92
92
|
this.authenticate = () => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
console.log(`Authenticating on ${this.
|
|
93
|
+
console.log(`Authenticating on ${this.getNetwork()} network`);
|
|
94
94
|
this.updateAuthState({ authenticating: true }, "authenticating");
|
|
95
95
|
try {
|
|
96
96
|
this._auth = yield auth_client_1.AuthClient.create();
|
|
@@ -137,10 +137,25 @@ class AgentManager {
|
|
|
137
137
|
this.getAgent = () => {
|
|
138
138
|
return this._agent;
|
|
139
139
|
};
|
|
140
|
+
this.getAgentHost = () => {
|
|
141
|
+
return this._agent._host;
|
|
142
|
+
};
|
|
140
143
|
this.getIsLocal = () => {
|
|
141
144
|
var _a, _b;
|
|
142
145
|
return ((_b = (_a = this._agent).isLocal) === null || _b === void 0 ? void 0 : _b.call(_a)) === true;
|
|
143
146
|
};
|
|
147
|
+
this.getNetwork = () => {
|
|
148
|
+
const hostname = this.getAgentHost().hostname;
|
|
149
|
+
if (hostname === "127.0.0.1" || hostname.endsWith("127.0.0.1")) {
|
|
150
|
+
return "local";
|
|
151
|
+
}
|
|
152
|
+
else if (constants_1.REMOTE_HOSTS.some((host) => hostname.endsWith(host))) {
|
|
153
|
+
return "remote";
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return "ic";
|
|
157
|
+
}
|
|
158
|
+
};
|
|
144
159
|
this.getAgentState = () => {
|
|
145
160
|
return this.agentStore.getState();
|
|
146
161
|
};
|
|
@@ -164,14 +179,18 @@ class AgentManager {
|
|
|
164
179
|
const identity = this.authStore.getState().identity;
|
|
165
180
|
return identity ? identity.getPrincipal() : null;
|
|
166
181
|
};
|
|
167
|
-
const _a = options || {}, { withDevtools, port = 4943, withLocalEnv, host: optionHost } = _a, agentOptions = __rest(_a, ["withDevtools", "port", "withLocalEnv", "host"]);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
const _a = options || {}, { withDevtools, port = 4943, withLocalEnv, withProcessEnv, host: optionHost } = _a, agentOptions = __rest(_a, ["withDevtools", "port", "withLocalEnv", "withProcessEnv", "host"]);
|
|
183
|
+
let host;
|
|
184
|
+
if (withProcessEnv) {
|
|
185
|
+
const processNetwork = (0, helper_1.getProcessEnvNetwork)();
|
|
186
|
+
host = processNetwork === "ic" ? constants_1.IC_HOST_NETWORK_URI : undefined;
|
|
187
|
+
}
|
|
188
|
+
else if (withLocalEnv) {
|
|
189
|
+
host = `http://127.0.0.1:${port}`;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
host = optionHost !== null && optionHost !== void 0 ? optionHost : constants_1.IC_HOST_NETWORK_URI;
|
|
193
|
+
}
|
|
175
194
|
this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAgentState, {
|
|
176
195
|
withDevtools,
|
|
177
196
|
name: "Reactor-Agent",
|
|
@@ -12,7 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.createReactorStore = void 0;
|
|
15
|
-
const utils_1 = require("./utils");
|
|
16
15
|
const createActorManager_1 = require("./createActorManager");
|
|
17
16
|
const createAgentManager_1 = require("./createAgentManager");
|
|
18
17
|
/**
|
|
@@ -24,13 +23,9 @@ const createAgentManager_1 = require("./createAgentManager");
|
|
|
24
23
|
* @includeExample ./packages/core/README.md:200-225
|
|
25
24
|
*/
|
|
26
25
|
const createReactorStore = (config) => {
|
|
27
|
-
const withLocalEnv = config.withProcessEnv
|
|
28
|
-
? (0, utils_1.isInLocalOrDevelopment)()
|
|
29
|
-
: undefined;
|
|
30
26
|
const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager } = config, agentParameters = __rest(config, ["idlFactory", "canisterId", "withDevtools", "initializeOnCreate", "withVisitor", "agentManager"]);
|
|
31
27
|
const agentManager = maybeAgentManager ||
|
|
32
|
-
(0, createAgentManager_1.createAgentManager)(Object.assign({ withDevtools,
|
|
33
|
-
withLocalEnv }, agentParameters));
|
|
28
|
+
(0, createAgentManager_1.createAgentManager)(Object.assign({ withDevtools }, agentParameters));
|
|
34
29
|
const actorManager = (0, createActorManager_1.createActorManager)({
|
|
35
30
|
idlFactory,
|
|
36
31
|
canisterId,
|
package/dist/types.d.ts
CHANGED
|
@@ -51,7 +51,6 @@ export type ActorMethodCall<A = Record<string, ActorMethod>> = <M extends Functi
|
|
|
51
51
|
export type ActorQuery<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(config: ActorQueryParameters<A, M>) => ActorQueryReturnType<A, M>;
|
|
52
52
|
export type ActorUpdate<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(config: ActorUpdateParameters<A, M>) => ActorUpdateReturnType<A, M>;
|
|
53
53
|
export interface CreateReactorCoreParameters extends CreateReactorStoreParameters {
|
|
54
|
-
withProcessEnv?: boolean;
|
|
55
54
|
}
|
|
56
55
|
export interface CreateReactorCoreReturnType<A = BaseActor> extends AgentManager, Omit<ActorManager<A>, "updateMethodState"> {
|
|
57
56
|
queryCall: ActorQuery<A>;
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOCAL_INTERNET_IDENTITY_PROVIDER = exports.IC_INTERNET_IDENTITY_PROVIDER = exports.DEFAULT_IC_DIDJS_ID = exports.DEFAULT_LOCAL_DIDJS_ID = exports.LOCAL_HOST_NETWORK_URI = exports.IC_HOST_NETWORK_URI = void 0;
|
|
3
|
+
exports.LOCAL_INTERNET_IDENTITY_PROVIDER = exports.IC_INTERNET_IDENTITY_PROVIDER = exports.DEFAULT_IC_DIDJS_ID = exports.DEFAULT_LOCAL_DIDJS_ID = exports.LOCAL_HOST_NETWORK_URI = exports.IC_HOST_NETWORK_URI = exports.REMOTE_HOSTS = void 0;
|
|
4
|
+
exports.REMOTE_HOSTS = [".github.dev", ".gitpod.io"];
|
|
4
5
|
exports.IC_HOST_NETWORK_URI = "https://ic0.app";
|
|
5
6
|
exports.LOCAL_HOST_NETWORK_URI = "http://127.0.0.1:4943";
|
|
6
7
|
exports.DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare function createStoreWithOptionalDevtools<T>(initialState: T, conf
|
|
|
6
6
|
}>(partial: T | Partial<T> | ((state: T) => T | Partial<T>), replace?: boolean | undefined, action?: A | undefined): void;
|
|
7
7
|
};
|
|
8
8
|
export declare const isInLocalOrDevelopment: () => boolean;
|
|
9
|
+
export declare const getProcessEnvNetwork: () => string;
|
|
9
10
|
export declare function isQuery(func: IDL.FuncClass): boolean;
|
|
10
11
|
export declare const jsonToString: (json: unknown, space?: number) => string;
|
|
11
12
|
export declare const generateRequestHash: (args?: unknown[]) => `0x${string}`;
|
package/dist/utils/helper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.isQuery = exports.isInLocalOrDevelopment = exports.createStoreWithOptionalDevtools = void 0;
|
|
3
|
+
exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.isQuery = exports.getProcessEnvNetwork = exports.isInLocalOrDevelopment = exports.createStoreWithOptionalDevtools = void 0;
|
|
4
4
|
const agent_1 = require("@dfinity/agent");
|
|
5
5
|
const middleware_1 = require("zustand/middleware");
|
|
6
6
|
const vanilla_1 = require("zustand/vanilla");
|
|
@@ -19,6 +19,14 @@ const isInLocalOrDevelopment = () => {
|
|
|
19
19
|
return typeof process !== "undefined" && process.env.DFX_NETWORK === "local";
|
|
20
20
|
};
|
|
21
21
|
exports.isInLocalOrDevelopment = isInLocalOrDevelopment;
|
|
22
|
+
const getProcessEnvNetwork = () => {
|
|
23
|
+
var _a;
|
|
24
|
+
if (typeof process === "undefined")
|
|
25
|
+
return "ic";
|
|
26
|
+
else
|
|
27
|
+
return (_a = process.env.DFX_NETWORK) !== null && _a !== void 0 ? _a : "ic";
|
|
28
|
+
};
|
|
29
|
+
exports.getProcessEnvNetwork = getProcessEnvNetwork;
|
|
22
30
|
function isQuery(func) {
|
|
23
31
|
return (func.annotations.includes("query") ||
|
|
24
32
|
func.annotations.includes("composite_query"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4-beta.0",
|
|
4
4
|
"description": "A library for intracting with the Internet Computer canisters",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=10"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "dfc8ce03a6a0f8aadf28bba2b21c70729278b5fd"
|
|
56
56
|
}
|