@ic-reactor/react 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/dist/context/actor/index.d.ts +4 -4
- package/dist/context/actor/index.js +6 -10
- package/dist/context/actor/types.d.ts +3 -4
- package/dist/context/agent/context.d.ts +7 -0
- package/dist/context/agent/context.js +56 -0
- package/dist/context/agent/hooks.d.ts +23 -3
- package/dist/context/agent/hooks.js +35 -9
- package/dist/context/agent/index.d.ts +1 -9
- package/dist/context/agent/index.js +1 -52
- package/dist/context/agent/types.d.ts +4 -3
- package/dist/core.d.ts +1 -0
- package/dist/core.js +8 -0
- package/dist/{hooks → helpers}/actor.d.ts +1 -1
- package/dist/{hooks → helpers}/actor.js +10 -9
- package/dist/helpers/agent.d.ts +6 -0
- package/dist/{hooks → helpers}/auth.d.ts +3 -3
- package/dist/{hooks → helpers}/auth.js +5 -6
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +19 -0
- package/dist/helpers/types.d.ts +4 -0
- package/dist/helpers/types.js +2 -0
- package/dist/hooks/index.d.ts +0 -3
- package/dist/hooks/index.js +0 -3
- package/dist/hooks/useActor.d.ts +9 -3
- package/dist/hooks/useActor.js +6 -1
- package/dist/hooks/useCandid.d.ts +1 -1
- package/dist/hooks/useCandid.js +1 -1
- package/dist/index.d.ts +15 -14
- package/dist/index.js +26 -19
- package/dist/types.d.ts +9 -6
- package/dist/types.js +18 -0
- package/package.json +4 -4
- package/dist/hooks/agent.d.ts +0 -6
- /package/dist/{hooks → helpers}/agent.js +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# IC-ReActor - React
|
|
2
|
-
|
|
3
1
|
`@ic-reactor/react` is a comprehensive React library designed to streamline interactions with the Internet Computer (IC) blockchain. It provides React hooks and utilities for efficient state management, authentication, and interaction with IC actors.
|
|
4
2
|
|
|
5
3
|
## Features
|
|
@@ -33,12 +31,12 @@ First, create an actor declaration file:
|
|
|
33
31
|
```ts
|
|
34
32
|
// store.ts
|
|
35
33
|
import { canisterId, idlFactory, actor } from "declaration/actor"
|
|
36
|
-
import {
|
|
34
|
+
import { createReactor } from "@ic-reactor/react"
|
|
37
35
|
|
|
38
36
|
type Actor = typeof actor
|
|
39
37
|
|
|
40
38
|
export const { useActorStore, useAuthClient, useQueryCall } =
|
|
41
|
-
|
|
39
|
+
createReactor<Actor>({
|
|
42
40
|
canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
43
41
|
idlFactory,
|
|
44
42
|
host: "https://localhost:4943",
|
|
@@ -131,24 +129,3 @@ const Login = () => {
|
|
|
131
129
|
|
|
132
130
|
export default Login
|
|
133
131
|
```
|
|
134
|
-
|
|
135
|
-
## API Reference
|
|
136
|
-
|
|
137
|
-
The library provides various hooks and utilities for interacting with IC actors:
|
|
138
|
-
|
|
139
|
-
- `useActorStore`: Hook for managing actor states.
|
|
140
|
-
- `useAuthStore` Hook for managing authentication states.
|
|
141
|
-
- `useAuthClient`: Hook for managing authentication with the IC blockchain.
|
|
142
|
-
- `useQueryCall`: Hook for querying data from an actor.
|
|
143
|
-
- `useUpdateCall`: Hook for updating data in an actor.
|
|
144
|
-
- Additional hooks for handling loading, errors, authentication, and more.
|
|
145
|
-
|
|
146
|
-
For detailed API usage and options, please refer to the [documentation](#).
|
|
147
|
-
|
|
148
|
-
## Contributing
|
|
149
|
-
|
|
150
|
-
Contributions to `@ic-reactor/react` are welcome! Please read our [contributing guidelines](#) for more information.
|
|
151
|
-
|
|
152
|
-
## License
|
|
153
|
-
|
|
154
|
-
`@ic-reactor/react` is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ActorUseMethodCallArg, ActorUseQueryArgs, ActorUseUpdateArgs } from "../../types";
|
|
3
3
|
import { CreateActorOptions, ActorContextType, ActorProviderProps } from "./types";
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
4
|
+
import type { ActorSubclass } from "@dfinity/agent";
|
|
5
|
+
export declare const ActorContext: React.Context<ActorContextType | null>, ActorProvider: React.FC<ActorProviderProps>, useActorContext: <A extends unknown = unknown>() => ActorContextType<A>, useActorState: () => import("../../types").UseActorStoreReturn<unknown>, useQueryCall: <M extends never>(args: ActorUseQueryArgs<unknown, M>) => import("../../types").ActorCallReturn<unknown, M>, useUpdateCall: <M extends never>(args: ActorUseUpdateArgs<unknown, M>) => import("../../types").ActorCallReturn<unknown, M>, useMethodCall: <M extends never>(args: ActorUseMethodCallArg<unknown, M>) => import("../../types").ActorUseMethodCallReturn<unknown, M, true>, useVisitMethod: (functionName: never) => never;
|
|
6
|
+
export declare function createReactorContext<Actor extends ActorSubclass<any>>({ canisterId: defaultCanisterId, ...defaultConfig }?: Partial<CreateActorOptions>): {
|
|
6
7
|
ActorContext: React.Context<ActorContextType | null>;
|
|
7
8
|
ActorProvider: React.FC<ActorProviderProps>;
|
|
8
9
|
useActorContext: <A extends unknown = Actor>() => ActorContextType<A>;
|
|
@@ -10,7 +11,6 @@ export declare const createReActorContext: <Actor extends unknown>({ canisterId:
|
|
|
10
11
|
useQueryCall: <M extends keyof Actor & string>(args: ActorUseQueryArgs<Actor, M>) => import("../../types").ActorCallReturn<Actor, M>;
|
|
11
12
|
useUpdateCall: <M_1 extends keyof Actor & string>(args: ActorUseUpdateArgs<Actor, M_1>) => import("../../types").ActorCallReturn<Actor, M_1>;
|
|
12
13
|
useMethodCall: <M_2 extends keyof Actor & string>(args: ActorUseMethodCallArg<Actor, M_2>) => import("../../types").ActorUseMethodCallReturn<Actor, M_2, true>;
|
|
13
|
-
useVisitMethod: (functionName: keyof Actor & string) => import("@ic-reactor/core").VisitService<Actor>[keyof Actor & string];
|
|
14
|
+
useVisitMethod: (functionName: keyof Actor & string) => import("@ic-reactor/core/dist/actor/types").VisitService<Actor>[keyof Actor & string];
|
|
14
15
|
initialize: () => Promise<void>;
|
|
15
16
|
};
|
|
16
|
-
export declare const ActorContext: React.Context<ActorContextType | null>, ActorProvider: React.FC<ActorProviderProps>, useActorContext: <A extends unknown = unknown>() => ActorContextType<A>, useActorState: () => import("../../types").UseActorStoreReturn<unknown>, useQueryCall: <M extends never>(args: ActorUseQueryArgs<unknown, M>) => import("../../types").ActorCallReturn<unknown, M>, useUpdateCall: <M extends never>(args: ActorUseUpdateArgs<unknown, M>) => import("../../types").ActorCallReturn<unknown, M>, useMethodCall: <M extends never>(args: ActorUseMethodCallArg<unknown, M>) => import("../../types").ActorUseMethodCallReturn<unknown, M, true>, useVisitMethod: (functionName: never) => never;
|
|
@@ -22,9 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
25
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
29
26
|
var t = {};
|
|
30
27
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -38,13 +35,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
38
35
|
};
|
|
39
36
|
var _a;
|
|
40
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.useVisitMethod = exports.useMethodCall = exports.useUpdateCall = exports.useQueryCall = exports.useActorState = exports.useActorContext = exports.ActorProvider = exports.ActorContext =
|
|
38
|
+
exports.createReactorContext = exports.useVisitMethod = exports.useMethodCall = exports.useUpdateCall = exports.useQueryCall = exports.useActorState = exports.useActorContext = exports.ActorProvider = exports.ActorContext = void 0;
|
|
42
39
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
43
40
|
const react_1 = __importStar(require("react"));
|
|
44
|
-
const actor_1 = require("../../
|
|
41
|
+
const actor_1 = require("../../helpers/actor");
|
|
45
42
|
const useActor_1 = require("../../hooks/useActor");
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
_a = createReactorContext(), exports.ActorContext = _a.ActorContext, exports.ActorProvider = _a.ActorProvider, exports.useActorContext = _a.useActorContext, exports.useActorState = _a.useActorState, exports.useQueryCall = _a.useQueryCall, exports.useUpdateCall = _a.useUpdateCall, exports.useMethodCall = _a.useMethodCall, exports.useVisitMethod = _a.useVisitMethod;
|
|
44
|
+
function createReactorContext(_a = {}) {
|
|
48
45
|
var { canisterId: defaultCanisterId } = _a, defaultConfig = __rest(_a, ["canisterId"]);
|
|
49
46
|
const ActorContext = (0, react_1.createContext)(null);
|
|
50
47
|
const ActorProvider = (_a) => {
|
|
@@ -87,6 +84,5 @@ const createReActorContext = (_a = {}) => {
|
|
|
87
84
|
useVisitMethod,
|
|
88
85
|
initialize,
|
|
89
86
|
};
|
|
90
|
-
}
|
|
91
|
-
exports.
|
|
92
|
-
_a = (0, exports.createReActorContext)(), exports.ActorContext = _a.ActorContext, exports.ActorProvider = _a.ActorProvider, exports.useActorContext = _a.useActorContext, exports.useActorState = _a.useActorState, exports.useQueryCall = _a.useQueryCall, exports.useUpdateCall = _a.useUpdateCall, exports.useMethodCall = _a.useMethodCall, exports.useVisitMethod = _a.useVisitMethod;
|
|
87
|
+
}
|
|
88
|
+
exports.createReactorContext = createReactorContext;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { IDL } from "@dfinity/candid";
|
|
3
|
-
import { ActorManagerOptions, BaseActor } from "@ic-reactor/core";
|
|
4
|
-
import { AgentContextType } from "
|
|
5
|
-
import { ActorHooks } from "../../types";
|
|
3
|
+
import { ActorManagerOptions, BaseActor } from "@ic-reactor/core/dist/types";
|
|
4
|
+
import { ActorHooks, AgentContextType } from "../../types";
|
|
6
5
|
export type ActorContextType<Actor = BaseActor, F extends boolean = true> = ActorHooks<Actor, F> & {
|
|
7
6
|
ActorContext: React.Context<ActorContextType<Actor, F> | null>;
|
|
8
7
|
useActorContext: <A = Actor>() => ActorContextType<A>;
|
|
9
8
|
ActorProvider: React.FC<ActorProviderProps>;
|
|
10
9
|
};
|
|
11
|
-
export type
|
|
10
|
+
export type CreateReactorContext = {
|
|
12
11
|
<A = BaseActor>(options?: Partial<CreateActorOptions> & {
|
|
13
12
|
withVisitor: true;
|
|
14
13
|
}): ActorContextType<A, true>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { AgentManagerOptions } from "@ic-reactor/core/dist/types";
|
|
3
|
+
import type { AgentContextValue, AgentProviderProps } from "./types";
|
|
4
|
+
export declare const AgentContext: React.Context<AgentContextValue | null>;
|
|
5
|
+
declare const AgentProvider: React.FC<AgentProviderProps>;
|
|
6
|
+
export { AgentProvider };
|
|
7
|
+
export declare const createAgentContext: (config: AgentManagerOptions) => AgentContextValue;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.createAgentContext = exports.AgentProvider = exports.AgentContext = void 0;
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const core_1 = require("@ic-reactor/core");
|
|
40
|
+
const agent_1 = require("../../helpers/agent");
|
|
41
|
+
const auth_1 = require("../../helpers/auth");
|
|
42
|
+
exports.AgentContext = (0, react_1.createContext)(null);
|
|
43
|
+
const AgentProvider = (_a) => {
|
|
44
|
+
var { children } = _a, config = __rest(_a, ["children"]);
|
|
45
|
+
const value = (0, react_1.useMemo)(() => (0, exports.createAgentContext)(config), [config]);
|
|
46
|
+
return react_1.default.createElement(exports.AgentContext.Provider, { value: value }, children);
|
|
47
|
+
};
|
|
48
|
+
exports.AgentProvider = AgentProvider;
|
|
49
|
+
AgentProvider.displayName = "AgentProvider";
|
|
50
|
+
const createAgentContext = (config) => {
|
|
51
|
+
const agentManager = (0, core_1.createAgentManager)(config);
|
|
52
|
+
const agenthooks = (0, agent_1.getAgentHooks)(agentManager);
|
|
53
|
+
const authHooks = (0, auth_1.getAuthHooks)(agentManager);
|
|
54
|
+
return Object.assign(Object.assign(Object.assign({}, agenthooks), authHooks), { agentManager });
|
|
55
|
+
};
|
|
56
|
+
exports.createAgentContext = createAgentContext;
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
import { AgentManager
|
|
2
|
-
import { AgentContextType } from "./types";
|
|
1
|
+
import { AgentManager } from "@ic-reactor/core/dist/agent";
|
|
2
|
+
import type { AgentContextType } from "./types";
|
|
3
|
+
import { AuthArgs } from "../../types";
|
|
4
|
+
export declare const useAgentManagerContext: (agentContext?: AgentContextType) => import("./types").AgentContextValue;
|
|
3
5
|
export declare const useAgentManager: (agentContext?: AgentContextType) => AgentManager;
|
|
4
|
-
export declare const
|
|
6
|
+
export declare const useAgent: (agentContext?: AgentContextType) => import("@dfinity/agent/lib/cjs/agent/http").HttpAgent | undefined;
|
|
7
|
+
export declare const useAuthState: (agentContext?: AgentContextType) => import("@ic-reactor/core/dist/agent/types").AuthState;
|
|
8
|
+
export declare const useAgentState: (agentContext?: AgentContextType) => import("@ic-reactor/core/dist/agent/types").AgentState;
|
|
9
|
+
export declare const useAuthClient: ({ agentContext, ...args }: AuthArgs & {
|
|
10
|
+
agentContext?: AgentContextType | undefined;
|
|
11
|
+
}) => {
|
|
12
|
+
authClient: import("@dfinity/auth-client").AuthClient | null;
|
|
13
|
+
authenticated: boolean;
|
|
14
|
+
authenticating: boolean;
|
|
15
|
+
identity: import("@dfinity/agent/lib/cjs/auth").Identity | null;
|
|
16
|
+
login: (options?: import("@dfinity/auth-client").AuthClientLoginOptions | undefined) => Promise<void>;
|
|
17
|
+
logout: (options?: {
|
|
18
|
+
returnTo?: string | undefined;
|
|
19
|
+
} | undefined) => Promise<void>;
|
|
20
|
+
authenticate: () => Promise<import("@dfinity/agent/lib/cjs/auth").Identity>;
|
|
21
|
+
loginLoading: boolean;
|
|
22
|
+
loginError: Error | null;
|
|
23
|
+
};
|
|
24
|
+
export declare const useUserPrincipal: (agentContext?: AgentContextType) => import("@dfinity/principal").Principal | undefined;
|
|
@@ -1,17 +1,43 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
14
|
+
exports.useUserPrincipal = exports.useAuthClient = exports.useAgentState = exports.useAuthState = exports.useAgent = exports.useAgentManager = exports.useAgentManagerContext = void 0;
|
|
4
15
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
16
|
+
const context_1 = require("./context");
|
|
17
|
+
const useAgentManagerContext = (agentContext) => {
|
|
18
|
+
const context = (0, react_1.useContext)(agentContext || context_1.AgentContext);
|
|
19
|
+
if (!context) {
|
|
20
|
+
throw new Error("Agent context must be used within a AgentProvider");
|
|
21
|
+
}
|
|
22
|
+
return context;
|
|
23
|
+
};
|
|
24
|
+
exports.useAgentManagerContext = useAgentManagerContext;
|
|
6
25
|
const useAgentManager = (agentContext) => {
|
|
7
|
-
const context = (0,
|
|
26
|
+
const context = (0, exports.useAgentManagerContext)(agentContext);
|
|
8
27
|
return context.agentManager;
|
|
9
28
|
};
|
|
10
29
|
exports.useAgentManager = useAgentManager;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
const useAgent = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useAgent();
|
|
31
|
+
exports.useAgent = useAgent;
|
|
32
|
+
const useAuthState = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useAuthState();
|
|
33
|
+
exports.useAuthState = useAuthState;
|
|
34
|
+
const useAgentState = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useAgentState();
|
|
35
|
+
exports.useAgentState = useAgentState;
|
|
36
|
+
const useAuthClient = (_a) => {
|
|
37
|
+
var { agentContext } = _a, args = __rest(_a, ["agentContext"]);
|
|
38
|
+
const context = (0, exports.useAgentManagerContext)(agentContext);
|
|
39
|
+
return context.useAuthClient(args);
|
|
16
40
|
};
|
|
17
|
-
exports.
|
|
41
|
+
exports.useAuthClient = useAuthClient;
|
|
42
|
+
const useUserPrincipal = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useUserPrincipal();
|
|
43
|
+
exports.useUserPrincipal = useUserPrincipal;
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { AgentManagerOptions } from "@ic-reactor/core";
|
|
3
|
-
import { AgentContextValue, AgentContextType, AgentProviderProps } from "./types";
|
|
4
|
-
export * from "./types";
|
|
1
|
+
export * from "./context";
|
|
5
2
|
export * from "./hooks";
|
|
6
|
-
export declare const AgentManagerContext: React.Context<AgentContextValue | null>;
|
|
7
|
-
export declare const useAgentManagerContext: (agentContext?: AgentContextType) => AgentContextValue;
|
|
8
|
-
export declare const createAgentContext: (config: AgentManagerOptions) => AgentContextValue;
|
|
9
|
-
declare const AgentProvider: React.FC<AgentProviderProps>;
|
|
10
|
-
export { AgentProvider };
|
|
@@ -10,60 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
28
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
29
|
-
var t = {};
|
|
30
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
31
|
-
t[p] = s[p];
|
|
32
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
33
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
34
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
35
|
-
t[p[i]] = s[p[i]];
|
|
36
|
-
}
|
|
37
|
-
return t;
|
|
38
|
-
};
|
|
39
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
|
|
41
|
-
const react_1 = __importStar(require("react"));
|
|
42
|
-
const core_1 = require("@ic-reactor/core");
|
|
43
|
-
const agent_1 = require("../../hooks/agent");
|
|
44
|
-
const auth_1 = require("../../hooks/auth");
|
|
45
|
-
__exportStar(require("./types"), exports);
|
|
17
|
+
__exportStar(require("./context"), exports);
|
|
46
18
|
__exportStar(require("./hooks"), exports);
|
|
47
|
-
exports.AgentManagerContext = (0, react_1.createContext)(null);
|
|
48
|
-
const useAgentManagerContext = (agentContext) => {
|
|
49
|
-
const context = (0, react_1.useContext)(agentContext || exports.AgentManagerContext);
|
|
50
|
-
if (!context) {
|
|
51
|
-
throw new Error("Agent context must be used within a AgentProvider");
|
|
52
|
-
}
|
|
53
|
-
return context;
|
|
54
|
-
};
|
|
55
|
-
exports.useAgentManagerContext = useAgentManagerContext;
|
|
56
|
-
const createAgentContext = (config) => {
|
|
57
|
-
const agentManager = (0, core_1.createAgentManager)(config);
|
|
58
|
-
const agenthooks = (0, agent_1.getAgentHooks)(agentManager);
|
|
59
|
-
const authHooks = (0, auth_1.getAuthHooks)(agentManager);
|
|
60
|
-
return Object.assign(Object.assign(Object.assign({}, agenthooks), authHooks), { agentManager });
|
|
61
|
-
};
|
|
62
|
-
exports.createAgentContext = createAgentContext;
|
|
63
|
-
const AgentProvider = (_a) => {
|
|
64
|
-
var { children } = _a, config = __rest(_a, ["children"]);
|
|
65
|
-
const value = (0, react_1.useMemo)(() => (0, exports.createAgentContext)(config), [config]);
|
|
66
|
-
return (react_1.default.createElement(exports.AgentManagerContext.Provider, { value: value }, children));
|
|
67
|
-
};
|
|
68
|
-
exports.AgentProvider = AgentProvider;
|
|
69
|
-
AgentProvider.displayName = "AgentProvider";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import type { AgentManagerOptions } from "@ic-reactor/core/dist/types";
|
|
3
|
+
import type { AgentManager } from "@ic-reactor/core/dist/agent";
|
|
4
|
+
import type { getAuthHooks } from "../../helpers/auth";
|
|
5
|
+
import type { getAgentHooks } from "../../helpers/agent";
|
|
5
6
|
export type AgentContextValue = ReturnType<typeof getAuthHooks> & ReturnType<typeof getAgentHooks> & {
|
|
6
7
|
agentManager: AgentManager;
|
|
7
8
|
};
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createReactorStore, createActorManager, createAgentManager, createCandidAdapter, } from "@ic-reactor/core";
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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; } });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ActorHooks } from "../types";
|
|
2
|
-
import { ActorManager } from "@ic-reactor/core";
|
|
2
|
+
import type { ActorManager } from "@ic-reactor/core/dist/actor";
|
|
3
3
|
export declare const getActorHooks: <A>({ initialize, canisterId, actorStore, callMethod, visitFunction, }: ActorManager<A>) => ActorHooks<A, true>;
|
|
@@ -43,7 +43,7 @@ const getActorHooks = ({ initialize, canisterId, actorStore, callMethod, visitFu
|
|
|
43
43
|
return serviceFields[functionName];
|
|
44
44
|
}, [functionName, serviceFields]);
|
|
45
45
|
};
|
|
46
|
-
const
|
|
46
|
+
const useReactorCall = ({ onError, onSuccess, onLoading, args = [], functionName, throwOnError = false, }) => {
|
|
47
47
|
const [state, setState] = (0, react_1.useState)(DEFAULT_STATE);
|
|
48
48
|
const reset = (0, react_1.useCallback)(() => setState(DEFAULT_STATE), []);
|
|
49
49
|
const call = (0, react_1.useCallback)((eventOrReplaceArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -75,7 +75,7 @@ const getActorHooks = ({ initialize, canisterId, actorStore, callMethod, visitFu
|
|
|
75
75
|
};
|
|
76
76
|
const useQueryCall = (_a) => {
|
|
77
77
|
var { refetchOnMount = true, refetchInterval = false } = _a, rest = __rest(_a, ["refetchOnMount", "refetchInterval"]);
|
|
78
|
-
const _b =
|
|
78
|
+
const _b = useReactorCall(rest), { call } = _b, state = __rest(_b, ["call"]);
|
|
79
79
|
const intervalId = (0, react_1.useRef)(undefined);
|
|
80
80
|
(0, react_1.useEffect)(() => {
|
|
81
81
|
// Auto-refresh logic
|
|
@@ -84,22 +84,23 @@ const getActorHooks = ({ initialize, canisterId, actorStore, callMethod, visitFu
|
|
|
84
84
|
call();
|
|
85
85
|
}, refetchInterval);
|
|
86
86
|
}
|
|
87
|
-
// Initial call logic
|
|
88
|
-
if (refetchOnMount) {
|
|
89
|
-
call();
|
|
90
|
-
}
|
|
91
87
|
return () => {
|
|
92
88
|
clearInterval(intervalId.current);
|
|
93
89
|
};
|
|
94
|
-
}, [
|
|
90
|
+
}, [refetchInterval]);
|
|
91
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
92
|
+
if (refetchOnMount) {
|
|
93
|
+
call();
|
|
94
|
+
}
|
|
95
|
+
}, []);
|
|
95
96
|
return Object.assign({ call }, state);
|
|
96
97
|
};
|
|
97
98
|
const useUpdateCall = (args) => {
|
|
98
|
-
return
|
|
99
|
+
return useReactorCall(args);
|
|
99
100
|
};
|
|
100
101
|
const useMethodCall = (args) => {
|
|
101
102
|
const visit = visitFunction[args.functionName];
|
|
102
|
-
return Object.assign({ visit },
|
|
103
|
+
return Object.assign({ visit }, useReactorCall(args));
|
|
103
104
|
};
|
|
104
105
|
return {
|
|
105
106
|
initialize,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AgentManager } from "@ic-reactor/core/dist/agent";
|
|
2
|
+
import type { HttpAgent } from "@ic-reactor/core/dist/types";
|
|
3
|
+
export declare const getAgentHooks: (agentManager: AgentManager) => {
|
|
4
|
+
useAgent: () => HttpAgent | undefined;
|
|
5
|
+
useAgentState: () => import("@ic-reactor/core/dist/types").AgentState;
|
|
6
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { AuthClientLoginOptions } from "@dfinity/auth-client";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Identity, Principal } from "@ic-reactor/core/dist/types";
|
|
3
|
+
import type { AgentManager } from "@ic-reactor/core/dist/agent";
|
|
3
4
|
import { AuthArgs } from "../types";
|
|
4
|
-
export type AuthHooks = ReturnType<typeof getAuthHooks>;
|
|
5
5
|
export declare const getAuthHooks: (agentManager: AgentManager) => {
|
|
6
6
|
useUserPrincipal: () => Principal | undefined;
|
|
7
|
-
|
|
7
|
+
useAuthState: () => import("@ic-reactor/core/dist/types").AuthState;
|
|
8
8
|
useAuthClient: ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, }?: AuthArgs) => {
|
|
9
9
|
authClient: import("@dfinity/auth-client").AuthClient | null;
|
|
10
10
|
authenticated: boolean;
|
|
@@ -14,18 +14,17 @@ const react_1 = require("react");
|
|
|
14
14
|
const zustand_1 = require("zustand");
|
|
15
15
|
const getAuthHooks = (agentManager) => {
|
|
16
16
|
const { authenticate: authenticator, authStore, isLocalEnv } = agentManager;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
return authState;
|
|
17
|
+
const useAuthState = () => {
|
|
18
|
+
return (0, zustand_1.useStore)(authStore, (state) => state);
|
|
20
19
|
};
|
|
21
20
|
const useUserPrincipal = () => {
|
|
22
|
-
const { identity } =
|
|
21
|
+
const { identity } = useAuthState();
|
|
23
22
|
return identity === null || identity === void 0 ? void 0 : identity.getPrincipal();
|
|
24
23
|
};
|
|
25
24
|
const useAuthClient = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
|
|
26
25
|
const [loginLoading, setLoginLoading] = (0, react_1.useState)(false);
|
|
27
26
|
const [loginError, setLoginError] = (0, react_1.useState)(null);
|
|
28
|
-
const { authClient, authenticated, authenticating, identity } =
|
|
27
|
+
const { authClient, authenticated, authenticating, identity } = useAuthState();
|
|
29
28
|
const authenticate = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
29
|
const authenticatePromise = new Promise((resolve, reject) => {
|
|
31
30
|
authenticator()
|
|
@@ -124,7 +123,7 @@ const getAuthHooks = (agentManager) => {
|
|
|
124
123
|
};
|
|
125
124
|
return {
|
|
126
125
|
useUserPrincipal,
|
|
127
|
-
|
|
126
|
+
useAuthState,
|
|
128
127
|
useAuthClient,
|
|
129
128
|
};
|
|
130
129
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./agent"), exports);
|
|
18
|
+
__exportStar(require("./actor"), exports);
|
|
19
|
+
__exportStar(require("./auth"), exports);
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -16,6 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./useActor"), exports);
|
|
18
18
|
__exportStar(require("./useCandid"), exports);
|
|
19
|
-
__exportStar(require("./agent"), exports);
|
|
20
|
-
__exportStar(require("./actor"), exports);
|
|
21
|
-
__exportStar(require("./auth"), exports);
|
package/dist/hooks/useActor.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IDL } from "@dfinity/candid";
|
|
2
|
+
import { ActorManagerOptions, BaseActor } from "@ic-reactor/core/dist/types";
|
|
3
|
+
import { AgentContextType } from "../types";
|
|
3
4
|
interface DynamicActorArgs extends Omit<ActorManagerOptions, "idlFactory" | "agentManager" | "canisterId"> {
|
|
4
5
|
canisterId: string;
|
|
5
6
|
idlFactory?: IDL.InterfaceFactory;
|
|
6
7
|
agentContext?: AgentContextType;
|
|
7
8
|
didjsCanisterId?: string;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* A hook to create an actor manager and fetch the actor's candid interface.
|
|
12
|
+
*
|
|
13
|
+
* @category Hooks
|
|
14
|
+
*/
|
|
9
15
|
export declare const useActor: <A = BaseActor>({ canisterId, agentContext, idlFactory: maybeIdlFactory, didjsCanisterId, ...config }: DynamicActorArgs) => {
|
|
10
|
-
fetchCandid: () => Promise<import("@ic-reactor/core").CandidDefenition | undefined>;
|
|
16
|
+
fetchCandid: () => Promise<import("@ic-reactor/core/dist/types").CandidDefenition | undefined>;
|
|
11
17
|
fetching: boolean;
|
|
12
18
|
fetchError: string | null;
|
|
13
19
|
actorManager: import("@ic-reactor/core").ActorManager<A> | null;
|
package/dist/hooks/useActor.js
CHANGED
|
@@ -16,6 +16,11 @@ const core_1 = require("@ic-reactor/core");
|
|
|
16
16
|
const react_1 = require("react");
|
|
17
17
|
const agent_1 = require("../context/agent");
|
|
18
18
|
const useCandid_1 = require("./useCandid");
|
|
19
|
+
/**
|
|
20
|
+
* A hook to create an actor manager and fetch the actor's candid interface.
|
|
21
|
+
*
|
|
22
|
+
* @category Hooks
|
|
23
|
+
*/
|
|
19
24
|
const useActor = (_a) => {
|
|
20
25
|
var { canisterId, agentContext, idlFactory: maybeIdlFactory, didjsCanisterId } = _a, config = __rest(_a, ["canisterId", "agentContext", "idlFactory", "didjsCanisterId"]);
|
|
21
26
|
const agentManager = (0, agent_1.useAgentManager)(agentContext);
|
|
@@ -29,7 +34,7 @@ const useActor = (_a) => {
|
|
|
29
34
|
return null;
|
|
30
35
|
}
|
|
31
36
|
else {
|
|
32
|
-
const manager = (0, core_1.
|
|
37
|
+
const manager = (0, core_1.createReactorStore)({
|
|
33
38
|
agentManager,
|
|
34
39
|
idlFactory,
|
|
35
40
|
canisterId,
|
|
@@ -5,7 +5,7 @@ interface UseIDLFactoryArgs {
|
|
|
5
5
|
idlFactory?: IDL.InterfaceFactory;
|
|
6
6
|
}
|
|
7
7
|
export declare const useCandid: ({ canisterId, didjsCanisterId, idlFactory, }: UseIDLFactoryArgs) => {
|
|
8
|
-
fetchCandid: () => Promise<import("@ic-reactor/core").CandidDefenition | undefined>;
|
|
8
|
+
fetchCandid: () => Promise<import("@ic-reactor/core/dist/types").CandidDefenition | undefined>;
|
|
9
9
|
candid: {
|
|
10
10
|
idlFactory?: IDL.InterfaceFactory | undefined;
|
|
11
11
|
init: ({ idl }: {
|
package/dist/hooks/useCandid.js
CHANGED
|
@@ -23,7 +23,7 @@ const useCandid = ({ canisterId, didjsCanisterId, idlFactory, }) => {
|
|
|
23
23
|
idlFactory,
|
|
24
24
|
init: () => [],
|
|
25
25
|
} }));
|
|
26
|
-
const agent = (0, agent_1.
|
|
26
|
+
const agent = (0, agent_1.useAgent)();
|
|
27
27
|
const fetchCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
if (!canisterId || !agent)
|
|
29
29
|
return;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
export * from "@ic-reactor/core";
|
|
4
|
-
export * from "./context/agent";
|
|
5
|
-
export * from "./context/actor";
|
|
6
|
-
export * from "./hooks";
|
|
7
|
-
export declare const createReActor: <A = BaseActor>({ isLocalEnv, withVisitor, withProcessEnv, ...options }: CreateReActorOptions) => {
|
|
1
|
+
import { BaseActor, CreateReactorOptions } from "@ic-reactor/core/dist/types";
|
|
2
|
+
export declare const createReactor: <A = BaseActor>({ isLocalEnv, withVisitor, withProcessEnv, ...options }: CreateReactorOptions) => {
|
|
8
3
|
useUserPrincipal: () => import("@dfinity/principal").Principal | undefined;
|
|
9
|
-
|
|
4
|
+
useAuthState: () => import("@ic-reactor/core/dist/types").AuthState;
|
|
10
5
|
useAuthClient: ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, }?: import("./types").AuthArgs) => {
|
|
11
6
|
authClient: import("@dfinity/auth-client").AuthClient | null;
|
|
12
7
|
authenticated: boolean;
|
|
13
8
|
authenticating: boolean;
|
|
14
|
-
identity: import("@ic-reactor/core").Identity | null;
|
|
9
|
+
identity: import("@ic-reactor/core/dist/types").Identity | null;
|
|
15
10
|
login: (options?: import("@dfinity/auth-client").AuthClientLoginOptions | undefined) => Promise<void>;
|
|
16
11
|
logout: (options?: {
|
|
17
12
|
returnTo?: string | undefined;
|
|
18
13
|
} | undefined) => Promise<void>;
|
|
19
|
-
authenticate: () => Promise<import("@ic-reactor/core").Identity>;
|
|
14
|
+
authenticate: () => Promise<import("@ic-reactor/core/dist/types").Identity>;
|
|
20
15
|
loginLoading: boolean;
|
|
21
16
|
loginError: Error | null;
|
|
22
17
|
};
|
|
@@ -24,8 +19,14 @@ export declare const createReActor: <A = BaseActor>({ isLocalEnv, withVisitor, w
|
|
|
24
19
|
useActorState: () => import("./types").UseActorStoreReturn<A>;
|
|
25
20
|
useQueryCall: import("./types").ActorQueryCall<A>;
|
|
26
21
|
useUpdateCall: import("./types").ActorUpdateCall<A>;
|
|
27
|
-
useMethodCall: <M extends import("@ic-reactor/core").FunctionName<A>>(args: import("./types").ActorUseMethodCallArg<A, M>) => import("./types").ActorUseMethodCallReturn<A, M, true>;
|
|
28
|
-
useVisitMethod: <M_1 extends import("@ic-reactor/core").FunctionName<A>>(functionName: M_1) => import("@ic-reactor/core").VisitService<A>[M_1];
|
|
29
|
-
getAgent: () => import("@ic-reactor/core").HttpAgent;
|
|
30
|
-
getVisitFunction: () => import("@ic-reactor/core").VisitService<A>;
|
|
22
|
+
useMethodCall: <M extends import("@ic-reactor/core/dist/types").FunctionName<A>>(args: import("./types").ActorUseMethodCallArg<A, M>) => import("./types").ActorUseMethodCallReturn<A, M, true>;
|
|
23
|
+
useVisitMethod: <M_1 extends import("@ic-reactor/core/dist/types").FunctionName<A>>(functionName: M_1) => import("@ic-reactor/core/dist/types").VisitService<A>[M_1];
|
|
24
|
+
getAgent: () => import("@ic-reactor/core/dist/types").HttpAgent;
|
|
25
|
+
getVisitFunction: () => import("@ic-reactor/core/dist/types").VisitService<A>;
|
|
31
26
|
};
|
|
27
|
+
export * from "./context/agent";
|
|
28
|
+
export * from "./context/actor";
|
|
29
|
+
export * as helpers from "./helpers";
|
|
30
|
+
export * as hooks from "./hooks";
|
|
31
|
+
export * as types from "./types";
|
|
32
|
+
export * as core from "./core";
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,21 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
17
29
|
var t = {};
|
|
18
30
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -25,26 +37,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
25
37
|
return t;
|
|
26
38
|
};
|
|
27
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.
|
|
40
|
+
exports.core = exports.types = exports.hooks = exports.helpers = exports.createReactor = void 0;
|
|
29
41
|
const core_1 = require("@ic-reactor/core");
|
|
30
|
-
const actor_1 = require("./
|
|
31
|
-
const auth_1 = require("./
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
__exportStar(require("@ic-reactor/core"), exports);
|
|
35
|
-
__exportStar(require("./context/agent"), exports);
|
|
36
|
-
__exportStar(require("./context/actor"), exports);
|
|
37
|
-
__exportStar(require("./hooks"), exports);
|
|
38
|
-
const createReActor = (_a) => {
|
|
42
|
+
const actor_1 = require("./helpers/actor");
|
|
43
|
+
const auth_1 = require("./helpers/auth");
|
|
44
|
+
const tools_1 = require("@ic-reactor/core/dist/tools");
|
|
45
|
+
const createReactor = (_a) => {
|
|
39
46
|
var { isLocalEnv, withVisitor, withProcessEnv } = _a, options = __rest(_a, ["isLocalEnv", "withVisitor", "withProcessEnv"]);
|
|
40
|
-
isLocalEnv =
|
|
41
|
-
|
|
42
|
-
(withProcessEnv
|
|
43
|
-
? typeof process !== "undefined" &&
|
|
44
|
-
(process.env.DFX_NETWORK === "local" ||
|
|
45
|
-
process.env.NODE_ENV === "development")
|
|
46
|
-
: false);
|
|
47
|
-
const actorManager = (0, core_1.createReActorStore)(Object.assign({ isLocalEnv,
|
|
47
|
+
isLocalEnv = isLocalEnv || (withProcessEnv ? (0, tools_1.isInLocalOrDevelopment)() : false);
|
|
48
|
+
const actorManager = (0, core_1.createReactorStore)(Object.assign({ isLocalEnv,
|
|
48
49
|
withVisitor }, options));
|
|
49
50
|
const getVisitFunction = () => {
|
|
50
51
|
if (!withVisitor) {
|
|
@@ -60,4 +61,10 @@ const createReActor = (_a) => {
|
|
|
60
61
|
return Object.assign(Object.assign({ getAgent,
|
|
61
62
|
getVisitFunction }, actorHooks), authHooks);
|
|
62
63
|
};
|
|
63
|
-
exports.
|
|
64
|
+
exports.createReactor = createReactor;
|
|
65
|
+
__exportStar(require("./context/agent"), exports);
|
|
66
|
+
__exportStar(require("./context/actor"), exports);
|
|
67
|
+
exports.helpers = __importStar(require("./helpers"));
|
|
68
|
+
exports.hooks = __importStar(require("./hooks"));
|
|
69
|
+
exports.types = __importStar(require("./types"));
|
|
70
|
+
exports.core = __importStar(require("./core"));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { ActorState, CanisterId,
|
|
3
|
-
import type { AuthHooks } from "./
|
|
4
|
-
|
|
2
|
+
import type { ActorState, CanisterId, CreateReactorOptions, ActorMethodArgs, ActorMethodReturnType, HttpAgent, Identity, Principal, FunctionName, VisitService } from "@ic-reactor/core/dist/types";
|
|
3
|
+
import type { AgentHooks, AuthHooks } from "./helpers/types";
|
|
4
|
+
export * from "@ic-reactor/core/dist/types";
|
|
5
|
+
export * from "./context/agent/types";
|
|
6
|
+
export * from "./context/actor/types";
|
|
7
|
+
export * from "./helpers/types";
|
|
5
8
|
export type AuthArgs = {
|
|
6
9
|
onAuthentication?: (promise: () => Promise<Identity>) => void;
|
|
7
10
|
onAuthenticationSuccess?: (identity: Identity) => void;
|
|
@@ -63,11 +66,11 @@ export type GetFunctions<A> = {
|
|
|
63
66
|
getAgent: () => HttpAgent;
|
|
64
67
|
getVisitFunction: () => VisitService<A>;
|
|
65
68
|
};
|
|
66
|
-
export type
|
|
67
|
-
<A>(options:
|
|
69
|
+
export type CreateReactor = {
|
|
70
|
+
<A>(options: CreateReactorOptions & {
|
|
68
71
|
withVisitor: true;
|
|
69
72
|
}): GetFunctions<A> & ActorHooks<A, true> & AuthHooks & AgentHooks;
|
|
70
|
-
<A>(options:
|
|
73
|
+
<A>(options: CreateReactorOptions & {
|
|
71
74
|
withVisitor?: false | undefined;
|
|
72
75
|
}): GetFunctions<A> & ActorHooks<A, false> & AuthHooks & AgentHooks;
|
|
73
76
|
};
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@ic-reactor/core/dist/types"), exports);
|
|
18
|
+
__exportStar(require("./context/agent/types"), exports);
|
|
19
|
+
__exportStar(require("./context/actor/types"), exports);
|
|
20
|
+
__exportStar(require("./helpers/types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A React library for interacting with Internet Computer canisters",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/b3hr4d/ic-reactor/issues"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.
|
|
27
|
+
"homepage": "https://b3pay.github.io/ic-reactor/modules/react.html",
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "npx jest",
|
|
30
30
|
"start": "tsc watch",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/core": "^1.0.
|
|
38
|
+
"@ic-reactor/core": "^1.0.2",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": ">=16.8",
|
|
49
49
|
"zustand": "4.5"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "4d19bef671056c8046ec64037f51d85380ff5bae"
|
|
52
52
|
}
|
package/dist/hooks/agent.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AgentManager, HttpAgent } from "@ic-reactor/core";
|
|
2
|
-
export type AgentHooks = ReturnType<typeof getAgentHooks>;
|
|
3
|
-
export declare const getAgentHooks: (agentManager: AgentManager) => {
|
|
4
|
-
useAgent: () => HttpAgent | undefined;
|
|
5
|
-
useAgentState: () => import("@ic-reactor/core").AgentState;
|
|
6
|
-
};
|
|
File without changes
|