react-query-firebase 3.1.1 → 3.3.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/react-native/analytics/useAnalytics.d.ts +1 -1
- package/dist/react-native/context/FirebaseContext.d.ts +8 -6
- package/dist/react-native/context/FirebaseContext.js +0 -1
- package/dist/react-native/context/FirebaseContextProvider.d.ts +3 -20
- package/dist/react-native/context/FirebaseContextProvider.js +5 -6
- package/dist/react-native/firestore/useAddDocMutation.d.ts +2 -2
- package/dist/react-native/firestore/useBatchWrite.d.ts +2 -2
- package/dist/react-native/firestore/useCollectionReference.d.ts +4 -4
- package/dist/react-native/firestore/useCollectionReference.js +1 -1
- package/dist/react-native/firestore/useCompositeFilter.d.ts +2 -2
- package/dist/react-native/firestore/useCompositeFilter.js +1 -11
- package/dist/react-native/firestore/useCountQuery.d.ts +3 -4
- package/dist/react-native/firestore/useDeleteDocMutation.d.ts +3 -3
- package/dist/react-native/firestore/useDocReference.d.ts +2 -2
- package/dist/react-native/firestore/useDocReference.js +1 -1
- package/dist/react-native/firestore/useDocReferences.d.ts +2 -2
- package/dist/react-native/firestore/useDocReferences.js +1 -1
- package/dist/react-native/firestore/useFirestore.d.ts +1 -1
- package/dist/react-native/firestore/useFirestoreQueryEngine.d.ts +2 -2
- package/dist/react-native/firestore/useFirestoreQueryEngine.js +4 -11
- package/dist/react-native/firestore/useGetRealtimeDocData.d.ts +2 -2
- package/dist/react-native/firestore/useInfiniteQuery.d.ts +3 -4
- package/dist/react-native/firestore/useInfiniteQuery.js +1 -3
- package/dist/react-native/firestore/useQuery.d.ts +4 -4
- package/dist/react-native/firestore/useQuery.js +1 -3
- package/dist/react-native/firestore/useQueryConstraints.d.ts +1 -1
- package/dist/react-native/firestore/useQueryConstraints.js +1 -1
- package/dist/react-native/firestore/useRunTransaction.d.ts +4 -4
- package/dist/react-native/firestore/useSetDocMutation.d.ts +2 -2
- package/dist/react-native/firestore/useUpdateDocMutation.d.ts +2 -2
- package/dist/react-native/firestore/utils/buildCompositeFilter.d.ts +9 -11
- package/dist/react-native/firestore/utils/buildCompositeFilter.js +11 -5
- package/dist/react-native/firestore/utils/buildQueryConstraint.d.ts +1 -1
- package/dist/react-native/firestore/utils/buildQueryConstraint.js +1 -1
- package/dist/react-native/firestore/utils/getDocRef.d.ts +4 -4
- package/dist/react-native/firestore/utils/getDocSnap.d.ts +1 -1
- package/dist/react-native/firestore/utils/getDocSnap.js +1 -1
- package/dist/react-native/index.d.ts +1 -0
- package/dist/react-native/index.js +1 -0
- package/dist/react-native/messaging/index.d.ts +4 -0
- package/dist/react-native/messaging/index.js +4 -0
- package/dist/react-native/messaging/useDeleteTokenMutation.d.ts +35 -0
- package/dist/react-native/messaging/useDeleteTokenMutation.js +36 -0
- package/dist/react-native/messaging/useGetTokenMutation.d.ts +48 -0
- package/dist/react-native/messaging/useGetTokenMutation.js +37 -0
- package/dist/react-native/messaging/useMessaging.d.ts +8 -0
- package/dist/react-native/messaging/useMessaging.js +13 -0
- package/dist/react-native/messaging/useOnMessageHandler.d.ts +6 -0
- package/dist/react-native/messaging/useOnMessageHandler.js +15 -0
- package/dist/web/context/FirebaseContext.d.ts +2 -0
- package/dist/web/context/FirebaseContext.js +0 -1
- package/dist/web/context/FirebaseContextProvider.js +3 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/messaging/index.d.ts +4 -0
- package/dist/web/messaging/index.js +4 -0
- package/dist/web/messaging/useDeleteTokenMutation.d.ts +35 -0
- package/dist/web/messaging/useDeleteTokenMutation.js +36 -0
- package/dist/web/messaging/useGetTokenMutation.d.ts +48 -0
- package/dist/web/messaging/useGetTokenMutation.js +37 -0
- package/dist/web/messaging/useMessaging.d.ts +8 -0
- package/dist/web/messaging/useMessaging.js +13 -0
- package/dist/web/messaging/useOnMessageHandler.d.ts +6 -0
- package/dist/web/messaging/useOnMessageHandler.js +15 -0
- package/package.json +32 -30
|
@@ -7,7 +7,7 @@ import { AppModel, type NonFilterQueryConstraint } from "../../../types/index.js
|
|
|
7
7
|
*
|
|
8
8
|
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
9
9
|
*
|
|
10
|
-
* @returns {
|
|
10
|
+
* @returns {QueryNonFilterConstraint}
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```jsx
|
|
@@ -6,7 +6,7 @@ import { orderBy, startAt, startAfter, endAt, endBefore, limit, limitToLast } fr
|
|
|
6
6
|
*
|
|
7
7
|
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
8
8
|
*
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {QueryNonFilterConstraint}
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```jsx
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference, DocumentReference, Firestore } from "@react-native-firebase/firestore";
|
|
2
2
|
import { AppModel } from "../../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* @inline
|
|
5
5
|
*/
|
|
6
6
|
export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
|
|
7
|
-
db:
|
|
8
|
-
reference?:
|
|
7
|
+
db: Firestore;
|
|
8
|
+
reference?: CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>;
|
|
9
9
|
path?: string;
|
|
10
10
|
pathSegments?: string[];
|
|
11
11
|
};
|
|
@@ -19,4 +19,4 @@ export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
|
|
|
19
19
|
*
|
|
20
20
|
* @returns {DocumentReference<AppModelType, AppModelType>} Returns a document reference
|
|
21
21
|
*/
|
|
22
|
-
export declare const getDocRef: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) =>
|
|
22
|
+
export declare const getDocRef: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) => DocumentReference<AppModelType, AppModelType> | null;
|
|
@@ -15,4 +15,4 @@ export type GetDocSnapOptions<AppModelType extends AppModel = AppModel> = GetDoc
|
|
|
15
15
|
*
|
|
16
16
|
* @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
|
|
17
17
|
*/
|
|
18
|
-
export declare const getDocSnap: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType>) => Promise<import("@react-native-firebase/firestore").
|
|
18
|
+
export declare const getDocSnap: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType>) => Promise<import("@react-native-firebase/firestore/dist/typescript/lib/types/firestore.js").DocumentSnapshot<AppModelType, AppModelType> | null>;
|
|
@@ -12,7 +12,7 @@ import { getDocRef } from "./getDocRef.js";
|
|
|
12
12
|
* @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
|
|
13
13
|
*/
|
|
14
14
|
export const getDocSnap = async ({ db, reference, path, pathSegments }) => {
|
|
15
|
-
const docRef =
|
|
15
|
+
const docRef = getDocRef({ db, reference, path, pathSegments });
|
|
16
16
|
if (docRef) {
|
|
17
17
|
return await firestoreGetDoc(docRef);
|
|
18
18
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseDeleteTokenMutationOptions<TContext = unknown> = {
|
|
7
|
+
/**
|
|
8
|
+
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
9
|
+
*/
|
|
10
|
+
options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "mutationFn">;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Executes a mutation and deletes token for push notifications
|
|
14
|
+
*
|
|
15
|
+
* @group Hook
|
|
16
|
+
*
|
|
17
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
18
|
+
*
|
|
19
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation result
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```jsx
|
|
23
|
+
* export const MyComponent = () => {
|
|
24
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
25
|
+
* options: {
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // ....
|
|
30
|
+
* mutate();
|
|
31
|
+
* // ....
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useDeleteTokenMutation: ({ options }: UseDeleteTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { deleteToken } from "@react-native-firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and deletes token for push notifications
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate();
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useDeleteTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async () => {
|
|
33
|
+
return await deleteToken(messaging);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseGetTokenMutationValues = {
|
|
7
|
+
/**
|
|
8
|
+
* API key
|
|
9
|
+
*/
|
|
10
|
+
vapidKey: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @inline
|
|
14
|
+
*/
|
|
15
|
+
export type UseGetTokenMutationOptions<TContext = unknown> = {
|
|
16
|
+
/**
|
|
17
|
+
* Options for useMutation hook excluding mutationFn.
|
|
18
|
+
*/
|
|
19
|
+
options?: Omit<UseMutationOptions<{
|
|
20
|
+
token: string;
|
|
21
|
+
}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, TContext>, "mutationFn">;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Executes a mutation and returns token for.current instance
|
|
25
|
+
*
|
|
26
|
+
* @group Hook
|
|
27
|
+
*
|
|
28
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
29
|
+
*
|
|
30
|
+
* @returns {UseMutationResult<{token: string;}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* export const MyComponent = () => {
|
|
35
|
+
* const {mutate} = useGetTokenMutation({
|
|
36
|
+
* options: {
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // ....
|
|
41
|
+
* mutate({vapidKey: 'key'});
|
|
42
|
+
* // ....
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const useGetTokenMutation: ({ options }: UseGetTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<{
|
|
47
|
+
token: string;
|
|
48
|
+
}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, unknown>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { getToken } from "@react-native-firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and returns token for.current instance
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<{token: string;}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useGetTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate({vapidKey: 'key'});
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useGetTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async ({ vapidKey }) => {
|
|
33
|
+
const token = await getToken(messaging, { vapidKey: vapidKey });
|
|
34
|
+
return { token };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { FirebaseContext } from "../context/FirebaseContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an instance of firestore bound to the closest context.
|
|
5
|
+
*
|
|
6
|
+
* @group Hook
|
|
7
|
+
*
|
|
8
|
+
* @returns {Messaging}
|
|
9
|
+
*/
|
|
10
|
+
export const useMessaging = () => {
|
|
11
|
+
const { messaging } = useContext(FirebaseContext);
|
|
12
|
+
return messaging;
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { onMessage } from "@react-native-firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to start listening for push notifications.
|
|
6
|
+
*/
|
|
7
|
+
export const useOnMessageHandler = ({ callback }) => {
|
|
8
|
+
const messaging = useMessaging();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = onMessage(messaging, callback);
|
|
11
|
+
return () => {
|
|
12
|
+
unsubscribe();
|
|
13
|
+
};
|
|
14
|
+
}, [messaging, callback]);
|
|
15
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Auth } from "firebase/auth";
|
|
2
2
|
import { Analytics } from "firebase/analytics";
|
|
3
3
|
import { Firestore } from "firebase/firestore";
|
|
4
|
+
import { Messaging } from "firebase/messaging";
|
|
4
5
|
import { FirebaseApp } from "firebase/app";
|
|
5
6
|
import { RemoteConfig } from "firebase/remote-config";
|
|
6
7
|
type FirebaseContextValue = {
|
|
@@ -9,6 +10,7 @@ type FirebaseContextValue = {
|
|
|
9
10
|
firebase: FirebaseApp;
|
|
10
11
|
remoteConfig: RemoteConfig;
|
|
11
12
|
firestore: Firestore;
|
|
13
|
+
messaging: Messaging;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* FirebaseContext is a shared context across children that provides access to firebase features
|
|
@@ -3,6 +3,7 @@ import { browserLocalPersistence, browserSessionPersistence, connectAuthEmulator
|
|
|
3
3
|
import { getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
|
|
4
4
|
import { getRemoteConfig } from "firebase/remote-config";
|
|
5
5
|
import { connectFirestoreEmulator, initializeFirestore } from "firebase/firestore";
|
|
6
|
+
import { getMessaging } from "firebase/messaging";
|
|
6
7
|
import { initializeApp } from "firebase/app";
|
|
7
8
|
import { FirebaseContext } from "./FirebaseContext.js";
|
|
8
9
|
/**
|
|
@@ -106,7 +107,8 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
106
107
|
auth,
|
|
107
108
|
analytics,
|
|
108
109
|
firestore,
|
|
109
|
-
remoteConfig
|
|
110
|
+
remoteConfig,
|
|
111
|
+
messaging: getMessaging(firebase)
|
|
110
112
|
}), [firebase, auth, analytics, firestore, remoteConfig]);
|
|
111
113
|
useEffect(() => {
|
|
112
114
|
if (contextValue.analytics) {
|
package/dist/web/index.d.ts
CHANGED
package/dist/web/index.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { FirebaseError } from "firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseDeleteTokenMutationOptions<TContext = unknown> = {
|
|
7
|
+
/**
|
|
8
|
+
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
9
|
+
*/
|
|
10
|
+
options?: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "mutationFn">;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Executes a mutation and deletes token for push notifications
|
|
14
|
+
*
|
|
15
|
+
* @group Hook
|
|
16
|
+
*
|
|
17
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
18
|
+
*
|
|
19
|
+
* @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation result
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```jsx
|
|
23
|
+
* export const MyComponent = () => {
|
|
24
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
25
|
+
* options: {
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // ....
|
|
30
|
+
* mutate();
|
|
31
|
+
* // ....
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useDeleteTokenMutation: ({ options }: UseDeleteTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, void, unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { deleteToken } from "firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and deletes token for push notifications
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate();
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useDeleteTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async () => {
|
|
33
|
+
await deleteToken(messaging);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { FirebaseError } from "firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseGetTokenMutationValues = {
|
|
7
|
+
/**
|
|
8
|
+
* API key
|
|
9
|
+
*/
|
|
10
|
+
vapidKey: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @inline
|
|
14
|
+
*/
|
|
15
|
+
export type UseGetTokenMutationOptions<TContext = unknown> = {
|
|
16
|
+
/**
|
|
17
|
+
* Options for useMutation hook excluding mutationFn.
|
|
18
|
+
*/
|
|
19
|
+
options?: Omit<UseMutationOptions<{
|
|
20
|
+
token: string;
|
|
21
|
+
}, FirebaseError, UseGetTokenMutationValues, TContext>, "mutationFn">;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Executes a mutation and returns token for.current instance
|
|
25
|
+
*
|
|
26
|
+
* @group Hook
|
|
27
|
+
*
|
|
28
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
29
|
+
*
|
|
30
|
+
* @returns {UseMutationResult<{token: string;}, FirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* export const MyComponent = () => {
|
|
35
|
+
* const {mutate} = useGetTokenMutation({
|
|
36
|
+
* options: {
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // ....
|
|
41
|
+
* mutate({vapidKey: 'key'});
|
|
42
|
+
* // ....
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const useGetTokenMutation: ({ options }: UseGetTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<{
|
|
47
|
+
token: string;
|
|
48
|
+
}, FirebaseError, UseGetTokenMutationValues, unknown>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { getToken } from "firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and returns token for.current instance
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<{token: string;}, FirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useGetTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate({vapidKey: 'key'});
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useGetTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async ({ vapidKey }) => {
|
|
33
|
+
const token = await getToken(messaging, { vapidKey: vapidKey });
|
|
34
|
+
return { token };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { FirebaseContext } from "../context/FirebaseContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an instance of firestore bound to the closest context.
|
|
5
|
+
*
|
|
6
|
+
* @group Hook
|
|
7
|
+
*
|
|
8
|
+
* @returns {Messaging}
|
|
9
|
+
*/
|
|
10
|
+
export const useMessaging = () => {
|
|
11
|
+
const { messaging } = useContext(FirebaseContext);
|
|
12
|
+
return messaging;
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { onMessage } from "firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to start listening for push notifications.
|
|
6
|
+
*/
|
|
7
|
+
export const useOnMessageHandler = ({ callback }) => {
|
|
8
|
+
const messaging = useMessaging();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = onMessage(messaging, callback);
|
|
11
|
+
return () => {
|
|
12
|
+
unsubscribe();
|
|
13
|
+
};
|
|
14
|
+
}, [messaging, callback]);
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
"url": "https://github.com/vpishuk/react-query-firebase/issues"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@react-native-firebase/analytics": "^
|
|
9
|
-
"@react-native-firebase/app": "^
|
|
10
|
-
"@react-native-firebase/auth": "^
|
|
11
|
-
"@react-native-firebase/crashlytics": "^
|
|
12
|
-
"@react-native-firebase/firestore": "^
|
|
13
|
-
"@react-native-firebase/installations": "^
|
|
14
|
-
"@react-native-firebase/
|
|
8
|
+
"@react-native-firebase/analytics": "^24.x.x",
|
|
9
|
+
"@react-native-firebase/app": "^24.x.x",
|
|
10
|
+
"@react-native-firebase/auth": "^24.x.x",
|
|
11
|
+
"@react-native-firebase/crashlytics": "^24.x.x",
|
|
12
|
+
"@react-native-firebase/firestore": "^24.x.x",
|
|
13
|
+
"@react-native-firebase/installations": "^24.x.x",
|
|
14
|
+
"@react-native-firebase/messaging": "^24.x.x",
|
|
15
|
+
"@react-native-firebase/remote-config": "^24.x.x",
|
|
15
16
|
"@tanstack/react-query": "^5.x.x",
|
|
16
17
|
"firebase": "^11.x.x || ^12.x.x",
|
|
17
18
|
"react": "^18.x.x || ^19.x.x"
|
|
@@ -21,34 +22,35 @@
|
|
|
21
22
|
},
|
|
22
23
|
"description": "This module offers react hooks to work with Firebase on react-native and web platforms",
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.
|
|
25
|
-
"@react-native-firebase/analytics": "^
|
|
26
|
-
"@react-native-firebase/app": "^
|
|
27
|
-
"@react-native-firebase/auth": "^
|
|
28
|
-
"@react-native-firebase/crashlytics": "^
|
|
29
|
-
"@react-native-firebase/firestore": "^
|
|
30
|
-
"@react-native-firebase/installations": "^
|
|
31
|
-
"@react-native-firebase/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
25
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.1",
|
|
26
|
+
"@react-native-firebase/analytics": "^24.0.0",
|
|
27
|
+
"@react-native-firebase/app": "^24.0.0",
|
|
28
|
+
"@react-native-firebase/auth": "^24.0.0",
|
|
29
|
+
"@react-native-firebase/crashlytics": "^24.0.0",
|
|
30
|
+
"@react-native-firebase/firestore": "^24.0.0",
|
|
31
|
+
"@react-native-firebase/installations": "^24.0.0",
|
|
32
|
+
"@react-native-firebase/messaging": "^24.0.0",
|
|
33
|
+
"@react-native-firebase/remote-config": "^24.0.0",
|
|
34
|
+
"@tanstack/react-query": "^5.99.2",
|
|
35
|
+
"@types/react": "^19.2.14",
|
|
36
|
+
"eslint": "^9.39.4",
|
|
35
37
|
"eslint-config-prettier": "^10.1.8",
|
|
36
38
|
"eslint-plugin-import": "^2.32.0",
|
|
37
|
-
"eslint-plugin-jest": "^29.
|
|
38
|
-
"eslint-plugin-jsonc": "^2.21.
|
|
39
|
-
"eslint-plugin-prettier": "^5.5.
|
|
39
|
+
"eslint-plugin-jest": "^29.15.2",
|
|
40
|
+
"eslint-plugin-jsonc": "^2.21.1",
|
|
41
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
40
42
|
"eslint-plugin-react": "^7.37.5",
|
|
41
|
-
"eslint-plugin-react-hooks": "^7.
|
|
42
|
-
"firebase": "^12.
|
|
43
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
44
|
+
"firebase": "^12.12.1",
|
|
43
45
|
"husky": "^9.1.7",
|
|
44
|
-
"lint-staged": "^16.
|
|
45
|
-
"prettier": "^3.
|
|
46
|
-
"react": "^19.2.
|
|
47
|
-
"typedoc": "^0.28.
|
|
48
|
-
"typedoc-plugin-markdown": "^4.
|
|
46
|
+
"lint-staged": "^16.4.0",
|
|
47
|
+
"prettier": "^3.8.3",
|
|
48
|
+
"react": "^19.2.5",
|
|
49
|
+
"typedoc": "^0.28.19",
|
|
50
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
49
51
|
"typedoc-vitepress-theme": "^1.1.2",
|
|
50
52
|
"typescript": "^5.9.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
53
|
+
"typescript-eslint": "^8.59.0",
|
|
52
54
|
"vitepress": "^1.6.4"
|
|
53
55
|
},
|
|
54
56
|
"homepage": "https://github.com/vpishuk/react-query-firebase",
|
|
@@ -91,5 +93,5 @@
|
|
|
91
93
|
"docs:build": "vitepress build docs",
|
|
92
94
|
"docs:preview": "vitepress preview docs"
|
|
93
95
|
},
|
|
94
|
-
"version": "3.
|
|
96
|
+
"version": "3.3.0"
|
|
95
97
|
}
|