@ic-reactor/react 2.0.0 → 3.0.0-beta.1

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.
Files changed (155) hide show
  1. package/README.md +105 -79
  2. package/dist/createActorHooks.d.ts +39 -0
  3. package/dist/createActorHooks.d.ts.map +1 -0
  4. package/dist/createActorHooks.js +30 -0
  5. package/dist/createActorHooks.js.map +1 -0
  6. package/dist/createAuthHooks.d.ts +37 -0
  7. package/dist/createAuthHooks.d.ts.map +1 -0
  8. package/dist/createAuthHooks.js +94 -0
  9. package/dist/createAuthHooks.js.map +1 -0
  10. package/dist/createInfiniteQuery.d.ts +129 -0
  11. package/dist/createInfiniteQuery.d.ts.map +1 -0
  12. package/dist/createInfiniteQuery.js +160 -0
  13. package/dist/createInfiniteQuery.js.map +1 -0
  14. package/dist/createMutation.d.ts +19 -0
  15. package/dist/createMutation.d.ts.map +1 -0
  16. package/dist/createMutation.js +98 -0
  17. package/dist/createMutation.js.map +1 -0
  18. package/dist/createQuery.d.ts +20 -0
  19. package/dist/createQuery.d.ts.map +1 -0
  20. package/dist/createQuery.js +111 -0
  21. package/dist/createQuery.js.map +1 -0
  22. package/dist/createSuspenseInfiniteQuery.d.ts +122 -0
  23. package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -0
  24. package/dist/createSuspenseInfiniteQuery.js +160 -0
  25. package/dist/createSuspenseInfiniteQuery.js.map +1 -0
  26. package/dist/createSuspenseQuery.d.ts +25 -0
  27. package/dist/createSuspenseQuery.d.ts.map +1 -0
  28. package/dist/createSuspenseQuery.js +116 -0
  29. package/dist/createSuspenseQuery.js.map +1 -0
  30. package/dist/hooks/index.d.ts +6 -2
  31. package/dist/hooks/index.d.ts.map +1 -0
  32. package/dist/hooks/index.js +6 -18
  33. package/dist/hooks/index.js.map +1 -0
  34. package/dist/hooks/useActorInfiniteQuery.d.ts +37 -0
  35. package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -0
  36. package/dist/hooks/useActorInfiniteQuery.js +33 -0
  37. package/dist/hooks/useActorInfiniteQuery.js.map +1 -0
  38. package/dist/hooks/useActorMutation.d.ts +23 -0
  39. package/dist/hooks/useActorMutation.d.ts.map +1 -0
  40. package/dist/hooks/useActorMutation.js +39 -0
  41. package/dist/hooks/useActorMutation.js.map +1 -0
  42. package/dist/hooks/useActorQuery.d.ts +32 -0
  43. package/dist/hooks/useActorQuery.d.ts.map +1 -0
  44. package/dist/hooks/useActorQuery.js +35 -0
  45. package/dist/hooks/useActorQuery.js.map +1 -0
  46. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +36 -0
  47. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -0
  48. package/dist/hooks/useActorSuspenseInfiniteQuery.js +33 -0
  49. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -0
  50. package/dist/hooks/useActorSuspenseQuery.d.ts +32 -0
  51. package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -0
  52. package/dist/hooks/useActorSuspenseQuery.js +36 -0
  53. package/dist/hooks/useActorSuspenseQuery.js.map +1 -0
  54. package/dist/index.d.ts +11 -8
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +17 -49
  57. package/dist/index.js.map +1 -0
  58. package/dist/types.d.ts +232 -13
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +5 -22
  61. package/dist/types.js.map +1 -0
  62. package/dist/validation.d.ts +131 -0
  63. package/dist/validation.d.ts.map +1 -0
  64. package/dist/validation.js +125 -0
  65. package/dist/validation.js.map +1 -0
  66. package/package.json +70 -35
  67. package/LICENSE.md +0 -8
  68. package/dist/context/actor/create.d.ts +0 -63
  69. package/dist/context/actor/create.js +0 -119
  70. package/dist/context/actor/hooks/useActorInterface.d.ts +0 -4
  71. package/dist/context/actor/hooks/useActorInterface.js +0 -10
  72. package/dist/context/actor/hooks/useActorState.d.ts +0 -21
  73. package/dist/context/actor/hooks/useActorState.js +0 -25
  74. package/dist/context/actor/hooks/useActorStore.d.ts +0 -32
  75. package/dist/context/actor/hooks/useActorStore.js +0 -36
  76. package/dist/context/actor/hooks/useInitializeActor.d.ts +0 -6
  77. package/dist/context/actor/hooks/useInitializeActor.js +0 -10
  78. package/dist/context/actor/hooks/useMethod.d.ts +0 -29
  79. package/dist/context/actor/hooks/useMethod.js +0 -34
  80. package/dist/context/actor/hooks/useMethodAttributes.d.ts +0 -7
  81. package/dist/context/actor/hooks/useMethodAttributes.js +0 -11
  82. package/dist/context/actor/hooks/useMethodNames.d.ts +0 -7
  83. package/dist/context/actor/hooks/useMethodNames.js +0 -11
  84. package/dist/context/actor/hooks/useQueryCall.d.ts +0 -28
  85. package/dist/context/actor/hooks/useQueryCall.js +0 -33
  86. package/dist/context/actor/hooks/useUpdateCall.d.ts +0 -29
  87. package/dist/context/actor/hooks/useUpdateCall.js +0 -34
  88. package/dist/context/actor/hooks/useVisitMethod.d.ts +0 -8
  89. package/dist/context/actor/hooks/useVisitMethod.js +0 -13
  90. package/dist/context/actor/hooks/useVisitService.d.ts +0 -8
  91. package/dist/context/actor/hooks/useVisitService.js +0 -13
  92. package/dist/context/actor/index.d.ts +0 -16
  93. package/dist/context/actor/index.js +0 -33
  94. package/dist/context/actor/provider.d.ts +0 -71
  95. package/dist/context/actor/provider.js +0 -75
  96. package/dist/context/actor/types.d.ts +0 -35
  97. package/dist/context/actor/types.js +0 -2
  98. package/dist/context/adapter/create.d.ts +0 -2
  99. package/dist/context/adapter/create.js +0 -102
  100. package/dist/context/adapter/hooks/useCandidAdapter.d.ts +0 -23
  101. package/dist/context/adapter/hooks/useCandidAdapter.js +0 -27
  102. package/dist/context/adapter/hooks/useCandidEvaluation.d.ts +0 -5
  103. package/dist/context/adapter/hooks/useCandidEvaluation.js +0 -9
  104. package/dist/context/adapter/index.d.ts +0 -6
  105. package/dist/context/adapter/index.js +0 -24
  106. package/dist/context/adapter/provider.d.ts +0 -23
  107. package/dist/context/adapter/provider.js +0 -27
  108. package/dist/context/adapter/types.d.ts +0 -52
  109. package/dist/context/adapter/types.js +0 -2
  110. package/dist/context/agent/create.d.ts +0 -74
  111. package/dist/context/agent/create.js +0 -104
  112. package/dist/context/agent/hooks/useAgent.d.ts +0 -14
  113. package/dist/context/agent/hooks/useAgent.js +0 -18
  114. package/dist/context/agent/hooks/useAgentManager.d.ts +0 -14
  115. package/dist/context/agent/hooks/useAgentManager.js +0 -18
  116. package/dist/context/agent/hooks/useAgentState.d.ts +0 -21
  117. package/dist/context/agent/hooks/useAgentState.js +0 -25
  118. package/dist/context/agent/hooks/useAuth.d.ts +0 -57
  119. package/dist/context/agent/hooks/useAuth.js +0 -61
  120. package/dist/context/agent/hooks/useAuthState.d.ts +0 -19
  121. package/dist/context/agent/hooks/useAuthState.js +0 -23
  122. package/dist/context/agent/hooks/useUserPrincipal.d.ts +0 -17
  123. package/dist/context/agent/hooks/useUserPrincipal.js +0 -21
  124. package/dist/context/agent/index.d.ts +0 -12
  125. package/dist/context/agent/index.js +0 -29
  126. package/dist/context/agent/provider.d.ts +0 -28
  127. package/dist/context/agent/provider.js +0 -32
  128. package/dist/context/agent/types.d.ts +0 -17
  129. package/dist/context/agent/types.js +0 -2
  130. package/dist/core.d.ts +0 -1
  131. package/dist/core.js +0 -9
  132. package/dist/createReactor.d.ts +0 -49
  133. package/dist/createReactor.js +0 -69
  134. package/dist/helpers/actorHooks.d.ts +0 -18
  135. package/dist/helpers/actorHooks.js +0 -283
  136. package/dist/helpers/agentHooks.d.ts +0 -3
  137. package/dist/helpers/agentHooks.js +0 -22
  138. package/dist/helpers/authHooks.d.ts +0 -2
  139. package/dist/helpers/authHooks.js +0 -120
  140. package/dist/helpers/extractActorContext.d.ts +0 -4
  141. package/dist/helpers/extractActorContext.js +0 -44
  142. package/dist/helpers/extractAgentContext.d.ts +0 -28
  143. package/dist/helpers/extractAgentContext.js +0 -59
  144. package/dist/helpers/index.d.ts +0 -5
  145. package/dist/helpers/index.js +0 -21
  146. package/dist/helpers/types.d.ts +0 -222
  147. package/dist/helpers/types.js +0 -2
  148. package/dist/hooks/types.d.ts +0 -22
  149. package/dist/hooks/types.js +0 -2
  150. package/dist/hooks/useActor.d.ts +0 -67
  151. package/dist/hooks/useActor.js +0 -197
  152. package/dist/hooks/useActorManager.d.ts +0 -68
  153. package/dist/hooks/useActorManager.js +0 -75
  154. package/dist/utils.d.ts +0 -1
  155. package/dist/utils.js +0 -17
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAuth = void 0;
4
- const __1 = require("..");
5
- /**
6
- * `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
7
- * It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
8
- *
9
- * @param options - An optional object containing the following properties:
10
- * - `onAuthentication`: Callback function triggered before authentication starts.
11
- * - `onAuthenticationSuccess`: Callback function triggered on successful authentication, receives the authenticated `Identity`.
12
- * - `onAuthenticationFailure`: Callback function triggered on authentication failure, receives the error.
13
- * - `onLogin`: Callback function triggered before the login process starts.
14
- * - `onLoginSuccess`: Callback function triggered on successful login, receives the user's `Principal`.
15
- * - `onLoginError`: Callback function triggered on login error, receives the error.
16
- * - `onLoggedOut`: Callback function triggered after logging out.
17
- *
18
- * @returns An object containing the following properties:
19
- * - `authenticated`: Boolean indicating if the user is currently authenticated.
20
- * - `authenticating`: Boolean indicating if an authentication process is currently underway.
21
- * - `identity`: The authenticated user's `Identity`, if available.
22
- * - `error`: Any error that occurred during the authentication process.
23
- * - `login`: Function to initiate the login process, optionally accepting `LoginParameters`.
24
- * - `logout`: Function to log the user out, optionally accepting `LogoutParameters`.
25
- * - `authenticate`: Function to authenticate the user, internally used by `login` and `logout`.
26
- * - `loginLoading`: Boolean indicating if a login operation is in progress.
27
- * - `loginError`: Error object if an error occurred during the login process.
28
- *
29
- * Usage:
30
- * This hook can be used to add authentication functionality to your IC application components, handling user login, logout, and authentication state management seamlessly.
31
- *
32
- * Example:
33
- * ```jsx
34
- * const YourComponent = () => {
35
- * const { login, logout, authenticated, identity, loginError } = useAuth({
36
- * onLoginSuccess: (principal) => console.log(`Logged in as ${principal}`),
37
- * onLoginError: (error) => console.error(`Login failed: ${error.message}`),
38
- * });
39
- *
40
- * if (loginError) {
41
- * return <div>Error logging in: {loginError.message}</div>;
42
- * }
43
- *
44
- * return (
45
- * <div>
46
- * {authenticated ? (
47
- * <>
48
- * <div>Authenticated as {identity.getPrincipal().toText()}</div>
49
- * <button onClick={() => logout()}>Logout</button>
50
- * </>
51
- * ) : (
52
- * <button onClick={() => login()}>Login</button>
53
- * )}
54
- * </div>
55
- * );
56
- * };
57
- * ```
58
- *
59
- * This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
60
- */
61
- exports.useAuth = __1.AgentHooks.useAuth;
@@ -1,19 +0,0 @@
1
- /**
2
- * Accesses the current authentication state.
3
- *
4
- * @example
5
- * ```jsx
6
- * function AuthStateComponent() {
7
- * const { authenticated, authenticating, identity, error } = useAuthState();
8
- *
9
- * return (
10
- * <div>
11
- * {authenticating ? 'Authenticating...' : ''}
12
- * {error ? `Error: ${error.message}` : ''}
13
- * {authenticated ? `User ${identity?.getPrincipal()} is authenticated.` : 'User is not authenticated.'}
14
- * </div>
15
- * );
16
- * }
17
- * ```
18
- */
19
- export declare const useAuthState: () => import("@ic-reactor/core/dist/types").AuthState;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAuthState = void 0;
4
- const __1 = require("..");
5
- /**
6
- * Accesses the current authentication state.
7
- *
8
- * @example
9
- * ```jsx
10
- * function AuthStateComponent() {
11
- * const { authenticated, authenticating, identity, error } = useAuthState();
12
- *
13
- * return (
14
- * <div>
15
- * {authenticating ? 'Authenticating...' : ''}
16
- * {error ? `Error: ${error.message}` : ''}
17
- * {authenticated ? `User ${identity?.getPrincipal()} is authenticated.` : 'User is not authenticated.'}
18
- * </div>
19
- * );
20
- * }
21
- * ```
22
- */
23
- exports.useAuthState = __1.AgentHooks.useAuthState;
@@ -1,17 +0,0 @@
1
- /**
2
- * Accesses the user's principal.
3
- *
4
- * @example
5
- * ```jsx
6
- * function UserPrincipalComponent() {
7
- * const userPrincipal = useUserPrincipal();
8
- *
9
- * return (
10
- * <div>
11
- * {userPrincipal ? `User principal: ${userPrincipal}` : 'User principal not found.'}
12
- * </div>
13
- * );
14
- * }
15
- * ```
16
- */
17
- export declare const useUserPrincipal: () => import("@dfinity/principal").Principal | undefined;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useUserPrincipal = void 0;
4
- const __1 = require("..");
5
- /**
6
- * Accesses the user's principal.
7
- *
8
- * @example
9
- * ```jsx
10
- * function UserPrincipalComponent() {
11
- * const userPrincipal = useUserPrincipal();
12
- *
13
- * return (
14
- * <div>
15
- * {userPrincipal ? `User principal: ${userPrincipal}` : 'User principal not found.'}
16
- * </div>
17
- * );
18
- * }
19
- * ```
20
- */
21
- exports.useUserPrincipal = __1.AgentHooks.useUserPrincipal;
@@ -1,12 +0,0 @@
1
- import { createAgentContext } from "./create";
2
- export { createAgentContext };
3
- /** @ignore */
4
- export declare const AgentHooks: import("./types").CreateAgentContextReturnType;
5
- export declare const AgentContext: import("react").Context<import("./types").AgentContext | null>;
6
- export * from "./provider";
7
- export * from "./hooks/useAgent";
8
- export * from "./hooks/useAgentState";
9
- export * from "./hooks/useAgentManager";
10
- export * from "./hooks/useAuth";
11
- export * from "./hooks/useAuthState";
12
- export * from "./hooks/useUserPrincipal";
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AgentContext = exports.AgentHooks = exports.createAgentContext = void 0;
18
- const create_1 = require("./create");
19
- Object.defineProperty(exports, "createAgentContext", { enumerable: true, get: function () { return create_1.createAgentContext; } });
20
- /** @ignore */
21
- exports.AgentHooks = (0, create_1.createAgentContext)();
22
- exports.AgentContext = exports.AgentHooks.AgentContext;
23
- __exportStar(require("./provider"), exports);
24
- __exportStar(require("./hooks/useAgent"), exports);
25
- __exportStar(require("./hooks/useAgentState"), exports);
26
- __exportStar(require("./hooks/useAgentManager"), exports);
27
- __exportStar(require("./hooks/useAuth"), exports);
28
- __exportStar(require("./hooks/useAuthState"), exports);
29
- __exportStar(require("./hooks/useUserPrincipal"), exports);
@@ -1,28 +0,0 @@
1
- /**
2
- * `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
3
- * It enables any child components to access and use the agent and authentication functionalities seamlessly.
4
- *
5
- * The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
6
- * create various hooks related to agent operations and authentication processes. These hooks are made available to all
7
- * child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
8
- *
9
- * @param children - Child components that can consume the context.
10
- * @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
11
- * will be created based on the provided options combined with default configuration.
12
- * @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
13
- * specified during the context creation and can include custom settings for the agent, such as identity,
14
- * host URL, etc.
15
- *
16
- * @example
17
- * Wrap your App with `AgentProvider` to provide all child components access to IC agent and authentication hooks.
18
- *
19
- * ```jsx
20
- * <AgentProvider>
21
- * <App />
22
- * </AgentProvider>
23
- * ```
24
- *
25
- * Inside `App` or any of its children, you can use the hooks provided through the context to interact with the IC,
26
- * manage authentication, and perform other agent-related tasks.
27
- */
28
- export declare const AgentProvider: import("react").FC<import("./types").AgentProviderProps>;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentProvider = void 0;
4
- const _1 = require(".");
5
- /**
6
- * `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
7
- * It enables any child components to access and use the agent and authentication functionalities seamlessly.
8
- *
9
- * The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
10
- * create various hooks related to agent operations and authentication processes. These hooks are made available to all
11
- * child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
12
- *
13
- * @param children - Child components that can consume the context.
14
- * @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
15
- * will be created based on the provided options combined with default configuration.
16
- * @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
17
- * specified during the context creation and can include custom settings for the agent, such as identity,
18
- * host URL, etc.
19
- *
20
- * @example
21
- * Wrap your App with `AgentProvider` to provide all child components access to IC agent and authentication hooks.
22
- *
23
- * ```jsx
24
- * <AgentProvider>
25
- * <App />
26
- * </AgentProvider>
27
- * ```
28
- *
29
- * Inside `App` or any of its children, you can use the hooks provided through the context to interact with the IC,
30
- * manage authentication, and perform other agent-related tasks.
31
- */
32
- exports.AgentProvider = _1.AgentHooks.AgentProvider;
@@ -1,17 +0,0 @@
1
- import type { PropsWithChildren } from "react";
2
- import type { AgentHooksReturnType, AuthHooksReturnType, AgentManager, AgentManagerParameters } from "../../types";
3
- export interface AgentContext extends AgentHooksReturnType, AuthHooksReturnType {
4
- agentManager: AgentManager;
5
- }
6
- export interface CreateAgentCotextParameters extends AgentManagerParameters {
7
- withProcessEnv?: boolean;
8
- disableAuthenticateOnMount?: boolean;
9
- }
10
- export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
11
- useAgentManager: () => AgentManager;
12
- AgentProvider: React.FC<AgentProviderProps>;
13
- AgentContext: React.Context<AgentContext | null>;
14
- }
15
- export interface AgentProviderProps extends PropsWithChildren, CreateAgentCotextParameters {
16
- agentManager?: AgentManager;
17
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/core.d.ts DELETED
@@ -1 +0,0 @@
1
- export { createReactorStore, createActorManager, createAgentManager, createCandidAdapter, createReactorCore, } from "@ic-reactor/core";
package/dist/core.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createReactorCore = exports.createCandidAdapter = exports.createAgentManager = exports.createActorManager = exports.createReactorStore = void 0;
4
- var core_1 = require("@ic-reactor/core");
5
- Object.defineProperty(exports, "createReactorStore", { enumerable: true, get: function () { return core_1.createReactorStore; } });
6
- Object.defineProperty(exports, "createActorManager", { enumerable: true, get: function () { return core_1.createActorManager; } });
7
- Object.defineProperty(exports, "createAgentManager", { enumerable: true, get: function () { return core_1.createAgentManager; } });
8
- Object.defineProperty(exports, "createCandidAdapter", { enumerable: true, get: function () { return core_1.createCandidAdapter; } });
9
- Object.defineProperty(exports, "createReactorCore", { enumerable: true, get: function () { return core_1.createReactorCore; } });
@@ -1,49 +0,0 @@
1
- import type { BaseActor, CreateReactorParameters, CreateReactorReturnType } from "./types";
2
- /**
3
- * Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application.
4
- * It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.
5
- *
6
- * @param config Configuration {@link CreateReactorParameters} for the reactor, including:
7
- * - `withProcessEnv` (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
8
- * - `withLocalEnv` (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
9
- * - `port` (optional): Port number for the local or development environment.
10
- *
11
- * @returns An object containing {@link CreateReactorReturnType} hooks and utilities:
12
- * - {@link getAgent} - Returns the current agent instance.
13
- * - {@link getVisitFunction} - Returns the visit function for the actor.
14
- * - {@link useQueryCall} - A hook for querying actor methods.
15
- * - {@link useUpdateCall} - A hook for updating actor methods.
16
- * - {@link useAuth} - A hook for managing authentication and user principal.
17
- * - {@link useActor} - A hook for managing actors and their methods.
18
- * - {@link useActorManager} - A hook for managing actor manager and its methods.
19
- * - {@link useAgentManager} - A hook for managing agent manager and its methods.
20
- * - {@link initialize} - A function to initialize the actor manager if not initialized.
21
- * - {@link useActorState} - A hook for managing actor state.
22
- * - {@link useAgent} - A hook for managing agent and its methods.
23
- * - {@link useAuthState} - A hook for managing authentication state.
24
- * - {@link useAgentState} - A hook for managing agent state.
25
- * - {@link useUserPrincipal} - A hook for managing user principal.
26
- * - {@link useVisitMethod} - A hook for visiting actor methods.
27
- *
28
- * @example
29
- * ```typescript
30
- * import { createReactor } from "@ic-reactor/react";
31
- * import type { CreateReactorParameters } from "@ic-reactor/react/dist/types";
32
- * import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"
33
- *
34
- * const config: CreateReactorParameters = {
35
- * canisterId,
36
- * idlFactory,
37
- * host: "https://localhost:8000", // IC network host |
38
- * withLocalEnv: true, // Set true for local network | one of these
39
- * withProcessEnv: true, // Use process.env to determine host |
40
- * port: 8000, // Port number for local network
41
- * };
42
- *
43
- * export type YourActor = typeof yourActor;
44
- *
45
- * export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
46
- * // Now you can use the returned hooks in your React components
47
- * ```
48
- */
49
- export declare const createReactor: <A = BaseActor>(config: CreateReactorParameters) => CreateReactorReturnType<A>;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createReactor = void 0;
4
- const core_1 = require("@ic-reactor/core");
5
- const helpers_1 = require("./helpers");
6
- /**
7
- * Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application.
8
- * It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.
9
- *
10
- * @param config Configuration {@link CreateReactorParameters} for the reactor, including:
11
- * - `withProcessEnv` (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
12
- * - `withLocalEnv` (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
13
- * - `port` (optional): Port number for the local or development environment.
14
- *
15
- * @returns An object containing {@link CreateReactorReturnType} hooks and utilities:
16
- * - {@link getAgent} - Returns the current agent instance.
17
- * - {@link getVisitFunction} - Returns the visit function for the actor.
18
- * - {@link useQueryCall} - A hook for querying actor methods.
19
- * - {@link useUpdateCall} - A hook for updating actor methods.
20
- * - {@link useAuth} - A hook for managing authentication and user principal.
21
- * - {@link useActor} - A hook for managing actors and their methods.
22
- * - {@link useActorManager} - A hook for managing actor manager and its methods.
23
- * - {@link useAgentManager} - A hook for managing agent manager and its methods.
24
- * - {@link initialize} - A function to initialize the actor manager if not initialized.
25
- * - {@link useActorState} - A hook for managing actor state.
26
- * - {@link useAgent} - A hook for managing agent and its methods.
27
- * - {@link useAuthState} - A hook for managing authentication state.
28
- * - {@link useAgentState} - A hook for managing agent state.
29
- * - {@link useUserPrincipal} - A hook for managing user principal.
30
- * - {@link useVisitMethod} - A hook for visiting actor methods.
31
- *
32
- * @example
33
- * ```typescript
34
- * import { createReactor } from "@ic-reactor/react";
35
- * import type { CreateReactorParameters } from "@ic-reactor/react/dist/types";
36
- * import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"
37
- *
38
- * const config: CreateReactorParameters = {
39
- * canisterId,
40
- * idlFactory,
41
- * host: "https://localhost:8000", // IC network host |
42
- * withLocalEnv: true, // Set true for local network | one of these
43
- * withProcessEnv: true, // Use process.env to determine host |
44
- * port: 8000, // Port number for local network
45
- * };
46
- *
47
- * export type YourActor = typeof yourActor;
48
- *
49
- * export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
50
- * // Now you can use the returned hooks in your React components
51
- * ```
52
- */
53
- const createReactor = (config) => {
54
- const actorManager = (0, core_1.createReactorStore)(config);
55
- const getVisitFunction = () => {
56
- return actorManager.visitFunction;
57
- };
58
- const getAgent = () => {
59
- return actorManager.agentManager.getAgent();
60
- };
61
- return {
62
- getAgent,
63
- getVisitFunction,
64
- ...(0, helpers_1.actorHooks)(actorManager),
65
- ...(0, helpers_1.authHooks)(actorManager.agentManager),
66
- ...(0, helpers_1.agentHooks)(actorManager.agentManager),
67
- };
68
- };
69
- exports.createReactor = createReactor;
@@ -1,18 +0,0 @@
1
- import type { ActorHooksReturnType } from "../types";
2
- import { type ActorManager, type BaseActor } from "@ic-reactor/core/dist/types";
3
- /**
4
- * Provides a set of React hooks designed for interacting with actors in an Internet Computer (IC) project using the React framework and Zustand for state management.
5
- *
6
- * @param actorManager An instance of ActorManager containing methods and properties to manage actors, including the actorStore, canisterId, visitFunction, callMethod, and initialize function.
7
- * @returns An object containing several hooks and utility functions for interacting with actors, managing state, and invoking actor methods.
8
- *
9
- * Hooks included:
10
- * - initialize: Function to initialize actor management.
11
- * - useActorState: Hook for accessing the actor's state including the canister ID.
12
- * - useVisitMethod: Hook for memoizing a method visit service for a given actor method name.
13
- * - useQueryCall: Hook specifically designed for query calls to actors with features such as automatic refetching on mount and at specified intervals.
14
- * - useUpdateCall: Hook specifically designed for update calls to actors with features such as error handling and loading state management.
15
- *
16
- * Each hook is designed to simplify the process of interacting with actors in IC projects by abstracting away the complexity of state management, error handling, and method invocation.
17
- */
18
- export declare const actorHooks: <A = BaseActor>(actorManager: ActorManager<A>) => ActorHooksReturnType<A>;