@ic-reactor/core 1.15.0 → 1.16.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 +18 -4
- package/dist/classes/actor/types.d.ts +2 -2
- package/dist/classes/agent/index.d.ts +1 -3
- package/dist/classes/agent/index.js +30 -20
- package/dist/classes/agent/types.d.ts +5 -4
- package/dist/classes/types.d.ts +12 -5
- package/dist/classes/types.js +1 -0
- package/dist/utils/constants.d.ts +0 -8
- package/dist/utils/constants.js +1 -9
- package/dist/utils/helper.d.ts +4 -3
- package/dist/utils/helper.js +4 -5
- package/package.json +3 -3
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.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.15.0/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -14,7 +14,14 @@ exports.ActorManager = void 0;
|
|
|
14
14
|
const agent_1 = require("@dfinity/agent");
|
|
15
15
|
const helper_1 = require("../../utils/helper");
|
|
16
16
|
const candid_1 = require("@dfinity/candid");
|
|
17
|
-
const
|
|
17
|
+
const ACTOR_INITIAL_STATE = {
|
|
18
|
+
name: "",
|
|
19
|
+
version: 0,
|
|
20
|
+
methodState: {},
|
|
21
|
+
initializing: false,
|
|
22
|
+
initialized: false,
|
|
23
|
+
error: undefined,
|
|
24
|
+
};
|
|
18
25
|
class ActorManager {
|
|
19
26
|
constructor(actorConfig) {
|
|
20
27
|
this._actor = null;
|
|
@@ -152,8 +159,15 @@ class ActorManager {
|
|
|
152
159
|
this.getState = () => {
|
|
153
160
|
return this.actorStore.getState();
|
|
154
161
|
};
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
// @ts-expect-error: Overrides subscribe method signature
|
|
163
|
+
this.subscribeActorState = (selectorOrListener, listener, options) => {
|
|
164
|
+
let unsubscribe = () => { };
|
|
165
|
+
if (listener) {
|
|
166
|
+
unsubscribe = this.actorStore.subscribe(selectorOrListener, listener, options);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
unsubscribe = this.actorStore.subscribe(selectorOrListener);
|
|
170
|
+
}
|
|
157
171
|
this._subscribers.push(unsubscribe);
|
|
158
172
|
return unsubscribe;
|
|
159
173
|
};
|
|
@@ -179,7 +193,7 @@ class ActorManager {
|
|
|
179
193
|
}
|
|
180
194
|
this._agentManager = agentManager;
|
|
181
195
|
// Initialize stores
|
|
182
|
-
this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(Object.assign(Object.assign({},
|
|
196
|
+
this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(Object.assign(Object.assign({}, ACTOR_INITIAL_STATE), { name }), {
|
|
183
197
|
withDevtools,
|
|
184
198
|
name: "reactor-actor",
|
|
185
199
|
store: canisterId.toString(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentManager } from "../agent";
|
|
2
|
-
import type { IDL,
|
|
2
|
+
import type { IDL, ActorMethod, ActorSubclass, Principal, StoreWithAllMiddleware } from "../../types";
|
|
3
3
|
import { CallConfig } from "@dfinity/agent";
|
|
4
4
|
export interface DefaultActorType {
|
|
5
5
|
[key: string]: ActorMethod;
|
|
@@ -48,7 +48,7 @@ export type ActorState<A = BaseActor> = {
|
|
|
48
48
|
error: Error | undefined;
|
|
49
49
|
methodState: ActorMethodStates<A>;
|
|
50
50
|
};
|
|
51
|
-
export type ActorStore<A = BaseActor> =
|
|
51
|
+
export type ActorStore<A = BaseActor> = StoreWithAllMiddleware<ActorState<A>>;
|
|
52
52
|
export type CallActorMethod<A = BaseActor> = <M extends FunctionName<A> = FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
|
|
53
53
|
export type MethodAttributes<A = BaseActor> = Record<FunctionName<A>, {
|
|
54
54
|
type: FunctionType;
|
|
@@ -8,12 +8,10 @@ export declare class AgentManager {
|
|
|
8
8
|
private _subscribers;
|
|
9
9
|
agentStore: AgentStore;
|
|
10
10
|
authStore: AuthStore;
|
|
11
|
-
private initialAgentState;
|
|
12
|
-
private initialAuthState;
|
|
13
11
|
private updateAgentState;
|
|
14
12
|
private updateAuthState;
|
|
15
13
|
constructor(options?: AgentManagerParameters);
|
|
16
|
-
|
|
14
|
+
initializeAgent: () => Promise<void>;
|
|
17
15
|
subscribeAgent: (callback: (agent: HttpAgent) => void, initialize?: boolean) => () => void;
|
|
18
16
|
unsubscribeAgent: (callback: (agent: HttpAgent) => void) => void;
|
|
19
17
|
private notifySubscribers;
|
|
@@ -26,23 +26,23 @@ const agent_1 = require("@dfinity/agent");
|
|
|
26
26
|
const helper_1 = require("../../utils/helper");
|
|
27
27
|
const auth_client_1 = require("@dfinity/auth-client");
|
|
28
28
|
const constants_1 = require("../../utils/constants");
|
|
29
|
+
const AGENT_INITIAL_STATE = {
|
|
30
|
+
initialized: false,
|
|
31
|
+
initializing: false,
|
|
32
|
+
error: undefined,
|
|
33
|
+
network: undefined,
|
|
34
|
+
};
|
|
35
|
+
const AUTH_INITIAL_STATE = {
|
|
36
|
+
identity: null,
|
|
37
|
+
authenticating: false,
|
|
38
|
+
authenticated: false,
|
|
39
|
+
error: undefined,
|
|
40
|
+
};
|
|
29
41
|
class AgentManager {
|
|
30
42
|
constructor(options) {
|
|
31
43
|
var _a;
|
|
32
44
|
this._auth = null;
|
|
33
45
|
this._subscribers = [];
|
|
34
|
-
this.initialAgentState = {
|
|
35
|
-
initialized: false,
|
|
36
|
-
initializing: false,
|
|
37
|
-
error: undefined,
|
|
38
|
-
network: "ic",
|
|
39
|
-
};
|
|
40
|
-
this.initialAuthState = {
|
|
41
|
-
identity: null,
|
|
42
|
-
authenticating: false,
|
|
43
|
-
authenticated: false,
|
|
44
|
-
error: undefined,
|
|
45
|
-
};
|
|
46
46
|
this.updateAgentState = (newState, action) => {
|
|
47
47
|
this.agentStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
|
|
48
48
|
};
|
|
@@ -155,15 +155,23 @@ class AgentManager {
|
|
|
155
155
|
this.getAgentState = () => {
|
|
156
156
|
return this.agentStore.getState();
|
|
157
157
|
};
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
// @ts-expect-error: Overrides subscribe method signature
|
|
159
|
+
this.subscribeAgentState = (selectorOrListener, listener, options) => {
|
|
160
|
+
if (listener) {
|
|
161
|
+
return this.agentStore.subscribe(selectorOrListener, listener, options);
|
|
162
|
+
}
|
|
163
|
+
return this.agentStore.subscribe(selectorOrListener);
|
|
160
164
|
};
|
|
161
165
|
// auth store
|
|
162
166
|
this.getAuthState = () => {
|
|
163
167
|
return this.authStore.getState();
|
|
164
168
|
};
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
// @ts-expect-error: Overrides subscribe method signature
|
|
170
|
+
this.subscribeAuthState = (selectorOrListener, listener, options) => {
|
|
171
|
+
if (listener) {
|
|
172
|
+
return this.authStore.subscribe(selectorOrListener, listener, options);
|
|
173
|
+
}
|
|
174
|
+
return this.authStore.subscribe(selectorOrListener);
|
|
167
175
|
};
|
|
168
176
|
this.getAuth = () => {
|
|
169
177
|
return this._auth;
|
|
@@ -175,7 +183,7 @@ class AgentManager {
|
|
|
175
183
|
const identity = this.authStore.getState().identity;
|
|
176
184
|
return identity ? identity.getPrincipal() : null;
|
|
177
185
|
};
|
|
178
|
-
const _b = options || {}, { withDevtools, port = 4943, withLocalEnv, withProcessEnv } = _b, agentOptions = __rest(_b, ["withDevtools", "port", "withLocalEnv", "withProcessEnv"]);
|
|
186
|
+
const _b = options || {}, { withDevtools, port = 4943, withLocalEnv, withProcessEnv, initializeOnCreate = true } = _b, agentOptions = __rest(_b, ["withDevtools", "port", "withLocalEnv", "withProcessEnv", "initializeOnCreate"]);
|
|
179
187
|
if (withProcessEnv) {
|
|
180
188
|
const processNetwork = (0, helper_1.getProcessEnvNetwork)();
|
|
181
189
|
agentOptions.host =
|
|
@@ -187,18 +195,20 @@ class AgentManager {
|
|
|
187
195
|
else {
|
|
188
196
|
agentOptions.host = (_a = agentOptions.host) !== null && _a !== void 0 ? _a : constants_1.IC_HOST_NETWORK_URI;
|
|
189
197
|
}
|
|
190
|
-
this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(
|
|
198
|
+
this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(AGENT_INITIAL_STATE, {
|
|
191
199
|
withDevtools,
|
|
192
200
|
name: "reactor-agent",
|
|
193
201
|
store: "agent",
|
|
194
202
|
});
|
|
195
|
-
this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(
|
|
203
|
+
this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(AUTH_INITIAL_STATE, {
|
|
196
204
|
withDevtools,
|
|
197
205
|
name: "reactor-agent",
|
|
198
206
|
store: "auth",
|
|
199
207
|
});
|
|
200
208
|
this._agent = agent_1.HttpAgent.createSync(agentOptions);
|
|
201
|
-
|
|
209
|
+
if (initializeOnCreate) {
|
|
210
|
+
this.initializeAgent();
|
|
211
|
+
}
|
|
202
212
|
}
|
|
203
213
|
}
|
|
204
214
|
exports.AgentManager = AgentManager;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
|
|
2
2
|
import type { AuthClient } from "@dfinity/auth-client";
|
|
3
|
-
import type {
|
|
3
|
+
import type { StoreWithAllMiddleware } from "../../types";
|
|
4
4
|
export { HttpAgentOptions, AuthClient, Identity };
|
|
5
5
|
export interface AgentManagerParameters extends HttpAgentOptions {
|
|
6
6
|
port?: number;
|
|
7
7
|
withLocalEnv?: boolean;
|
|
8
8
|
withDevtools?: boolean;
|
|
9
9
|
withProcessEnv?: boolean;
|
|
10
|
+
initializeOnCreate?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export interface AgentState {
|
|
12
13
|
initialized: boolean;
|
|
13
14
|
initializing: boolean;
|
|
14
15
|
error: Error | undefined;
|
|
15
|
-
network: string;
|
|
16
|
+
network: string | undefined;
|
|
16
17
|
}
|
|
17
18
|
export interface AuthState {
|
|
18
19
|
identity: Identity | null;
|
|
@@ -23,5 +24,5 @@ export interface AuthState {
|
|
|
23
24
|
export interface UpdateAgentParameters extends HttpAgentOptions {
|
|
24
25
|
agent?: HttpAgent;
|
|
25
26
|
}
|
|
26
|
-
export type AgentStore =
|
|
27
|
-
export type AuthStore =
|
|
27
|
+
export type AgentStore = StoreWithAllMiddleware<AgentState>;
|
|
28
|
+
export type AuthStore = StoreWithAllMiddleware<AuthState>;
|
package/dist/classes/types.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
export * from "./agent/types";
|
|
2
2
|
export * from "./actor/types";
|
|
3
3
|
export * from "./adapter/types";
|
|
4
|
-
import type
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { type StateCreator, type StoreApi, type StoreMutatorIdentifier, type Mutate } from "zustand";
|
|
5
|
+
export type StoreWithMiddleware<T, Mis extends [StoreMutatorIdentifier, unknown][] = [], Mos extends [StoreMutatorIdentifier, unknown][] = []> = StateCreator<T, Mis, Mos>;
|
|
6
|
+
export type StoreApiWithMiddleware<T, Mos extends [StoreMutatorIdentifier, unknown][] = []> = Mutate<StoreApi<T>, Mos>;
|
|
7
|
+
export type WithDevtools = ["zustand/devtools", never];
|
|
8
|
+
export type WithSubscribeSelector = ["zustand/subscribeWithSelector", never];
|
|
9
|
+
export type StoreWithAllMiddleware<T> = StoreApiWithMiddleware<T, [
|
|
10
|
+
WithDevtools,
|
|
11
|
+
WithSubscribeSelector
|
|
12
|
+
]>;
|
|
13
|
+
export type StoreWithSubscribeOnly<T> = StoreApiWithMiddleware<T, [
|
|
14
|
+
WithSubscribeSelector
|
|
15
|
+
]>;
|
package/dist/classes/types.js
CHANGED
|
@@ -14,6 +14,7 @@ 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
|
+
// Re-export existing types
|
|
17
18
|
__exportStar(require("./agent/types"), exports);
|
|
18
19
|
__exportStar(require("./actor/types"), exports);
|
|
19
20
|
__exportStar(require("./adapter/types"), exports);
|
|
@@ -6,11 +6,3 @@ export declare const DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
|
|
|
6
6
|
export declare const DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
|
|
7
7
|
export declare const IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
|
|
8
8
|
export declare const LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
|
|
9
|
-
export declare const ACTOR_INITIAL_STATE: {
|
|
10
|
-
name: string;
|
|
11
|
-
version: number;
|
|
12
|
-
methodState: {};
|
|
13
|
-
initializing: boolean;
|
|
14
|
-
initialized: boolean;
|
|
15
|
-
error: undefined;
|
|
16
|
-
};
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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.LOCAL_HOSTS = exports.REMOTE_HOSTS = void 0;
|
|
4
4
|
exports.REMOTE_HOSTS = [".github.dev", ".gitpod.io"];
|
|
5
5
|
exports.LOCAL_HOSTS = ["localhost", "127.0.0.1"];
|
|
6
6
|
exports.IC_HOST_NETWORK_URI = "https://ic0.app";
|
|
@@ -9,11 +9,3 @@ exports.DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
|
|
|
9
9
|
exports.DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
|
|
10
10
|
exports.IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
|
|
11
11
|
exports.LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
|
|
12
|
-
exports.ACTOR_INITIAL_STATE = {
|
|
13
|
-
name: "",
|
|
14
|
-
version: 0,
|
|
15
|
-
methodState: {},
|
|
16
|
-
initializing: false,
|
|
17
|
-
initialized: false,
|
|
18
|
-
error: undefined,
|
|
19
|
-
};
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DevtoolsOptions } from "zustand/middleware";
|
|
2
|
-
import {
|
|
3
|
-
import type { CompiledResult, BaseActor, CandidDefenition, IDL, StoreApiWithDevtools, ExtractOk } from "../types";
|
|
2
|
+
import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, StoreWithAllMiddleware, StoreWithSubscribeOnly } from "../types";
|
|
4
3
|
/**
|
|
5
4
|
* Creates a Zustand store with optional DevTools middleware.
|
|
6
5
|
*
|
|
@@ -8,7 +7,9 @@ import type { CompiledResult, BaseActor, CandidDefenition, IDL, StoreApiWithDevt
|
|
|
8
7
|
* @param config - Configuration options for DevTools.
|
|
9
8
|
* @returns A Zustand store with DevTools enabled if configured, otherwise a standard store.
|
|
10
9
|
*/
|
|
11
|
-
export declare function createStoreWithOptionalDevtools<T>(initialState: T, config: DevtoolsOptions
|
|
10
|
+
export declare function createStoreWithOptionalDevtools<T extends object>(initialState: T, config: DevtoolsOptions & {
|
|
11
|
+
withDevtools?: boolean;
|
|
12
|
+
}): StoreWithAllMiddleware<T> | StoreWithSubscribeOnly<T>;
|
|
12
13
|
export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
|
|
13
14
|
/**
|
|
14
15
|
* Checks if the current environment is local or development.
|
package/dist/utils/helper.js
CHANGED
|
@@ -28,14 +28,13 @@ const constants_1 = require("./constants");
|
|
|
28
28
|
* @returns A Zustand store with DevTools enabled if configured, otherwise a standard store.
|
|
29
29
|
*/
|
|
30
30
|
function createStoreWithOptionalDevtools(initialState, config) {
|
|
31
|
+
const createState = () => initialState;
|
|
31
32
|
if (config.withDevtools) {
|
|
32
|
-
return (0, zustand_1.createStore)((0, middleware_1.
|
|
33
|
+
return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)((0, middleware_1.devtools)(createState, Object.assign({ serialize: {
|
|
33
34
|
replacer: (_, value) => typeof value === "bigint" ? value.toString() : value,
|
|
34
|
-
} }, config)));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return (0, zustand_1.createStore)(() => initialState);
|
|
35
|
+
} }, config))));
|
|
38
36
|
}
|
|
37
|
+
return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)(createState));
|
|
39
38
|
}
|
|
40
39
|
const importCandidDefinition = (candidDef) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
40
|
if (typeof window === "undefined") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.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",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@dfinity/principal": ">=2.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ic-reactor/parser": "^0.4.
|
|
45
|
+
"@ic-reactor/parser": "^0.4.4",
|
|
46
46
|
"@types/node": "^22.9.0",
|
|
47
47
|
"ts-loader": "^9.5.1",
|
|
48
48
|
"webpack": "^5.96.1"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=10"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "6110fb3f75c7927086d828c912855589e2a33eb3"
|
|
64
64
|
}
|