@ic-reactor/core 1.0.4 → 1.0.5
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
CHANGED
|
@@ -203,7 +203,7 @@ const { agentManager, callMethod } = createReactorStore<Candid>({
|
|
|
203
203
|
|
|
204
204
|
// Usage example
|
|
205
205
|
await agentManager.authenticate()
|
|
206
|
-
const authClient = agentManager.
|
|
206
|
+
const authClient = agentManager.getAuth()
|
|
207
207
|
|
|
208
208
|
authClient?.login({
|
|
209
209
|
onSuccess: () => {
|
|
@@ -6,7 +6,7 @@ export interface DefaultActorType {
|
|
|
6
6
|
[key: string]: ActorMethod;
|
|
7
7
|
}
|
|
8
8
|
export type BaseActor<T = DefaultActorType> = ActorSubclass<T>;
|
|
9
|
-
export type FunctionName<A = BaseActor> = keyof A
|
|
9
|
+
export type FunctionName<A = BaseActor> = Extract<keyof A, string>;
|
|
10
10
|
export type FunctionType = "query" | "update";
|
|
11
11
|
export type CanisterId = string | Principal;
|
|
12
12
|
export interface ActorManagerParameters {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HttpAgent } from "@dfinity/agent";
|
|
2
|
-
import type { AgentStore, AgentManagerParameters, UpdateAgentParameters, AuthStore } from "./types";
|
|
2
|
+
import type { AgentStore, AgentManagerParameters, UpdateAgentParameters, AuthStore, AuthClient } from "./types";
|
|
3
3
|
export declare class AgentManager {
|
|
4
4
|
private _agent;
|
|
5
|
+
private _auth;
|
|
5
6
|
private _subscribers;
|
|
6
7
|
agentStore: AgentStore;
|
|
7
8
|
authStore: AuthStore;
|
|
@@ -22,7 +23,7 @@ export declare class AgentManager {
|
|
|
22
23
|
subscribeAgentState: AgentStore["subscribe"];
|
|
23
24
|
getAuthState: AuthStore["getState"];
|
|
24
25
|
subscribeAuthState: AuthStore["subscribe"];
|
|
25
|
-
|
|
26
|
+
getAuth: () => AuthClient | null;
|
|
26
27
|
getIdentity: () => import("@dfinity/agent").Identity | null;
|
|
27
28
|
getPrincipal: () => import("@dfinity/principal").Principal | null;
|
|
28
29
|
}
|
|
@@ -49,6 +49,7 @@ const helper_1 = require("../../tools/helper");
|
|
|
49
49
|
const constants_1 = require("../../tools/constants");
|
|
50
50
|
class AgentManager {
|
|
51
51
|
constructor(options) {
|
|
52
|
+
this._auth = null;
|
|
52
53
|
this._subscribers = [];
|
|
53
54
|
this.initialAgentState = {
|
|
54
55
|
initialized: false,
|
|
@@ -57,7 +58,6 @@ class AgentManager {
|
|
|
57
58
|
};
|
|
58
59
|
this.initialAuthState = {
|
|
59
60
|
identity: null,
|
|
60
|
-
authClient: null,
|
|
61
61
|
authenticating: false,
|
|
62
62
|
authenticated: false,
|
|
63
63
|
error: undefined,
|
|
@@ -110,13 +110,12 @@ class AgentManager {
|
|
|
110
110
|
console.error("Failed to import @dfinity/auth-client:", error);
|
|
111
111
|
throw new Error("Authentication failed: @dfinity/auth-client package is missing.");
|
|
112
112
|
});
|
|
113
|
-
|
|
114
|
-
const authenticated = yield
|
|
115
|
-
const identity =
|
|
113
|
+
this._auth = yield AuthClient.create();
|
|
114
|
+
const authenticated = yield this._auth.isAuthenticated();
|
|
115
|
+
const identity = this._auth.getIdentity();
|
|
116
116
|
this._agent.replaceIdentity(identity);
|
|
117
117
|
this.notifySubscribers();
|
|
118
118
|
this.updateAuthState({
|
|
119
|
-
authClient,
|
|
120
119
|
authenticated,
|
|
121
120
|
identity,
|
|
122
121
|
authenticating: false,
|
|
@@ -145,8 +144,8 @@ class AgentManager {
|
|
|
145
144
|
this.subscribeAuthState = (listener) => {
|
|
146
145
|
return this.authStore.subscribe(listener);
|
|
147
146
|
};
|
|
148
|
-
this.
|
|
149
|
-
return this.
|
|
147
|
+
this.getAuth = () => {
|
|
148
|
+
return this._auth;
|
|
150
149
|
};
|
|
151
150
|
this.getIdentity = () => {
|
|
152
151
|
return this.authStore.getState().identity;
|
package/dist/main.js
CHANGED
|
@@ -114,7 +114,7 @@ const createReactorCore = (config) => {
|
|
|
114
114
|
return actorMethod(functionName, ...args);
|
|
115
115
|
};
|
|
116
116
|
const login = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
-
const authClient = agentManager.
|
|
117
|
+
const authClient = agentManager.getAuth();
|
|
118
118
|
if (!authClient) {
|
|
119
119
|
yield agentManager.authenticate();
|
|
120
120
|
}
|
|
@@ -126,7 +126,7 @@ const createReactorCore = (config) => {
|
|
|
126
126
|
: constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER }, options));
|
|
127
127
|
});
|
|
128
128
|
const logout = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
-
const authClient = agentManager.
|
|
129
|
+
const authClient = agentManager.getAuth();
|
|
130
130
|
if (!authClient) {
|
|
131
131
|
throw new Error("Auth client not initialized");
|
|
132
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=10"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c52ec12bc91d5a0e2c5fc7c6e163530a1aa5e47f"
|
|
47
47
|
}
|