@ic-reactor/react 3.12.4 → 3.13.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 +410 -44
- package/dist/auth/auth-client-compat.d.ts +122 -0
- package/dist/auth/auth-client-compat.d.ts.map +1 -0
- package/dist/auth/auth-client-compat.js +162 -0
- package/dist/auth/auth-client-compat.js.map +1 -0
- package/dist/auth/authentication-manager.d.ts +287 -5
- package/dist/auth/authentication-manager.d.ts.map +1 -1
- package/dist/auth/authentication-manager.js +920 -150
- package/dist/auth/authentication-manager.js.map +1 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +1 -1
- package/dist/auth/createIdentityAttributeHooks.js +36 -20
- package/dist/auth/createIdentityAttributeHooks.js.map +1 -1
- package/dist/auth/identity-attributes-manager.d.ts +2 -1
- package/dist/auth/identity-attributes-manager.d.ts.map +1 -1
- package/dist/auth/identity-attributes-manager.js +90 -6
- package/dist/auth/identity-attributes-manager.js.map +1 -1
- package/dist/auth/identity-attributes.d.ts.map +1 -1
- package/dist/auth/identity-attributes.js +57 -0
- package/dist/auth/identity-attributes.js.map +1 -1
- package/dist/auth/local-ii-probe.d.ts +12 -1
- package/dist/auth/local-ii-probe.d.ts.map +1 -1
- package/dist/auth/local-ii-probe.js +22 -3
- package/dist/auth/local-ii-probe.js.map +1 -1
- package/dist/auth/types.d.ts +48 -5
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/createActorHooks.d.ts +9 -20
- package/dist/createActorHooks.d.ts.map +1 -1
- package/dist/createActorHooks.js.map +1 -1
- package/dist/createInfiniteQuery.d.ts +51 -10
- package/dist/createInfiniteQuery.d.ts.map +1 -1
- package/dist/createInfiniteQuery.js +39 -15
- package/dist/createInfiniteQuery.js.map +1 -1
- package/dist/createMutation.d.ts +4 -1
- package/dist/createMutation.d.ts.map +1 -1
- package/dist/createMutation.js +121 -84
- package/dist/createMutation.js.map +1 -1
- package/dist/createQuery.d.ts +35 -2
- package/dist/createQuery.d.ts.map +1 -1
- package/dist/createQuery.js +104 -17
- package/dist/createQuery.js.map +1 -1
- package/dist/createReactorProvider.d.ts +158 -0
- package/dist/createReactorProvider.d.ts.map +1 -0
- package/dist/createReactorProvider.js +256 -0
- package/dist/createReactorProvider.js.map +1 -0
- package/dist/createSuspenseInfiniteQuery.d.ts +16 -9
- package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/createSuspenseInfiniteQuery.js +59 -27
- package/dist/createSuspenseInfiniteQuery.js.map +1 -1
- package/dist/createSuspenseQuery.d.ts +23 -2
- package/dist/createSuspenseQuery.d.ts.map +1 -1
- package/dist/createSuspenseQuery.js +68 -21
- package/dist/createSuspenseQuery.js.map +1 -1
- package/dist/defineDisplayReactor.d.ts +43 -0
- package/dist/defineDisplayReactor.d.ts.map +1 -0
- package/dist/defineDisplayReactor.js +42 -0
- package/dist/defineDisplayReactor.js.map +1 -0
- package/dist/defineReactor.d.ts +46 -72
- package/dist/defineReactor.d.ts.map +1 -1
- package/dist/defineReactor.js +11 -176
- package/dist/defineReactor.js.map +1 -1
- package/dist/defineReactorShared.d.ts +84 -0
- package/dist/defineReactorShared.d.ts.map +1 -0
- package/dist/defineReactorShared.js +139 -0
- package/dist/defineReactorShared.js.map +1 -0
- package/dist/hooks/createAuthHooks.d.ts +9 -2
- package/dist/hooks/createAuthHooks.d.ts.map +1 -1
- package/dist/hooks/createAuthHooks.js +184 -24
- package/dist/hooks/createAuthHooks.js.map +1 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +36 -8
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -1
- package/dist/hooks/useActorInfiniteQuery.js +54 -21
- package/dist/hooks/useActorInfiniteQuery.js.map +1 -1
- package/dist/hooks/useActorMethod.d.ts +37 -4
- package/dist/hooks/useActorMethod.d.ts.map +1 -1
- package/dist/hooks/useActorMethod.js +201 -57
- package/dist/hooks/useActorMethod.js.map +1 -1
- package/dist/hooks/useActorMutation.d.ts +15 -12
- package/dist/hooks/useActorMutation.d.ts.map +1 -1
- package/dist/hooks/useActorMutation.js +14 -13
- package/dist/hooks/useActorMutation.js.map +1 -1
- package/dist/hooks/useActorQuery.d.ts +17 -4
- package/dist/hooks/useActorQuery.d.ts.map +1 -1
- package/dist/hooks/useActorQuery.js +30 -9
- package/dist/hooks/useActorQuery.js.map +1 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +17 -5
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +37 -17
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +2 -2
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -1
- package/dist/hooks/useActorSuspenseQuery.js +20 -9
- package/dist/hooks/useActorSuspenseQuery.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/ownedAuthentication.d.ts +52 -0
- package/dist/ownedAuthentication.d.ts.map +1 -0
- package/dist/ownedAuthentication.js +49 -0
- package/dist/ownedAuthentication.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +23 -0
- package/dist/server.js.map +1 -0
- package/dist/testing.d.ts +19 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +19 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +428 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +159 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +301 -1
- package/dist/utils.js.map +1 -1
- package/dist/validation.d.ts +12 -7
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +34 -15
- package/dist/validation.js.map +1 -1
- package/llms.txt +259 -33
- package/package.json +17 -5
- package/src/auth/auth-client-compat.ts +273 -0
- package/src/auth/authentication-manager.ts +918 -96
- package/src/auth/createIdentityAttributeHooks.ts +47 -21
- package/src/auth/identity-attributes-manager.ts +100 -5
- package/src/auth/identity-attributes.ts +75 -0
- package/src/auth/local-ii-probe.ts +29 -3
- package/src/auth/types.ts +49 -6
- package/src/createActorHooks.ts +50 -42
- package/src/createInfiniteQuery.ts +120 -28
- package/src/createMutation.ts +213 -132
- package/src/createQuery.ts +164 -32
- package/src/createReactorProvider.ts +365 -0
- package/src/createSuspenseInfiniteQuery.ts +93 -43
- package/src/createSuspenseQuery.ts +102 -32
- package/src/defineDisplayReactor.ts +62 -0
- package/src/defineReactor.ts +81 -263
- package/src/defineReactorShared.ts +268 -0
- package/src/hooks/createAuthHooks.ts +210 -28
- package/src/hooks/useActorInfiniteQuery.ts +156 -55
- package/src/hooks/useActorMethod.ts +295 -92
- package/src/hooks/useActorMutation.ts +42 -30
- package/src/hooks/useActorQuery.ts +43 -10
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +110 -54
- package/src/hooks/useActorSuspenseQuery.ts +30 -15
- package/src/index.ts +8 -0
- package/src/ownedAuthentication.ts +81 -0
- package/src/server.ts +23 -0
- package/src/testing.ts +18 -0
- package/src/types.ts +492 -22
- package/src/utils.ts +387 -3
- package/src/validation.ts +43 -19
package/dist/defineReactor.js
CHANGED
|
@@ -1,180 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* choice into a `display` flag.
|
|
7
|
-
* Use this when one-call bootstrap is enough. If you need reusable
|
|
8
|
-
* method-specific operations outside React, compose with query/mutation
|
|
9
|
-
* factories after setup.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { defineReactor } from "@ic-reactor/react"
|
|
14
|
-
* import { idlFactory, type _SERVICE } from "./declarations/backend"
|
|
15
|
-
*
|
|
16
|
-
* const { reactor, useActorQuery, useActorMutation } = defineReactor<_SERVICE>({
|
|
17
|
-
* name: "backend",
|
|
18
|
-
* idlFactory,
|
|
19
|
-
* canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
20
|
-
* display: true, // ⇒ DisplayReactor (string principals/bigints)
|
|
21
|
-
* })
|
|
22
|
-
*
|
|
23
|
-
* function Profile() {
|
|
24
|
-
* const { data } = useActorQuery({ functionName: "get_profile" })
|
|
25
|
-
* return <div>{data?.name}</div>
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example Reuse an existing ClientManager (multiple canisters share one agent)
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const ledger = defineReactor<_LEDGER>({ name: "ledger", idlFactory: ledgerIdl })
|
|
32
|
-
* const index = defineReactor<_INDEX>({
|
|
33
|
-
* name: "index",
|
|
34
|
-
* idlFactory: indexIdl,
|
|
35
|
-
* clientManager: ledger.clientManager,
|
|
36
|
-
* authentication: ledger.authentication, // one Internet Identity session
|
|
37
|
-
* })
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example Internet Identity is wired up out of the box
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const { useAuth, useIdentityAttributes } = defineReactor<_SERVICE>({
|
|
43
|
-
* name: "backend",
|
|
44
|
-
* idlFactory,
|
|
45
|
-
* // Needed when the app is served from more than one origin.
|
|
46
|
-
* auth: { derivationOrigin: "https://app.example.com" },
|
|
47
|
-
* })
|
|
48
|
-
*
|
|
49
|
-
* function LoginButton() {
|
|
50
|
-
* const { login, logout, isAuthenticated, principal } = useAuth()
|
|
51
|
-
* return isAuthenticated
|
|
52
|
-
* ? <button onClick={() => logout()}>{principal?.toText()}</button>
|
|
53
|
-
* : <button onClick={() => login()}>Sign in</button>
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
import { ClientManager, Reactor, DisplayReactor, reactorRetry, } from "@ic-reactor/core";
|
|
58
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
59
|
-
import { createActorHooks } from "./createActorHooks.js";
|
|
60
|
-
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
61
|
-
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
62
|
-
import { createIdentityAttributeHooks } from "./auth/createIdentityAttributeHooks.js";
|
|
63
|
-
import { createAuthHooks } from "./hooks/createAuthHooks.js";
|
|
64
|
-
/**
|
|
65
|
-
* The QueryClient this module creates when the caller does not supply one.
|
|
66
|
-
*
|
|
67
|
-
* React Query retries every failure three times by default, which for canister
|
|
68
|
-
* calls means four attempts and several seconds of backoff on outcomes that
|
|
69
|
-
* cannot change — a canister `Err`, a validation failure, a Candid encode
|
|
70
|
-
* error that never reached the network. `reactorRetry` keeps the same three
|
|
71
|
-
* attempts for transport failures and stops immediately on the rest.
|
|
72
|
-
*
|
|
73
|
-
* A caller-supplied `queryClient` is left exactly as given; opt in there with
|
|
74
|
-
* `defaultOptions: { queries: { retry: reactorRetry } }`.
|
|
75
|
-
*/
|
|
76
|
-
const createDefaultQueryClient = () => new QueryClient({
|
|
77
|
-
defaultOptions: { queries: { retry: reactorRetry } },
|
|
78
|
-
});
|
|
1
|
+
// DisplayReactor is only for the deprecated `display: true` path. It is what
|
|
2
|
+
// puts DisplayReactor and zod in every bundle that uses defineReactor; drop it
|
|
3
|
+
// with that path.
|
|
4
|
+
import { DisplayReactor, Reactor } from "@ic-reactor/core";
|
|
5
|
+
import { defineReactorWith } from "./defineReactorShared.js";
|
|
79
6
|
export function defineReactor(params) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (providedClientManager &&
|
|
86
|
-
providedAuthentication &&
|
|
87
|
-
providedAuthentication.clientManager !== providedClientManager) {
|
|
88
|
-
throw new Error(`[ic-reactor] defineReactor("${name}") received an \`authentication\` manager bound to a different \`clientManager\`. ` +
|
|
89
|
-
`Sign-in would update the authentication manager's agent while this reactor calls through another one, ` +
|
|
90
|
-
`leaving its calls anonymous. Pass \`clientManager: authentication.clientManager\`, or omit \`clientManager\` to adopt it.`);
|
|
7
|
+
if (params.display) {
|
|
8
|
+
// What defineDisplayReactor builds, but under this function's name, so an
|
|
9
|
+
// error names the call the app actually made.
|
|
10
|
+
const { validators } = params;
|
|
11
|
+
return defineReactorWith("defineReactor", params, (config) => new DisplayReactor({ ...config, validators }));
|
|
91
12
|
}
|
|
92
|
-
|
|
93
|
-
// already constructed, so these options could only be dropped on the floor.
|
|
94
|
-
if (providedAuthentication && auth) {
|
|
95
|
-
throw new Error(`[ic-reactor] defineReactor("${name}") received both \`authentication\` and \`auth\`. ` +
|
|
96
|
-
`The supplied manager is already configured, so \`auth\` (${Object.keys(auth).join(", ")}) would be ignored. ` +
|
|
97
|
-
`Pass those options where that AuthenticationManager is created, or drop \`authentication\` to build one here.`);
|
|
98
|
-
}
|
|
99
|
-
// Same reasoning as `auth`, and it matters more here: an ignored
|
|
100
|
-
// `allowEnvConfig: false` reads as "I locked the cookie out" while the
|
|
101
|
-
// supplied manager carries whatever decision it was built with.
|
|
102
|
-
if ((providedClientManager || providedAuthentication) &&
|
|
103
|
-
(allowEnvConfig !== undefined || allowEnvRootKey !== undefined)) {
|
|
104
|
-
const passed = [
|
|
105
|
-
allowEnvConfig !== undefined && "allowEnvConfig",
|
|
106
|
-
allowEnvRootKey !== undefined && "allowEnvRootKey",
|
|
107
|
-
]
|
|
108
|
-
.filter(Boolean)
|
|
109
|
-
.join(", ");
|
|
110
|
-
throw new Error(`[ic-reactor] defineReactor("${name}") received both a ClientManager and \`${passed}\`. ` +
|
|
111
|
-
`That option is resolved when a ClientManager is constructed, so the supplied one already carries its own ` +
|
|
112
|
-
`decision and this would be ignored — silently changing nothing about whether the ic_env cookie is trusted. ` +
|
|
113
|
-
`Pass it where that ClientManager is created, or drop \`clientManager\` to build one here.`);
|
|
114
|
-
}
|
|
115
|
-
const clientManager = providedClientManager ??
|
|
116
|
-
providedAuthentication?.clientManager ??
|
|
117
|
-
new ClientManager({
|
|
118
|
-
queryClient: providedQueryClient ?? createDefaultQueryClient(),
|
|
119
|
-
agentOptions,
|
|
120
|
-
// Forwarded, not dropped: the type has always accepted these (it extends
|
|
121
|
-
// ClientManagerParameters) while the call ignored them, so the one
|
|
122
|
-
// documented setup path silently discarded the ic_env opt-in it advertised.
|
|
123
|
-
allowEnvConfig,
|
|
124
|
-
allowEnvRootKey,
|
|
125
|
-
});
|
|
126
|
-
// Always report the QueryClient actually in use: when a ClientManager is
|
|
127
|
-
// supplied or adopted, its own QueryClient is the one queries run against.
|
|
128
|
-
const queryClient = clientManager.queryClient;
|
|
129
|
-
const reactorConfig = {
|
|
130
|
-
clientManager,
|
|
131
|
-
name,
|
|
132
|
-
idlFactory,
|
|
133
|
-
canisterId,
|
|
134
|
-
pollingOptions,
|
|
135
|
-
};
|
|
136
|
-
// The Reactor / DisplayReactor union cannot be expressed through the shared
|
|
137
|
-
// implementation signature, so the body is intentionally untyped here; the
|
|
138
|
-
// public overloads above carry the precise types for callers.
|
|
139
|
-
const reactor = display
|
|
140
|
-
? new DisplayReactor({
|
|
141
|
-
...reactorConfig,
|
|
142
|
-
validators: params
|
|
143
|
-
.validators,
|
|
144
|
-
})
|
|
145
|
-
: new Reactor(reactorConfig);
|
|
146
|
-
// `reactor` is `any` above, which would let the overloads infer `Service`
|
|
147
|
-
// as `unknown` and type every hook's arguments as `never`.
|
|
148
|
-
const hooks = createActorHooks(reactor);
|
|
149
|
-
// Auth is built on first use. `AuthenticationManager` dynamically imports the
|
|
150
|
-
// optional `@icp-sdk/auth` peer as soon as it is constructed, and reactors
|
|
151
|
-
// that never touch authentication should not pay for that.
|
|
152
|
-
let authenticationInstance;
|
|
153
|
-
const getAuthentication = () => (authenticationInstance ?? (authenticationInstance = providedAuthentication ??
|
|
154
|
-
new AuthenticationManager({ ...auth, clientManager })));
|
|
155
|
-
let identityAttributesInstance;
|
|
156
|
-
const getIdentityAttributes = () => (identityAttributesInstance ?? (identityAttributesInstance = new IdentityAttributesManager(getAuthentication())));
|
|
157
|
-
let authHooks;
|
|
158
|
-
const getAuthHooks = () => (authHooks ?? (authHooks = createAuthHooks(getAuthentication())));
|
|
159
|
-
let attributeHooks;
|
|
160
|
-
const getAttributeHooks = () => (attributeHooks ?? (attributeHooks = createIdentityAttributeHooks(getIdentityAttributes())));
|
|
161
|
-
return {
|
|
162
|
-
...hooks,
|
|
163
|
-
reactor,
|
|
164
|
-
clientManager,
|
|
165
|
-
queryClient,
|
|
166
|
-
// Stable wrappers: the hook call order inside them never changes, so the
|
|
167
|
-
// rules of hooks still hold.
|
|
168
|
-
useAuth: () => getAuthHooks().useAuth(),
|
|
169
|
-
useAgentState: () => getAuthHooks().useAgentState(),
|
|
170
|
-
useUserPrincipal: () => getAuthHooks().useUserPrincipal(),
|
|
171
|
-
useIdentityAttributes: () => getAttributeHooks().useIdentityAttributes(),
|
|
172
|
-
get authentication() {
|
|
173
|
-
return getAuthentication();
|
|
174
|
-
},
|
|
175
|
-
get identityAttributes() {
|
|
176
|
-
return getIdentityAttributes();
|
|
177
|
-
},
|
|
178
|
-
};
|
|
13
|
+
return defineReactorWith("defineReactor", params, (config) => new Reactor(config));
|
|
179
14
|
}
|
|
180
15
|
//# sourceMappingURL=defineReactor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineReactor.js","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defineReactor.js","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,+EAA+E;AAC/E,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAmH5D,MAAM,UAAU,aAAa,CAC3B,MAAyE;IAIzE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,0EAA0E;QAC1E,8CAA8C;QAC9C,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;QAC7B,OAAO,iBAAiB,CACtB,eAAe,EACf,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,cAAc,CAAU,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC,CACnE,CAAA;IACH,CAAC;IAED,OAAO,iBAAiB,CACtB,eAAe,EACf,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,OAAO,CAAU,MAAM,CAAC,CACzC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The body `defineReactor` and `defineDisplayReactor` share.
|
|
3
|
+
*
|
|
4
|
+
* It takes the reactor's construction as a callback, so this module imports
|
|
5
|
+
* neither reactor class. That matters for bundle size: `DisplayReactor` builds
|
|
6
|
+
* its codecs on zod, and a module that imported it here would put zod in every
|
|
7
|
+
* app that calls `defineReactor`, whether or not it ever builds a
|
|
8
|
+
* DisplayReactor. Keep it that way — no `DisplayReactor` import in this file.
|
|
9
|
+
*/
|
|
10
|
+
import { ClientManager } from "@ic-reactor/core";
|
|
11
|
+
import type { Reactor, TransformKey, ReactorParameters, ClientManagerParameters } from "@ic-reactor/core";
|
|
12
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
13
|
+
import { ActorHooks } from "./createActorHooks.js";
|
|
14
|
+
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
15
|
+
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
16
|
+
import type { UseIdentityAttributesReturn } from "./auth/createIdentityAttributeHooks.js";
|
|
17
|
+
import type { CreateAuthHooksReturn } from "./hooks/createAuthHooks.js";
|
|
18
|
+
import type { AuthenticationManagerParameters } from "./auth/authentication-manager.js";
|
|
19
|
+
/** Options shared by both the standard and display variants of defineReactor. */
|
|
20
|
+
export interface DefineReactorSharedParameters extends Omit<ReactorParameters, "clientManager">, Omit<ClientManagerParameters, "queryClient"> {
|
|
21
|
+
/**
|
|
22
|
+
* Reuse an existing ClientManager (e.g. to share one agent across canisters).
|
|
23
|
+
* When omitted, a ClientManager is created from the agent options below.
|
|
24
|
+
*
|
|
25
|
+
* A supplied or adopted manager brings its own agent and QueryClient, so
|
|
26
|
+
* `agentOptions`, `queryClient` and `allowEnvConfig` apply only when this
|
|
27
|
+
* call creates one.
|
|
28
|
+
*/
|
|
29
|
+
clientManager?: ClientManager;
|
|
30
|
+
/**
|
|
31
|
+
* QueryClient for a ClientManager created by this call.
|
|
32
|
+
*
|
|
33
|
+
* Ignored when `clientManager` or `authentication` is supplied — queries run
|
|
34
|
+
* against that manager's own QueryClient, which is what is returned.
|
|
35
|
+
*/
|
|
36
|
+
queryClient?: QueryClient;
|
|
37
|
+
/**
|
|
38
|
+
* Reuse an existing AuthenticationManager, so several reactors share one
|
|
39
|
+
* Internet Identity session. When omitted, one is created for this reactor.
|
|
40
|
+
*
|
|
41
|
+
* Its `clientManager` is adopted for this reactor, so sign-in updates the
|
|
42
|
+
* same agent the reactor calls through. Supplying a different `clientManager`
|
|
43
|
+
* alongside it is rejected.
|
|
44
|
+
*/
|
|
45
|
+
authentication?: AuthenticationManager;
|
|
46
|
+
/**
|
|
47
|
+
* Internet Identity options forwarded to the AuthenticationManager
|
|
48
|
+
* (`identityProvider`, `derivationOrigin`, `idleOptions`, `storage`, …).
|
|
49
|
+
*
|
|
50
|
+
* Not every option reaches both `@icp-sdk/auth` majors. `idleOptions`,
|
|
51
|
+
* `storage`, `keyType` and `identity` are honoured only by v8: v10 has no
|
|
52
|
+
* equivalent, so IC Reactor drops each with a one-time warning. For idle
|
|
53
|
+
* handling on v10, pass `maxTimeToIdle` to `login()` and set
|
|
54
|
+
* `disableBrowserActivity` here. `disableBrowserActivity` is v10-only.
|
|
55
|
+
*
|
|
56
|
+
* Mutually exclusive with `authentication`: a manager built elsewhere is
|
|
57
|
+
* already configured, so these could not be applied to it.
|
|
58
|
+
*/
|
|
59
|
+
auth?: Omit<AuthenticationManagerParameters, "clientManager">;
|
|
60
|
+
}
|
|
61
|
+
/** The reactor instance plus its bound hooks and shared infrastructure. */
|
|
62
|
+
export type DefineReactorResult<Service, Transform extends TransformKey, R extends Reactor<Service, Transform>> = ActorHooks<Service, Transform> & CreateAuthHooksReturn & {
|
|
63
|
+
reactor: R;
|
|
64
|
+
clientManager: ClientManager;
|
|
65
|
+
queryClient: QueryClient;
|
|
66
|
+
/** Internet Identity session manager backing `useAuth`. */
|
|
67
|
+
authentication: AuthenticationManager;
|
|
68
|
+
/** Signed identity attribute requests backing `useIdentityAttributes`. */
|
|
69
|
+
identityAttributes: IdentityAttributesManager;
|
|
70
|
+
useIdentityAttributes: () => UseIdentityAttributesReturn;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Builds the ClientManager, the reactor `createReactor` returns, its hooks and
|
|
74
|
+
* the lazily created auth managers, for `defineReactor` and
|
|
75
|
+
* `defineDisplayReactor`. Not part of the public API.
|
|
76
|
+
*
|
|
77
|
+
* `caller` is the function the app called; the errors below name it, so an
|
|
78
|
+
* app that called `defineDisplayReactor` is not sent looking for a
|
|
79
|
+
* `defineReactor` call it never made.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export declare function defineReactorWith<Service, Transform extends TransformKey, R extends Reactor<Service, Transform>>(caller: "defineReactor" | "defineDisplayReactor", params: DefineReactorSharedParameters, createReactor: (config: ReactorParameters) => R): DefineReactorResult<Service, Transform, R>;
|
|
84
|
+
//# sourceMappingURL=defineReactorShared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineReactorShared.d.ts","sourceRoot":"","sources":["../src/defineReactorShared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAgB,MAAM,kBAAkB,CAAA;AAC9D,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,uBAA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AA;CACzD,CAAA;AAmBH;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EACP,SAAS,SAAS,YAAY,EAC9B,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EAErC,MAAM,EAAE,eAAe,GAAG,sBAAsB,EAChD,MAAM,EAAE,6BAA6B,EACrC,aAAa,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,CAAC,GAC9C,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CA6I5C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The body `defineReactor` and `defineDisplayReactor` share.
|
|
3
|
+
*
|
|
4
|
+
* It takes the reactor's construction as a callback, so this module imports
|
|
5
|
+
* neither reactor class. That matters for bundle size: `DisplayReactor` builds
|
|
6
|
+
* its codecs on zod, and a module that imported it here would put zod in every
|
|
7
|
+
* app that calls `defineReactor`, whether or not it ever builds a
|
|
8
|
+
* DisplayReactor. Keep it that way — no `DisplayReactor` import in this file.
|
|
9
|
+
*/
|
|
10
|
+
import { ClientManager, reactorRetry } from "@ic-reactor/core";
|
|
11
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
12
|
+
import { createActorHooks } from "./createActorHooks.js";
|
|
13
|
+
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
14
|
+
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
15
|
+
import { createIdentityAttributeHooks } from "./auth/createIdentityAttributeHooks.js";
|
|
16
|
+
import { createAuthHooks } from "./hooks/createAuthHooks.js";
|
|
17
|
+
import { registerAuthentication } from "./ownedAuthentication.js";
|
|
18
|
+
/**
|
|
19
|
+
* The QueryClient this module creates when the caller does not supply one.
|
|
20
|
+
*
|
|
21
|
+
* React Query retries every failure three times by default, which for canister
|
|
22
|
+
* calls means four attempts and several seconds of backoff on outcomes that
|
|
23
|
+
* cannot change — a canister `Err`, a validation failure, a Candid encode
|
|
24
|
+
* error that never reached the network. `reactorRetry` keeps the same three
|
|
25
|
+
* attempts for transport failures and stops immediately on the rest.
|
|
26
|
+
*
|
|
27
|
+
* A caller-supplied `queryClient` is left exactly as given; opt in there with
|
|
28
|
+
* `defaultOptions: { queries: { retry: reactorRetry } }`.
|
|
29
|
+
*/
|
|
30
|
+
const createDefaultQueryClient = () => new QueryClient({
|
|
31
|
+
defaultOptions: { queries: { retry: reactorRetry } },
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Builds the ClientManager, the reactor `createReactor` returns, its hooks and
|
|
35
|
+
* the lazily created auth managers, for `defineReactor` and
|
|
36
|
+
* `defineDisplayReactor`. Not part of the public API.
|
|
37
|
+
*
|
|
38
|
+
* `caller` is the function the app called; the errors below name it, so an
|
|
39
|
+
* app that called `defineDisplayReactor` is not sent looking for a
|
|
40
|
+
* `defineReactor` call it never made.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export function defineReactorWith(caller, params, createReactor) {
|
|
45
|
+
const { clientManager: providedClientManager, queryClient: providedQueryClient, authentication: providedAuthentication, auth, agentOptions, allowEnvConfig, allowEnvRootKey, name, idlFactory, canisterId, pollingOptions, } = params;
|
|
46
|
+
// A shared AuthenticationManager updates the identity on its own
|
|
47
|
+
// ClientManager. Giving this reactor a different one would leave its calls
|
|
48
|
+
// anonymous after sign-in, so adopt the manager's rather than building a new
|
|
49
|
+
// one, and refuse an explicit mismatch instead of splitting them silently.
|
|
50
|
+
if (providedClientManager &&
|
|
51
|
+
providedAuthentication &&
|
|
52
|
+
providedAuthentication.clientManager !== providedClientManager) {
|
|
53
|
+
throw new Error(`[ic-reactor] ${caller}("${name}") received an \`authentication\` manager bound to a different \`clientManager\`. ` +
|
|
54
|
+
`Sign-in would update the authentication manager's agent while this reactor calls through another one, ` +
|
|
55
|
+
`leaving its calls anonymous. Pass \`clientManager: authentication.clientManager\`, or omit \`clientManager\` to adopt it.`);
|
|
56
|
+
}
|
|
57
|
+
// `auth` configures a manager this call would build; an existing one is
|
|
58
|
+
// already constructed, so these options could only be dropped on the floor.
|
|
59
|
+
if (providedAuthentication && auth) {
|
|
60
|
+
throw new Error(`[ic-reactor] ${caller}("${name}") received both \`authentication\` and \`auth\`. ` +
|
|
61
|
+
`The supplied manager is already configured, so \`auth\` (${Object.keys(auth).join(", ")}) would be ignored. ` +
|
|
62
|
+
`Pass those options where that AuthenticationManager is created, or drop \`authentication\` to build one here.`);
|
|
63
|
+
}
|
|
64
|
+
// Same reasoning as `auth`, and it matters more here: an ignored
|
|
65
|
+
// `allowEnvConfig: false` reads as "I locked the cookie out" while the
|
|
66
|
+
// supplied manager carries whatever decision it was built with.
|
|
67
|
+
if ((providedClientManager || providedAuthentication) &&
|
|
68
|
+
(allowEnvConfig !== undefined || allowEnvRootKey !== undefined)) {
|
|
69
|
+
const passed = [
|
|
70
|
+
allowEnvConfig !== undefined && "allowEnvConfig",
|
|
71
|
+
allowEnvRootKey !== undefined && "allowEnvRootKey",
|
|
72
|
+
]
|
|
73
|
+
.filter(Boolean)
|
|
74
|
+
.join(", ");
|
|
75
|
+
throw new Error(`[ic-reactor] ${caller}("${name}") received both a ClientManager and \`${passed}\`. ` +
|
|
76
|
+
`That option is resolved when a ClientManager is constructed, so the supplied one already carries its own ` +
|
|
77
|
+
`decision and this would be ignored — silently changing nothing about whether the ic_env cookie is trusted. ` +
|
|
78
|
+
`Pass it where that ClientManager is created, or drop \`clientManager\` to build one here.`);
|
|
79
|
+
}
|
|
80
|
+
const clientManager = providedClientManager ??
|
|
81
|
+
providedAuthentication?.clientManager ??
|
|
82
|
+
new ClientManager({
|
|
83
|
+
queryClient: providedQueryClient ?? createDefaultQueryClient(),
|
|
84
|
+
agentOptions,
|
|
85
|
+
// Forwarded, not dropped: the type has always accepted these (it extends
|
|
86
|
+
// ClientManagerParameters) while the call ignored them, so the one
|
|
87
|
+
// documented setup path silently discarded the ic_env opt-in it advertised.
|
|
88
|
+
allowEnvConfig,
|
|
89
|
+
allowEnvRootKey,
|
|
90
|
+
});
|
|
91
|
+
// Always report the QueryClient actually in use: when a ClientManager is
|
|
92
|
+
// supplied or adopted, its own QueryClient is the one queries run against.
|
|
93
|
+
const queryClient = clientManager.queryClient;
|
|
94
|
+
const reactor = createReactor({
|
|
95
|
+
clientManager,
|
|
96
|
+
name,
|
|
97
|
+
idlFactory,
|
|
98
|
+
canisterId,
|
|
99
|
+
pollingOptions,
|
|
100
|
+
});
|
|
101
|
+
const hooks = createActorHooks(reactor);
|
|
102
|
+
// Auth is built on first use. `AuthenticationManager` dynamically imports the
|
|
103
|
+
// optional `@icp-sdk/auth` peer as soon as it is constructed, and reactors
|
|
104
|
+
// that never touch authentication should not pay for that.
|
|
105
|
+
let authenticationInstance;
|
|
106
|
+
const getAuthentication = () => (authenticationInstance ?? (authenticationInstance = providedAuthentication ??
|
|
107
|
+
new AuthenticationManager({ ...auth, clientManager })));
|
|
108
|
+
let identityAttributesInstance;
|
|
109
|
+
const getIdentityAttributes = () => (identityAttributesInstance ?? (identityAttributesInstance = new IdentityAttributesManager(getAuthentication())));
|
|
110
|
+
let authHooks;
|
|
111
|
+
const getAuthHooks = () => (authHooks ?? (authHooks = createAuthHooks(getAuthentication())));
|
|
112
|
+
let attributeHooks;
|
|
113
|
+
const getAttributeHooks = () => (attributeHooks ?? (attributeHooks = createIdentityAttributeHooks(getIdentityAttributes())));
|
|
114
|
+
const result = {
|
|
115
|
+
...hooks,
|
|
116
|
+
reactor,
|
|
117
|
+
clientManager,
|
|
118
|
+
queryClient,
|
|
119
|
+
// Stable wrappers: the hook call order inside them never changes, so the
|
|
120
|
+
// rules of hooks still hold.
|
|
121
|
+
useAuth: () => getAuthHooks().useAuth(),
|
|
122
|
+
useAgentState: () => getAuthHooks().useAgentState(),
|
|
123
|
+
useUserPrincipal: () => getAuthHooks().useUserPrincipal(),
|
|
124
|
+
useIdentityAttributes: () => getAttributeHooks().useIdentityAttributes(),
|
|
125
|
+
get authentication() {
|
|
126
|
+
return getAuthentication();
|
|
127
|
+
},
|
|
128
|
+
get identityAttributes() {
|
|
129
|
+
return getIdentityAttributes();
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
// For `createReactorProvider`, which disposes the manager this result
|
|
133
|
+
// builds when its tree unmounts. It reads the manager without the getter
|
|
134
|
+
// above, so a tree that never touched authentication does not build one
|
|
135
|
+
// just to release it. A supplied manager is not this result's to release.
|
|
136
|
+
registerAuthentication(result, () => providedAuthentication ? undefined : authenticationInstance);
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=defineReactorShared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineReactorShared.js","sourceRoot":"","sources":["../src/defineReactorShared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAO9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAc,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAA;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAiEjE;;;;;;;;;;;GAWG;AACH,MAAM,wBAAwB,GAAG,GAAG,EAAE,CACpC,IAAI,WAAW,CAAC;IACd,cAAc,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE;CACrD,CAAC,CAAA;AAEJ;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAK/B,MAAgD,EAChD,MAAqC,EACrC,aAA+C;IAE/C,MAAM,EACJ,a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6BAA6B;QAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE;QACvC,aAAa,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,aAAa,EAAE;QACnD,gBAAgB,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,gBAAgB,EAAE;QACzD,qBAAqB,EAAE,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,qBAAqB,EAAE;QACxE,IAAI,cAAc;YAChB,OAAO,iBAAiB,EAAE,CAAA;QAC5B,CAAC;QACD,IAAI,kBAAkB;YACpB,OAAO,qBAAqB,EAAE,CAAA;QAChC,CAAC;KACF,CAAA;IAED,sEAAsE;IACtE,yEAAyE;IACzE,wEAAwE;IACxE,0EAA0E;IAC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,CAClC,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAC5D,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -10,6 +10,13 @@ export interface UseAuthReturn {
|
|
|
10
10
|
returnTo?: string;
|
|
11
11
|
}) => Promise<void>;
|
|
12
12
|
isAuthenticated: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* `true` while a sign-in or sign-out is in progress, and until the session
|
|
15
|
+
* restore the first `useAuth()` starts has settled: on the first render, in
|
|
16
|
+
* a server render and while the stored session is read. A restore that fails
|
|
17
|
+
* settles it too. Show a loading state while it is `true` rather than
|
|
18
|
+
* treating `isAuthenticated: false` as signed out.
|
|
19
|
+
*/
|
|
13
20
|
isAuthenticating: boolean;
|
|
14
21
|
/**
|
|
15
22
|
* The signed-in user's principal, or `null` while signed out. A signed-out
|
|
@@ -35,8 +42,8 @@ export interface CreateAuthHooksReturn {
|
|
|
35
42
|
* const { login, logout, principal, isAuthenticated } = useAuth()
|
|
36
43
|
*
|
|
37
44
|
* return isAuthenticated
|
|
38
|
-
* ? <button onClick={logout}>Logout {principal?.toText()}</button>
|
|
39
|
-
* : <button onClick={login}>Login with II</button>
|
|
45
|
+
* ? <button onClick={() => logout()}>Logout {principal?.toText()}</button>
|
|
46
|
+
* : <button onClick={() => login()}>Login with II</button>
|
|
40
47
|
* }
|
|
41
48
|
*/
|
|
42
49
|
export declare const createAuthHooks: (authentication: AuthenticationManager) => CreateAuthHooksReturn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAuthHooks.d.ts","sourceRoot":"","sources":["../../src/hooks/createAuthHooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAa,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IACjD,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,2BAA2B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1D,eAAe,EAAE,OAAO,CAAA;IACxB,gBAAgB,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,SAAS,EAAE,SAAS,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;CACzB;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,UAAU,CAAA;IAC/B,gBAAgB,E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