@ic-reactor/core 3.5.1 → 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.
Files changed (75) hide show
  1. package/README.md +6 -11
  2. package/dist/client.d.ts +17 -79
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +49 -527
  5. package/dist/client.js.map +1 -1
  6. package/dist/display/visitor.d.ts.map +1 -1
  7. package/dist/display/visitor.js +6 -1
  8. package/dist/display/visitor.js.map +1 -1
  9. package/dist/display-reactor.d.ts +3 -0
  10. package/dist/display-reactor.d.ts.map +1 -1
  11. package/dist/display-reactor.js +3 -0
  12. package/dist/display-reactor.js.map +1 -1
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +0 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/reactor.d.ts +4 -4
  18. package/dist/reactor.d.ts.map +1 -1
  19. package/dist/reactor.js +27 -10
  20. package/dist/reactor.js.map +1 -1
  21. package/dist/types/client.d.ts +1 -120
  22. package/dist/types/client.d.ts.map +1 -1
  23. package/dist/types/display-reactor.d.ts.map +1 -1
  24. package/dist/types/reactor.d.ts +8 -0
  25. package/dist/types/reactor.d.ts.map +1 -1
  26. package/dist/types/variant.d.ts.map +1 -1
  27. package/dist/utils/agent.d.ts +3 -2
  28. package/dist/utils/agent.d.ts.map +1 -1
  29. package/dist/utils/agent.js +9 -3
  30. package/dist/utils/agent.js.map +1 -1
  31. package/dist/utils/constants.d.ts +0 -2
  32. package/dist/utils/constants.d.ts.map +1 -1
  33. package/dist/utils/constants.js +0 -2
  34. package/dist/utils/constants.js.map +1 -1
  35. package/dist/utils/helper.d.ts +14 -1
  36. package/dist/utils/helper.d.ts.map +1 -1
  37. package/dist/utils/helper.js +48 -9
  38. package/dist/utils/helper.js.map +1 -1
  39. package/dist/utils/index.d.ts +1 -0
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/index.js.map +1 -1
  43. package/dist/utils/polling.d.ts.map +1 -1
  44. package/dist/utils/polling.js +2 -2
  45. package/dist/utils/polling.js.map +1 -1
  46. package/dist/utils/query-data.d.ts +4 -0
  47. package/dist/utils/query-data.d.ts.map +1 -0
  48. package/dist/utils/query-data.js +3 -0
  49. package/dist/utils/query-data.js.map +1 -0
  50. package/dist/version.d.ts.map +1 -1
  51. package/dist/version.js +2 -2
  52. package/dist/version.js.map +1 -1
  53. package/llms.txt +43 -0
  54. package/package.json +16 -18
  55. package/src/client.ts +53 -627
  56. package/src/display/visitor.ts +10 -1
  57. package/src/display-reactor.ts +3 -0
  58. package/src/index.ts +0 -1
  59. package/src/reactor.ts +48 -18
  60. package/src/types/client.ts +1 -138
  61. package/src/types/display-reactor.ts +1 -2
  62. package/src/types/reactor.ts +15 -0
  63. package/src/types/variant.ts +8 -6
  64. package/src/utils/agent.ts +12 -3
  65. package/src/utils/constants.ts +0 -5
  66. package/src/utils/helper.ts +52 -7
  67. package/src/utils/index.ts +1 -0
  68. package/src/utils/polling.ts +3 -3
  69. package/src/utils/query-data.ts +5 -0
  70. package/src/version.ts +2 -2
  71. package/dist/identity-attributes.d.ts +0 -14
  72. package/dist/identity-attributes.d.ts.map +0 -1
  73. package/dist/identity-attributes.js +0 -161
  74. package/dist/identity-attributes.js.map +0 -1
  75. package/src/identity-attributes.ts +0 -256
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
- [![npm version](https://img.shields.io/npm/v/@ic-reactor/core.svg)](https://www.npmjs.com/package/@ic-reactor/core)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@ic-reactor/core.svg)](https://www.npmjs.com/package/@ic-reactor/core)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
10
10
  </div>
11
11
 
12
12
  ---
@@ -160,15 +160,12 @@ const identity = await clientManager.authenticate()
160
160
 
161
161
  ### Identity Attributes / OpenID email and profile values
162
162
 
163
- `ClientManager` uses the `@icp-sdk/auth` v6 `signIn()` / `requestAttributes()`
163
+ `ClientManager` uses the `@icp-sdk/auth` v7 `signIn()` / `requestAttributes()`
164
164
  API. Apps can request signed identity attributes directly, without adding a
165
165
  local compatibility shim.
166
166
 
167
167
  ```typescript
168
- import {
169
- IDENTITY_ATTRIBUTES_BETA_PROVIDER,
170
- identityAttributeKeys,
171
- } from "@ic-reactor/core"
168
+ import { identityAttributeKeys } from "@ic-reactor/core"
172
169
 
173
170
  const nonce = await backend.registerBegin()
174
171
 
@@ -176,7 +173,6 @@ const result = await clientManager.requestOpenIdIdentityAttributes({
176
173
  nonce,
177
174
  openIdProvider: "microsoft",
178
175
  keys: ["email", "name"],
179
- identityProvider: IDENTITY_ATTRIBUTES_BETA_PROVIDER,
180
176
  windowOpenerFeatures: popupCenter(),
181
177
  })
182
178
 
@@ -209,7 +205,6 @@ const result = await clientManager.requestIdentityAttributes({
209
205
  openIdProvider: "https://issuer.example.com",
210
206
  keys: ["sub", "email"],
211
207
  }),
212
- identityProvider: "https://beta.id.ai/authorize",
213
208
  })
214
209
  ```
215
210
 
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, AuthState, AuthClientLike, ClientManagerAuthClientOptions, ClientManagerSignInOptions, IdentityAttributeResult, RequestIdentityAttributesParameters, RequestOpenIdIdentityAttributesParameters } from "./types/client";
2
+ import type { ClientManagerParameters, AgentState } from "./types/client";
3
3
  import type { Principal } from "@icp-sdk/core/principal";
4
- import type { QueryClient } from "@tanstack/react-query";
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 and authentication state.
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), handles authentication via AuthClient,
10
- * and integrates with TanStack Query's QueryClient for state management.
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/react-query";
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
- * withLocalEnv: true, // Use local replica
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({ port, withLocalEnv, withProcessEnv, withCanisterEnv, agentOptions, queryClient, authClient, }: ClientManagerParameters);
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
- * and triggers the authentication (session restoration) in the background.
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
@@ -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,EACV,uBAAuB,EACvB,UAAU,EACV,SAAS,EAET,cAAc,EACd,8BAA8B,EAC9B,0BAA0B,EAC1B,uBAAuB,EACvB,mCAAmC,EACnC,yCAAyC,EAC1C,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAuB/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,aAAa;;IAQxB;;OAEG;IACI,WAAW,EAAE,WAAW,CAAA;IAC/B;;OAEG;IACI,UAAU,EAAE,UAAU,CAAA;IAC7B;;OAEG;IACI,SAAS,EAAE,SAAS,CAAA;IAE3B,OAAO,CAAC,WAAW,CAAC,CAAe;IACnC,OAAO,CAAC,WAAW,CAAC,CAA+B;IACnD,OAAO,CAAC,qBAAqB,CAAC,CAAuB;IACrD,OAAO,CAAC,4BAA4B,CAAC,CAEpC;IACD,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO,CAAC,qBAAqB,CAAQ;IACrC,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,kBAAkB,CAAC,CAAQ;IAEnC;;;;OAIG;gBACS,EACV,IAAW,EACX,YAAY,EACZ,cAAc,EACd,eAAe,EACf,YAAiB,EACjB,WAAW,EACX,UAAU,GACX,EAAE,uBAAuB;IAgG1B;;;;;;O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