@ic-reactor/react 1.0.1 → 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 -2
- package/dist/context/actor/index.d.ts +1 -1
- package/dist/context/actor/index.js +5 -5
- package/dist/context/actor/types.d.ts +1 -1
- package/dist/context/agent/context.d.ts +2 -0
- package/dist/context/agent/context.js +5 -4
- package/dist/context/agent/hooks.d.ts +1 -1
- package/dist/context/agent/hooks.js +3 -3
- package/dist/context/agent/types.d.ts +2 -2
- package/dist/core.d.ts +1 -0
- package/dist/core.js +8 -0
- package/dist/{hooks → helpers}/actor.js +4 -4
- package/dist/{hooks → helpers}/auth.d.ts +1 -1
- 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/hooks/index.d.ts +0 -3
- package/dist/hooks/index.js +0 -3
- package/dist/hooks/useActor.d.ts +1 -1
- package/dist/hooks/useActor.js +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +15 -15
- package/dist/types.d.ts +6 -6
- package/dist/types.js +1 -1
- package/package.json +3 -3
- /package/dist/{hooks → helpers}/actor.d.ts +0 -0
- /package/dist/{hooks → helpers}/agent.d.ts +0 -0
- /package/dist/{hooks → helpers}/agent.js +0 -0
- /package/dist/{hooks → helpers}/types.d.ts +0 -0
- /package/dist/{hooks → helpers}/types.js +0 -0
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ First, create an actor declaration file:
|
|
|
31
31
|
```ts
|
|
32
32
|
// store.ts
|
|
33
33
|
import { canisterId, idlFactory, actor } from "declaration/actor"
|
|
34
|
-
import {
|
|
34
|
+
import { createReactor } from "@ic-reactor/react"
|
|
35
35
|
|
|
36
36
|
type Actor = typeof actor
|
|
37
37
|
|
|
38
38
|
export const { useActorStore, useAuthClient, useQueryCall } =
|
|
39
|
-
|
|
39
|
+
createReactor<Actor>({
|
|
40
40
|
canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
41
41
|
idlFactory,
|
|
42
42
|
host: "https://localhost:4943",
|
|
@@ -3,7 +3,7 @@ import { ActorUseMethodCallArg, ActorUseQueryArgs, ActorUseUpdateArgs } from "..
|
|
|
3
3
|
import { CreateActorOptions, ActorContextType, ActorProviderProps } from "./types";
|
|
4
4
|
import type { ActorSubclass } from "@dfinity/agent";
|
|
5
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
|
|
6
|
+
export declare function createReactorContext<Actor extends ActorSubclass<any>>({ canisterId: defaultCanisterId, ...defaultConfig }?: Partial<CreateActorOptions>): {
|
|
7
7
|
ActorContext: React.Context<ActorContextType | null>;
|
|
8
8
|
ActorProvider: React.FC<ActorProviderProps>;
|
|
9
9
|
useActorContext: <A extends unknown = Actor>() => ActorContextType<A>;
|
|
@@ -35,13 +35,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
35
35
|
};
|
|
36
36
|
var _a;
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
38
|
+
exports.createReactorContext = exports.useVisitMethod = exports.useMethodCall = exports.useUpdateCall = exports.useQueryCall = exports.useActorState = exports.useActorContext = exports.ActorProvider = exports.ActorContext = void 0;
|
|
39
39
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
40
40
|
const react_1 = __importStar(require("react"));
|
|
41
|
-
const actor_1 = require("../../
|
|
41
|
+
const actor_1 = require("../../helpers/actor");
|
|
42
42
|
const useActor_1 = require("../../hooks/useActor");
|
|
43
|
-
_a =
|
|
44
|
-
function
|
|
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 = {}) {
|
|
45
45
|
var { canisterId: defaultCanisterId } = _a, defaultConfig = __rest(_a, ["canisterId"]);
|
|
46
46
|
const ActorContext = (0, react_1.createContext)(null);
|
|
47
47
|
const ActorProvider = (_a) => {
|
|
@@ -85,4 +85,4 @@ function createReActorContext(_a = {}) {
|
|
|
85
85
|
initialize,
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
exports.
|
|
88
|
+
exports.createReactorContext = createReactorContext;
|
|
@@ -7,7 +7,7 @@ export type ActorContextType<Actor = BaseActor, F extends boolean = true> = Acto
|
|
|
7
7
|
useActorContext: <A = Actor>() => ActorContextType<A>;
|
|
8
8
|
ActorProvider: React.FC<ActorProviderProps>;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
10
|
+
export type CreateReactorContext = {
|
|
11
11
|
<A = BaseActor>(options?: Partial<CreateActorOptions> & {
|
|
12
12
|
withVisitor: true;
|
|
13
13
|
}): ActorContextType<A, true>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { AgentManagerOptions } from "@ic-reactor/core/dist/types";
|
|
2
3
|
import type { AgentContextValue, AgentProviderProps } from "./types";
|
|
3
4
|
export declare const AgentContext: React.Context<AgentContextValue | null>;
|
|
4
5
|
declare const AgentProvider: React.FC<AgentProviderProps>;
|
|
5
6
|
export { AgentProvider };
|
|
7
|
+
export declare const createAgentContext: (config: AgentManagerOptions) => AgentContextValue;
|
|
@@ -34,15 +34,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
34
34
|
return t;
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.AgentProvider = exports.AgentContext = void 0;
|
|
37
|
+
exports.createAgentContext = exports.AgentProvider = exports.AgentContext = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const core_1 = require("@ic-reactor/core");
|
|
40
|
-
const agent_1 = require("../../
|
|
41
|
-
const auth_1 = require("../../
|
|
40
|
+
const agent_1 = require("../../helpers/agent");
|
|
41
|
+
const auth_1 = require("../../helpers/auth");
|
|
42
42
|
exports.AgentContext = (0, react_1.createContext)(null);
|
|
43
43
|
const AgentProvider = (_a) => {
|
|
44
44
|
var { children } = _a, config = __rest(_a, ["children"]);
|
|
45
|
-
const value = (0, react_1.useMemo)(() => createAgentContext(config), [config]);
|
|
45
|
+
const value = (0, react_1.useMemo)(() => (0, exports.createAgentContext)(config), [config]);
|
|
46
46
|
return react_1.default.createElement(exports.AgentContext.Provider, { value: value }, children);
|
|
47
47
|
};
|
|
48
48
|
exports.AgentProvider = AgentProvider;
|
|
@@ -53,3 +53,4 @@ const createAgentContext = (config) => {
|
|
|
53
53
|
const authHooks = (0, auth_1.getAuthHooks)(agentManager);
|
|
54
54
|
return Object.assign(Object.assign(Object.assign({}, agenthooks), authHooks), { agentManager });
|
|
55
55
|
};
|
|
56
|
+
exports.createAgentContext = createAgentContext;
|
|
@@ -4,7 +4,7 @@ import { AuthArgs } from "../../types";
|
|
|
4
4
|
export declare const useAgentManagerContext: (agentContext?: AgentContextType) => import("./types").AgentContextValue;
|
|
5
5
|
export declare const useAgentManager: (agentContext?: AgentContextType) => AgentManager;
|
|
6
6
|
export declare const useAgent: (agentContext?: AgentContextType) => import("@dfinity/agent/lib/cjs/agent/http").HttpAgent | undefined;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const useAuthState: (agentContext?: AgentContextType) => import("@ic-reactor/core/dist/agent/types").AuthState;
|
|
8
8
|
export declare const useAgentState: (agentContext?: AgentContextType) => import("@ic-reactor/core/dist/agent/types").AgentState;
|
|
9
9
|
export declare const useAuthClient: ({ agentContext, ...args }: AuthArgs & {
|
|
10
10
|
agentContext?: AgentContextType | undefined;
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.useUserPrincipal = exports.useAuthClient = exports.useAgentState = exports.
|
|
14
|
+
exports.useUserPrincipal = exports.useAuthClient = exports.useAgentState = exports.useAuthState = exports.useAgent = exports.useAgentManager = exports.useAgentManagerContext = void 0;
|
|
15
15
|
const react_1 = require("react");
|
|
16
16
|
const context_1 = require("./context");
|
|
17
17
|
const useAgentManagerContext = (agentContext) => {
|
|
@@ -29,8 +29,8 @@ const useAgentManager = (agentContext) => {
|
|
|
29
29
|
exports.useAgentManager = useAgentManager;
|
|
30
30
|
const useAgent = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useAgent();
|
|
31
31
|
exports.useAgent = useAgent;
|
|
32
|
-
const
|
|
33
|
-
exports.
|
|
32
|
+
const useAuthState = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useAuthState();
|
|
33
|
+
exports.useAuthState = useAuthState;
|
|
34
34
|
const useAgentState = (agentContext) => (0, exports.useAgentManagerContext)(agentContext).useAgentState();
|
|
35
35
|
exports.useAgentState = useAgentState;
|
|
36
36
|
const useAuthClient = (_a) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
2
|
import type { AgentManagerOptions } from "@ic-reactor/core/dist/types";
|
|
3
3
|
import type { AgentManager } from "@ic-reactor/core/dist/agent";
|
|
4
|
-
import type { getAuthHooks } from "../../
|
|
5
|
-
import type { getAgentHooks } from "../../
|
|
4
|
+
import type { getAuthHooks } from "../../helpers/auth";
|
|
5
|
+
import type { getAgentHooks } from "../../helpers/agent";
|
|
6
6
|
export type AgentContextValue = ReturnType<typeof getAuthHooks> & ReturnType<typeof getAgentHooks> & {
|
|
7
7
|
agentManager: AgentManager;
|
|
8
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; } });
|
|
@@ -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
|
|
@@ -96,11 +96,11 @@ const getActorHooks = ({ initialize, canisterId, actorStore, callMethod, visitFu
|
|
|
96
96
|
return Object.assign({ call }, state);
|
|
97
97
|
};
|
|
98
98
|
const useUpdateCall = (args) => {
|
|
99
|
-
return
|
|
99
|
+
return useReactorCall(args);
|
|
100
100
|
};
|
|
101
101
|
const useMethodCall = (args) => {
|
|
102
102
|
const visit = visitFunction[args.functionName];
|
|
103
|
-
return Object.assign({ visit },
|
|
103
|
+
return Object.assign({ visit }, useReactorCall(args));
|
|
104
104
|
};
|
|
105
105
|
return {
|
|
106
106
|
initialize,
|
|
@@ -4,7 +4,7 @@ import type { AgentManager } from "@ic-reactor/core/dist/agent";
|
|
|
4
4
|
import { AuthArgs } from "../types";
|
|
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
|
@@ -16,6 +16,6 @@ export declare const useActor: <A = BaseActor>({ canisterId, agentContext, idlFa
|
|
|
16
16
|
fetchCandid: () => Promise<import("@ic-reactor/core/dist/types").CandidDefenition | undefined>;
|
|
17
17
|
fetching: boolean;
|
|
18
18
|
fetchError: string | null;
|
|
19
|
-
actorManager: import("@ic-reactor/core
|
|
19
|
+
actorManager: import("@ic-reactor/core").ActorManager<A> | null;
|
|
20
20
|
};
|
|
21
21
|
export {};
|
package/dist/hooks/useActor.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseActor,
|
|
2
|
-
export declare const
|
|
1
|
+
import { BaseActor, CreateReactorOptions } from "@ic-reactor/core/dist/types";
|
|
2
|
+
export declare const createReactor: <A = BaseActor>({ isLocalEnv, withVisitor, withProcessEnv, ...options }: CreateReactorOptions) => {
|
|
3
3
|
useUserPrincipal: () => import("@dfinity/principal").Principal | undefined;
|
|
4
|
-
|
|
4
|
+
useAuthState: () => import("@ic-reactor/core/dist/types").AuthState;
|
|
5
5
|
useAuthClient: ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, }?: import("./types").AuthArgs) => {
|
|
6
6
|
authClient: import("@dfinity/auth-client").AuthClient | null;
|
|
7
7
|
authenticated: boolean;
|
|
@@ -24,7 +24,9 @@ export declare const createReActor: <A = BaseActor>({ isLocalEnv, withVisitor, w
|
|
|
24
24
|
getAgent: () => import("@ic-reactor/core/dist/types").HttpAgent;
|
|
25
25
|
getVisitFunction: () => import("@ic-reactor/core/dist/types").VisitService<A>;
|
|
26
26
|
};
|
|
27
|
-
export *
|
|
28
|
-
export *
|
|
27
|
+
export * from "./context/agent";
|
|
28
|
+
export * from "./context/actor";
|
|
29
|
+
export * as helpers from "./helpers";
|
|
29
30
|
export * as hooks from "./hooks";
|
|
30
31
|
export * as types from "./types";
|
|
32
|
+
export * as core from "./core";
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,9 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
18
21
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
22
|
if (mod && mod.__esModule) return mod;
|
|
20
23
|
var result = {};
|
|
@@ -34,20 +37,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
34
37
|
return t;
|
|
35
38
|
};
|
|
36
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.
|
|
40
|
+
exports.core = exports.types = exports.hooks = exports.helpers = exports.createReactor = void 0;
|
|
38
41
|
const core_1 = require("@ic-reactor/core");
|
|
39
|
-
const actor_1 = require("./
|
|
40
|
-
const auth_1 = require("./
|
|
41
|
-
const
|
|
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) => {
|
|
42
46
|
var { isLocalEnv, withVisitor, withProcessEnv } = _a, options = __rest(_a, ["isLocalEnv", "withVisitor", "withProcessEnv"]);
|
|
43
|
-
isLocalEnv =
|
|
44
|
-
|
|
45
|
-
(withProcessEnv
|
|
46
|
-
? typeof process !== "undefined" &&
|
|
47
|
-
(process.env.DFX_NETWORK === "local" ||
|
|
48
|
-
process.env.NODE_ENV === "development")
|
|
49
|
-
: false);
|
|
50
|
-
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,
|
|
51
49
|
withVisitor }, options));
|
|
52
50
|
const getVisitFunction = () => {
|
|
53
51
|
if (!withVisitor) {
|
|
@@ -63,8 +61,10 @@ const createReActor = (_a) => {
|
|
|
63
61
|
return Object.assign(Object.assign({ getAgent,
|
|
64
62
|
getVisitFunction }, actorHooks), authHooks);
|
|
65
63
|
};
|
|
66
|
-
exports.
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
exports.createReactor = createReactor;
|
|
65
|
+
__exportStar(require("./context/agent"), exports);
|
|
66
|
+
__exportStar(require("./context/actor"), exports);
|
|
67
|
+
exports.helpers = __importStar(require("./helpers"));
|
|
69
68
|
exports.hooks = __importStar(require("./hooks"));
|
|
70
69
|
exports.types = __importStar(require("./types"));
|
|
70
|
+
exports.core = __importStar(require("./core"));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { ActorState, CanisterId,
|
|
3
|
-
import type { AgentHooks, AuthHooks } from "./
|
|
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
4
|
export * from "@ic-reactor/core/dist/types";
|
|
5
5
|
export * from "./context/agent/types";
|
|
6
6
|
export * from "./context/actor/types";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./helpers/types";
|
|
8
8
|
export type AuthArgs = {
|
|
9
9
|
onAuthentication?: (promise: () => Promise<Identity>) => void;
|
|
10
10
|
onAuthenticationSuccess?: (identity: Identity) => void;
|
|
@@ -66,11 +66,11 @@ export type GetFunctions<A> = {
|
|
|
66
66
|
getAgent: () => HttpAgent;
|
|
67
67
|
getVisitFunction: () => VisitService<A>;
|
|
68
68
|
};
|
|
69
|
-
export type
|
|
70
|
-
<A>(options:
|
|
69
|
+
export type CreateReactor = {
|
|
70
|
+
<A>(options: CreateReactorOptions & {
|
|
71
71
|
withVisitor: true;
|
|
72
72
|
}): GetFunctions<A> & ActorHooks<A, true> & AuthHooks & AgentHooks;
|
|
73
|
-
<A>(options:
|
|
73
|
+
<A>(options: CreateReactorOptions & {
|
|
74
74
|
withVisitor?: false | undefined;
|
|
75
75
|
}): GetFunctions<A> & ActorHooks<A, false> & AuthHooks & AgentHooks;
|
|
76
76
|
};
|
package/dist/types.js
CHANGED
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("@ic-reactor/core/dist/types"), exports);
|
|
18
18
|
__exportStar(require("./context/agent/types"), exports);
|
|
19
19
|
__exportStar(require("./context/actor/types"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
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",
|
|
@@ -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
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|