@ic-reactor/react 3.12.2 → 3.12.4
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 -1
- package/dist/auth/authentication-manager.d.ts +11 -1
- package/dist/auth/authentication-manager.d.ts.map +1 -1
- package/dist/auth/authentication-manager.js +49 -7
- package/dist/auth/authentication-manager.js.map +1 -1
- package/dist/createActorHooks.d.ts +17 -6
- package/dist/createActorHooks.d.ts.map +1 -1
- package/dist/createActorHooks.js.map +1 -1
- package/dist/createMutation.d.ts.map +1 -1
- package/dist/createMutation.js +33 -7
- package/dist/createMutation.js.map +1 -1
- package/dist/defineReactor.js +3 -4
- package/dist/defineReactor.js.map +1 -1
- package/dist/hooks/createAuthHooks.d.ts +5 -0
- package/dist/hooks/createAuthHooks.d.ts.map +1 -1
- package/dist/hooks/createAuthHooks.js +18 -4
- package/dist/hooks/createAuthHooks.js.map +1 -1
- package/dist/hooks/useActorMethod.d.ts +21 -11
- package/dist/hooks/useActorMethod.d.ts.map +1 -1
- package/dist/hooks/useActorMethod.js +29 -14
- package/dist/hooks/useActorMethod.js.map +1 -1
- package/dist/hooks/useActorMutation.d.ts.map +1 -1
- package/dist/hooks/useActorMutation.js +5 -2
- package/dist/hooks/useActorMutation.js.map +1 -1
- package/package.json +7 -8
- package/src/auth/authentication-manager.ts +53 -7
- package/src/createActorHooks.ts +34 -13
- package/src/createMutation.ts +39 -14
- package/src/defineReactor.ts +4 -3
- package/src/hooks/createAuthHooks.ts +30 -7
- package/src/hooks/useActorMethod.ts +79 -38
- package/src/hooks/useActorMutation.ts +5 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type UseQueryResult, type UseMutationResult, type QueryKey, type QueryObserverOptions } from "@tanstack/react-query";
|
|
2
|
-
import { Reactor, BaseActor, FunctionName, TransformKey, ReactorArgs, ReactorReturnOk, ReactorReturnErr, FunctionType } from "@ic-reactor/core";
|
|
2
|
+
import { Reactor, BaseActor, FunctionName, TransformKey, ReactorArgs, ReactorReturnOk, ReactorQueryData, ReactorReturnErr, FunctionType } from "@ic-reactor/core";
|
|
3
3
|
import { CallConfig } from "@icp-sdk/core/agent";
|
|
4
4
|
/**
|
|
5
5
|
* Configuration for useActorMethod hook.
|
|
@@ -9,7 +9,7 @@ import { CallConfig } from "@icp-sdk/core/agent";
|
|
|
9
9
|
* Query-specific options (like refetchInterval) only apply to query methods.
|
|
10
10
|
* Mutation-specific options (like invalidateQueries) only apply to mutation methods.
|
|
11
11
|
*/
|
|
12
|
-
export interface UseActorMethodParameters<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> extends Omit<QueryObserverOptions<ReactorReturnOk<Service, Method, Transform
|
|
12
|
+
export interface UseActorMethodParameters<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> extends Omit<QueryObserverOptions<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>, ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, QueryKey>, "queryKey" | "queryFn"> {
|
|
13
13
|
/** The reactor instance to use for method calls */
|
|
14
14
|
reactor: Reactor<Service, Transform>;
|
|
15
15
|
/** The method name to call on the canister */
|
|
@@ -23,8 +23,11 @@ export interface UseActorMethodParameters<Service = BaseActor, Method extends Fu
|
|
|
23
23
|
/**
|
|
24
24
|
* Callback when the method call succeeds.
|
|
25
25
|
* Works for both query and mutation methods.
|
|
26
|
+
*
|
|
27
|
+
* A method's `undefined` result arrives as `null`, as in `useActorQuery`,
|
|
28
|
+
* for query and update methods alike.
|
|
26
29
|
*/
|
|
27
|
-
onSuccess?: (data: ReactorReturnOk<Service, Method, Transform
|
|
30
|
+
onSuccess?: (data: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>) => void;
|
|
28
31
|
/**
|
|
29
32
|
* Callback when the method call fails.
|
|
30
33
|
* Works for both query and mutation methods.
|
|
@@ -46,8 +49,12 @@ export type UseActorMethodConfig<Service = BaseActor, Method extends FunctionNam
|
|
|
46
49
|
* Provides a unified interface for both query and mutation methods.
|
|
47
50
|
*/
|
|
48
51
|
export interface UseActorMethodResult<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> {
|
|
49
|
-
/**
|
|
50
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The returned data from the method call. A method's `undefined` result is
|
|
54
|
+
* `null` here, as in `useActorQuery`, so `undefined` only means no call has
|
|
55
|
+
* settled yet.
|
|
56
|
+
*/
|
|
57
|
+
data: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>> | undefined;
|
|
51
58
|
/** Whether the method is currently executing */
|
|
52
59
|
isLoading: boolean;
|
|
53
60
|
/** Alias for isLoading - whether a mutation is pending */
|
|
@@ -67,21 +74,24 @@ export interface UseActorMethodResult<Service = BaseActor, Method extends Functi
|
|
|
67
74
|
* For queries: triggers a refetch
|
|
68
75
|
* For mutations: executes the mutation with the provided args
|
|
69
76
|
*/
|
|
70
|
-
call: (args?: ReactorArgs<Service, Method, Transform>) => Promise<ReactorReturnOk<Service, Method, Transform
|
|
77
|
+
call: (args?: ReactorArgs<Service, Method, Transform>) => Promise<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>> | undefined>;
|
|
71
78
|
/**
|
|
72
|
-
* Reset the state (
|
|
73
|
-
* For queries:
|
|
79
|
+
* Reset the state (data and error).
|
|
80
|
+
* For queries: resets this hook's own cache entry to its initial state, so
|
|
81
|
+
* `data` goes back to `initialData` when one was given and is cleared
|
|
82
|
+
* otherwise. An enabled hook then refetches. Other args of the same method
|
|
83
|
+
* are left alone.
|
|
74
84
|
* For mutations: resets the mutation state
|
|
75
85
|
*/
|
|
76
86
|
reset: () => void;
|
|
77
87
|
/**
|
|
78
88
|
* For queries only: Refetch the query
|
|
79
89
|
*/
|
|
80
|
-
refetch: () => Promise<ReactorReturnOk<Service, Method, Transform
|
|
90
|
+
refetch: () => Promise<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>> | undefined>;
|
|
81
91
|
/** The raw query result (only available for query methods) */
|
|
82
|
-
queryResult?: UseQueryResult<ReactorReturnOk<Service, Method, Transform
|
|
92
|
+
queryResult?: UseQueryResult<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>>;
|
|
83
93
|
/** The raw mutation result (only available for mutation methods) */
|
|
84
|
-
mutationResult?: UseMutationResult<ReactorReturnOk<Service, Method, Transform
|
|
94
|
+
mutationResult?: UseMutationResult<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>, ReactorArgs<Service, Method, Transform>>;
|
|
85
95
|
}
|
|
86
96
|
/**
|
|
87
97
|
* A unified hook for calling canister methods that automatically handles
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorMethod.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorMethod.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,YAAY,EACb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"useActorMethod.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorMethod.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,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AAC;IAElC;;OAEG;gBACS,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,UACtC,IAAI,CACV,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACpD,SAAS,CACV;EAQN"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { useQuery, useMutation, } from "@tanstack/react-query";
|
|
3
|
+
import { normalizeQueryData } from "../utils.js";
|
|
3
4
|
/**
|
|
4
5
|
* A unified hook for calling canister methods that automatically handles
|
|
5
6
|
* both query and mutation methods based on the Candid interface.
|
|
@@ -47,11 +48,16 @@ export function useActorMethod({ reactor, functionName, args, callConfig, queryK
|
|
|
47
48
|
// QueryClient) and `onSuccess` never fired when data came from the cache
|
|
48
49
|
// or a deduped sibling. They are dispatched from the settled observer
|
|
49
50
|
// result below instead.
|
|
50
|
-
|
|
51
|
+
//
|
|
52
|
+
// TanStack Query fails a query whose queryFn resolves `undefined`, with
|
|
53
|
+
// "data is undefined", and a successful call can resolve it. A
|
|
54
|
+
// DisplayReactor decodes an `opt` None to `undefined`, and a `()` query
|
|
55
|
+
// returns nothing. Every other query path normalizes the value to `null`.
|
|
56
|
+
queryFn: async () => normalizeQueryData((await reactor.callMethod({
|
|
51
57
|
functionName,
|
|
52
58
|
args,
|
|
53
59
|
callConfig,
|
|
54
|
-
}),
|
|
60
|
+
}))),
|
|
55
61
|
enabled: isQuery && enabled,
|
|
56
62
|
...queryOptions,
|
|
57
63
|
}, reactor.queryClient);
|
|
@@ -84,20 +90,21 @@ export function useActorMethod({ reactor, functionName, args, callConfig, queryK
|
|
|
84
90
|
// ============================================================================
|
|
85
91
|
const mutationResult = useMutation({
|
|
86
92
|
mutationKey: queryKey,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
// Normalized like the query branch, so `data`, `call()` and `onSuccess`
|
|
94
|
+
// mean the same thing for both kinds of method. The hook cannot type the
|
|
95
|
+
// two branches apart: a Candid service type does not say which methods
|
|
96
|
+
// are queries.
|
|
97
|
+
mutationFn: async (mutationArgs) => normalizeQueryData((await reactor.callMethod({
|
|
98
|
+
functionName,
|
|
99
|
+
args: mutationArgs ?? args,
|
|
100
|
+
callConfig,
|
|
101
|
+
}))),
|
|
95
102
|
onSuccess: (data) => {
|
|
96
103
|
onSuccessRef.current?.(data);
|
|
97
104
|
// Invalidate specified queries after successful mutation
|
|
98
105
|
if (invalidateQueries && invalidateQueries.length > 0) {
|
|
99
106
|
invalidateQueries.forEach((key) => {
|
|
100
|
-
reactor.queryClient.invalidateQueries({ queryKey: key });
|
|
107
|
+
void reactor.queryClient.invalidateQueries({ queryKey: key });
|
|
101
108
|
});
|
|
102
109
|
}
|
|
103
110
|
},
|
|
@@ -120,11 +127,12 @@ export function useActorMethod({ reactor, functionName, args, callConfig, queryK
|
|
|
120
127
|
try {
|
|
121
128
|
const result = await reactor.queryClient.fetchQuery({
|
|
122
129
|
queryKey: buildQueryKey(callArgs),
|
|
123
|
-
|
|
130
|
+
// Normalize for the same reason as the observer's queryFn.
|
|
131
|
+
queryFn: async () => normalizeQueryData((await reactor.callMethod({
|
|
124
132
|
functionName,
|
|
125
133
|
args: callArgs,
|
|
126
134
|
callConfig,
|
|
127
|
-
}),
|
|
135
|
+
}))),
|
|
128
136
|
staleTime: 0,
|
|
129
137
|
});
|
|
130
138
|
// Dispatched here rather than by the observer effect: this result
|
|
@@ -164,7 +172,14 @@ export function useActorMethod({ reactor, functionName, args, callConfig, queryK
|
|
|
164
172
|
// ============================================================================
|
|
165
173
|
const reset = useCallback(() => {
|
|
166
174
|
if (isQuery) {
|
|
167
|
-
|
|
175
|
+
// Reset, not remove. `removeQueries` drops the entry without notifying
|
|
176
|
+
// its observers, so this hook kept rendering the old data while bound to
|
|
177
|
+
// a query that was no longer in the cache. No later invalidation reached
|
|
178
|
+
// it, including the one an identity switch runs. `resetQueries` notifies
|
|
179
|
+
// the observer and refetches the entry when the hook is enabled. It is
|
|
180
|
+
// `exact` because only this hook's entry should reset. A prefix match on
|
|
181
|
+
// a no-args key would also reset every args variant other hooks render.
|
|
182
|
+
void reactor.queryClient.resetQueries({ queryKey, exact: true });
|
|
168
183
|
}
|
|
169
184
|
else {
|
|
170
185
|
mutationResult.reset();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorMethod.js","sourceRoot":"","sources":["../../src/hooks/useActorMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAC/D,OAAO,EACL,QAAQ,EACR,WAAW,GAKZ,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"useActorMethod.js","sourceRoot":"","sources":["../../src/hooks/useActorMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAC/D,OAAO,EACL,QAAQ,EACR,WAAW,GAKZ,MAAM,uBAAuB,CAAA;AAa9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AA0JhD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAI5B,EACA,OAAO,EACP,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAG,IAAI,EACd,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,GAAG,YAAY,EACsC;IAQrD,0DAA0D;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE;QAC3B,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAC7D,OAAO,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;IAC5C,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,C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AiB,CACnB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAC3C,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAC5C,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CACxC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,OAAO,EACP,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,EACpC,SAAS,SAAS,YAAY,GAAG,QAAQ,EACzC,2GASC,0BAA0B,CAC3B,OAAO,EACP,MAAM,EACN,SAAS,CACV,KAAG,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CA6EpD,CAAA"}
|
|
@@ -39,11 +39,14 @@ export const useActorMutation = ({ reactor, functionName, invalidateQueries, onS
|
|
|
39
39
|
}
|
|
40
40
|
await onSuccess?.(...params);
|
|
41
41
|
}, [reactor, invalidateQueries, onSuccess]);
|
|
42
|
-
const handleError = useCallback((error, variables, context, mutation) => {
|
|
42
|
+
const handleError = useCallback(async (error, variables, context, mutation) => {
|
|
43
43
|
if (isCanisterError(error)) {
|
|
44
44
|
onCanisterError?.(error, variables);
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// Awaited like `onSuccess` above. TanStack Query waits for the promise
|
|
47
|
+
// `onError` returns before it runs `onSettled` and settles the mutation,
|
|
48
|
+
// and it can only wait for a promise this wrapper passes back.
|
|
49
|
+
await onError?.(error, variables, context, mutation);
|
|
47
50
|
}, [onCanisterError, onError]);
|
|
48
51
|
// Not memoized. The deps could only ever list the values destructured above,
|
|
49
52
|
// never the `options` rest bucket, so everything passed straight through —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorMutation.js","sourceRoot":"","sources":["../../src/hooks/useActorMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EACL,WAAW,GAIZ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,EAAE,CAAC;YAC3B,eAAe,EAAE,CAAC,KAAY,EAAE,SAAS,CAAC,CAAA;QAC5C,CAAC;QACD,uEAAuE;QACvE,yEAAyE;QACzE,+DAA+D;QAC/D,MAAM,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAc,EAAE,QAAe,CAAC,CAAA;IACpE,CAAC,EACD,CAAC,eAAe,EAAE,OAAO,CAAC,CAC3B,CAAA;IAED,6EAA6E;IAC7E,2EAA2E;IAC3E,+EAA+E;IAC/E,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,+BAA+B;IAC/B,EAAE;IACF,6EAA6E;IAC7E,8EAA8E;IAC9E,6BAA6B;IAC7B,OAAO,WAAW,CAChB;QACE,GAAG,OAAO;QACV,UAAU;QACV,SAAS,EAAE,aAAa;QACxB,OAAO,EAAE,WAAW;KACrB,EACD,OAAO,CAAC,WAAW,CACpB,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.4",
|
|
4
4
|
"description": "IC Reactor React library for building Internet Computer apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"author": "Behrad Deylami",
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@ic-reactor/core": "^3.12.
|
|
56
|
+
"@ic-reactor/core": "^3.12.4"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@icp-sdk/auth": "^8.0.0",
|
|
@@ -70,14 +70,14 @@
|
|
|
70
70
|
"@testing-library/dom": "^10.4.1",
|
|
71
71
|
"@testing-library/jest-dom": "^7.0.1",
|
|
72
72
|
"@testing-library/react": "^16.3.3",
|
|
73
|
-
"@types/react": "^19.
|
|
74
|
-
"@types/react-dom": "^19.
|
|
73
|
+
"@types/react": "^19.3.0",
|
|
74
|
+
"@types/react-dom": "^19.3.0",
|
|
75
75
|
"fake-indexeddb": "^6.2.5",
|
|
76
76
|
"jsdom": "^30.0.1",
|
|
77
|
-
"react": "^19.
|
|
78
|
-
"react-dom": "^19.
|
|
77
|
+
"react": "^19.3.0",
|
|
78
|
+
"react-dom": "^19.3.0",
|
|
79
79
|
"size-limit": "^13.0.3",
|
|
80
|
-
"vitest": "^
|
|
80
|
+
"vitest": "^5.0.0"
|
|
81
81
|
},
|
|
82
82
|
"size-limit": [
|
|
83
83
|
{
|
|
@@ -106,7 +106,6 @@
|
|
|
106
106
|
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc",
|
|
107
107
|
"test": "vitest run",
|
|
108
108
|
"size": "size-limit",
|
|
109
|
-
"analyze": "size-limit",
|
|
110
109
|
"typecheck": "tsc --noEmit -p tsconfig.typecheck.json"
|
|
111
110
|
}
|
|
112
111
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Identity } from "@icp-sdk/core/agent"
|
|
2
|
+
import { AnonymousIdentity } from "@icp-sdk/core/agent"
|
|
2
3
|
import type {
|
|
3
4
|
AuthClientLike,
|
|
4
5
|
AuthClientSignInOptions,
|
|
@@ -202,7 +203,7 @@ export class AuthenticationManager {
|
|
|
202
203
|
* module has not been loaded yet.
|
|
203
204
|
*
|
|
204
205
|
* Callers that must stay inside a user gesture use this instead of
|
|
205
|
-
*
|
|
206
|
+
* `ensureClient`; awaiting anything before opening the identity
|
|
206
207
|
* provider window loses the gesture.
|
|
207
208
|
*/
|
|
208
209
|
public getPreparedClient(
|
|
@@ -228,9 +229,13 @@ export class AuthenticationManager {
|
|
|
228
229
|
if (stillValid) {
|
|
229
230
|
return this.authState.identity || undefined
|
|
230
231
|
}
|
|
231
|
-
// Expired
|
|
232
|
-
//
|
|
233
|
-
|
|
232
|
+
// Expired. Re-deriving state from the client will not help: the v8
|
|
233
|
+
// client keeps handing out the lapsed delegation from getIdentity()
|
|
234
|
+
// until signOut() runs (only a fresh page load purges it), so the
|
|
235
|
+
// expired identity would go straight back on the agent and every
|
|
236
|
+
// refetch would be signed with it. End the session explicitly.
|
|
237
|
+
await this.expireSession()
|
|
238
|
+
return undefined
|
|
234
239
|
}
|
|
235
240
|
if (this.authPromise) {
|
|
236
241
|
return this.authPromise
|
|
@@ -267,17 +272,29 @@ export class AuthenticationManager {
|
|
|
267
272
|
return undefined
|
|
268
273
|
}
|
|
269
274
|
}
|
|
270
|
-
const
|
|
275
|
+
const clientIdentity = await this.authClient!.getIdentity()
|
|
271
276
|
const isAuthenticated = await this.authClient!.isAuthenticated()
|
|
272
277
|
|
|
273
278
|
if (revision !== this.authStateRevision) {
|
|
274
279
|
// Superseded — leave whatever ran in the meantime in place.
|
|
275
280
|
return this.authState.identity || undefined
|
|
276
281
|
}
|
|
282
|
+
// A client that says it is not authenticated but still hands out a
|
|
283
|
+
// non-anonymous identity is holding a delegation it will no longer
|
|
284
|
+
// vouch for (expired, mid-session). Nothing may be signed with it.
|
|
285
|
+
const identity =
|
|
286
|
+
isAuthenticated || clientIdentity.getPrincipal().isAnonymous()
|
|
287
|
+
? clientIdentity
|
|
288
|
+
: new AnonymousIdentity()
|
|
277
289
|
// Restoring an anonymous session is the common first-load case; pushing
|
|
278
290
|
// it through updateAgent would invalidate the whole query cache on
|
|
279
|
-
// every mount for nothing.
|
|
280
|
-
|
|
291
|
+
// every mount for nothing. It is only skipped while the agent is
|
|
292
|
+
// anonymous too, so a lapsed delegation still gets replaced.
|
|
293
|
+
if (
|
|
294
|
+
isAuthenticated ||
|
|
295
|
+
!identity.getPrincipal().isAnonymous() ||
|
|
296
|
+
!this.agentIsAnonymous()
|
|
297
|
+
) {
|
|
281
298
|
this.clientManager.updateAgent(identity)
|
|
282
299
|
}
|
|
283
300
|
this.updateState({
|
|
@@ -473,6 +490,35 @@ export class AuthenticationManager {
|
|
|
473
490
|
}
|
|
474
491
|
}
|
|
475
492
|
|
|
493
|
+
/** Whether the shared agent currently signs as the anonymous principal. */
|
|
494
|
+
private agentIsAnonymous(): boolean {
|
|
495
|
+
const installed = this.clientManager.identity
|
|
496
|
+
return installed === undefined || installed.getPrincipal().isAnonymous()
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* End a session whose delegation has lapsed: ask the client to forget it,
|
|
501
|
+
* put the anonymous identity on the agent -- which also sweeps the previous
|
|
502
|
+
* user's caller-scoped cache entries and refetches the rest anonymously --
|
|
503
|
+
* and publish the signed-out state. `signOut` failing changes nothing here:
|
|
504
|
+
* the delegation is already unusable, and the agent must not keep it.
|
|
505
|
+
*/
|
|
506
|
+
private async expireSession() {
|
|
507
|
+
try {
|
|
508
|
+
await this.authClient?.signOut()
|
|
509
|
+
} catch {
|
|
510
|
+
// Nothing to keep; fall through to anonymous either way.
|
|
511
|
+
}
|
|
512
|
+
const identity = new AnonymousIdentity()
|
|
513
|
+
this.clientManager.updateAgent(identity)
|
|
514
|
+
this.updateState({
|
|
515
|
+
identity,
|
|
516
|
+
isAuthenticated: false,
|
|
517
|
+
isAuthenticating: false,
|
|
518
|
+
error: undefined,
|
|
519
|
+
})
|
|
520
|
+
}
|
|
521
|
+
|
|
476
522
|
private async syncStateFromClient(revision = this.authStateRevision) {
|
|
477
523
|
if (!this.authClient) {
|
|
478
524
|
return
|
package/src/createActorHooks.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
ReactorQueryData,
|
|
25
25
|
BaseActor,
|
|
26
26
|
FunctionName,
|
|
27
|
+
ReactorArgs,
|
|
27
28
|
TransformKey,
|
|
28
29
|
} from "@ic-reactor/core"
|
|
29
30
|
import {
|
|
@@ -43,42 +44,59 @@ import {
|
|
|
43
44
|
useActorMethod,
|
|
44
45
|
UseActorMethodParameters,
|
|
45
46
|
} from "./hooks/useActorMethod.js"
|
|
47
|
+
import type { CallConfig } from "@icp-sdk/core/agent"
|
|
46
48
|
import { InfiniteQueryConfig } from "./createInfiniteQuery.js"
|
|
47
49
|
import { SuspenseInfiniteQueryConfig } from "./createSuspenseInfiniteQuery.js"
|
|
48
50
|
import { QueryConfig, SuspenseQueryConfig, MutationConfig } from "./types.js"
|
|
49
51
|
|
|
52
|
+
/**
|
|
53
|
+
* The bound query hooks forward their config to `useActorQuery` and
|
|
54
|
+
* `useActorSuspenseQuery`, which take `callConfig`. `QueryConfig` is shared with
|
|
55
|
+
* `createQuery`, which does not use it, so it is added here and not there.
|
|
56
|
+
*/
|
|
57
|
+
type WithCallConfig<Config> = Config & {
|
|
58
|
+
/** Agent call configuration (canisterId override, effectiveCanisterId, etc.) */
|
|
59
|
+
callConfig?: CallConfig
|
|
60
|
+
}
|
|
61
|
+
|
|
50
62
|
export type ActorHooks<Service, Transform extends TransformKey> = {
|
|
51
63
|
useActorQuery: {
|
|
52
64
|
<Method extends FunctionName<Service>>(
|
|
53
|
-
config:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
config: WithCallConfig<
|
|
66
|
+
QueryConfig<
|
|
67
|
+
Service,
|
|
68
|
+
Method,
|
|
69
|
+
Transform,
|
|
70
|
+
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>
|
|
71
|
+
>
|
|
58
72
|
>
|
|
59
73
|
): UseQueryResult<
|
|
60
74
|
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
61
75
|
ReactorReturnErr<Service, Method, Transform>
|
|
62
76
|
>
|
|
63
77
|
<Method extends FunctionName<Service>, TData>(
|
|
64
|
-
config: QueryConfig<Service, Method, Transform, TData
|
|
78
|
+
config: WithCallConfig<QueryConfig<Service, Method, Transform, TData>>
|
|
65
79
|
): UseQueryResult<TData, ReactorReturnErr<Service, Method, Transform>>
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
useActorSuspenseQuery: {
|
|
69
83
|
<Method extends FunctionName<Service>>(
|
|
70
|
-
config:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
config: WithCallConfig<
|
|
85
|
+
SuspenseQueryConfig<
|
|
86
|
+
Service,
|
|
87
|
+
Method,
|
|
88
|
+
Transform,
|
|
89
|
+
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>
|
|
90
|
+
>
|
|
75
91
|
>
|
|
76
92
|
): UseSuspenseQueryResult<
|
|
77
93
|
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
78
94
|
ReactorReturnErr<Service, Method, Transform>
|
|
79
95
|
>
|
|
80
96
|
<Method extends FunctionName<Service>, TData>(
|
|
81
|
-
config:
|
|
97
|
+
config: WithCallConfig<
|
|
98
|
+
SuspenseQueryConfig<Service, Method, Transform, TData>
|
|
99
|
+
>
|
|
82
100
|
): UseSuspenseQueryResult<
|
|
83
101
|
TData,
|
|
84
102
|
ReactorReturnErr<Service, Method, Transform>
|
|
@@ -115,7 +133,10 @@ export type ActorHooks<Service, Transform extends TransformKey> = {
|
|
|
115
133
|
config: MutationConfig<Service, Method, Transform>
|
|
116
134
|
) => UseMutationResult<
|
|
117
135
|
ReactorReturnOk<Service, Method, Transform>,
|
|
118
|
-
ReactorReturnErr<Service, Method, Transform
|
|
136
|
+
ReactorReturnErr<Service, Method, Transform>,
|
|
137
|
+
// Without this TVariables defaults to `unknown` and mutate/mutateAsync
|
|
138
|
+
// accept anything; the standalone hook and createMutation both pass it.
|
|
139
|
+
ReactorArgs<Service, Method, Transform>
|
|
119
140
|
>
|
|
120
141
|
|
|
121
142
|
useActorMethod: <Method extends FunctionName<Service>>(
|
package/src/createMutation.ts
CHANGED
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
* await transferMutation.execute([{ to: "aaaaa-aa", amount: "1000" }])
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
useMutation,
|
|
30
|
+
type MutationFunctionContext,
|
|
31
|
+
} from "@tanstack/react-query"
|
|
29
32
|
import type {
|
|
30
33
|
Reactor,
|
|
31
34
|
FunctionName,
|
|
@@ -99,6 +102,9 @@ const createMutationImpl = <
|
|
|
99
102
|
* object behaves the same through both call paths. Only hook-level callbacks
|
|
100
103
|
* are absent, because there is no hook here to supply them.
|
|
101
104
|
*
|
|
105
|
+
* The callbacks get the same `{ client, meta, mutationKey }` context
|
|
106
|
+
* TanStack Query passes them on the hook path.
|
|
107
|
+
*
|
|
102
108
|
* The error is rethrown after the callbacks run, so `await execute(...)`
|
|
103
109
|
* still rejects for the caller.
|
|
104
110
|
*
|
|
@@ -107,6 +113,25 @@ const createMutationImpl = <
|
|
|
107
113
|
const execute = async (
|
|
108
114
|
args: ReactorArgs<Service, Method, Transform>
|
|
109
115
|
): Promise<ReactorReturnOk<Service, Method, Transform>> => {
|
|
116
|
+
// TanStack Query builds this for the hook path, and the callback types
|
|
117
|
+
// declare it as always present. None of it is mutation state, so this path
|
|
118
|
+
// builds the same object. Passing `undefined` made a callback that reads
|
|
119
|
+
// `context.client` throw here and nowhere else.
|
|
120
|
+
//
|
|
121
|
+
// The hook path takes `meta` and `mutationKey` from the client's defaulted
|
|
122
|
+
// options, so this runs the same spread through `defaultMutationOptions`.
|
|
123
|
+
// Reading `factoryOptions` alone dropped mutation defaults registered on
|
|
124
|
+
// the QueryClient (`defaultOptions.mutations`, `setMutationDefaults`).
|
|
125
|
+
const effectiveOptions = reactor.queryClient.defaultMutationOptions({
|
|
126
|
+
mutationKey: reactor.getQueryOptions({ functionName }).queryKey,
|
|
127
|
+
...factoryOptions,
|
|
128
|
+
})
|
|
129
|
+
const context: MutationFunctionContext = {
|
|
130
|
+
client: reactor.queryClient,
|
|
131
|
+
meta: effectiveOptions.meta,
|
|
132
|
+
mutationKey: effectiveOptions.mutationKey,
|
|
133
|
+
}
|
|
134
|
+
|
|
110
135
|
let result: ReactorReturnOk<Service, Method, Transform>
|
|
111
136
|
try {
|
|
112
137
|
result = await callFn(args)
|
|
@@ -114,12 +139,14 @@ const createMutationImpl = <
|
|
|
114
139
|
if (isCanisterError(error)) {
|
|
115
140
|
factoryOnCanisterError?.(error, args)
|
|
116
141
|
}
|
|
117
|
-
//
|
|
118
|
-
|
|
142
|
+
// `onMutate` does not run on this path, so there is no result to pass.
|
|
143
|
+
// Awaited like `onSuccess` below and like the hook path, so an async
|
|
144
|
+
// rollback or report finishes before `execute()` rejects.
|
|
145
|
+
await factoryOnError?.(
|
|
119
146
|
error as Parameters<NonNullable<typeof factoryOnError>>[0],
|
|
120
147
|
args,
|
|
121
|
-
undefined
|
|
122
|
-
|
|
148
|
+
undefined,
|
|
149
|
+
context
|
|
123
150
|
)
|
|
124
151
|
throw error
|
|
125
152
|
}
|
|
@@ -127,12 +154,7 @@ const createMutationImpl = <
|
|
|
127
154
|
if (factoryInvalidateQueries) {
|
|
128
155
|
await invalidateAll(reactor.queryClient, factoryInvalidateQueries)
|
|
129
156
|
}
|
|
130
|
-
await factoryOnSuccess?.(
|
|
131
|
-
result,
|
|
132
|
-
args,
|
|
133
|
-
undefined as never,
|
|
134
|
-
undefined as never
|
|
135
|
-
)
|
|
157
|
+
await factoryOnSuccess?.(result, args, undefined, context)
|
|
136
158
|
return result
|
|
137
159
|
}
|
|
138
160
|
|
|
@@ -169,13 +191,16 @@ const createMutationImpl = <
|
|
|
169
191
|
// 4. Hook onSuccess
|
|
170
192
|
await restOptions.onSuccess?.(...args)
|
|
171
193
|
},
|
|
172
|
-
onError: (error, variables, context, mutation) => {
|
|
194
|
+
onError: async (error, variables, context, mutation) => {
|
|
173
195
|
if (isCanisterError(error)) {
|
|
174
196
|
factoryOnCanisterError?.(error, variables)
|
|
175
197
|
hookOnCanisterError?.(error, variables)
|
|
176
198
|
}
|
|
177
|
-
|
|
178
|
-
|
|
199
|
+
// Awaited in order, like `onSuccess`. TanStack Query holds
|
|
200
|
+
// `onSettled` and the settled state until this promise resolves, so
|
|
201
|
+
// an async `onError` must be part of it.
|
|
202
|
+
await factoryOnError?.(error, variables, context, mutation)
|
|
203
|
+
await restOptions.onError?.(error, variables, context, mutation)
|
|
179
204
|
},
|
|
180
205
|
// `onMutate` and `onSettled` are composed like `onSuccess`/`onError`
|
|
181
206
|
// above. They used to arrive through the `...restOptions` spread, so a
|
package/src/defineReactor.ts
CHANGED
|
@@ -175,7 +175,6 @@ export function defineReactor<Service = BaseActor>(
|
|
|
175
175
|
|
|
176
176
|
export function defineReactor<Service = BaseActor>(
|
|
177
177
|
params: DefineReactorParameters | DefineDisplayReactorParameters<Service>
|
|
178
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
178
|
): DefineReactorResult<Service, any, any> {
|
|
180
179
|
const {
|
|
181
180
|
clientManager: providedClientManager,
|
|
@@ -267,7 +266,7 @@ export function defineReactor<Service = BaseActor>(
|
|
|
267
266
|
// The Reactor / DisplayReactor union cannot be expressed through the shared
|
|
268
267
|
// implementation signature, so the body is intentionally untyped here; the
|
|
269
268
|
// public overloads above carry the precise types for callers.
|
|
270
|
-
|
|
269
|
+
|
|
271
270
|
const reactor: any = display
|
|
272
271
|
? new DisplayReactor<Service>({
|
|
273
272
|
...reactorConfig,
|
|
@@ -276,7 +275,9 @@ export function defineReactor<Service = BaseActor>(
|
|
|
276
275
|
})
|
|
277
276
|
: new Reactor<Service>(reactorConfig)
|
|
278
277
|
|
|
279
|
-
|
|
278
|
+
// `reactor` is `any` above, which would let the overloads infer `Service`
|
|
279
|
+
// as `unknown` and type every hook's arguments as `never`.
|
|
280
|
+
const hooks = createActorHooks<Service, any>(reactor)
|
|
280
281
|
|
|
281
282
|
// Auth is built on first use. `AuthenticationManager` dynamically imports the
|
|
282
283
|
// optional `@icp-sdk/auth` peer as soon as it is constructed, and reactors
|