@ic-reactor/core 1.12.0 → 1.14.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 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.11.0/ic-reactor-core.min.js"></script>
22
+ <script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.12.0/ic-reactor-core.min.js"></script>
23
23
  ```
24
24
 
25
25
  ### Using `createReactorCore`
@@ -14,11 +14,7 @@ export declare class ActorManager<A = BaseActor> {
14
14
  visitFunction: VisitService<A>;
15
15
  methodAttributes: MethodAttributes<A>;
16
16
  private updateState;
17
- updateMethodState: (method: FunctionName<A>, hash: string, newState: Partial<{
18
- data: ActorMethodReturnType<A[FunctionName<A>]> | undefined;
19
- loading: boolean;
20
- error: Error | undefined;
21
- }>) => void;
17
+ updateMethodState: (method: FunctionName<A>, hash: string, newState: Partial<ActorMethodState<A, typeof method>[string]>) => void;
22
18
  constructor(actorConfig: ActorManagerParameters);
23
19
  initialize: (options?: UpdateAgentParameters) => Promise<void>;
24
20
  extractInterface: () => IDL.ServiceClass;
@@ -23,12 +23,13 @@ class ActorManager {
23
23
  this.actorStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
24
24
  };
25
25
  this.updateMethodState = (method, hash, newState) => {
26
+ const actionName = `${method}:${newState.error ? "error" : newState.loading ? "loading" : "loaded"}`;
26
27
  this.actorStore.setState((state) => {
27
28
  const methodState = state.methodState[method] || {};
28
29
  const currentMethodState = methodState[hash] || DEFAULT_STATE;
29
30
  const updatedMethodState = Object.assign(Object.assign({}, methodState), { [hash]: Object.assign(Object.assign({}, currentMethodState), newState) });
30
31
  return Object.assign(Object.assign({}, state), { methodState: Object.assign(Object.assign({}, state.methodState), { [method]: updatedMethodState }) });
31
- }, false, method);
32
+ }, false, actionName);
32
33
  };
33
34
  this.initialize = (options) => __awaiter(this, void 0, void 0, function* () {
34
35
  yield this._agentManager.updateAgent(options);
@@ -122,9 +122,9 @@ class AgentManager {
122
122
  yield this._auth.login(Object.assign(Object.assign({ identityProvider: this.getIsLocal()
123
123
  ? constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER
124
124
  : constants_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: (msg) => __awaiter(this, void 0, void 0, function* () {
125
- var _c;
125
+ var _a;
126
126
  yield this.authenticate();
127
- (_c = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _c === void 0 ? void 0 : _c.call(options, msg);
127
+ (_a = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _a === void 0 ? void 0 : _a.call(options, msg);
128
128
  }) }));
129
129
  });
130
130
  this.logout = (options) => __awaiter(this, void 0, void 0, function* () {
@@ -150,15 +150,7 @@ class AgentManager {
150
150
  };
151
151
  this.getNetwork = () => {
152
152
  const hostname = this.getAgentHostName();
153
- if (constants_1.LOCAL_HOSTS.some((host) => hostname.endsWith(host))) {
154
- return "local";
155
- }
156
- else if (constants_1.REMOTE_HOSTS.some((host) => hostname.endsWith(host))) {
157
- return "remote";
158
- }
159
- else {
160
- return "ic";
161
- }
153
+ return (0, helper_1.getNetworkByHostname)(hostname);
162
154
  };
163
155
  this.getAgentState = () => {
164
156
  return this.agentStore.getState();
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { ActorMethod, ActorSubclass, HttpAgentOptions, HttpAgent, Identity, CallConfig } from "@dfinity/agent";
3
2
  import type { Principal } from "@dfinity/principal";
4
3
  import type { IDL } from "@dfinity/candid";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSimpleHash = exports.stringifyStable = void 0;
3
+ exports.stringifyStable = stringifyStable;
4
+ exports.createSimpleHash = createSimpleHash;
4
5
  /**
5
6
  * Creates a stable string representation of any JavaScript value
6
7
  * Handles circular references and maintains consistent object key ordering
@@ -46,7 +47,6 @@ function stringifyStable(value) {
46
47
  return value;
47
48
  });
48
49
  }
49
- exports.stringifyStable = stringifyStable;
50
50
  /**
51
51
  * Creates a simple numeric hash code and returns it as a hex string
52
52
  * @param value - Any JavaScript value
@@ -68,4 +68,3 @@ function createSimpleHash(value, length = 8) {
68
68
  // Pad with zeros to match desired length
69
69
  return hexString.padStart(length, "0");
70
70
  }
71
- exports.createSimpleHash = createSimpleHash;
@@ -8,6 +8,7 @@ export declare function createStoreWithOptionalDevtools<T>(initialState: T, conf
8
8
  export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
9
9
  export declare const isInLocalOrDevelopment: () => boolean;
10
10
  export declare const getProcessEnvNetwork: () => string;
11
+ export declare function getNetworkByHostname(hostname: string): "local" | "remote" | "ic";
11
12
  export declare function isQuery(func: IDL.FuncClass): boolean;
12
13
  export declare const jsonToString: (json: unknown, space?: number) => string;
13
14
  export declare const generateRequestHash: (args?: unknown[]) => `0x${string}`;
@@ -9,11 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createCompiledResult = exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.isQuery = exports.getProcessEnvNetwork = exports.isInLocalOrDevelopment = exports.importCandidDefinition = exports.createStoreWithOptionalDevtools = void 0;
12
+ exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.getProcessEnvNetwork = exports.isInLocalOrDevelopment = exports.importCandidDefinition = void 0;
13
+ exports.createStoreWithOptionalDevtools = createStoreWithOptionalDevtools;
14
+ exports.getNetworkByHostname = getNetworkByHostname;
15
+ exports.isQuery = isQuery;
16
+ exports.createCompiledResult = createCompiledResult;
13
17
  const agent_1 = require("@dfinity/agent");
14
18
  const middleware_1 = require("zustand/middleware");
15
19
  const vanilla_1 = require("zustand/vanilla");
16
20
  const hash_1 = require("./hash");
21
+ const constants_1 = require("./constants");
17
22
  function createStoreWithOptionalDevtools(initialState, config) {
18
23
  if (config.withDevtools) {
19
24
  return (0, vanilla_1.createStore)((0, middleware_1.devtools)(() => initialState, Object.assign({ serialize: {
@@ -24,7 +29,6 @@ function createStoreWithOptionalDevtools(initialState, config) {
24
29
  return (0, vanilla_1.createStore)(() => initialState);
25
30
  }
26
31
  }
27
- exports.createStoreWithOptionalDevtools = createStoreWithOptionalDevtools;
28
32
  const importCandidDefinition = (candidDef) => __awaiter(void 0, void 0, void 0, function* () {
29
33
  if (typeof window === "undefined") {
30
34
  // Node.js environment
@@ -66,11 +70,21 @@ const getProcessEnvNetwork = () => {
66
70
  return (_a = process.env.DFX_NETWORK) !== null && _a !== void 0 ? _a : "ic";
67
71
  };
68
72
  exports.getProcessEnvNetwork = getProcessEnvNetwork;
73
+ function getNetworkByHostname(hostname) {
74
+ if (constants_1.LOCAL_HOSTS.some((host) => hostname.endsWith(host))) {
75
+ return "local";
76
+ }
77
+ else if (constants_1.REMOTE_HOSTS.some((host) => hostname.endsWith(host))) {
78
+ return "remote";
79
+ }
80
+ else {
81
+ return "ic";
82
+ }
83
+ }
69
84
  function isQuery(func) {
70
85
  return (func.annotations.includes("query") ||
71
86
  func.annotations.includes("composite_query"));
72
87
  }
73
- exports.isQuery = isQuery;
74
88
  const jsonToString = (json, space = 2) => {
75
89
  return JSON.stringify(json, (_, value) => (typeof value === "bigint" ? `BigInt(${value})` : value), space);
76
90
  };
@@ -126,4 +140,3 @@ function createCompiledResult(result) {
126
140
  };
127
141
  }
128
142
  }
129
- exports.createCompiledResult = createCompiledResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.12.0",
3
+ "version": "1.14.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",
@@ -25,23 +25,24 @@
25
25
  "url": "https://github.com/b3hr4d/ic-reactor/issues"
26
26
  },
27
27
  "homepage": "https://b3pay.github.io/ic-reactor/modules/core.html",
28
- "peerDependencies": {
29
- "@dfinity/agent": ">=2.1.2",
30
- "@dfinity/auth-client": ">=2.1.2",
31
- "@dfinity/candid": ">=2.1.2",
32
- "@dfinity/identity": ">=2.1.2",
33
- "@dfinity/principal": ">=2.1.2"
34
- },
35
28
  "dependencies": {
36
- "@dfinity/agent": ">=2.0.0",
37
- "@dfinity/auth-client": ">=2.0.0",
38
- "@dfinity/candid": ">=2.0.0",
39
- "@dfinity/identity": ">=2.0.0",
40
- "@dfinity/principal": ">=2.0.0",
29
+ "@dfinity/agent": ">=2.1",
30
+ "@dfinity/auth-client": ">=2.1",
31
+ "@dfinity/candid": ">=2.1",
32
+ "@dfinity/identity": ">=2.1",
33
+ "@dfinity/principal": ">=2.1",
41
34
  "zustand": "4.5.5"
42
35
  },
36
+ "peerDependencies": {
37
+ "@dfinity/agent": ">=2.1",
38
+ "@dfinity/auth-client": ">=2.1",
39
+ "@dfinity/candid": ">=2.1",
40
+ "@dfinity/identity": ">=2.1",
41
+ "@dfinity/principal": ">=2.1"
42
+ },
43
43
  "devDependencies": {
44
- "@ic-reactor/parser": "^0.4.1"
44
+ "@ic-reactor/parser": "^0.4.3",
45
+ "@types/node": "^22.9.0"
45
46
  },
46
47
  "scripts": {
47
48
  "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
@@ -56,5 +57,5 @@
56
57
  "engines": {
57
58
  "node": ">=10"
58
59
  },
59
- "gitHead": "8f8b4be20c0c89a58110e782f0d613cef9e7a04f"
60
+ "gitHead": "fee4b92574ba3fd295e28fb49105f0a07c6fdb61"
60
61
  }