@ic-reactor/core 1.7.0 → 1.7.2

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.6.5/ic-reactor-core.min.js"></script>
22
+ <script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.7.1/ic-reactor-core.min.js"></script>
23
23
  ```
24
24
 
25
25
  ### Using `createReactorCore`
@@ -13,7 +13,6 @@ export declare class ActorManager<A = BaseActor> {
13
13
  actorStore: ActorStore<A>;
14
14
  visitFunction: VisitService<A>;
15
15
  methodAttributes: MethodAttributes<A>;
16
- private initialState;
17
16
  private updateState;
18
17
  updateMethodState: (method: FunctionName<A>, hash: string, newState: Partial<{
19
18
  data: ActorMethodReturnType<A[FunctionName<A>]> | undefined;
@@ -14,16 +14,11 @@ 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 utils_1 = require("../../utils");
17
18
  class ActorManager {
18
19
  constructor(actorConfig) {
19
20
  this._actor = null;
20
21
  this._subscribers = [];
21
- this.initialState = {
22
- methodState: {},
23
- initializing: false,
24
- initialized: false,
25
- error: undefined,
26
- };
27
22
  this.updateState = (newState, action) => {
28
23
  this.actorStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
29
24
  };
@@ -144,24 +139,24 @@ class ActorManager {
144
139
  this._unsubscribeAgent();
145
140
  this._subscribers.forEach((unsubscribe) => unsubscribe());
146
141
  };
147
- const { agentManager, canisterId, idlFactory, withVisitor = false, withDevtools = false, initializeOnCreate = true, } = actorConfig;
142
+ const { agentManager, idlFactory, canisterId, name = canisterId.toString(), withVisitor = false, withDevtools = false, initializeOnCreate = true, } = actorConfig;
148
143
  if (!canisterId) {
149
144
  throw new Error("CanisterId is required!");
150
145
  }
151
146
  this.canisterId = canisterId.toString();
152
147
  if (!idlFactory) {
153
- throw new Error("IDL factory is required!");
148
+ throw new Error("IDLFactory is required!");
154
149
  }
155
150
  this._idlFactory = idlFactory;
156
151
  this.methodAttributes = this.extractMethodAttributes();
157
152
  if (!agentManager) {
158
- throw new Error("Agent manager is required!");
153
+ throw new Error("AgentManager is required!");
159
154
  }
160
155
  this._agentManager = agentManager;
161
156
  // Initialize stores
162
- this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialState, {
157
+ this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(Object.assign(Object.assign({}, utils_1.ACTOR_INITIAL_STATE), { name }), {
163
158
  withDevtools,
164
- name: "Reactor-Actor",
159
+ name: "reactor-actor",
165
160
  store: canisterId.toString(),
166
161
  });
167
162
  this._unsubscribeAgent = this._agentManager.subscribeAgent(this.initializeActor, initializeOnCreate);
@@ -9,8 +9,9 @@ export type FunctionName<A = BaseActor> = Extract<keyof A, string>;
9
9
  export type FunctionType = "query" | "update";
10
10
  export type CanisterId = string | Principal;
11
11
  export interface ActorManagerParameters {
12
- agentManager: AgentManager;
13
12
  idlFactory: IDL.InterfaceFactory;
13
+ agentManager: AgentManager;
14
+ name?: string;
14
15
  canisterId: CanisterId;
15
16
  withVisitor?: boolean;
16
17
  withDevtools?: boolean;
@@ -40,6 +41,7 @@ export type ActorMethodType<A, M extends keyof A> = {
40
41
  withOptions: (options: CallConfig) => (...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
41
42
  };
42
43
  export type ActorState<A = BaseActor> = {
44
+ name: string;
43
45
  initialized: boolean;
44
46
  initializing: boolean;
45
47
  error: Error | undefined;
@@ -193,12 +193,12 @@ class AgentManager {
193
193
  }
194
194
  this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAgentState, {
195
195
  withDevtools,
196
- name: "Reactor-Agent",
196
+ name: "reactor-agent",
197
197
  store: "agent",
198
198
  });
199
199
  this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAuthState, {
200
200
  withDevtools,
201
- name: "Reactor-Agent",
201
+ name: "reactor-agent",
202
202
  store: "auth",
203
203
  });
204
204
  this._agent = new agent_1.HttpAgent(agentOptions);
@@ -6,3 +6,10 @@ 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
+ methodState: {};
12
+ initializing: boolean;
13
+ initialized: boolean;
14
+ error: undefined;
15
+ };
@@ -1,6 +1,6 @@
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 = exports.LOCAL_HOSTS = exports.REMOTE_HOSTS = void 0;
3
+ exports.ACTOR_INITIAL_STATE = 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,3 +9,10 @@ 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
+ methodState: {},
15
+ initializing: false,
16
+ initialized: false,
17
+ error: undefined,
18
+ };
@@ -47,15 +47,8 @@ const jsonToString = (json, space = 2) => {
47
47
  };
48
48
  exports.jsonToString = jsonToString;
49
49
  const generateRequestHash = (args = []) => {
50
- const serializedArgs = args
51
- .map((arg) => {
52
- if (typeof arg === "bigint") {
53
- return arg.toString();
54
- }
55
- return JSON.stringify(arg);
56
- })
57
- .join("|");
58
- return (0, exports.stringToHash)(serializedArgs !== null && serializedArgs !== void 0 ? serializedArgs : "");
50
+ const serializedArgs = (0, agent_1.hashValue)(args);
51
+ return `0x${(0, agent_1.toHex)(serializedArgs)}`;
59
52
  };
60
53
  exports.generateRequestHash = generateRequestHash;
61
54
  const generateHash = (field) => {
@@ -74,5 +67,5 @@ const stringToHash = (str) => {
74
67
  };
75
68
  exports.stringToHash = stringToHash;
76
69
  function toHexString(bytes) {
77
- return new Uint8Array(bytes).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
70
+ return (0, agent_1.toHex)(bytes);
78
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
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",
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=10"
58
58
  },
59
- "gitHead": "0fac1036d11ae1b2498e6568d5eff514bd657116"
59
+ "gitHead": "9b338aa4b97dc0fb2476c57253f4e274effc0cfe"
60
60
  }