@frak-labs/react-sdk 0.2.1 → 1.0.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.
@@ -0,0 +1,63 @@
1
+ import type { UserReferralStatusType } from "@frak-labs/core-sdk";
2
+ import { getUserReferralStatus } from "@frak-labs/core-sdk/actions";
3
+ import { ClientNotFound, type FrakRpcError } from "@frak-labs/frame-connector";
4
+ import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
5
+ import { useFrakClient } from "./useFrakClient";
6
+
7
+ /** @ignore */
8
+ type QueryOptions = Omit<
9
+ UseQueryOptions<
10
+ UserReferralStatusType | null,
11
+ FrakRpcError,
12
+ UserReferralStatusType | null
13
+ >,
14
+ "queryKey" | "queryFn"
15
+ >;
16
+
17
+ /** @inline */
18
+ interface UseGetUserReferralStatusParams {
19
+ /**
20
+ * Optional query options, see {@link @tanstack/react-query!useQuery | `useQuery()`} for more infos
21
+ */
22
+ query?: QueryOptions;
23
+ /**
24
+ * Time in ms to cache the result at the core SDK level. Default: 30_000 (30s). Set to 0 to disable.
25
+ */
26
+ cacheTime?: number;
27
+ }
28
+
29
+ /**
30
+ * Hook that return a query to fetch the current user's referral status on the current merchant
31
+ *
32
+ * Returns `null` when the user's identity cannot be resolved.
33
+ *
34
+ * It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.getUserReferralStatus | `getUserReferralStatus()`} action
35
+ *
36
+ * @param args - Optional config object with `query` for customizing the underlying {@link @tanstack/react-query!useQuery | `useQuery()`}
37
+ *
38
+ * @group hooks
39
+ *
40
+ * @returns
41
+ * The query hook wrapping the `getUserReferralStatus()` action
42
+ * The `data` result is a {@link @frak-labs/core-sdk!index.UserReferralStatusType | `UserReferralStatusType`} or `null`
43
+ *
44
+ * @see {@link @frak-labs/core-sdk!actions.getUserReferralStatus | `getUserReferralStatus()`} for more info about the underlying action
45
+ * @see {@link @tanstack/react-query!useQuery | `useQuery()`} for more info about the useQuery options and response
46
+ */
47
+ export function useGetUserReferralStatus({
48
+ query,
49
+ cacheTime,
50
+ }: UseGetUserReferralStatusParams = {}) {
51
+ const client = useFrakClient();
52
+
53
+ return useQuery({
54
+ ...query,
55
+ queryKey: ["frak-sdk", "get-user-referral-status"],
56
+ queryFn: async () => {
57
+ if (!client) {
58
+ throw new ClientNotFound();
59
+ }
60
+ return getUserReferralStatus(client, { cacheTime });
61
+ },
62
+ });
63
+ }
@@ -0,0 +1,35 @@
1
+ import { setupReferral } from "@frak-labs/core-sdk/actions";
2
+ import { ClientNotFound } from "@frak-labs/frame-connector";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { useFrakClient } from "./useFrakClient";
5
+
6
+ /**
7
+ * Hook that automatically processes referral context and emits a DOM event on success
8
+ *
9
+ * Runs once when the Frak client becomes available. Fire-and-forget — the referral
10
+ * result is tracked via a `"frak:referral-success"` DOM event on `window`, not via
11
+ * the returned query data.
12
+ *
13
+ * @group hooks
14
+ *
15
+ * @returns The query handle (data is not meaningful — listen for `REFERRAL_SUCCESS_EVENT` on `window` instead)
16
+ *
17
+ * @see {@link @frak-labs/core-sdk!actions.setupReferral | `setupReferral()`} for more info about the underlying action
18
+ * @see {@link @frak-labs/core-sdk!actions.REFERRAL_SUCCESS_EVENT | `REFERRAL_SUCCESS_EVENT`} for the event name constant
19
+ */
20
+ export function useSetupReferral() {
21
+ const client = useFrakClient();
22
+
23
+ return useQuery({
24
+ queryKey: ["frak-sdk", "setup-referral"],
25
+ queryFn: async () => {
26
+ if (!client) {
27
+ throw new ClientNotFound();
28
+ }
29
+ await setupReferral(client);
30
+ return null;
31
+ },
32
+ enabled: !!client,
33
+ staleTime: Number.POSITIVE_INFINITY,
34
+ });
35
+ }
package/src/index.ts CHANGED
@@ -3,13 +3,17 @@
3
3
  // Hooks export
4
4
  export {
5
5
  useDisplayModal,
6
+ useDisplaySharingPage,
6
7
  useFrakClient,
7
8
  useFrakConfig,
8
9
  useGetMerchantInformation,
10
+ useGetMergeToken,
11
+ useGetUserReferralStatus,
9
12
  useOpenSso,
10
13
  usePrepareSso,
11
14
  useReferralInteraction,
12
15
  useSendTransactionAction,
16
+ useSetupReferral,
13
17
  useSiweAuthenticate,
14
18
  useWalletStatus,
15
19
  } from "./hook";