@dynamic-labs-sdk/react-hooks 1.16.1 → 1.17.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/dist/foundation/useBaseQuery/useBaseQuery.d.ts +11 -8
- package/dist/foundation/useBaseQuery/useBaseQuery.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useAuthenticateTotpMfaDevice/useAuthenticateTotpMfaDevice.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useCompleteDeviceRegistration/useCompleteDeviceRegistration.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useDeleteMfaDevice/useDeleteMfaDevice.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useRegisterTotpMfaDevice/useRegisterTotpMfaDevice.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useRevokeAllRegisteredDevices/useRevokeAllRegisteredDevices.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useRevokeRegisteredDevice/useRevokeRegisteredDevice.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useSetDefaultMfaDevice/useSetDefaultMfaDevice.d.ts.map +1 -1
- package/dist/index.cjs +77 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +77 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/middlewares/invalidatesQueries/index.d.ts +2 -0
- package/dist/middlewares/invalidatesQueries/index.d.ts.map +1 -0
- package/dist/middlewares/invalidatesQueries/invalidatesQueries.d.ts +19 -0
- package/dist/middlewares/invalidatesQueries/invalidatesQueries.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getCore } from "@dynamic-labs-sdk/client/core";
|
|
|
7
7
|
|
|
8
8
|
//#region package.json
|
|
9
9
|
var name = "@dynamic-labs-sdk/react-hooks";
|
|
10
|
-
var version = "1.
|
|
10
|
+
var version = "1.17.0";
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/modules/DynamicContext/DynamicContext.ts
|
|
@@ -147,8 +147,9 @@ const EMPTY_MIDDLEWARES = [];
|
|
|
147
147
|
* so consumers can opt into retries / custom staleTime / etc.
|
|
148
148
|
* - Callers pass `enabled: false` (typically derived from whether their
|
|
149
149
|
* pseudo-required arguments are present) to short-circuit fetches.
|
|
150
|
-
* - Callers pass `middlewares` (named
|
|
151
|
-
* the query only runs when every one returns
|
|
150
|
+
* - Callers pass `middlewares` (named hooks that gate the query and/or run
|
|
151
|
+
* reactive subscriptions) and the query only runs when every one returns
|
|
152
|
+
* `true`.
|
|
152
153
|
*
|
|
153
154
|
* Returns the full `useQuery` result — `data`, `error`, `isLoading`,
|
|
154
155
|
* `isFetching`, `isSuccess`, `refetch`, `status`, etc.
|
|
@@ -302,6 +303,48 @@ const useAuthenticatePasskeyMFA = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
302
303
|
mutationFn: ({ client, variables }) => authenticatePasskeyMFA(variables, client)
|
|
303
304
|
});
|
|
304
305
|
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/middlewares/invalidatesQueries/invalidatesQueries.ts
|
|
308
|
+
/**
|
|
309
|
+
* Mutation middleware factory that invalidates one or more query hooks when
|
|
310
|
+
* the mutation succeeds, so any mounted consumer of those queries refetches.
|
|
311
|
+
*
|
|
312
|
+
* Pass the query hooks' names (their `queryKey` leaf, e.g. `'useGetMfaDevices'`);
|
|
313
|
+
* each is namespaced under `QUERY_KEY_PREFIX` to match the keys `useBaseQuery`
|
|
314
|
+
* creates. The invalidation loop lives here, not in `useBaseMutation`.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* useBaseMutation({
|
|
319
|
+
* middlewares: [invalidatesQueries('useGetMfaDevices')],
|
|
320
|
+
* mutationFn: ({ client, variables }) => deleteMfaDevice(variables, client),
|
|
321
|
+
* });
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
const invalidatesQueries = (...queryKeys) => () => {
|
|
325
|
+
const queryClient = useQueryClient();
|
|
326
|
+
const client = useDynamicClient();
|
|
327
|
+
/**
|
|
328
|
+
* Swallows an `invalidateQueries` rejection so a failed refetch never
|
|
329
|
+
* surfaces as an unhandled rejection nor rejects the combined invalidation
|
|
330
|
+
* promise, while still logging it at debug level so internal devs can see
|
|
331
|
+
* which query failed to refetch. Curried over the query key and extracted
|
|
332
|
+
* to a named handler so the invalidation map stays within the
|
|
333
|
+
* function-nesting limit.
|
|
334
|
+
*/
|
|
335
|
+
const debugInvalidationFailure = (queryKey) => (error) => {
|
|
336
|
+
getCore(client).logger.debug("[invalidatesQueries] failed to invalidate query", {
|
|
337
|
+
error,
|
|
338
|
+
queryKey,
|
|
339
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
return { onSuccess: () => Promise.all(queryKeys.map((key) => {
|
|
343
|
+
const queryKey = [...QUERY_KEY_PREFIX, key];
|
|
344
|
+
return queryClient.invalidateQueries({ queryKey }).catch(debugInvalidationFailure(queryKey));
|
|
345
|
+
})) };
|
|
346
|
+
};
|
|
347
|
+
|
|
305
348
|
//#endregion
|
|
306
349
|
//#region src/hooks/wrappers/functions/useAuthenticateTotpMfaDevice/useAuthenticateTotpMfaDevice.ts
|
|
307
350
|
/**
|
|
@@ -319,10 +362,13 @@ const useAuthenticatePasskeyMFA = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
319
362
|
* </button>
|
|
320
363
|
* ```
|
|
321
364
|
*/
|
|
322
|
-
const useAuthenticateTotpMfaDevice = ({ mutateParams } = {}) =>
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
365
|
+
const useAuthenticateTotpMfaDevice = ({ mutateParams } = {}) => {
|
|
366
|
+
return useBaseMutation({
|
|
367
|
+
middlewares: [invalidatesQueries("useGetMfaDevices")],
|
|
368
|
+
mutateParams,
|
|
369
|
+
mutationFn: ({ client, variables }) => authenticateTotpMfaDevice(variables, client)
|
|
370
|
+
});
|
|
371
|
+
};
|
|
326
372
|
|
|
327
373
|
//#endregion
|
|
328
374
|
//#region src/foundation/useBaseState/useBaseState.ts
|
|
@@ -584,6 +630,7 @@ const useAddCoinbaseOnrampOrderEventListener = ({ listener }) => {
|
|
|
584
630
|
* ```
|
|
585
631
|
*/
|
|
586
632
|
const useCompleteDeviceRegistration = ({ mutateParams } = {}) => useBaseMutation({
|
|
633
|
+
middlewares: [invalidatesQueries("useGetRegisteredDevices")],
|
|
587
634
|
mutateParams,
|
|
588
635
|
mutationFn: ({ client, variables }) => completeDeviceRegistration(variables, client)
|
|
589
636
|
});
|
|
@@ -764,10 +811,13 @@ const useCreateNewMfaRecoveryCodes = ({ mutateParams } = {}) => useBaseMutation(
|
|
|
764
811
|
* </button>
|
|
765
812
|
* ```
|
|
766
813
|
*/
|
|
767
|
-
const useDeleteMfaDevice = ({ mutateParams } = {}) =>
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
814
|
+
const useDeleteMfaDevice = ({ mutateParams } = {}) => {
|
|
815
|
+
return useBaseMutation({
|
|
816
|
+
middlewares: [invalidatesQueries("useGetMfaDevices")],
|
|
817
|
+
mutateParams,
|
|
818
|
+
mutationFn: ({ client, variables }) => deleteMfaDevice(variables, client)
|
|
819
|
+
});
|
|
820
|
+
};
|
|
771
821
|
|
|
772
822
|
//#endregion
|
|
773
823
|
//#region src/hooks/wrappers/functions/useDeletePasskey/useDeletePasskey.ts
|
|
@@ -1282,6 +1332,7 @@ const useRegisterPasskey = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
1282
1332
|
* ```
|
|
1283
1333
|
*/
|
|
1284
1334
|
const useRegisterTotpMfaDevice = ({ mutateParams } = {}) => useBaseMutation({
|
|
1335
|
+
middlewares: [invalidatesQueries("useGetMfaDevices")],
|
|
1285
1336
|
mutateParams,
|
|
1286
1337
|
mutationFn: ({ client }) => registerTotpMfaDevice(client)
|
|
1287
1338
|
});
|
|
@@ -1342,10 +1393,13 @@ const useRequestExternalAuthElevatedToken = ({ mutateParams } = {}) => useBaseMu
|
|
|
1342
1393
|
* </button>
|
|
1343
1394
|
* ```
|
|
1344
1395
|
*/
|
|
1345
|
-
const useRevokeAllRegisteredDevices = ({ mutateParams } = {}) =>
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1396
|
+
const useRevokeAllRegisteredDevices = ({ mutateParams } = {}) => {
|
|
1397
|
+
return useBaseMutation({
|
|
1398
|
+
middlewares: [invalidatesQueries("useGetRegisteredDevices")],
|
|
1399
|
+
mutateParams,
|
|
1400
|
+
mutationFn: ({ client }) => revokeAllRegisteredDevices(client)
|
|
1401
|
+
});
|
|
1402
|
+
};
|
|
1349
1403
|
|
|
1350
1404
|
//#endregion
|
|
1351
1405
|
//#region src/hooks/wrappers/functions/useRevokeRegisteredDevice/useRevokeRegisteredDevice.ts
|
|
@@ -1368,10 +1422,13 @@ const useRevokeAllRegisteredDevices = ({ mutateParams } = {}) => useBaseMutation
|
|
|
1368
1422
|
* </button>
|
|
1369
1423
|
* ```
|
|
1370
1424
|
*/
|
|
1371
|
-
const useRevokeRegisteredDevice = ({ mutateParams } = {}) =>
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1425
|
+
const useRevokeRegisteredDevice = ({ mutateParams } = {}) => {
|
|
1426
|
+
return useBaseMutation({
|
|
1427
|
+
middlewares: [invalidatesQueries("useGetRegisteredDevices")],
|
|
1428
|
+
mutateParams,
|
|
1429
|
+
mutationFn: ({ client, variables }) => revokeRegisteredDevice(variables, client)
|
|
1430
|
+
});
|
|
1431
|
+
};
|
|
1375
1432
|
|
|
1376
1433
|
//#endregion
|
|
1377
1434
|
//#region src/hooks/wrappers/functions/useSendEmailOTP/useSendEmailOTP.ts
|
|
@@ -1446,6 +1503,7 @@ const useSendSmsOTP = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
1446
1503
|
* ```
|
|
1447
1504
|
*/
|
|
1448
1505
|
const useSetDefaultMfaDevice = ({ mutateParams } = {}) => useBaseMutation({
|
|
1506
|
+
middlewares: [invalidatesQueries("useGetMfaDevices")],
|
|
1449
1507
|
mutateParams,
|
|
1450
1508
|
mutationFn: ({ client, variables }) => setDefaultMfaDevice(variables, client)
|
|
1451
1509
|
});
|