@ic-reactor/core 1.0.9 → 1.1.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.
|
@@ -58,7 +58,7 @@ class ActorManager {
|
|
|
58
58
|
initializing: true,
|
|
59
59
|
initialized: false,
|
|
60
60
|
methodState: {},
|
|
61
|
-
});
|
|
61
|
+
}, "initializing");
|
|
62
62
|
try {
|
|
63
63
|
if (!agent) {
|
|
64
64
|
throw new Error("Agent not initialized");
|
|
@@ -73,11 +73,11 @@ class ActorManager {
|
|
|
73
73
|
this.updateState({
|
|
74
74
|
initializing: false,
|
|
75
75
|
initialized: true,
|
|
76
|
-
});
|
|
76
|
+
}, "initialized");
|
|
77
77
|
}
|
|
78
78
|
catch (error) {
|
|
79
79
|
console.error("Error in initializeActor:", error);
|
|
80
|
-
this.updateState({ error: error, initializing: false });
|
|
80
|
+
this.updateState({ error: error, initializing: false }, "error");
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
this.callMethod = (functionName, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -118,7 +118,8 @@ class ActorManager {
|
|
|
118
118
|
// Initialize stores
|
|
119
119
|
this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialState, {
|
|
120
120
|
withDevtools,
|
|
121
|
-
|
|
121
|
+
name: "Reactor-Actor",
|
|
122
|
+
store: canisterId.toString(),
|
|
122
123
|
});
|
|
123
124
|
this._unsubscribeAgent = this._agentManager.subscribeAgent(this.initializeActor, initializeOnCreate);
|
|
124
125
|
if (withVisitor) {
|
|
@@ -47,16 +47,16 @@ class AgentManager {
|
|
|
47
47
|
this.authStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
|
|
48
48
|
};
|
|
49
49
|
this.initializeAgent = () => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
this.updateAgentState({ initializing: true });
|
|
50
|
+
this.updateAgentState({ initializing: true }, "initializing");
|
|
51
51
|
if (this.isLocalEnv) {
|
|
52
52
|
try {
|
|
53
53
|
yield this._agent.fetchRootKey();
|
|
54
|
-
this.updateAgentState({ initialized: true, initializing: false });
|
|
55
54
|
}
|
|
56
55
|
catch (error) {
|
|
57
|
-
this.updateAgentState({ error: error, initializing: false });
|
|
56
|
+
this.updateAgentState({ error: error, initializing: false }, "error");
|
|
58
57
|
}
|
|
59
58
|
}
|
|
59
|
+
this.updateAgentState({ initialized: true, initializing: false }, "initialized");
|
|
60
60
|
});
|
|
61
61
|
this.subscribeAgent = (callback, initialize = true) => {
|
|
62
62
|
if (initialize) {
|
|
@@ -84,7 +84,7 @@ class AgentManager {
|
|
|
84
84
|
yield this.notifySubscribers();
|
|
85
85
|
});
|
|
86
86
|
this.authenticate = () => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
this.updateAuthState({ authenticating: true });
|
|
87
|
+
this.updateAuthState({ authenticating: true }, "authenticating");
|
|
88
88
|
try {
|
|
89
89
|
this._auth = yield auth_client_1.AuthClient.create();
|
|
90
90
|
const authenticated = yield this._auth.isAuthenticated();
|
|
@@ -95,16 +95,16 @@ class AgentManager {
|
|
|
95
95
|
authenticated,
|
|
96
96
|
identity,
|
|
97
97
|
authenticating: false,
|
|
98
|
-
});
|
|
98
|
+
}, "authenticated");
|
|
99
99
|
return identity;
|
|
100
100
|
}
|
|
101
101
|
catch (error) {
|
|
102
|
-
this.updateAuthState({ error: error, authenticating: false });
|
|
102
|
+
this.updateAuthState({ error: error, authenticating: false }, "error");
|
|
103
103
|
throw error;
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
this.login = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
this.updateAuthState({ authenticating: true });
|
|
107
|
+
this.updateAuthState({ authenticating: true }, "login");
|
|
108
108
|
if (!this._auth) {
|
|
109
109
|
yield this.authenticate();
|
|
110
110
|
}
|
|
@@ -153,7 +153,7 @@ class AgentManager {
|
|
|
153
153
|
const identity = this.authStore.getState().identity;
|
|
154
154
|
return identity ? identity.getPrincipal() : null;
|
|
155
155
|
};
|
|
156
|
-
const _a = options || {}, { withDevtools, port = 4943, withLocalEnv, host: optionHost } = _a,
|
|
156
|
+
const _a = options || {}, { withDevtools, port = 4943, withLocalEnv, host: optionHost } = _a, agentOptions = __rest(_a, ["withDevtools", "port", "withLocalEnv", "host"]);
|
|
157
157
|
const host = withLocalEnv
|
|
158
158
|
? `http://127.0.0.1:${port}`
|
|
159
159
|
: optionHost
|
|
@@ -163,13 +163,15 @@ class AgentManager {
|
|
|
163
163
|
: constants_1.IC_HOST_NETWORK_URI;
|
|
164
164
|
this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAgentState, {
|
|
165
165
|
withDevtools,
|
|
166
|
+
name: "Reactor-Agent",
|
|
166
167
|
store: "agent",
|
|
167
168
|
});
|
|
168
169
|
this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAuthState, {
|
|
169
170
|
withDevtools,
|
|
171
|
+
name: "Reactor-Agent",
|
|
170
172
|
store: "auth",
|
|
171
173
|
});
|
|
172
|
-
this._agent = new agent_1.HttpAgent(Object.assign(Object.assign({},
|
|
174
|
+
this._agent = new agent_1.HttpAgent(Object.assign(Object.assign({}, agentOptions), { host }));
|
|
173
175
|
this.isLocalEnv = this._agent.isLocal();
|
|
174
176
|
this.initializeAgent();
|
|
175
177
|
}
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
+
import { DevtoolsOptions } from "zustand/middleware";
|
|
1
2
|
import type { BaseActor } from "../types";
|
|
2
|
-
|
|
3
|
-
withDevtools?: boolean;
|
|
4
|
-
store: string;
|
|
5
|
-
}
|
|
6
|
-
export declare function createStoreWithOptionalDevtools<T>(initialState: T, config: StoreParameters): Omit<import("zustand/vanilla").StoreApi<T>, "setState"> & {
|
|
3
|
+
export declare function createStoreWithOptionalDevtools<T>(initialState: T, config: DevtoolsOptions): Omit<import("zustand/vanilla").StoreApi<T>, "setState"> & {
|
|
7
4
|
setState<A extends string | {
|
|
8
5
|
type: string;
|
|
9
6
|
}>(partial: T | Partial<T> | ((state: T) => T | Partial<T>), replace?: boolean | undefined, action?: A | undefined): void;
|
|
10
7
|
};
|
|
11
8
|
export declare const isInLocalOrDevelopment: () => boolean;
|
|
12
|
-
export declare const jsonToString: (json: unknown) => string;
|
|
9
|
+
export declare const jsonToString: (json: unknown, space?: number) => string;
|
|
13
10
|
export declare const generateRequestHash: (args?: unknown[]) => `0x${string}`;
|
|
14
11
|
export declare const generateHash: (field?: unknown) => `0x${string}`;
|
|
15
12
|
export declare const generateActorHash: (actor: BaseActor) => `0x${string}`;
|
|
16
13
|
export declare const stringToHash: (str: string) => `0x${string}`;
|
|
17
|
-
export {};
|
package/dist/utils/helper.js
CHANGED
|
@@ -6,13 +6,9 @@ const middleware_1 = require("zustand/middleware");
|
|
|
6
6
|
const vanilla_1 = require("zustand/vanilla");
|
|
7
7
|
function createStoreWithOptionalDevtools(initialState, config) {
|
|
8
8
|
if (config.withDevtools) {
|
|
9
|
-
return (0, vanilla_1.createStore)((0, middleware_1.devtools)(() => initialState, {
|
|
10
|
-
name: "Reactor",
|
|
11
|
-
store: config.store,
|
|
12
|
-
serialize: {
|
|
9
|
+
return (0, vanilla_1.createStore)((0, middleware_1.devtools)(() => initialState, Object.assign({ serialize: {
|
|
13
10
|
replacer: (_, value) => typeof value === "bigint" ? value.toString() : value,
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
11
|
+
} }, config)));
|
|
16
12
|
}
|
|
17
13
|
else {
|
|
18
14
|
return (0, vanilla_1.createStore)(() => initialState);
|
|
@@ -25,8 +21,8 @@ const isInLocalOrDevelopment = () => {
|
|
|
25
21
|
process.env.NODE_ENV === "development"));
|
|
26
22
|
};
|
|
27
23
|
exports.isInLocalOrDevelopment = isInLocalOrDevelopment;
|
|
28
|
-
const jsonToString = (json) => {
|
|
29
|
-
return JSON.stringify(json, (_, value) => (typeof value === "bigint" ? `BigInt(${value})` : value),
|
|
24
|
+
const jsonToString = (json, space = 2) => {
|
|
25
|
+
return JSON.stringify(json, (_, value) => (typeof value === "bigint" ? `BigInt(${value})` : value), space);
|
|
30
26
|
};
|
|
31
27
|
exports.jsonToString = jsonToString;
|
|
32
28
|
const generateRequestHash = (args = []) => {
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -14,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Principal = exports.IDL = void 0;
|
|
17
18
|
__exportStar(require("./helper"), exports);
|
|
18
19
|
__exportStar(require("./constants"), exports);
|
|
20
|
+
var candid_1 = require("@dfinity/candid");
|
|
21
|
+
Object.defineProperty(exports, "IDL", { enumerable: true, get: function () { return candid_1.IDL; } });
|
|
22
|
+
var principal_1 = require("@dfinity/principal");
|
|
23
|
+
Object.defineProperty(exports, "Principal", { enumerable: true, get: function () { return principal_1.Principal; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=10"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a7b6cc0c3cea60c49e3780af8862eb171506bb2a"
|
|
50
50
|
}
|