@ic-reactor/core 3.6.0 → 3.7.0
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 +4 -4
- package/dist/client.d.ts +17 -79
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +49 -527
- package/dist/client.js.map +1 -1
- package/dist/display/visitor.d.ts.map +1 -1
- package/dist/display/visitor.js +6 -1
- package/dist/display/visitor.js.map +1 -1
- package/dist/display-reactor.d.ts +3 -0
- package/dist/display-reactor.d.ts.map +1 -1
- package/dist/display-reactor.js +3 -0
- package/dist/display-reactor.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/reactor.d.ts +4 -4
- package/dist/reactor.d.ts.map +1 -1
- package/dist/reactor.js +27 -10
- package/dist/reactor.js.map +1 -1
- package/dist/types/client.d.ts +1 -120
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/display-reactor.d.ts.map +1 -1
- package/dist/types/reactor.d.ts +8 -0
- package/dist/types/reactor.d.ts.map +1 -1
- package/dist/types/variant.d.ts.map +1 -1
- package/dist/utils/agent.d.ts +3 -2
- package/dist/utils/agent.d.ts.map +1 -1
- package/dist/utils/agent.js +9 -3
- package/dist/utils/agent.js.map +1 -1
- package/dist/utils/constants.d.ts +0 -2
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +0 -2
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/helper.d.ts +14 -1
- package/dist/utils/helper.d.ts.map +1 -1
- package/dist/utils/helper.js +48 -9
- package/dist/utils/helper.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/polling.d.ts.map +1 -1
- package/dist/utils/polling.js +2 -2
- package/dist/utils/polling.js.map +1 -1
- package/dist/utils/query-data.d.ts +4 -0
- package/dist/utils/query-data.d.ts.map +1 -0
- package/dist/utils/query-data.js +3 -0
- package/dist/utils/query-data.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/llms.txt +43 -0
- package/package.json +15 -17
- package/src/client.ts +53 -626
- package/src/display/visitor.ts +10 -1
- package/src/display-reactor.ts +3 -0
- package/src/index.ts +0 -1
- package/src/reactor.ts +48 -18
- package/src/types/client.ts +1 -138
- package/src/types/display-reactor.ts +1 -2
- package/src/types/reactor.ts +15 -0
- package/src/types/variant.ts +8 -6
- package/src/utils/agent.ts +12 -3
- package/src/utils/constants.ts +0 -5
- package/src/utils/helper.ts +52 -7
- package/src/utils/index.ts +1 -0
- package/src/utils/polling.ts +3 -3
- package/src/utils/query-data.ts +5 -0
- package/src/version.ts +2 -2
- package/dist/identity-attributes.d.ts +0 -19
- package/dist/identity-attributes.d.ts.map +0 -1
- package/dist/identity-attributes.js +0 -167
- package/dist/identity-attributes.js.map +0 -1
- package/src/identity-attributes.ts +0 -263
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
<strong>The Core Library for Internet Computer Applications</strong>
|
|
5
5
|
<br><br>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@ic-reactor/core)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
---
|
package/dist/client.d.ts
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import type { Identity } from "@icp-sdk/core/agent";
|
|
2
|
-
import type { ClientManagerParameters, AgentState
|
|
2
|
+
import type { ClientManagerParameters, AgentState } from "./types/client";
|
|
3
3
|
import type { Principal } from "@icp-sdk/core/principal";
|
|
4
|
-
import type { QueryClient } from "@tanstack/
|
|
4
|
+
import type { QueryClient } from "@tanstack/query-core";
|
|
5
5
|
import { HttpAgent } from "@icp-sdk/core/agent";
|
|
6
6
|
/**
|
|
7
|
-
* ClientManager is a central class for managing the Internet Computer (IC) agent
|
|
7
|
+
* ClientManager is a central class for managing the Internet Computer (IC) agent.
|
|
8
8
|
*
|
|
9
|
-
* It initializes the agent (connecting to local or mainnet)
|
|
10
|
-
*
|
|
9
|
+
* It initializes the agent (connecting to local or mainnet) and integrates
|
|
10
|
+
* with TanStack Query's QueryClient for state management.
|
|
11
|
+
* Use this as a singleton shared by all reactors in an app.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```typescript
|
|
14
15
|
* import { ClientManager } from "@ic-reactor/core";
|
|
15
|
-
* import { QueryClient } from "@tanstack/
|
|
16
|
+
* import { QueryClient } from "@tanstack/query-core";
|
|
16
17
|
*
|
|
17
18
|
* const queryClient = new QueryClient();
|
|
18
19
|
* const clientManager = new ClientManager({
|
|
19
20
|
* queryClient,
|
|
20
|
-
*
|
|
21
|
+
* agentOptions: { host: "http://127.0.0.1:4943" },
|
|
21
22
|
* });
|
|
22
23
|
*
|
|
23
24
|
* await clientManager.initialize();
|
|
24
25
|
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Reuse the same ClientManager across multiple canisters
|
|
30
|
+
* const backend = new Reactor<BackendService>({ clientManager, idlFactory: backendIdl, name: "backend" })
|
|
31
|
+
* const ledger = new Reactor<LedgerService>({ clientManager, idlFactory: ledgerIdl, name: "ledger" })
|
|
32
|
+
* ```
|
|
25
33
|
*/
|
|
26
34
|
export declare class ClientManager {
|
|
27
35
|
#private;
|
|
@@ -33,41 +41,21 @@ export declare class ClientManager {
|
|
|
33
41
|
* Current state of the HttpAgent, including initialization status, network, and error information.
|
|
34
42
|
*/
|
|
35
43
|
agentState: AgentState;
|
|
36
|
-
/**
|
|
37
|
-
* Current authentication state, including the active identity, authentication progress, and errors.
|
|
38
|
-
*/
|
|
39
|
-
authState: AuthState;
|
|
40
44
|
private initPromise?;
|
|
41
|
-
private authPromise?;
|
|
42
|
-
private authClientConstructor?;
|
|
43
|
-
private authClientConstructorPromise?;
|
|
44
|
-
private authStateRevision;
|
|
45
|
-
private authClientWasProvided;
|
|
46
|
-
private port;
|
|
47
|
-
private internetIdentityId?;
|
|
48
45
|
/**
|
|
49
46
|
* Creates a new instance of ClientManager.
|
|
50
47
|
*
|
|
51
48
|
* @param parameters - Configuration options for the agent and network environment.
|
|
52
49
|
*/
|
|
53
|
-
constructor({
|
|
50
|
+
constructor({ agentOptions, queryClient }: ClientManagerParameters);
|
|
54
51
|
/**
|
|
55
52
|
* Orchestrates the complete initialization of the ClientManager.
|
|
56
53
|
* This method awaits the agent's core initialization (e.g., fetching root keys)
|
|
57
|
-
*
|
|
54
|
+
* Authentication session restoration is handled by AuthenticationManager.
|
|
58
55
|
*
|
|
59
56
|
* @returns A promise that resolves to the ClientManager instance when core initialization is complete.
|
|
60
57
|
*/
|
|
61
58
|
initialize(): Promise<this>;
|
|
62
|
-
/**
|
|
63
|
-
* Preloads and creates an AuthClient before a user gesture is needed.
|
|
64
|
-
*
|
|
65
|
-
* Browser signer transports must open their channel directly from a click
|
|
66
|
-
* handler. Apps that pass dynamic auth options, such as OpenID provider
|
|
67
|
-
* aliases, can call this from hover/focus/effect code so the later click path
|
|
68
|
-
* can call signIn/requestAttributes without first awaiting a dynamic import.
|
|
69
|
-
*/
|
|
70
|
-
prepareAuthClient(options?: ClientManagerAuthClientOptions): Promise<AuthClientLike | undefined>;
|
|
71
59
|
/**
|
|
72
60
|
* Specifically initializes the HttpAgent.
|
|
73
61
|
* On local networks, this includes fetching the root key for certificate verification.
|
|
@@ -75,51 +63,10 @@ export declare class ClientManager {
|
|
|
75
63
|
* @returns A promise that resolves when the agent is fully initialized.
|
|
76
64
|
*/
|
|
77
65
|
initializeAgent(): Promise<void>;
|
|
78
|
-
private authModuleMissing;
|
|
79
|
-
/**
|
|
80
|
-
* Attempts to initialize the authentication client and restore a previous session.
|
|
81
|
-
*
|
|
82
|
-
* If an `AuthClient` is already initialized (passed in constructor or previously created),
|
|
83
|
-
* it uses that instance. Otherwise, it dynamically imports the `@icp-sdk/auth` module
|
|
84
|
-
* and creates a new AuthClient.
|
|
85
|
-
*
|
|
86
|
-
* If the module is missing and no client is provided, it fails gracefully by marking authentication as unavailable.
|
|
87
|
-
*
|
|
88
|
-
* @returns A promise that resolves to the restored Identity, or undefined if auth fails or is unavailable.
|
|
89
|
-
*/
|
|
90
|
-
authenticate: () => Promise<Identity | undefined>;
|
|
91
|
-
/**
|
|
92
|
-
* Triggers the login flow using the Internet Identity provider.
|
|
93
|
-
*
|
|
94
|
-
* @param loginOptions - Options for the login flow, including identity provider and callbacks.
|
|
95
|
-
* @throws An error if the authentication module is not installed.
|
|
96
|
-
*/
|
|
97
|
-
login: (loginOptions?: ClientManagerSignInOptions) => Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Logs out the user and reverts the agent to an anonymous identity.
|
|
100
|
-
*
|
|
101
|
-
* @throws An error if the authentication module is not installed.
|
|
102
|
-
*/
|
|
103
|
-
logout: (options?: {
|
|
104
|
-
returnTo?: string;
|
|
105
|
-
}) => Promise<void>;
|
|
106
|
-
requestIdentityAttributes: ({ keys, nonce, identityProvider, openIdProvider, windowOpenerFeatures, signIn, maxTimeToLive, targets, }: RequestIdentityAttributesParameters) => Promise<IdentityAttributeResult>;
|
|
107
|
-
requestOpenIdIdentityAttributes: ({ nonce, openIdProvider, keys, identityProvider, windowOpenerFeatures, signIn, maxTimeToLive, targets, }: RequestOpenIdIdentityAttributesParameters) => Promise<IdentityAttributeResult>;
|
|
108
66
|
/**
|
|
109
67
|
* The underlying HttpAgent managed by this class.
|
|
110
68
|
*/
|
|
111
69
|
get agent(): HttpAgent;
|
|
112
|
-
/**
|
|
113
|
-
* The AuthClient instance used for authentication, if available.
|
|
114
|
-
*/
|
|
115
|
-
get authClient(): AuthClientLike | undefined;
|
|
116
|
-
private initializeAuthClient;
|
|
117
|
-
private signInOrRecoverAuthenticatedIdentity;
|
|
118
|
-
private loadAuthClientConstructor;
|
|
119
|
-
private createAuthClient;
|
|
120
|
-
private ensurePreparedAuthClient;
|
|
121
|
-
private shouldRecreateAuthClient;
|
|
122
|
-
private syncAuthStateFromClient;
|
|
123
70
|
/**
|
|
124
71
|
* The host URL of the current IC agent.
|
|
125
72
|
*/
|
|
@@ -157,7 +104,6 @@ export declare class ClientManager {
|
|
|
157
104
|
* Sync time with a specific subnet.
|
|
158
105
|
*/
|
|
159
106
|
syncTimeWithSubnet(subnetId: Principal): Promise<void>;
|
|
160
|
-
private getDefaultIdentityProvider;
|
|
161
107
|
/**
|
|
162
108
|
* Subscribes to identity changes (e.g., after login/logout).
|
|
163
109
|
* @param callback - Function called with the new identity.
|
|
@@ -170,12 +116,6 @@ export declare class ClientManager {
|
|
|
170
116
|
* @returns An unsubscribe function.
|
|
171
117
|
*/
|
|
172
118
|
subscribeAgentState(callback: (state: AgentState) => void): () => void;
|
|
173
|
-
/**
|
|
174
|
-
* Subscribes to changes in the authentication state.
|
|
175
|
-
* @param callback - Function called with the updated authentication state.
|
|
176
|
-
* @returns An unsubscribe function.
|
|
177
|
-
*/
|
|
178
|
-
subscribeAuthState(callback: (state: AuthState) => void): () => void;
|
|
179
119
|
/**
|
|
180
120
|
* Replaces the current agent's identity and invalidates TanStack queries.
|
|
181
121
|
* @param identity - The new identity to use.
|
|
@@ -183,8 +123,6 @@ export declare class ClientManager {
|
|
|
183
123
|
updateAgent(identity: Identity): void;
|
|
184
124
|
private notifySubscribers;
|
|
185
125
|
private notifyAgentStateSubscribers;
|
|
186
|
-
private notifyAuthStateSubscribers;
|
|
187
126
|
private updateAgentState;
|
|
188
|
-
private updateAuthState;
|
|
189
127
|
}
|
|
190
128
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAU/C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,aAAa;;IAMxB;;OAEG;IACI,WAAW,EAAE,WAAW,CAAA;IAC/B;;OAEG;IACI,UAAU,EAAE,UAAU,CAAA;IAC7B,OAAO,CAAC,WAAW,CAAC,CAAe;IAEnC;;;;OAIG;gBACS,EAAE,YAAiB,EAAE,WAAW,EAAE,EAAE,uBAAuB;IA+DvE;;;;;;OAMG;IACU,UAAU;IAKvB;;;;;OAKG;IACU,eAAe;IAuC5B;;OAEG;IACH,IAAI,KAAK,cAER;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,GAAG,GAAG,SAAS,CAE/B;IAED;;OAEG;IACH,IAAI,aAAa,WAEhB;IAED;;OAEG;IACH,IAAI,OAAO,YAEV;IAED;;OAEG;IACH,IAAI,OAAO,8BAGV;IAED;;OAEG;IACI,gBAAgB;IAIvB;;;OAGG;IACI,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAiBlE;;OAEG;IACI,oBAAoB,IAAI,MAAM,EAAE;IAIvC;;OAEG;IACI,uBAAuB,CAAC,UAAU,EAAE,MAAM;IAIjD;;OAEG;IACI,kBAAkB,CAAC,QAAQ,EAAE,SAAS;IAI7C;;;;OAIG;IACI,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI;IASvD;;;;OAIG;IACI,mBAAmB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI;IAShE;;;OAGG;IACI,WAAW,CAAC,QAAQ,EAAE,QAAQ;IAwBrC,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,gBAAgB;CAIzB"}
|