@b3dotfun/sdk 0.0.47 → 0.0.48

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.
Files changed (151) hide show
  1. package/README.md +225 -6
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +5 -3
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  6. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
  7. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
  8. package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
  9. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  10. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  11. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  12. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  13. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
  14. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  15. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
  16. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  17. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
  18. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  19. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
  20. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  21. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
  22. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
  23. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
  24. package/dist/cjs/global-account/react/hooks/useAuthentication.js +141 -81
  25. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  26. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
  27. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
  28. package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
  29. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  30. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
  31. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
  32. package/dist/cjs/notifications/index.d.ts +3 -0
  33. package/dist/cjs/notifications/index.js +25 -0
  34. package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
  35. package/dist/cjs/notifications/react/hooks/index.js +17 -0
  36. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
  37. package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
  38. package/dist/cjs/notifications/react/index.d.ts +1 -0
  39. package/dist/cjs/notifications/react/index.js +17 -0
  40. package/dist/cjs/notifications/services/api.d.ts +67 -0
  41. package/dist/cjs/notifications/services/api.js +184 -0
  42. package/dist/cjs/notifications/services/index.d.ts +1 -0
  43. package/dist/cjs/notifications/services/index.js +17 -0
  44. package/dist/cjs/notifications/types/index.d.ts +51 -0
  45. package/dist/cjs/notifications/types/index.js +2 -0
  46. package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
  47. package/dist/cjs/shared/utils/auth-token.js +17 -0
  48. package/dist/cjs/shared/utils/index.d.ts +1 -0
  49. package/dist/cjs/shared/utils/index.js +1 -0
  50. package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -3
  51. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  52. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
  53. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  54. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
  55. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
  56. package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
  57. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  58. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  59. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  60. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  61. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
  62. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  63. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
  64. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  65. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
  66. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  67. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
  68. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  69. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  70. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
  71. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
  72. package/dist/esm/global-account/react/hooks/useAuthentication.js +144 -84
  73. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  74. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
  75. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
  76. package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
  77. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  78. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
  79. package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
  80. package/dist/esm/notifications/index.d.ts +3 -0
  81. package/dist/esm/notifications/index.js +7 -0
  82. package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
  83. package/dist/esm/notifications/react/hooks/index.js +1 -0
  84. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
  85. package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
  86. package/dist/esm/notifications/react/index.d.ts +1 -0
  87. package/dist/esm/notifications/react/index.js +1 -0
  88. package/dist/esm/notifications/services/api.d.ts +67 -0
  89. package/dist/esm/notifications/services/api.js +179 -0
  90. package/dist/esm/notifications/services/index.d.ts +1 -0
  91. package/dist/esm/notifications/services/index.js +1 -0
  92. package/dist/esm/notifications/types/index.d.ts +51 -0
  93. package/dist/esm/shared/utils/auth-token.d.ts +7 -0
  94. package/dist/esm/shared/utils/auth-token.js +11 -0
  95. package/dist/esm/shared/utils/index.d.ts +1 -0
  96. package/dist/esm/shared/utils/index.js +1 -0
  97. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  98. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  99. package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
  100. package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  101. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  102. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  103. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  104. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  105. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
  106. package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  107. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
  108. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  109. package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
  110. package/dist/types/notifications/index.d.ts +3 -0
  111. package/dist/types/notifications/react/hooks/index.d.ts +1 -0
  112. package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
  113. package/dist/types/notifications/react/index.d.ts +1 -0
  114. package/dist/types/notifications/services/api.d.ts +67 -0
  115. package/dist/types/notifications/services/index.d.ts +1 -0
  116. package/dist/types/notifications/types/index.d.ts +51 -0
  117. package/dist/types/shared/utils/auth-token.d.ts +7 -0
  118. package/dist/types/shared/utils/index.d.ts +1 -0
  119. package/package.json +23 -3
  120. package/src/anyspend/react/components/AnySpendCustom.tsx +5 -3
  121. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
  122. package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
  123. package/src/global-account/react/components/B3Provider/types.ts +4 -0
  124. package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
  125. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
  126. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  127. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  128. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
  129. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
  130. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
  131. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  132. package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
  133. package/src/global-account/react/hooks/useAuthentication.ts +170 -89
  134. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
  135. package/src/global-account/react/hooks/useUserQuery.ts +95 -0
  136. package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
  137. package/src/global-account/react/stores/useModalStore.ts +0 -2
  138. package/src/notifications/index.ts +9 -0
  139. package/src/notifications/react/hooks/index.ts +1 -0
  140. package/src/notifications/react/hooks/useNotifications.ts +153 -0
  141. package/src/notifications/react/index.ts +1 -0
  142. package/src/notifications/services/api.ts +217 -0
  143. package/src/notifications/services/index.ts +1 -0
  144. package/src/notifications/types/index.ts +58 -0
  145. package/src/shared/utils/auth-token.ts +13 -0
  146. package/src/shared/utils/index.ts +1 -0
  147. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
  148. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  149. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
  150. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  151. /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
@@ -0,0 +1,58 @@
1
+ import { Users } from "@b3dotfun/b3-api";
2
+ /**
3
+ * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
4
+ *
5
+ * Custom hook to manage user state with react-query
6
+ * This allows for invalidation and refetching of user data
7
+ */
8
+ export declare function useUserQuery(): {
9
+ user: {
10
+ email?: string | undefined;
11
+ username?: string | undefined;
12
+ telNumber?: string | undefined;
13
+ ens?: string | undefined;
14
+ avatar?: string | undefined;
15
+ preferences?: {} | undefined;
16
+ referredBy?: string | {} | undefined;
17
+ sourceApp?: string | undefined;
18
+ referralCode?: string | undefined;
19
+ userGroups?: number[] | undefined;
20
+ isMigratedFromBSMNT?: boolean | undefined;
21
+ privyLinkedAccounts?: {
22
+ name?: string | undefined;
23
+ address?: string | undefined;
24
+ email?: string | undefined;
25
+ chain_type?: string | undefined;
26
+ lv?: number | undefined;
27
+ wallet_client_type?: string | undefined;
28
+ smart_wallet_type?: string | undefined;
29
+ subject?: string | undefined;
30
+ type: string;
31
+ }[] | undefined;
32
+ twProfiles?: {
33
+ type: string;
34
+ details: {
35
+ id?: string | undefined;
36
+ name?: string | undefined;
37
+ address?: string | undefined;
38
+ email?: string | undefined;
39
+ phone?: string | undefined;
40
+ username?: string | undefined;
41
+ fid?: string | undefined;
42
+ };
43
+ }[] | undefined;
44
+ _id: string | {};
45
+ userId: string;
46
+ smartAccountAddress: string;
47
+ createdAt: number;
48
+ updatedAt: number;
49
+ partnerIds: {
50
+ privyId?: string | undefined;
51
+ thirdwebId?: string | undefined;
52
+ };
53
+ } | undefined;
54
+ setUser: (newUser?: Users) => void;
55
+ refetchUser: () => Promise<void>;
56
+ clearUser: () => void;
57
+ queryKey: string[];
58
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUserQuery = useUserQuery;
4
+ const debug_1 = require("../../../shared/utils/debug");
5
+ const react_query_1 = require("@tanstack/react-query");
6
+ const debug = (0, debug_1.debugB3React)("useUserQuery");
7
+ const USER_QUERY_KEY = ["b3-user"];
8
+ /**
9
+ * Retrieves the user from localStorage
10
+ */
11
+ function getUserFromStorage() {
12
+ if (typeof window === "undefined") {
13
+ return null;
14
+ }
15
+ try {
16
+ const storedUser = localStorage.getItem("b3-user");
17
+ return storedUser ? JSON.parse(storedUser) : null;
18
+ }
19
+ catch (error) {
20
+ console.warn("Failed to restore user from localStorage:", error);
21
+ return null;
22
+ }
23
+ }
24
+ /**
25
+ * Saves user to localStorage
26
+ */
27
+ function saveUserToStorage(user) {
28
+ if (typeof window === "undefined") {
29
+ return;
30
+ }
31
+ if (user) {
32
+ localStorage.setItem("b3-user", JSON.stringify(user));
33
+ }
34
+ else {
35
+ localStorage.removeItem("b3-user");
36
+ }
37
+ }
38
+ /**
39
+ * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
40
+ *
41
+ * Custom hook to manage user state with react-query
42
+ * This allows for invalidation and refetching of user data
43
+ */
44
+ function useUserQuery() {
45
+ const queryClient = (0, react_query_1.useQueryClient)();
46
+ // Query to get user data (primarily from cache/localStorage)
47
+ const { data: user } = (0, react_query_1.useQuery)({
48
+ queryKey: USER_QUERY_KEY,
49
+ queryFn: getUserFromStorage,
50
+ staleTime: Infinity, // User data doesn't go stale automatically
51
+ gcTime: Infinity, // Keep in cache indefinitely
52
+ initialData: getUserFromStorage,
53
+ });
54
+ // Mutation to update user
55
+ const setUserMutation = (0, react_query_1.useMutation)({
56
+ mutationFn: async (newUser) => {
57
+ const userToSave = newUser ?? null;
58
+ saveUserToStorage(userToSave);
59
+ return userToSave;
60
+ },
61
+ onSuccess: data => {
62
+ queryClient.setQueryData(USER_QUERY_KEY, data);
63
+ debug("User updated", data);
64
+ },
65
+ });
66
+ // Helper function to set user (maintains backward compatibility)
67
+ const setUser = (newUser) => {
68
+ setUserMutation.mutate(newUser);
69
+ };
70
+ // Helper function to invalidate and refetch user
71
+ const refetchUser = async () => {
72
+ await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
73
+ return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
74
+ };
75
+ // Helper function to clear user
76
+ const clearUser = () => {
77
+ setUser(undefined);
78
+ };
79
+ return {
80
+ user: user ?? undefined,
81
+ setUser,
82
+ refetchUser,
83
+ clearUser,
84
+ queryKey: USER_QUERY_KEY,
85
+ };
86
+ }
@@ -0,0 +1,13 @@
1
+ export declare function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
2
+ [k: string]: import("viem").HttpTransport<undefined, false>;
3
+ }, readonly [import("wagmi").CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
4
+ connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
5
+ accounts: withCapabilities extends true ? readonly {
6
+ address: `0x${string}`;
7
+ capabilities: Record<string, unknown>;
8
+ }[] : readonly `0x${string}`[];
9
+ chainId: number;
10
+ }>;
11
+ }, {
12
+ "thirdweb:lastChainId": number;
13
+ }>]>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWagmiConfig = useWagmiConfig;
4
+ const constants_1 = require("../../../shared/constants");
5
+ const supported_1 = require("../../../shared/constants/chains/supported");
6
+ const thirdweb_1 = require("../../../shared/utils/thirdweb");
7
+ const wagmi_adapter_1 = require("@thirdweb-dev/wagmi-adapter");
8
+ const react_1 = require("react");
9
+ const viem_1 = require("viem");
10
+ const wagmi_1 = require("wagmi");
11
+ function useWagmiConfig(partnerId, rpcUrls) {
12
+ // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
13
+ // when parent component passes new object references with same content
14
+ const rpcUrlsString = (0, react_1.useMemo)(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
15
+ const ecocystemConfig = (0, react_1.useMemo)(() => {
16
+ return {
17
+ ecosystemId: constants_1.ecosystemWalletId,
18
+ partnerId: partnerId,
19
+ client: thirdweb_1.client,
20
+ };
21
+ }, [partnerId]);
22
+ /**
23
+ * Creates wagmi config with optional custom RPC URLs
24
+ * @param rpcUrls - Optional mapping of chain IDs to RPC URLs
25
+ */
26
+ const wagmiConfig = (0, react_1.useMemo)(() => {
27
+ const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
28
+ return (0, wagmi_1.createConfig)({
29
+ chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
30
+ transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, viem_1.http)(parsedRpcUrls?.[chain.id])])),
31
+ connectors: [
32
+ (0, wagmi_adapter_1.inAppWalletConnector)({
33
+ ...ecocystemConfig,
34
+ client: thirdweb_1.client,
35
+ }),
36
+ // injected(),
37
+ // coinbaseWallet({ appName: "HypeDuel" }),
38
+ ],
39
+ });
40
+ }, [rpcUrlsString, ecocystemConfig]);
41
+ return wagmiConfig;
42
+ }
@@ -32,8 +32,6 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
32
32
  sessionKeyAddress?: Address;
33
33
  /** Unique identifier for the partner application */
34
34
  partnerId: string;
35
- /** Whether to authenticate with Sign In With Ethereum */
36
- loginWithSiwe?: boolean;
37
35
  /** Whether to close the modal after successful login */
38
36
  closeAfterLogin?: boolean;
39
37
  /** Source of the sign-in request */
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./services";
3
+ export { getAuthToken } from "../shared/utils/auth-token";
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getAuthToken = void 0;
18
+ // Export types
19
+ __exportStar(require("./types"), exports);
20
+ // Export services
21
+ __exportStar(require("./services"), exports);
22
+ // Re-export auth token getter from shared for convenience
23
+ // Note: Auth token is managed by B3 Global Account authentication
24
+ var auth_token_1 = require("../shared/utils/auth-token");
25
+ Object.defineProperty(exports, "getAuthToken", { enumerable: true, get: function () { return auth_token_1.getAuthToken; } });
@@ -0,0 +1 @@
1
+ export * from "./useNotifications";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./useNotifications"), exports);
@@ -0,0 +1,42 @@
1
+ import type { UserData } from "../../types";
2
+ /**
3
+ * React hook for managing B3 notifications
4
+ * Automatically uses the authenticated user's ID from JWT
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * import { useNotifications } from '../../../notifications/react';
9
+ *
10
+ * function NotificationSettings() {
11
+ * const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
12
+ *
13
+ * if (loading) return <div>Loading...</div>;
14
+ *
15
+ * return (
16
+ * <div>
17
+ * {!isEmailConnected && (
18
+ * <button onClick={() => connectEmail('user@example.com')}>
19
+ * Connect Email
20
+ * </button>
21
+ * )}
22
+ * <button onClick={connectTelegram}>Connect Telegram</button>
23
+ * </div>
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function useNotifications(): {
29
+ user: UserData | null;
30
+ loading: boolean;
31
+ error: Error | null;
32
+ refresh: () => Promise<void>;
33
+ connectEmail: (email: string) => Promise<void>;
34
+ connectTelegram: () => Promise<void>;
35
+ updateChannel: (channelId: string, updates: {
36
+ enabled?: boolean;
37
+ }) => Promise<void>;
38
+ deleteChannel: (channelId: string) => Promise<void>;
39
+ isEmailConnected: boolean;
40
+ isTelegramConnected: boolean;
41
+ isDiscordConnected: boolean;
42
+ };
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNotifications = useNotifications;
4
+ const react_1 = require("react");
5
+ const api_1 = require("../../services/api");
6
+ /**
7
+ * React hook for managing B3 notifications
8
+ * Automatically uses the authenticated user's ID from JWT
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * import { useNotifications } from '../../../notifications/react';
13
+ *
14
+ * function NotificationSettings() {
15
+ * const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
16
+ *
17
+ * if (loading) return <div>Loading...</div>;
18
+ *
19
+ * return (
20
+ * <div>
21
+ * {!isEmailConnected && (
22
+ * <button onClick={() => connectEmail('user@example.com')}>
23
+ * Connect Email
24
+ * </button>
25
+ * )}
26
+ * <button onClick={connectTelegram}>Connect Telegram</button>
27
+ * </div>
28
+ * );
29
+ * }
30
+ * ```
31
+ */
32
+ function useNotifications() {
33
+ const [user, setUser] = (0, react_1.useState)(null);
34
+ const [loading, setLoading] = (0, react_1.useState)(true);
35
+ const [error, setError] = (0, react_1.useState)(null);
36
+ // Refs to track polling timers for cleanup
37
+ const telegramPollIntervalRef = (0, react_1.useRef)(null);
38
+ const telegramPollTimeoutRef = (0, react_1.useRef)(null);
39
+ // Cleanup function for Telegram polling
40
+ const cleanupTelegramPolling = () => {
41
+ if (telegramPollIntervalRef.current) {
42
+ clearInterval(telegramPollIntervalRef.current);
43
+ telegramPollIntervalRef.current = null;
44
+ }
45
+ if (telegramPollTimeoutRef.current) {
46
+ clearTimeout(telegramPollTimeoutRef.current);
47
+ telegramPollTimeoutRef.current = null;
48
+ }
49
+ };
50
+ // Load user data on mount
51
+ (0, react_1.useEffect)(() => {
52
+ loadUser();
53
+ }, []);
54
+ // Cleanup polling on unmount
55
+ (0, react_1.useEffect)(() => {
56
+ return () => {
57
+ cleanupTelegramPolling();
58
+ };
59
+ }, []);
60
+ const loadUser = async () => {
61
+ try {
62
+ setLoading(true);
63
+ setError(null);
64
+ const userData = await api_1.notificationsAPI.getUser();
65
+ setUser(userData);
66
+ }
67
+ catch (err) {
68
+ setError(err instanceof Error ? err : new Error("Failed to load user"));
69
+ console.error("Failed to load user:", err);
70
+ }
71
+ finally {
72
+ setLoading(false);
73
+ }
74
+ };
75
+ const connectEmail = async (email) => {
76
+ try {
77
+ await api_1.notificationsAPI.connectEmail(email);
78
+ await loadUser(); // Refresh user data
79
+ }
80
+ catch (err) {
81
+ console.error("Failed to connect email:", err);
82
+ throw err;
83
+ }
84
+ };
85
+ const connectTelegram = async () => {
86
+ try {
87
+ // Clear any existing polling before starting new one
88
+ cleanupTelegramPolling();
89
+ const { deepLink } = await api_1.notificationsAPI.getTelegramLink();
90
+ window.open(deepLink, "_blank");
91
+ // Poll for connection status
92
+ telegramPollIntervalRef.current = setInterval(async () => {
93
+ try {
94
+ const { connected } = await api_1.notificationsAPI.checkTelegramStatus();
95
+ if (connected) {
96
+ cleanupTelegramPolling();
97
+ await loadUser(); // Refresh user data
98
+ }
99
+ }
100
+ catch (err) {
101
+ console.error("Failed to check Telegram status:", err);
102
+ }
103
+ }, 2000);
104
+ // Stop polling after 2 minutes
105
+ telegramPollTimeoutRef.current = setTimeout(() => {
106
+ cleanupTelegramPolling();
107
+ }, 120000);
108
+ }
109
+ catch (err) {
110
+ console.error("Failed to connect Telegram:", err);
111
+ throw err;
112
+ }
113
+ };
114
+ const updateChannel = async (channelId, updates) => {
115
+ try {
116
+ await api_1.notificationsAPI.updateChannel(channelId, updates);
117
+ await loadUser(); // Refresh user data
118
+ }
119
+ catch (err) {
120
+ console.error("Failed to update channel:", err);
121
+ throw err;
122
+ }
123
+ };
124
+ const deleteChannel = async (channelId) => {
125
+ try {
126
+ await api_1.notificationsAPI.deleteChannel(channelId);
127
+ await loadUser(); // Refresh user data
128
+ }
129
+ catch (err) {
130
+ console.error("Failed to delete channel:", err);
131
+ throw err;
132
+ }
133
+ };
134
+ return {
135
+ user,
136
+ loading,
137
+ error,
138
+ refresh: loadUser,
139
+ connectEmail,
140
+ connectTelegram,
141
+ updateChannel,
142
+ deleteChannel,
143
+ // Convenience helpers
144
+ isEmailConnected: user?.channels?.find(c => c.channel_type === "email")?.enabled === 1,
145
+ isTelegramConnected: user?.channels?.find(c => c.channel_type === "telegram")?.enabled === 1,
146
+ isDiscordConnected: user?.channels?.find(c => c.channel_type === "discord")?.enabled === 1,
147
+ };
148
+ }
@@ -0,0 +1 @@
1
+ export * from "./hooks";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hooks"), exports);
@@ -0,0 +1,67 @@
1
+ import type { NotificationHistory, NotificationPreferences, SendNotificationRequest, TelegramLinkResponse, TelegramStatusResponse, UserData } from "../types";
2
+ export declare function setApiUrl(url: string): void;
3
+ export declare function getApiUrl(): string;
4
+ export declare const notificationsAPI: {
5
+ /**
6
+ * Register the current user (userId extracted from JWT)
7
+ */
8
+ registerUser(): Promise<any>;
9
+ /**
10
+ * Get current user's profile and preferences
11
+ */
12
+ getUser(): Promise<UserData>;
13
+ /**
14
+ * Get current user's notification history
15
+ */
16
+ getHistory(appId?: string, limit?: number): Promise<NotificationHistory[]>;
17
+ /**
18
+ * Add a notification channel for current user
19
+ */
20
+ addChannel(channelType: string, channelIdentifier: string, metadata?: Record<string, any>): Promise<any>;
21
+ /**
22
+ * Connect email for current user
23
+ */
24
+ connectEmail(email: string): Promise<any>;
25
+ /**
26
+ * Update a notification channel
27
+ */
28
+ updateChannel(channelId: string, updates: {
29
+ enabled?: boolean;
30
+ channelIdentifier?: string;
31
+ metadata?: Record<string, any>;
32
+ }): Promise<any>;
33
+ /**
34
+ * Delete a notification channel
35
+ */
36
+ deleteChannel(channelId: string): Promise<any>;
37
+ /**
38
+ * Get Telegram deep link for current user
39
+ */
40
+ getTelegramLink(): Promise<TelegramLinkResponse>;
41
+ /**
42
+ * Check current user's Telegram connection status
43
+ */
44
+ checkTelegramStatus(): Promise<TelegramStatusResponse>;
45
+ /**
46
+ * Save notification preferences for an app
47
+ * @param appId - The application ID
48
+ * @param settings - Notification preferences including channels, type, and enabled status (defaults to true)
49
+ */
50
+ savePreferences(appId: string, settings: NotificationPreferences): Promise<any>;
51
+ /**
52
+ * Get notification settings for an app
53
+ */
54
+ getAppSettings(appId: string): Promise<any>;
55
+ /**
56
+ * Get current user's in-app notifications
57
+ */
58
+ getInAppNotifications(): Promise<any>;
59
+ /**
60
+ * Mark a notification as read
61
+ */
62
+ markNotificationAsRead(notificationId: string): Promise<any>;
63
+ /**
64
+ * Send a notification (requires auth)
65
+ */
66
+ sendNotification(data: SendNotificationRequest): Promise<any>;
67
+ };