@ic-reactor/react 1.0.4 → 1.0.6
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 +13 -23
- package/dist/helpers/{actor.d.ts → actorHooks.d.ts} +4 -7
- package/dist/helpers/{actor.js → actorHooks.js} +8 -15
- package/dist/helpers/agentHooks.d.ts +3 -0
- package/dist/helpers/{agent.js → agentHooks.js} +3 -3
- package/dist/helpers/authHooks.d.ts +2 -0
- package/dist/helpers/authHooks.js +123 -0
- package/dist/helpers/extractActorContext.d.ts +3 -0
- package/dist/helpers/extractActorContext.js +51 -0
- package/dist/helpers/extractAgentContext.d.ts +27 -0
- package/dist/helpers/extractAgentContext.js +56 -0
- package/dist/helpers/index.d.ts +5 -3
- package/dist/helpers/index.js +5 -3
- package/dist/helpers/types.d.ts +30 -40
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/main.d.ts +38 -2
- package/dist/main.js +39 -21
- package/dist/provider/ActorProvider.d.ts +26 -0
- package/dist/provider/ActorProvider.js +29 -0
- package/dist/provider/AgentProvider.d.ts +29 -0
- package/dist/provider/AgentProvider.js +32 -0
- package/dist/provider/actorHooks.d.ts +1 -0
- package/dist/provider/actorHooks.js +5 -0
- package/dist/provider/agentHooks.d.ts +1 -0
- package/dist/provider/agentHooks.js +5 -0
- package/dist/provider/context/actor.d.ts +64 -0
- package/dist/provider/context/actor.js +117 -0
- package/dist/provider/context/agent.d.ts +71 -0
- package/dist/provider/context/agent.js +124 -0
- package/dist/provider/hooks/actor/index.d.ts +4 -0
- package/dist/provider/hooks/actor/index.js +20 -0
- package/dist/provider/hooks/actor/useActorState.d.ts +21 -0
- package/dist/provider/hooks/actor/useActorState.js +25 -0
- package/dist/provider/hooks/actor/useQueryCall.d.ts +28 -0
- package/dist/provider/hooks/actor/useQueryCall.js +34 -0
- package/dist/provider/hooks/actor/useUpdateCall.d.ts +29 -0
- package/dist/provider/hooks/actor/useUpdateCall.js +35 -0
- package/dist/provider/hooks/actor/useVisitMethod.d.ts +8 -0
- package/dist/provider/hooks/actor/useVisitMethod.js +14 -0
- package/dist/provider/hooks/agent/index.d.ts +6 -0
- package/dist/provider/hooks/agent/index.js +22 -0
- package/dist/provider/hooks/agent/useAgent.d.ts +14 -0
- package/dist/provider/hooks/agent/useAgent.js +18 -0
- package/dist/provider/hooks/agent/useAgentManager.d.ts +15 -0
- package/dist/provider/hooks/agent/useAgentManager.js +18 -0
- package/dist/provider/hooks/agent/useAgentState.d.ts +21 -0
- package/dist/provider/hooks/agent/useAgentState.js +25 -0
- package/dist/provider/hooks/agent/useAuth.d.ts +57 -0
- package/dist/provider/hooks/agent/useAuth.js +61 -0
- package/dist/provider/hooks/agent/useAuthState.d.ts +19 -0
- package/dist/provider/hooks/agent/useAuthState.js +23 -0
- package/dist/provider/hooks/agent/useUserPrincipal.d.ts +17 -0
- package/dist/provider/hooks/agent/useUserPrincipal.js +21 -0
- package/dist/provider/hooks/index.d.ts +3 -0
- package/dist/provider/{agent → hooks}/index.js +3 -2
- package/dist/provider/hooks/types.d.ts +15 -0
- package/dist/provider/hooks/useActor.d.ts +65 -0
- package/dist/{hooks/useReactor.js → provider/hooks/useActor.js} +53 -29
- package/dist/provider/index.d.ts +5 -2
- package/dist/provider/index.js +8 -2
- package/dist/provider/types.d.ts +27 -0
- package/dist/{hooks/index.js → provider/types.js} +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/types.js +2 -4
- package/package.json +3 -3
- package/dist/helpers/agent.d.ts +0 -3
- package/dist/helpers/auth.d.ts +0 -3
- package/dist/helpers/auth.js +0 -108
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/types.d.ts +0 -19
- package/dist/hooks/useReactor.d.ts +0 -41
- package/dist/provider/actor/context.d.ts +0 -20
- package/dist/provider/actor/context.js +0 -184
- package/dist/provider/actor/index.d.ts +0 -3
- package/dist/provider/actor/index.js +0 -9
- package/dist/provider/actor/types.d.ts +0 -21
- package/dist/provider/actor/types.js +0 -2
- package/dist/provider/agent/context.d.ts +0 -7
- package/dist/provider/agent/context.js +0 -56
- package/dist/provider/agent/hooks.d.ts +0 -12
- package/dist/provider/agent/hooks.js +0 -43
- package/dist/provider/agent/index.d.ts +0 -2
- package/dist/provider/agent/types.d.ts +0 -12
- package/dist/provider/agent/types.js +0 -2
- /package/dist/{hooks → provider/hooks}/types.js +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
__exportStar(require("./useActorState"), exports);
|
|
18
|
+
__exportStar(require("./useQueryCall"), exports);
|
|
19
|
+
__exportStar(require("./useUpdateCall"), exports);
|
|
20
|
+
__exportStar(require("./useVisitMethod"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for accessing the current state of the actor, including the canister ID.
|
|
3
|
+
*
|
|
4
|
+
* @returns An object containing the current state of the actor from Zustand's store and the canister ID.
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* function ActorStateComponent() {
|
|
8
|
+
* const { canisterId, initializing, error, initialized } = useActorState();
|
|
9
|
+
*
|
|
10
|
+
* return (
|
|
11
|
+
* <div>
|
|
12
|
+
* <p>Canister ID: {canisterId}</p>
|
|
13
|
+
* <p>Initializing: {initializing.toString()}</p>
|
|
14
|
+
* <p>Initialized: {initialized.toString()}</p>
|
|
15
|
+
* <p>Error: {error?.message}</p>
|
|
16
|
+
* </div>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
*```
|
|
20
|
+
*/
|
|
21
|
+
export declare const useActorState: () => import("../../../types").UseActorState;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useActorState = void 0;
|
|
4
|
+
const actorHooks_1 = require("../../actorHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for accessing the current state of the actor, including the canister ID.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing the current state of the actor from Zustand's store and the canister ID.
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function ActorStateComponent() {
|
|
12
|
+
* const { canisterId, initializing, error, initialized } = useActorState();
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <div>
|
|
16
|
+
* <p>Canister ID: {canisterId}</p>
|
|
17
|
+
* <p>Initializing: {initializing.toString()}</p>
|
|
18
|
+
* <p>Initialized: {initialized.toString()}</p>
|
|
19
|
+
* <p>Error: {error?.message}</p>
|
|
20
|
+
* </div>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
*```
|
|
24
|
+
*/
|
|
25
|
+
exports.useActorState = actorHooks_1.ActorHooks.useActorState;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FunctionName, UseQueryCallParameters } from "../../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
4
|
+
*
|
|
5
|
+
* @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
|
|
6
|
+
* @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function QueryCallComponent() {
|
|
10
|
+
* const { call, data, loading } = useQueryCall({
|
|
11
|
+
* functionName: 'getUserProfile',
|
|
12
|
+
* args: ['123'],
|
|
13
|
+
* refetchOnMount: true,
|
|
14
|
+
* refetchInterval: 5000, // refetch every 5 seconds
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* if (loading) return <p>Loading profile...</p>;
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <p>User Profile: {JSON.stringify(data)}</p>
|
|
22
|
+
* <button onClick={call}>Refetch</button>
|
|
23
|
+
* </div>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function useQueryCall<A, M extends FunctionName<A> = FunctionName<A>>(args: UseQueryCallParameters<A, M>): import("../../../types").UseMethodCallReturnType<A, M>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useQueryCall = void 0;
|
|
4
|
+
const actorHooks_1 = require("../../actorHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
7
|
+
*
|
|
8
|
+
* @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
|
|
9
|
+
* @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* function QueryCallComponent() {
|
|
13
|
+
* const { call, data, loading } = useQueryCall({
|
|
14
|
+
* functionName: 'getUserProfile',
|
|
15
|
+
* args: ['123'],
|
|
16
|
+
* refetchOnMount: true,
|
|
17
|
+
* refetchInterval: 5000, // refetch every 5 seconds
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* if (loading) return <p>Loading profile...</p>;
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <div>
|
|
24
|
+
* <p>User Profile: {JSON.stringify(data)}</p>
|
|
25
|
+
* <button onClick={call}>Refetch</button>
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function useQueryCall(args) {
|
|
32
|
+
return actorHooks_1.ActorHooks.useQueryCall(args);
|
|
33
|
+
}
|
|
34
|
+
exports.useQueryCall = useQueryCall;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseActor, FunctionName, UseUpdateCallParameters } from "../../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
4
|
+
*
|
|
5
|
+
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
6
|
+
* @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function UpdateCallComponent() {
|
|
10
|
+
* const { call, data, loading } = useUpdateCall({
|
|
11
|
+
* functionName: 'updateUserProfile',
|
|
12
|
+
* args: ['123', { name: 'John Doe' }],
|
|
13
|
+
* onLoading: (loading) => console.log('Loading:', loading),
|
|
14
|
+
* onError: (error) => console.error('Error:', error),
|
|
15
|
+
* onSuccess: (data) => console.log('Success:', data),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* if (loading) return <p>Updating profile...</p>;
|
|
19
|
+
*
|
|
20
|
+
* return (
|
|
21
|
+
* <div>
|
|
22
|
+
* <p>Updated Profile: {JSON.stringify(data)}</p>
|
|
23
|
+
* <button onClick={call}>Update</button>
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function useUpdateCall<A = BaseActor, M extends FunctionName<A> = FunctionName<A>>(args: UseUpdateCallParameters<A, M>): import("../../../types").UseMethodCallReturnType<A, M>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUpdateCall = void 0;
|
|
4
|
+
const actorHooks_1 = require("../../actorHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
7
|
+
*
|
|
8
|
+
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
9
|
+
* @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* function UpdateCallComponent() {
|
|
13
|
+
* const { call, data, loading } = useUpdateCall({
|
|
14
|
+
* functionName: 'updateUserProfile',
|
|
15
|
+
* args: ['123', { name: 'John Doe' }],
|
|
16
|
+
* onLoading: (loading) => console.log('Loading:', loading),
|
|
17
|
+
* onError: (error) => console.error('Error:', error),
|
|
18
|
+
* onSuccess: (data) => console.log('Success:', data),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (loading) return <p>Updating profile...</p>;
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <div>
|
|
25
|
+
* <p>Updated Profile: {JSON.stringify(data)}</p>
|
|
26
|
+
* <button onClick={call}>Update</button>
|
|
27
|
+
* </div>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function useUpdateCall(args) {
|
|
33
|
+
return actorHooks_1.ActorHooks.useUpdateCall(args);
|
|
34
|
+
}
|
|
35
|
+
exports.useUpdateCall = useUpdateCall;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseActor, FunctionName } from "../../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes and returns a visit service function for a specific actor method.
|
|
4
|
+
*
|
|
5
|
+
* @param functionName The name of the actor method to visit.
|
|
6
|
+
* @returns The visit service function for the specified method.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useVisitMethod<A = BaseActor>(functionName: FunctionName<A>): <V extends import("@dfinity/candid/lib/cjs/idl").Visitor<unknown, unknown>>(extractorClass: V, data?: import("@ic-reactor/core/dist/classes/actor/types").VisitorType<V>["data"] | undefined) => ReturnType<V["visitFunc"]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useVisitMethod = void 0;
|
|
4
|
+
const actorHooks_1 = require("../../actorHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Memoizes and returns a visit service function for a specific actor method.
|
|
7
|
+
*
|
|
8
|
+
* @param functionName The name of the actor method to visit.
|
|
9
|
+
* @returns The visit service function for the specified method.
|
|
10
|
+
*/
|
|
11
|
+
function useVisitMethod(functionName) {
|
|
12
|
+
return actorHooks_1.ActorHooks.useVisitMethod(functionName);
|
|
13
|
+
}
|
|
14
|
+
exports.useVisitMethod = useVisitMethod;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
__exportStar(require("./useAgent"), exports);
|
|
18
|
+
__exportStar(require("./useAgentState"), exports);
|
|
19
|
+
__exportStar(require("./useAgentManager"), exports);
|
|
20
|
+
__exportStar(require("./useAuth"), exports);
|
|
21
|
+
__exportStar(require("./useAuthState"), exports);
|
|
22
|
+
__exportStar(require("./useUserPrincipal"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses the current agent instance.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*```jsx
|
|
6
|
+
* function AgentComponent() {
|
|
7
|
+
* const agent = useAgent();
|
|
8
|
+
*
|
|
9
|
+
* // Use agent for interacting with the Internet Computer.
|
|
10
|
+
* return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
|
|
11
|
+
* }
|
|
12
|
+
*```
|
|
13
|
+
*/
|
|
14
|
+
export declare const useAgent: () => import("@dfinity/agent").HttpAgent | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAgent = void 0;
|
|
4
|
+
const agentHooks_1 = require("../../agentHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Accesses the current agent instance.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*```jsx
|
|
10
|
+
* function AgentComponent() {
|
|
11
|
+
* const agent = useAgent();
|
|
12
|
+
*
|
|
13
|
+
* // Use agent for interacting with the Internet Computer.
|
|
14
|
+
* return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
|
|
15
|
+
* }
|
|
16
|
+
*```
|
|
17
|
+
*/
|
|
18
|
+
exports.useAgent = agentHooks_1.AgentHooks.useAgent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*```jsx
|
|
7
|
+
* function AgentManagerComponent() {
|
|
8
|
+
* const agentManager = useAgentManager();
|
|
9
|
+
*
|
|
10
|
+
* // Use agentManager for managing agent configurations, etc.
|
|
11
|
+
* return <div>Agent Manager ready.</div>;
|
|
12
|
+
* }
|
|
13
|
+
*```
|
|
14
|
+
*/
|
|
15
|
+
export declare const useAgentManager: (agentContext?: import("react").Context<import("../../types").AgentContext | null> | undefined) => import("@ic-reactor/core/dist/types").AgentManager;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAgentManager = void 0;
|
|
4
|
+
const agentHooks_1 = require("../../agentHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*```jsx
|
|
10
|
+
* function AgentManagerComponent() {
|
|
11
|
+
* const agentManager = useAgentManager();
|
|
12
|
+
*
|
|
13
|
+
* // Use agentManager for managing agent configurations, etc.
|
|
14
|
+
* return <div>Agent Manager ready.</div>;
|
|
15
|
+
* }
|
|
16
|
+
*```
|
|
17
|
+
*/
|
|
18
|
+
exports.useAgentManager = agentHooks_1.AgentHooks.useAgentManager;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses the current state of the agent.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```jsx
|
|
6
|
+
* function AgentStateComponent() {
|
|
7
|
+
* const { initialized, initializing } = useAgentState();
|
|
8
|
+
*
|
|
9
|
+
* return (
|
|
10
|
+
* <div>
|
|
11
|
+
* {initialized
|
|
12
|
+
* ? 'Agent is initialized.'
|
|
13
|
+
* : initializing
|
|
14
|
+
* ? 'Agent is initializing...'
|
|
15
|
+
* : 'Agent is not initialized.'}
|
|
16
|
+
* </div>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const useAgentState: () => import("@ic-reactor/core/dist/types").AgentState;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAgentState = void 0;
|
|
4
|
+
const agentHooks_1 = require("../../agentHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Accesses the current state of the agent.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```jsx
|
|
10
|
+
* function AgentStateComponent() {
|
|
11
|
+
* const { initialized, initializing } = useAgentState();
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <div>
|
|
15
|
+
* {initialized
|
|
16
|
+
* ? 'Agent is initialized.'
|
|
17
|
+
* : initializing
|
|
18
|
+
* ? 'Agent is initializing...'
|
|
19
|
+
* : 'Agent is not initialized.'}
|
|
20
|
+
* </div>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
exports.useAgentState = agentHooks_1.AgentHooks.useAgentState;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
|
|
3
|
+
* It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
|
|
4
|
+
*
|
|
5
|
+
* @param options - An optional object containing the following properties:
|
|
6
|
+
* - `onAuthentication`: Callback function triggered before authentication starts.
|
|
7
|
+
* - `onAuthenticationSuccess`: Callback function triggered on successful authentication, receives the authenticated `Identity`.
|
|
8
|
+
* - `onAuthenticationFailure`: Callback function triggered on authentication failure, receives the error.
|
|
9
|
+
* - `onLogin`: Callback function triggered before the login process starts.
|
|
10
|
+
* - `onLoginSuccess`: Callback function triggered on successful login, receives the user's `Principal`.
|
|
11
|
+
* - `onLoginError`: Callback function triggered on login error, receives the error.
|
|
12
|
+
* - `onLoggedOut`: Callback function triggered after logging out.
|
|
13
|
+
*
|
|
14
|
+
* @returns An object containing the following properties:
|
|
15
|
+
* - `authenticated`: Boolean indicating if the user is currently authenticated.
|
|
16
|
+
* - `authenticating`: Boolean indicating if an authentication process is currently underway.
|
|
17
|
+
* - `identity`: The authenticated user's `Identity`, if available.
|
|
18
|
+
* - `error`: Any error that occurred during the authentication process.
|
|
19
|
+
* - `login`: Function to initiate the login process, optionally accepting `LoginParameters`.
|
|
20
|
+
* - `logout`: Function to log the user out, optionally accepting `LogoutParameters`.
|
|
21
|
+
* - `authenticate`: Function to authenticate the user, internally used by `login` and `logout`.
|
|
22
|
+
* - `loginLoading`: Boolean indicating if a login operation is in progress.
|
|
23
|
+
* - `loginError`: Error object if an error occurred during the login process.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* This hook can be used to add authentication functionality to your IC application components, handling user login, logout, and authentication state management seamlessly.
|
|
27
|
+
*
|
|
28
|
+
* Example:
|
|
29
|
+
* ```jsx
|
|
30
|
+
* const YourComponent = () => {
|
|
31
|
+
* const { login, logout, authenticated, identity, loginError } = useAuth({
|
|
32
|
+
* onLoginSuccess: (principal) => console.log(`Logged in as ${principal}`),
|
|
33
|
+
* onLoginError: (error) => console.error(`Login failed: ${error.message}`),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* if (loginError) {
|
|
37
|
+
* return <div>Error logging in: {loginError.message}</div>;
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* return (
|
|
41
|
+
* <div>
|
|
42
|
+
* {authenticated ? (
|
|
43
|
+
* <>
|
|
44
|
+
* <div>Authenticated as {identity.getPrincipal().toText()}</div>
|
|
45
|
+
* <button onClick={() => logout()}>Logout</button>
|
|
46
|
+
* </>
|
|
47
|
+
* ) : (
|
|
48
|
+
* <button onClick={() => login()}>Login</button>
|
|
49
|
+
* )}
|
|
50
|
+
* </div>
|
|
51
|
+
* );
|
|
52
|
+
* };
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
|
|
56
|
+
*/
|
|
57
|
+
export declare const useAuth: (options?: import("../../../types").UseAuthParameters | undefined) => import("../../../types").UseAuthReturnType;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAuth = void 0;
|
|
4
|
+
const agentHooks_1 = require("../../agentHooks");
|
|
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 = agentHooks_1.AgentHooks.useAuth;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses the current authentication state.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```jsx
|
|
6
|
+
* function AuthStateComponent() {
|
|
7
|
+
* const { isAuthenticated, authenticating, identity, error } = useAuthState();
|
|
8
|
+
*
|
|
9
|
+
* return (
|
|
10
|
+
* <div>
|
|
11
|
+
* {authenticating ? 'Authenticating...' : ''}
|
|
12
|
+
* {error ? `Error: ${error.message}` : ''}
|
|
13
|
+
* {isAuthenticated ? `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;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAuthState = void 0;
|
|
4
|
+
const agentHooks_1 = require("../../agentHooks");
|
|
5
|
+
/**
|
|
6
|
+
* Accesses the current authentication state.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```jsx
|
|
10
|
+
* function AuthStateComponent() {
|
|
11
|
+
* const { isAuthenticated, authenticating, identity, error } = useAuthState();
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <div>
|
|
15
|
+
* {authenticating ? 'Authenticating...' : ''}
|
|
16
|
+
* {error ? `Error: ${error.message}` : ''}
|
|
17
|
+
* {isAuthenticated ? `User ${identity?.getPrincipal()} is authenticated.` : 'User is not authenticated.'}
|
|
18
|
+
* </div>
|
|
19
|
+
* );
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
exports.useAuthState = agentHooks_1.AgentHooks.useAuthState;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUserPrincipal = void 0;
|
|
4
|
+
const agentHooks_1 = require("../../agentHooks");
|
|
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 = agentHooks_1.AgentHooks.useUserPrincipal;
|
|
@@ -14,5 +14,6 @@ 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
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./actor"), exports);
|
|
18
|
+
__exportStar(require("./agent"), exports);
|
|
19
|
+
__exportStar(require("./useActor"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { IDL } from "@dfinity/candid";
|
|
3
|
+
import { AgentContext } from "../types";
|
|
4
|
+
import { ActorHooksReturnType, ActorManagerParameters, BaseActor } from "../../types";
|
|
5
|
+
export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
6
|
+
canisterId: string;
|
|
7
|
+
idlFactory?: IDL.InterfaceFactory;
|
|
8
|
+
agentContext?: React.Context<AgentContext | null>;
|
|
9
|
+
didjsCanisterId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface UseActorReturn<A = BaseActor> {
|
|
12
|
+
hooks: ActorHooksReturnType<A> | null;
|
|
13
|
+
fetching: boolean;
|
|
14
|
+
fetchError: string | null;
|
|
15
|
+
}
|