@ic-reactor/react 1.7.7 → 1.7.9
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/dist/context/actor/create.d.ts +63 -0
- package/dist/context/actor/create.js +106 -0
- package/dist/context/actor/hooks/useActorInterface.js +11 -0
- package/dist/{hooks/actor → context/actor/hooks}/useActorState.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useActorState.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useActorStore.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useActorStore.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useMethod.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useMethod.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useMethodAttributes.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useMethodAttributes.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useMethodNames.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useMethodNames.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useQueryCall.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useQueryCall.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useUpdateCall.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useUpdateCall.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useVisitMethod.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useVisitMethod.js +2 -5
- package/dist/{hooks/actor → context/actor/hooks}/useVisitService.d.ts +1 -1
- package/dist/{hooks/actor → context/actor/hooks}/useVisitService.js +2 -5
- package/dist/context/actor/index.d.ts +15 -63
- package/dist/context/actor/index.js +29 -103
- package/dist/{provider/actor.d.ts → context/actor/provider.d.ts} +2 -2
- package/dist/{provider/actor.js → context/actor/provider.js} +3 -6
- package/dist/context/actor/types.d.ts +1 -0
- package/dist/context/adapter/create.d.ts +2 -0
- package/dist/context/adapter/create.js +50 -0
- package/dist/{hooks/adapter → context/adapter/hooks}/useCandidAdapter.js +2 -5
- package/dist/context/adapter/index.d.ts +6 -2
- package/dist/context/adapter/index.js +20 -47
- package/dist/{provider/adapter.d.ts → context/adapter/provider.d.ts} +1 -1
- package/dist/{provider/adapter.js → context/adapter/provider.js} +2 -5
- package/dist/context/agent/create.d.ts +74 -0
- package/dist/context/agent/create.js +112 -0
- package/dist/{hooks/agent → context/agent/hooks}/useAgent.js +2 -5
- package/dist/{hooks/agent → context/agent/hooks}/useAgentManager.js +2 -5
- package/dist/{hooks/agent → context/agent/hooks}/useAgentState.js +2 -5
- package/dist/{hooks/agent → context/agent/hooks}/useAuth.d.ts +1 -1
- package/dist/{hooks/agent → context/agent/hooks}/useAuth.js +2 -5
- package/dist/{hooks/agent → context/agent/hooks}/useAuthState.js +2 -5
- package/dist/{hooks/agent → context/agent/hooks}/useUserPrincipal.js +2 -5
- package/dist/context/agent/index.d.ts +11 -74
- package/dist/context/agent/index.js +25 -109
- package/dist/{provider/agent.d.ts → context/agent/provider.d.ts} +1 -1
- package/dist/{provider/agent.js → context/agent/provider.js} +2 -5
- package/dist/hooks/index.d.ts +0 -3
- package/dist/hooks/index.js +0 -3
- package/dist/hooks/types.d.ts +2 -0
- package/dist/hooks/useActor.js +17 -11
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- package/package.json +3 -3
- package/dist/context/index.d.ts +0 -3
- package/dist/context/index.js +0 -19
- package/dist/context/types.d.ts +0 -3
- package/dist/context/types.js +0 -19
- package/dist/hooks/actor/hooks.d.ts +0 -2
- package/dist/hooks/actor/hooks.js +0 -5
- package/dist/hooks/actor/index.d.ts +0 -10
- package/dist/hooks/actor/index.js +0 -26
- package/dist/hooks/actor/useActorInterface.js +0 -14
- package/dist/hooks/adapter/hooks.d.ts +0 -2
- package/dist/hooks/adapter/hooks.js +0 -5
- package/dist/hooks/adapter/index.d.ts +0 -1
- package/dist/hooks/adapter/index.js +0 -17
- package/dist/hooks/agent/hooks.d.ts +0 -2
- package/dist/hooks/agent/hooks.js +0 -5
- package/dist/hooks/agent/index.d.ts +0 -6
- package/dist/hooks/agent/index.js +0 -22
- package/dist/provider/index.d.ts +0 -3
- package/dist/provider/index.js +0 -19
- /package/dist/{hooks/actor → context/actor/hooks}/useActorInterface.d.ts +0 -0
- /package/dist/{hooks/adapter → context/adapter/hooks}/useCandidAdapter.d.ts +0 -0
- /package/dist/{hooks/agent → context/agent/hooks}/useAgent.d.ts +0 -0
- /package/dist/{hooks/agent → context/agent/hooks}/useAgentManager.d.ts +0 -0
- /package/dist/{hooks/agent → context/agent/hooks}/useAgentState.d.ts +0 -0
- /package/dist/{hooks/agent → context/agent/hooks}/useAuthState.d.ts +0 -0
- /package/dist/{hooks/agent → context/agent/hooks}/useUserPrincipal.d.ts +0 -0
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
27
27
|
*/
|
|
28
|
-
export declare const ActorProvider: import("react").FC<import("
|
|
28
|
+
export declare const ActorProvider: import("react").FC<import("./types").ActorProviderProps>;
|
|
29
29
|
/**
|
|
30
30
|
* `ActorHookProvider` is a React functional component that serves as a context provider for IC actor hooks within a React application.
|
|
31
31
|
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided actor hooks and configuration.
|
|
@@ -47,4 +47,4 @@ export declare const ActorProvider: import("react").FC<import("../context/types"
|
|
|
47
47
|
* ```
|
|
48
48
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor hooks through the context provided by `ActorHookProvider`.
|
|
49
49
|
*/
|
|
50
|
-
export declare const ActorHookProvider: import("react").FC<import("
|
|
50
|
+
export declare const ActorHookProvider: import("react").FC<import("./types").ActorHookProviderProps<import("@ic-reactor/core/dist/types").BaseActor>>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ActorHookProvider = exports.ActorProvider = void 0;
|
|
7
|
-
const
|
|
4
|
+
const _1 = require(".");
|
|
8
5
|
/**
|
|
9
6
|
* `ActorProvider` is a React functional component that serves as a context provider for IC actor interactions within a React application.
|
|
10
7
|
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided canister ID and configuration.
|
|
@@ -31,7 +28,7 @@ const hooks_1 = __importDefault(require("../hooks/actor/hooks"));
|
|
|
31
28
|
* ```
|
|
32
29
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
33
30
|
*/
|
|
34
|
-
exports.ActorProvider =
|
|
31
|
+
exports.ActorProvider = _1.ActorHooks.ActorProvider;
|
|
35
32
|
/**
|
|
36
33
|
* `ActorHookProvider` is a React functional component that serves as a context provider for IC actor hooks within a React application.
|
|
37
34
|
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided actor hooks and configuration.
|
|
@@ -53,4 +50,4 @@ exports.ActorProvider = hooks_1.default.ActorProvider;
|
|
|
53
50
|
* ```
|
|
54
51
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor hooks through the context provided by `ActorHookProvider`.
|
|
55
52
|
*/
|
|
56
|
-
exports.ActorHookProvider =
|
|
53
|
+
exports.ActorHookProvider = _1.ActorHooks.ActorHookProvider;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createAdapterContext = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const agent_1 = require("../agent");
|
|
20
|
+
const core_1 = require("@ic-reactor/core");
|
|
21
|
+
function createAdapterContext(config = {}) {
|
|
22
|
+
const { withParser: _withParser, didjsCanisterId: _didjsCanisterId } = config, defaultConfig = __rest(config, ["withParser", "didjsCanisterId"]);
|
|
23
|
+
const CandidAdapterContext = react_1.default.createContext(null);
|
|
24
|
+
const useCandidAdapter = () => {
|
|
25
|
+
const candidAdapter = react_1.default.useContext(CandidAdapterContext);
|
|
26
|
+
return candidAdapter;
|
|
27
|
+
};
|
|
28
|
+
const CandidAdapterProvider = (_a) => {
|
|
29
|
+
var { children, withParser = _withParser, loadingComponent = react_1.default.createElement("div", null, "Loading Parser..."), didjsCanisterId = _didjsCanisterId } = _a, restConfig = __rest(_a, ["children", "withParser", "loadingComponent", "didjsCanisterId"]);
|
|
30
|
+
const config = react_1.default.useMemo(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
|
|
31
|
+
const [initalized, setInitialized] = react_1.default.useState(false);
|
|
32
|
+
const agentManager = (0, agent_1.useAgentManager)();
|
|
33
|
+
const candidAdapter = react_1.default.useMemo(() => (0, core_1.createCandidAdapter)(Object.assign({ agentManager, didjsCanisterId }, config)), [didjsCanisterId, agentManager]);
|
|
34
|
+
react_1.default.useEffect(() => {
|
|
35
|
+
if (withParser) {
|
|
36
|
+
candidAdapter.initializeParser().then(() => setInitialized(true));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
setInitialized(true);
|
|
40
|
+
}
|
|
41
|
+
}, []);
|
|
42
|
+
return (react_1.default.createElement(CandidAdapterContext.Provider, { value: candidAdapter }, initalized ? children : loadingComponent));
|
|
43
|
+
};
|
|
44
|
+
CandidAdapterProvider.displayName = "CandidAdapterProvider";
|
|
45
|
+
return {
|
|
46
|
+
useCandidAdapter,
|
|
47
|
+
CandidAdapterProvider,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.createAdapterContext = createAdapterContext;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useCandidAdapter = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* Accesses the `CandidAdapter` to download the actor's Candid interface.
|
|
10
7
|
*
|
|
@@ -27,4 +24,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
27
24
|
* }
|
|
28
25
|
*```
|
|
29
26
|
*/
|
|
30
|
-
exports.useCandidAdapter =
|
|
27
|
+
exports.useCandidAdapter = __1.AdapterHooks.useCandidAdapter;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
1
|
+
import { createAdapterContext } from "./create";
|
|
2
|
+
export { createAdapterContext };
|
|
3
|
+
/** @ignore */
|
|
4
|
+
export declare const AdapterHooks: import("./types").CreateCandidAdapterContextReturnType;
|
|
5
|
+
export * from "./provider";
|
|
6
|
+
export * from "./hooks/useCandidAdapter";
|
|
@@ -1,50 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
var
|
|
14
|
-
|
|
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
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createAdapterContext = void 0;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const useCandidAdapter = () => {
|
|
25
|
-
const candidAdapter = react_1.default.useContext(CandidAdapterContext);
|
|
26
|
-
return candidAdapter;
|
|
27
|
-
};
|
|
28
|
-
const CandidAdapterProvider = (_a) => {
|
|
29
|
-
var { children, withParser = _withParser, loadingComponent = react_1.default.createElement("div", null, "Loading Parser..."), didjsCanisterId = _didjsCanisterId } = _a, restConfig = __rest(_a, ["children", "withParser", "loadingComponent", "didjsCanisterId"]);
|
|
30
|
-
const config = react_1.default.useMemo(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
|
|
31
|
-
const [initalized, setInitialized] = react_1.default.useState(false);
|
|
32
|
-
const agentManager = (0, hooks_1.useAgentManager)();
|
|
33
|
-
const candidAdapter = react_1.default.useMemo(() => (0, core_1.createCandidAdapter)(Object.assign({ agentManager, didjsCanisterId }, config)), [didjsCanisterId, agentManager]);
|
|
34
|
-
react_1.default.useEffect(() => {
|
|
35
|
-
if (withParser) {
|
|
36
|
-
candidAdapter.initializeParser().then(() => setInitialized(true));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
setInitialized(true);
|
|
40
|
-
}
|
|
41
|
-
}, []);
|
|
42
|
-
return (react_1.default.createElement(CandidAdapterContext.Provider, { value: candidAdapter }, initalized ? children : loadingComponent));
|
|
43
|
-
};
|
|
44
|
-
CandidAdapterProvider.displayName = "CandidAdapterProvider";
|
|
45
|
-
return {
|
|
46
|
-
useCandidAdapter,
|
|
47
|
-
CandidAdapterProvider,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.createAdapterContext = createAdapterContext;
|
|
17
|
+
exports.AdapterHooks = exports.createAdapterContext = void 0;
|
|
18
|
+
const create_1 = require("./create");
|
|
19
|
+
Object.defineProperty(exports, "createAdapterContext", { enumerable: true, get: function () { return create_1.createAdapterContext; } });
|
|
20
|
+
/** @ignore */
|
|
21
|
+
exports.AdapterHooks = (0, create_1.createAdapterContext)();
|
|
22
|
+
__exportStar(require("./provider"), exports);
|
|
23
|
+
__exportStar(require("./hooks/useCandidAdapter"), exports);
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
* export default App
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare const CandidAdapterProvider: import("react").FC<import("
|
|
24
|
+
export declare const CandidAdapterProvider: import("react").FC<import("./types").CandidAdapterProviderProps>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CandidAdapterProvider = void 0;
|
|
7
|
-
const
|
|
4
|
+
const _1 = require(".");
|
|
8
5
|
/**
|
|
9
6
|
* `CandidAdapterProvider` is a React component that provides the CandidAdapter to its children.
|
|
10
7
|
* It initializes the CandidAdapter with the provided options and makes it available to all children.
|
|
@@ -27,4 +24,4 @@ const hooks_1 = __importDefault(require("../hooks/adapter/hooks"));
|
|
|
27
24
|
* export default App
|
|
28
25
|
* ```
|
|
29
26
|
*/
|
|
30
|
-
exports.CandidAdapterProvider =
|
|
27
|
+
exports.CandidAdapterProvider = _1.AdapterHooks.CandidAdapterProvider;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CreateAgentContextReturnType, CreateAgentCotextParameters } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
4
|
+
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
5
|
+
*
|
|
6
|
+
* @param config A partial configuration object {@link CreateAgentCotextParameters}, allowing customization of the agent's behavior.
|
|
7
|
+
*
|
|
8
|
+
* @returns
|
|
9
|
+
* An object containing the {@link AgentProvider} component and various hooks for interacting with the agent and authentication state.
|
|
10
|
+
* The {@link AgentProvider} component is a React context provider that should wrap your app or components needing access to agent functionalities.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
14
|
+
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
15
|
+
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
16
|
+
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* // agent.ts
|
|
21
|
+
* import { createAgentContext } from "@ic-reactor/react";
|
|
22
|
+
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
23
|
+
*
|
|
24
|
+
* // Optional: Define custom agent configuration
|
|
25
|
+
* const agentConfig: CreateAgentCotextParameters = {
|
|
26
|
+
* host: "https://localhost:8000",
|
|
27
|
+
* // or
|
|
28
|
+
* // withLocalEnv: true,
|
|
29
|
+
* // port: 8000,
|
|
30
|
+
* };
|
|
31
|
+
*
|
|
32
|
+
* export const {
|
|
33
|
+
* AgentProvider,
|
|
34
|
+
* useAgent,
|
|
35
|
+
* useAuth,
|
|
36
|
+
* useAuthState,
|
|
37
|
+
* useAgentState,
|
|
38
|
+
* useAgentManager,
|
|
39
|
+
* useUserPrincipal,
|
|
40
|
+
* } = createAgentContext(agentConfig);
|
|
41
|
+
*```
|
|
42
|
+
* Now you can use the returned hooks in your React components
|
|
43
|
+
*
|
|
44
|
+
* ```tsx
|
|
45
|
+
* // App.tsx
|
|
46
|
+
* import React from 'react';
|
|
47
|
+
* import { AgentProvider } from './agent';
|
|
48
|
+
*
|
|
49
|
+
* const App = () => (
|
|
50
|
+
* <AgentProvider>
|
|
51
|
+
* <Login />
|
|
52
|
+
* <YourActor />
|
|
53
|
+
* </AgentProvider>
|
|
54
|
+
* );
|
|
55
|
+
*
|
|
56
|
+
* const Login = () => {
|
|
57
|
+
* const { login } = useAuth()
|
|
58
|
+
* const principal = useUserPrincipal()
|
|
59
|
+
*
|
|
60
|
+
* return (
|
|
61
|
+
* <div>
|
|
62
|
+
* <button onClick={() => login()}>Login</button>
|
|
63
|
+
* <p>User: {principal?.toText()}</p>
|
|
64
|
+
* </div>
|
|
65
|
+
* )
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* This setup allows you to use the agent and authentication hooks within
|
|
71
|
+
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
72
|
+
* with the Internet Computer blockchain.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createAgentContext(config?: CreateAgentCotextParameters): CreateAgentContextReturnType;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createAgentContext = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const core_1 = require("@ic-reactor/core");
|
|
20
|
+
const agentHooks_1 = require("../../helpers/agentHooks");
|
|
21
|
+
const authHooks_1 = require("../../helpers/authHooks");
|
|
22
|
+
const extractAgentContext_1 = require("../../helpers/extractAgentContext");
|
|
23
|
+
/**
|
|
24
|
+
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
25
|
+
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
26
|
+
*
|
|
27
|
+
* @param config A partial configuration object {@link CreateAgentCotextParameters}, allowing customization of the agent's behavior.
|
|
28
|
+
*
|
|
29
|
+
* @returns
|
|
30
|
+
* An object containing the {@link AgentProvider} component and various hooks for interacting with the agent and authentication state.
|
|
31
|
+
* The {@link AgentProvider} component is a React context provider that should wrap your app or components needing access to agent functionalities.
|
|
32
|
+
*
|
|
33
|
+
* Usage:
|
|
34
|
+
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
35
|
+
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
36
|
+
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
37
|
+
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* // agent.ts
|
|
42
|
+
* import { createAgentContext } from "@ic-reactor/react";
|
|
43
|
+
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
44
|
+
*
|
|
45
|
+
* // Optional: Define custom agent configuration
|
|
46
|
+
* const agentConfig: CreateAgentCotextParameters = {
|
|
47
|
+
* host: "https://localhost:8000",
|
|
48
|
+
* // or
|
|
49
|
+
* // withLocalEnv: true,
|
|
50
|
+
* // port: 8000,
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* export const {
|
|
54
|
+
* AgentProvider,
|
|
55
|
+
* useAgent,
|
|
56
|
+
* useAuth,
|
|
57
|
+
* useAuthState,
|
|
58
|
+
* useAgentState,
|
|
59
|
+
* useAgentManager,
|
|
60
|
+
* useUserPrincipal,
|
|
61
|
+
* } = createAgentContext(agentConfig);
|
|
62
|
+
*```
|
|
63
|
+
* Now you can use the returned hooks in your React components
|
|
64
|
+
*
|
|
65
|
+
* ```tsx
|
|
66
|
+
* // App.tsx
|
|
67
|
+
* import React from 'react';
|
|
68
|
+
* import { AgentProvider } from './agent';
|
|
69
|
+
*
|
|
70
|
+
* const App = () => (
|
|
71
|
+
* <AgentProvider>
|
|
72
|
+
* <Login />
|
|
73
|
+
* <YourActor />
|
|
74
|
+
* </AgentProvider>
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* const Login = () => {
|
|
78
|
+
* const { login } = useAuth()
|
|
79
|
+
* const principal = useUserPrincipal()
|
|
80
|
+
*
|
|
81
|
+
* return (
|
|
82
|
+
* <div>
|
|
83
|
+
* <button onClick={() => login()}>Login</button>
|
|
84
|
+
* <p>User: {principal?.toText()}</p>
|
|
85
|
+
* </div>
|
|
86
|
+
* )
|
|
87
|
+
* };
|
|
88
|
+
*
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* This setup allows you to use the agent and authentication hooks within
|
|
92
|
+
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
93
|
+
* with the Internet Computer blockchain.
|
|
94
|
+
*/
|
|
95
|
+
function createAgentContext(config = {}) {
|
|
96
|
+
const { disableAuthenticateOnMount: defaultDisable } = config, contextOptions = __rest(config, ["disableAuthenticateOnMount"]);
|
|
97
|
+
const AgentContext = react_1.default.createContext(null);
|
|
98
|
+
const AgentProvider = (_a) => {
|
|
99
|
+
var { children, agentManager: mybeAgentManager, disableAuthenticateOnMount = defaultDisable !== null && defaultDisable !== void 0 ? defaultDisable : false } = _a, options = __rest(_a, ["children", "agentManager", "disableAuthenticateOnMount"]);
|
|
100
|
+
const hooks = react_1.default.useMemo(() => {
|
|
101
|
+
const agentManager = mybeAgentManager !== null && mybeAgentManager !== void 0 ? mybeAgentManager : (0, core_1.createAgentManager)(Object.assign(Object.assign({}, options), contextOptions));
|
|
102
|
+
if (!disableAuthenticateOnMount) {
|
|
103
|
+
agentManager.authenticate();
|
|
104
|
+
}
|
|
105
|
+
return Object.assign(Object.assign(Object.assign({}, (0, agentHooks_1.agentHooks)(agentManager)), (0, authHooks_1.authHooks)(agentManager)), { agentManager });
|
|
106
|
+
}, []);
|
|
107
|
+
return (react_1.default.createElement(AgentContext.Provider, { value: hooks }, children));
|
|
108
|
+
};
|
|
109
|
+
AgentProvider.displayName = "AgentProvider";
|
|
110
|
+
return Object.assign({ AgentProvider }, (0, extractAgentContext_1.extractAgentContext)(AgentContext));
|
|
111
|
+
}
|
|
112
|
+
exports.createAgentContext = createAgentContext;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useAgent = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* Accesses the current agent instance.
|
|
10
7
|
*
|
|
@@ -18,4 +15,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
18
15
|
* }
|
|
19
16
|
*```
|
|
20
17
|
*/
|
|
21
|
-
exports.useAgent =
|
|
18
|
+
exports.useAgent = __1.AgentHooks.useAgent;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useAgentManager = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
10
7
|
*
|
|
@@ -18,4 +15,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
18
15
|
* }
|
|
19
16
|
*```
|
|
20
17
|
*/
|
|
21
|
-
exports.useAgentManager =
|
|
18
|
+
exports.useAgentManager = __1.AgentHooks.useAgentManager;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useAgentState = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* Accesses the current state of the agent.
|
|
10
7
|
*
|
|
@@ -25,4 +22,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
25
22
|
* }
|
|
26
23
|
* ```
|
|
27
24
|
*/
|
|
28
|
-
exports.useAgentState =
|
|
25
|
+
exports.useAgentState = __1.AgentHooks.useAgentState;
|
|
@@ -54,4 +54,4 @@
|
|
|
54
54
|
*
|
|
55
55
|
* This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
|
|
56
56
|
*/
|
|
57
|
-
export declare const useAuth: (options?: import("
|
|
57
|
+
export declare const useAuth: (options?: import("../../../types").UseAuthParameters | undefined) => import("../../../types").UseAuthReturnType;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useAuth = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
|
|
10
7
|
* It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
|
|
@@ -61,4 +58,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
61
58
|
*
|
|
62
59
|
* This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
|
|
63
60
|
*/
|
|
64
|
-
exports.useAuth =
|
|
61
|
+
exports.useAuth = __1.AgentHooks.useAuth;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useAuthState = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* Accesses the current authentication state.
|
|
10
7
|
*
|
|
@@ -23,4 +20,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
23
20
|
* }
|
|
24
21
|
* ```
|
|
25
22
|
*/
|
|
26
|
-
exports.useAuthState =
|
|
23
|
+
exports.useAuthState = __1.AgentHooks.useAuthState;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useUserPrincipal = void 0;
|
|
7
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
8
5
|
/**
|
|
9
6
|
* Accesses the user's principal.
|
|
10
7
|
*
|
|
@@ -21,4 +18,4 @@ const hooks_1 = __importDefault(require("./hooks"));
|
|
|
21
18
|
* }
|
|
22
19
|
* ```
|
|
23
20
|
*/
|
|
24
|
-
exports.useUserPrincipal =
|
|
21
|
+
exports.useUserPrincipal = __1.AgentHooks.useUserPrincipal;
|
|
@@ -1,74 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
14
|
-
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
15
|
-
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
16
|
-
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* // agent.ts
|
|
21
|
-
* import { createAgentContext } from "@ic-reactor/react";
|
|
22
|
-
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
23
|
-
*
|
|
24
|
-
* // Optional: Define custom agent configuration
|
|
25
|
-
* const agentConfig: CreateAgentCotextParameters = {
|
|
26
|
-
* host: "https://localhost:8000",
|
|
27
|
-
* // or
|
|
28
|
-
* // withLocalEnv: true,
|
|
29
|
-
* // port: 8000,
|
|
30
|
-
* };
|
|
31
|
-
*
|
|
32
|
-
* export const {
|
|
33
|
-
* AgentProvider,
|
|
34
|
-
* useAgent,
|
|
35
|
-
* useAuth,
|
|
36
|
-
* useAuthState,
|
|
37
|
-
* useAgentState,
|
|
38
|
-
* useAgentManager,
|
|
39
|
-
* useUserPrincipal,
|
|
40
|
-
* } = createAgentContext(agentConfig);
|
|
41
|
-
*```
|
|
42
|
-
* Now you can use the returned hooks in your React components
|
|
43
|
-
*
|
|
44
|
-
* ```tsx
|
|
45
|
-
* // App.tsx
|
|
46
|
-
* import React from 'react';
|
|
47
|
-
* import { AgentProvider } from './agent';
|
|
48
|
-
*
|
|
49
|
-
* const App = () => (
|
|
50
|
-
* <AgentProvider>
|
|
51
|
-
* <Login />
|
|
52
|
-
* <YourActor />
|
|
53
|
-
* </AgentProvider>
|
|
54
|
-
* );
|
|
55
|
-
*
|
|
56
|
-
* const Login = () => {
|
|
57
|
-
* const { login } = useAuth()
|
|
58
|
-
* const principal = useUserPrincipal()
|
|
59
|
-
*
|
|
60
|
-
* return (
|
|
61
|
-
* <div>
|
|
62
|
-
* <button onClick={() => login()}>Login</button>
|
|
63
|
-
* <p>User: {principal?.toText()}</p>
|
|
64
|
-
* </div>
|
|
65
|
-
* )
|
|
66
|
-
* };
|
|
67
|
-
*
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* This setup allows you to use the agent and authentication hooks within
|
|
71
|
-
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
72
|
-
* with the Internet Computer blockchain.
|
|
73
|
-
*/
|
|
74
|
-
export declare const createAgentContext: (config?: CreateAgentCotextParameters) => CreateAgentContextReturnType;
|
|
1
|
+
import { createAgentContext } from "./create";
|
|
2
|
+
export { createAgentContext };
|
|
3
|
+
/** @ignore */
|
|
4
|
+
export declare const AgentHooks: import("./types").CreateAgentContextReturnType;
|
|
5
|
+
export * from "./provider";
|
|
6
|
+
export * from "./hooks/useAgent";
|
|
7
|
+
export * from "./hooks/useAgentState";
|
|
8
|
+
export * from "./hooks/useAgentManager";
|
|
9
|
+
export * from "./hooks/useAuth";
|
|
10
|
+
export * from "./hooks/useAuthState";
|
|
11
|
+
export * from "./hooks/useUserPrincipal";
|