@ic-reactor/core 1.2.1 → 1.2.3

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
@@ -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.2.0/ic-reactor-core.min.js"></script>
22
+ <script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.2.2/ic-reactor-core.min.js"></script>
23
23
  ```
24
24
 
25
25
  ### Using `createReactorCore`
@@ -42,7 +42,7 @@ const { queryCall, updateCall, getPrincipal, login } =
42
42
  })
43
43
  ```
44
44
 
45
- You can find All available methods are returned from the `createReactorCore` function here: [ReactorCore](https://b3pay.github.io/ic-reactor/interfaces/core.types.ReactorCore.html)
45
+ You can find All available methods are returned from the `createReactorCore` function [here](https://b3pay.github.io/ic-reactor/interfaces/core.types.CreateReactorCoreReturnType.html).
46
46
 
47
47
  ```typescript
48
48
  // later in your code
@@ -20,6 +20,7 @@ export declare class ActorManager<A = BaseActor> {
20
20
  }>) => void;
21
21
  constructor(actorConfig: ActorManagerParameters);
22
22
  initialize: (options?: UpdateAgentParameters) => Promise<void>;
23
+ extractMethodNames: () => Array<FunctionName<A>>;
23
24
  extractService: () => VisitService<A>;
24
25
  extractInterface: () => IDL.ServiceClass;
25
26
  private initializeActor;
@@ -37,6 +37,10 @@ class ActorManager {
37
37
  this.initialize = (options) => __awaiter(this, void 0, void 0, function* () {
38
38
  yield this._agentManager.updateAgent(options);
39
39
  });
40
+ this.extractMethodNames = () => {
41
+ const iface = this.extractInterface();
42
+ return iface._fields.map((service) => service[0]);
43
+ };
40
44
  this.extractService = () => {
41
45
  const iface = this.extractInterface();
42
46
  return iface._fields.reduce((acc, service) => {
@@ -116,9 +120,12 @@ class ActorManager {
116
120
  this._subscribers.forEach((unsubscribe) => unsubscribe());
117
121
  };
118
122
  const { agentManager, canisterId, idlFactory, withVisitor = false, withDevtools = false, initializeOnCreate = true, } = actorConfig;
123
+ if (!canisterId) {
124
+ throw new Error("CanisterId is required!");
125
+ }
126
+ this._agentManager = agentManager;
119
127
  this.canisterId = canisterId;
120
128
  this._idlFactory = idlFactory;
121
- this._agentManager = agentManager;
122
129
  // Initialize stores
123
130
  this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialState, {
124
131
  withDevtools,
@@ -8,7 +8,6 @@ export declare class AgentManager {
8
8
  private _subscribers;
9
9
  agentStore: AgentStore;
10
10
  authStore: AuthStore;
11
- isLocalEnv: boolean;
12
11
  private initialAgentState;
13
12
  private initialAuthState;
14
13
  private updateAgentState;
@@ -25,6 +24,7 @@ export declare class AgentManager {
25
24
  returnTo?: string;
26
25
  }) => Promise<void>;
27
26
  getAgent: () => HttpAgent;
27
+ getIsLocal: () => boolean;
28
28
  getAgentState: AgentStore["getState"];
29
29
  subscribeAgentState: AgentStore["subscribe"];
30
30
  getAuthState: AuthStore["getState"];
@@ -48,12 +48,13 @@ class AgentManager {
48
48
  this.authStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
49
49
  };
50
50
  this.initializeAgent = () => __awaiter(this, void 0, void 0, function* () {
51
+ const isLocalEnv = this.getIsLocal();
51
52
  this.updateAgentState({
52
53
  initializing: true,
53
54
  error: undefined,
54
- network: this.isLocalEnv ? "local" : "ic",
55
+ network: isLocalEnv ? "local" : "ic",
55
56
  }, "initializing");
56
- if (this.isLocalEnv) {
57
+ if (isLocalEnv) {
57
58
  try {
58
59
  yield this._agent.fetchRootKey();
59
60
  }
@@ -83,7 +84,6 @@ class AgentManager {
83
84
  }
84
85
  else if (options) {
85
86
  this._agent = new agent_1.HttpAgent(options);
86
- this.isLocalEnv = this._agent.isLocal();
87
87
  yield this.initializeAgent();
88
88
  }
89
89
  yield this.notifySubscribers();
@@ -116,7 +116,7 @@ class AgentManager {
116
116
  if (!this._auth) {
117
117
  throw new Error("Auth client not initialized");
118
118
  }
119
- yield this._auth.login(Object.assign(Object.assign({ identityProvider: this.isLocalEnv
119
+ yield this._auth.login(Object.assign(Object.assign({ identityProvider: this.getIsLocal()
120
120
  ? constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER
121
121
  : constants_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: () => __awaiter(this, void 0, void 0, function* () {
122
122
  var _b;
@@ -135,6 +135,9 @@ class AgentManager {
135
135
  this.getAgent = () => {
136
136
  return this._agent;
137
137
  };
138
+ this.getIsLocal = () => {
139
+ return this._agent.isLocal();
140
+ };
138
141
  this.getAgentState = () => {
139
142
  return this.agentStore.getState();
140
143
  };
@@ -177,7 +180,6 @@ class AgentManager {
177
180
  store: "auth",
178
181
  });
179
182
  this._agent = new agent_1.HttpAgent(Object.assign(Object.assign({}, agentOptions), { host }));
180
- this.isLocalEnv = this._agent.isLocal();
181
183
  this.initializeAgent();
182
184
  }
183
185
  }
@@ -7,6 +7,6 @@ import { ActorManagerParameters, BaseActor } from "./types";
7
7
  * It also provides a way to interact with the actor's state.
8
8
  *
9
9
  * @category Main
10
- * @includeExample ./packages/core/README.md:262-277
10
+ * @includeExample ./packages/core/README.md:268-283
11
11
  */
12
12
  export declare const createActorManager: <A = BaseActor>(config: ActorManagerParameters) => ActorManager<A>;
@@ -9,7 +9,7 @@ const actor_1 = require("./classes/actor");
9
9
  * It also provides a way to interact with the actor's state.
10
10
  *
11
11
  * @category Main
12
- * @includeExample ./packages/core/README.md:262-277
12
+ * @includeExample ./packages/core/README.md:268-283
13
13
  */
14
14
  const createActorManager = (config) => {
15
15
  return new actor_1.ActorManager(config);
@@ -7,6 +7,6 @@ import { AgentManagerParameters } from "./types";
7
7
  * login and logout to the internet identity.
8
8
  *
9
9
  * @category Main
10
- * @includeExample ./packages/core/README.md:226-254
10
+ * @includeExample ./packages/core/README.md:232-260
11
11
  */
12
12
  export declare const createAgentManager: (config?: AgentManagerParameters) => AgentManager;
@@ -9,7 +9,7 @@ const agent_1 = require("./classes/agent");
9
9
  * login and logout to the internet identity.
10
10
  *
11
11
  * @category Main
12
- * @includeExample ./packages/core/README.md:226-254
12
+ * @includeExample ./packages/core/README.md:232-260
13
13
  */
14
14
  const createAgentManager = (config) => {
15
15
  return new agent_1.AgentManager(config);
@@ -6,6 +6,6 @@ import { CandidAdapterParameters } from "./types";
6
6
  * If both methods fail, it throws an error.
7
7
  *
8
8
  * @category Main
9
- * @includeExample ./packages/core/README.md:145-186
9
+ * @includeExample ./packages/core/README.md:151-192
10
10
  */
11
11
  export declare const createCandidAdapter: (config: CandidAdapterParameters) => CandidAdapter;
@@ -8,7 +8,7 @@ const candid_1 = require("./classes/candid");
8
8
  * If both methods fail, it throws an error.
9
9
  *
10
10
  * @category Main
11
- * @includeExample ./packages/core/README.md:145-186
11
+ * @includeExample ./packages/core/README.md:151-192
12
12
  */
13
13
  const createCandidAdapter = (config) => {
14
14
  return new candid_1.CandidAdapter(config);
@@ -5,6 +5,6 @@ import type { BaseActor, CreateReactorCoreParameters, CreateReactorCoreReturnTyp
5
5
  * Its create a new agent manager if not provided.
6
6
  *
7
7
  * @category Main
8
- * @includeExample ./packages/core/README.md:26-80
8
+ * @includeExample ./packages/core/README.md:32-86
9
9
  */
10
10
  export declare const createReactorCore: <A = BaseActor>(config: CreateReactorCoreParameters) => CreateReactorCoreReturnType<A>;
@@ -29,7 +29,7 @@ const createReactorStore_1 = require("./createReactorStore");
29
29
  * Its create a new agent manager if not provided.
30
30
  *
31
31
  * @category Main
32
- * @includeExample ./packages/core/README.md:26-80
32
+ * @includeExample ./packages/core/README.md:32-86
33
33
  */
34
34
  const createReactorCore = (config) => {
35
35
  const _a = (0, createReactorStore_1.createReactorStore)(config), { subscribeActorState, updateMethodState, callMethod, getState, agentManager } = _a, rest = __rest(_a, ["subscribeActorState", "updateMethodState", "callMethod", "getState", "agentManager"]);
@@ -6,6 +6,6 @@ import type { BaseActor, CreateReactorStoreParameters } from "./types";
6
6
  * It also creates a new actor manager with the given options.
7
7
  *
8
8
  * @category Main
9
- * @includeExample ./packages/core/README.md:194-220
9
+ * @includeExample ./packages/core/README.md:200-226
10
10
  */
11
11
  export declare const createReactorStore: <A = BaseActor>(config: CreateReactorStoreParameters) => ActorManager<A>;
@@ -21,7 +21,7 @@ const createAgentManager_1 = require("./createAgentManager");
21
21
  * It also creates a new actor manager with the given options.
22
22
  *
23
23
  * @category Main
24
- * @includeExample ./packages/core/README.md:194-220
24
+ * @includeExample ./packages/core/README.md:200-226
25
25
  */
26
26
  const createReactorStore = (config) => {
27
27
  const withLocalEnv = config.withProcessEnv
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
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": "c45e2ae6da1eee146b9e5f3178318de4d66419de"
55
+ "gitHead": "ae71ae0c7eee0ebe8a97751d4222054668a6b994"
56
56
  }