@b3dotfun/sdk 0.0.44 → 0.0.46

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 (85) hide show
  1. package/README.md +222 -3
  2. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -6
  3. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +1 -6
  4. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  5. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +3 -3
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
  8. package/dist/cjs/anyspend/types/api.d.ts +13 -10
  9. package/dist/cjs/anyspend/utils/orderPayload.js +0 -4
  10. package/dist/cjs/notifications/index.d.ts +3 -0
  11. package/dist/cjs/notifications/index.js +25 -0
  12. package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
  13. package/dist/cjs/notifications/react/hooks/index.js +17 -0
  14. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
  15. package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
  16. package/dist/cjs/notifications/react/index.d.ts +1 -0
  17. package/dist/cjs/notifications/react/index.js +17 -0
  18. package/dist/cjs/notifications/services/api.d.ts +67 -0
  19. package/dist/cjs/notifications/services/api.js +184 -0
  20. package/dist/cjs/notifications/services/index.d.ts +1 -0
  21. package/dist/cjs/notifications/services/index.js +17 -0
  22. package/dist/cjs/notifications/types/index.d.ts +51 -0
  23. package/dist/cjs/notifications/types/index.js +2 -0
  24. package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
  25. package/dist/cjs/shared/utils/auth-token.js +17 -0
  26. package/dist/cjs/shared/utils/index.d.ts +1 -0
  27. package/dist/cjs/shared/utils/index.js +1 -0
  28. package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -6
  29. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +1 -6
  30. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  31. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +3 -3
  32. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  33. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
  34. package/dist/esm/anyspend/types/api.d.ts +13 -10
  35. package/dist/esm/anyspend/utils/orderPayload.js +0 -4
  36. package/dist/esm/notifications/index.d.ts +3 -0
  37. package/dist/esm/notifications/index.js +7 -0
  38. package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
  39. package/dist/esm/notifications/react/hooks/index.js +1 -0
  40. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
  41. package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
  42. package/dist/esm/notifications/react/index.d.ts +1 -0
  43. package/dist/esm/notifications/react/index.js +1 -0
  44. package/dist/esm/notifications/services/api.d.ts +67 -0
  45. package/dist/esm/notifications/services/api.js +179 -0
  46. package/dist/esm/notifications/services/index.d.ts +1 -0
  47. package/dist/esm/notifications/services/index.js +1 -0
  48. package/dist/esm/notifications/types/index.d.ts +51 -0
  49. package/dist/esm/shared/utils/auth-token.d.ts +7 -0
  50. package/dist/esm/shared/utils/auth-token.js +11 -0
  51. package/dist/esm/shared/utils/index.d.ts +1 -0
  52. package/dist/esm/shared/utils/index.js +1 -0
  53. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  54. package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  55. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
  56. package/dist/types/anyspend/types/api.d.ts +13 -10
  57. package/dist/types/notifications/index.d.ts +3 -0
  58. package/dist/types/notifications/react/hooks/index.d.ts +1 -0
  59. package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
  60. package/dist/types/notifications/react/index.d.ts +1 -0
  61. package/dist/types/notifications/services/api.d.ts +67 -0
  62. package/dist/types/notifications/services/index.d.ts +1 -0
  63. package/dist/types/notifications/types/index.d.ts +51 -0
  64. package/dist/types/shared/utils/auth-token.d.ts +7 -0
  65. package/dist/types/shared/utils/index.d.ts +1 -0
  66. package/package.json +21 -1
  67. package/src/anyspend/react/components/common/OrderDetails.tsx +1 -7
  68. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +1 -7
  69. package/src/anyspend/react/hooks/useAnyspendFlow.ts +3 -3
  70. package/src/anyspend/types/api.ts +13 -10
  71. package/src/anyspend/utils/orderPayload.ts +0 -4
  72. package/src/notifications/index.ts +9 -0
  73. package/src/notifications/react/hooks/index.ts +1 -0
  74. package/src/notifications/react/hooks/useNotifications.ts +153 -0
  75. package/src/notifications/react/index.ts +1 -0
  76. package/src/notifications/services/api.ts +217 -0
  77. package/src/notifications/services/index.ts +1 -0
  78. package/src/notifications/types/index.ts +58 -0
  79. package/src/shared/utils/auth-token.ts +13 -0
  80. package/src/shared/utils/index.ts +1 -0
  81. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
  82. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  83. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
  84. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  85. /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
@@ -18,6 +18,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
18
18
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
19
19
  oneClickBuyUrl: string | null;
20
20
  stripePaymentIntentId: string | null;
21
+ settlement: {
22
+ actualDstAmount: string | null;
23
+ } | null;
21
24
  } & {
22
25
  type: "swap";
23
26
  payload: import("../..").components["schemas"]["SwapPayload"];
@@ -41,6 +44,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
41
44
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
42
45
  oneClickBuyUrl: string | null;
43
46
  stripePaymentIntentId: string | null;
47
+ settlement: {
48
+ actualDstAmount: string | null;
49
+ } | null;
44
50
  } & {
45
51
  type: "hype_duel";
46
52
  payload: import("../..").components["schemas"]["HypeDuelPayload"];
@@ -64,6 +70,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
64
70
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
65
71
  oneClickBuyUrl: string | null;
66
72
  stripePaymentIntentId: string | null;
73
+ settlement: {
74
+ actualDstAmount: string | null;
75
+ } | null;
67
76
  } & {
68
77
  type: "custom";
69
78
  payload: import("../..").components["schemas"]["CustomPayload"];
@@ -87,6 +96,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
87
96
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
88
97
  oneClickBuyUrl: string | null;
89
98
  stripePaymentIntentId: string | null;
99
+ settlement: {
100
+ actualDstAmount: string | null;
101
+ } | null;
90
102
  } & {
91
103
  type: "mint_nft";
92
104
  payload: import("../..").components["schemas"]["MintNftPayload"];
@@ -110,6 +122,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
110
122
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
111
123
  oneClickBuyUrl: string | null;
112
124
  stripePaymentIntentId: string | null;
125
+ settlement: {
126
+ actualDstAmount: string | null;
127
+ } | null;
113
128
  } & {
114
129
  type: "join_tournament";
115
130
  payload: import("../..").components["schemas"]["JoinTournamentPayload"];
@@ -133,6 +148,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
133
148
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
134
149
  oneClickBuyUrl: string | null;
135
150
  stripePaymentIntentId: string | null;
151
+ settlement: {
152
+ actualDstAmount: string | null;
153
+ } | null;
136
154
  } & {
137
155
  type: "fund_tournament";
138
156
  payload: import("../..").components["schemas"]["FundTournamentPayload"];
@@ -159,6 +177,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
159
177
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
160
178
  oneClickBuyUrl: string | null;
161
179
  stripePaymentIntentId: string | null;
180
+ settlement: {
181
+ actualDstAmount: string | null;
182
+ } | null;
162
183
  } & {
163
184
  type: "swap";
164
185
  payload: import("../..").components["schemas"]["SwapPayload"];
@@ -182,6 +203,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
182
203
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
183
204
  oneClickBuyUrl: string | null;
184
205
  stripePaymentIntentId: string | null;
206
+ settlement: {
207
+ actualDstAmount: string | null;
208
+ } | null;
185
209
  } & {
186
210
  type: "hype_duel";
187
211
  payload: import("../..").components["schemas"]["HypeDuelPayload"];
@@ -205,6 +229,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
205
229
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
206
230
  oneClickBuyUrl: string | null;
207
231
  stripePaymentIntentId: string | null;
232
+ settlement: {
233
+ actualDstAmount: string | null;
234
+ } | null;
208
235
  } & {
209
236
  type: "custom";
210
237
  payload: import("../..").components["schemas"]["CustomPayload"];
@@ -228,6 +255,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
228
255
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
229
256
  oneClickBuyUrl: string | null;
230
257
  stripePaymentIntentId: string | null;
258
+ settlement: {
259
+ actualDstAmount: string | null;
260
+ } | null;
231
261
  } & {
232
262
  type: "mint_nft";
233
263
  payload: import("../..").components["schemas"]["MintNftPayload"];
@@ -251,6 +281,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
251
281
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
252
282
  oneClickBuyUrl: string | null;
253
283
  stripePaymentIntentId: string | null;
284
+ settlement: {
285
+ actualDstAmount: string | null;
286
+ } | null;
254
287
  } & {
255
288
  type: "join_tournament";
256
289
  payload: import("../..").components["schemas"]["JoinTournamentPayload"];
@@ -274,6 +307,9 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
274
307
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
275
308
  oneClickBuyUrl: string | null;
276
309
  stripePaymentIntentId: string | null;
310
+ settlement: {
311
+ actualDstAmount: string | null;
312
+ } | null;
277
313
  } & {
278
314
  type: "fund_tournament";
279
315
  payload: import("../..").components["schemas"]["FundTournamentPayload"];
@@ -434,6 +434,11 @@ export interface paths {
434
434
  executeTx: components["schemas"]["ExecuteTx"] | null;
435
435
  /** @description Refund transactions if order failed */
436
436
  refundTxs: components["schemas"]["RefundTx"][];
437
+ /**
438
+ * @description Points awarded for this order (only present when order status is executed)
439
+ * @example 100
440
+ */
441
+ points: number | null;
437
442
  };
438
443
  /** @example 200 */
439
444
  statusCode: number;
@@ -1112,11 +1117,6 @@ export interface components {
1112
1117
  * @example 990000
1113
1118
  */
1114
1119
  expectedDstAmount: string;
1115
- /**
1116
- * @description Actual received amount (null for new orders)
1117
- * @example 990000
1118
- */
1119
- actualDstAmount: string | null;
1120
1120
  };
1121
1121
  /** @description HypeDuel-specific payload */
1122
1122
  HypeDuelPayload: {
@@ -1125,11 +1125,6 @@ export interface components {
1125
1125
  * @example 990000
1126
1126
  */
1127
1127
  expectedDstAmount: string;
1128
- /**
1129
- * @description Actual received amount (null for new orders)
1130
- * @example 990000
1131
- */
1132
- actualDstAmount: string | null;
1133
1128
  };
1134
1129
  /** @description Custom execution payload */
1135
1130
  CustomPayload: {
@@ -1315,6 +1310,14 @@ export interface components {
1315
1310
  * @example pi_3Rko0sJnoDg53PsP0PDLsHkR
1316
1311
  */
1317
1312
  stripePaymentIntentId: string | null;
1313
+ /** @description Settlement information for executed orders */
1314
+ settlement: {
1315
+ /**
1316
+ * @description Actual received amount after execution
1317
+ * @example 990000
1318
+ */
1319
+ actualDstAmount: string | null;
1320
+ } | null;
1318
1321
  };
1319
1322
  SwapOrder: components["schemas"]["BaseOrder"] & {
1320
1323
  /**
@@ -5,8 +5,6 @@ export const buildPayload = (orderType, params) => {
5
5
  case "swap":
6
6
  return {
7
7
  expectedDstAmount,
8
- actualDstAmount: null,
9
- amountInAfterFee: null,
10
8
  };
11
9
  case "mint_nft":
12
10
  if (nft?.type === "erc1155") {
@@ -43,8 +41,6 @@ export const buildPayload = (orderType, params) => {
43
41
  case "hype_duel":
44
42
  return {
45
43
  expectedDstAmount,
46
- actualDstAmount: null,
47
- amountInAfterFee: null,
48
44
  };
49
45
  default:
50
46
  throw new Error(`Invalid order type: ${orderType}`);
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./services";
3
+ export { getAuthToken } from "../shared/utils/auth-token";
@@ -0,0 +1,7 @@
1
+ // Export types
2
+ export * from "./types/index.js";
3
+ // Export services
4
+ export * from "./services/index.js";
5
+ // Re-export auth token getter from shared for convenience
6
+ // Note: Auth token is managed by B3 Global Account authentication
7
+ export { getAuthToken } from "../shared/utils/auth-token.js";
@@ -0,0 +1 @@
1
+ export * from "./useNotifications";
@@ -0,0 +1 @@
1
+ export * from "./useNotifications.js";
@@ -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,145 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { notificationsAPI } from "../../services/api.js";
3
+ /**
4
+ * React hook for managing B3 notifications
5
+ * Automatically uses the authenticated user's ID from JWT
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { useNotifications } from '../../../notifications/react/index.js';
10
+ *
11
+ * function NotificationSettings() {
12
+ * const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
13
+ *
14
+ * if (loading) return <div>Loading...</div>;
15
+ *
16
+ * return (
17
+ * <div>
18
+ * {!isEmailConnected && (
19
+ * <button onClick={() => connectEmail('user@example.com')}>
20
+ * Connect Email
21
+ * </button>
22
+ * )}
23
+ * <button onClick={connectTelegram}>Connect Telegram</button>
24
+ * </div>
25
+ * );
26
+ * }
27
+ * ```
28
+ */
29
+ export function useNotifications() {
30
+ const [user, setUser] = useState(null);
31
+ const [loading, setLoading] = useState(true);
32
+ const [error, setError] = useState(null);
33
+ // Refs to track polling timers for cleanup
34
+ const telegramPollIntervalRef = useRef(null);
35
+ const telegramPollTimeoutRef = useRef(null);
36
+ // Cleanup function for Telegram polling
37
+ const cleanupTelegramPolling = () => {
38
+ if (telegramPollIntervalRef.current) {
39
+ clearInterval(telegramPollIntervalRef.current);
40
+ telegramPollIntervalRef.current = null;
41
+ }
42
+ if (telegramPollTimeoutRef.current) {
43
+ clearTimeout(telegramPollTimeoutRef.current);
44
+ telegramPollTimeoutRef.current = null;
45
+ }
46
+ };
47
+ // Load user data on mount
48
+ useEffect(() => {
49
+ loadUser();
50
+ }, []);
51
+ // Cleanup polling on unmount
52
+ useEffect(() => {
53
+ return () => {
54
+ cleanupTelegramPolling();
55
+ };
56
+ }, []);
57
+ const loadUser = async () => {
58
+ try {
59
+ setLoading(true);
60
+ setError(null);
61
+ const userData = await notificationsAPI.getUser();
62
+ setUser(userData);
63
+ }
64
+ catch (err) {
65
+ setError(err instanceof Error ? err : new Error("Failed to load user"));
66
+ console.error("Failed to load user:", err);
67
+ }
68
+ finally {
69
+ setLoading(false);
70
+ }
71
+ };
72
+ const connectEmail = async (email) => {
73
+ try {
74
+ await notificationsAPI.connectEmail(email);
75
+ await loadUser(); // Refresh user data
76
+ }
77
+ catch (err) {
78
+ console.error("Failed to connect email:", err);
79
+ throw err;
80
+ }
81
+ };
82
+ const connectTelegram = async () => {
83
+ try {
84
+ // Clear any existing polling before starting new one
85
+ cleanupTelegramPolling();
86
+ const { deepLink } = await notificationsAPI.getTelegramLink();
87
+ window.open(deepLink, "_blank");
88
+ // Poll for connection status
89
+ telegramPollIntervalRef.current = setInterval(async () => {
90
+ try {
91
+ const { connected } = await notificationsAPI.checkTelegramStatus();
92
+ if (connected) {
93
+ cleanupTelegramPolling();
94
+ await loadUser(); // Refresh user data
95
+ }
96
+ }
97
+ catch (err) {
98
+ console.error("Failed to check Telegram status:", err);
99
+ }
100
+ }, 2000);
101
+ // Stop polling after 2 minutes
102
+ telegramPollTimeoutRef.current = setTimeout(() => {
103
+ cleanupTelegramPolling();
104
+ }, 120000);
105
+ }
106
+ catch (err) {
107
+ console.error("Failed to connect Telegram:", err);
108
+ throw err;
109
+ }
110
+ };
111
+ const updateChannel = async (channelId, updates) => {
112
+ try {
113
+ await notificationsAPI.updateChannel(channelId, updates);
114
+ await loadUser(); // Refresh user data
115
+ }
116
+ catch (err) {
117
+ console.error("Failed to update channel:", err);
118
+ throw err;
119
+ }
120
+ };
121
+ const deleteChannel = async (channelId) => {
122
+ try {
123
+ await notificationsAPI.deleteChannel(channelId);
124
+ await loadUser(); // Refresh user data
125
+ }
126
+ catch (err) {
127
+ console.error("Failed to delete channel:", err);
128
+ throw err;
129
+ }
130
+ };
131
+ return {
132
+ user,
133
+ loading,
134
+ error,
135
+ refresh: loadUser,
136
+ connectEmail,
137
+ connectTelegram,
138
+ updateChannel,
139
+ deleteChannel,
140
+ // Convenience helpers
141
+ isEmailConnected: user?.channels?.find(c => c.channel_type === "email")?.enabled === 1,
142
+ isTelegramConnected: user?.channels?.find(c => c.channel_type === "telegram")?.enabled === 1,
143
+ isDiscordConnected: user?.channels?.find(c => c.channel_type === "discord")?.enabled === 1,
144
+ };
145
+ }
@@ -0,0 +1 @@
1
+ export * from "./hooks";
@@ -0,0 +1 @@
1
+ export * from "./hooks/index.js";
@@ -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
+ };
@@ -0,0 +1,179 @@
1
+ import { getAuthToken } from "../../shared/utils/auth-token.js";
2
+ const DEFAULT_API_URL = "https://notifications.b3.fun";
3
+ let apiUrl = DEFAULT_API_URL;
4
+ export function setApiUrl(url) {
5
+ apiUrl = url;
6
+ }
7
+ export function getApiUrl() {
8
+ return apiUrl;
9
+ }
10
+ function getHeaders(includeAuth = false) {
11
+ const headers = {
12
+ "Content-Type": "application/json",
13
+ };
14
+ if (includeAuth) {
15
+ const token = getAuthToken();
16
+ if (token) {
17
+ headers["Authorization"] = `Bearer ${token}`;
18
+ }
19
+ }
20
+ return headers;
21
+ }
22
+ export const notificationsAPI = {
23
+ // ===== USER MANAGEMENT =====
24
+ /**
25
+ * Register the current user (userId extracted from JWT)
26
+ */
27
+ async registerUser() {
28
+ const res = await fetch(`${apiUrl}/users`, {
29
+ method: "POST",
30
+ headers: getHeaders(true),
31
+ });
32
+ if (!res.ok) {
33
+ const errorBody = await res.text().catch(() => "Could not read error body");
34
+ throw new Error(`API Error: ${res.status} ${res.statusText} - ${errorBody}`);
35
+ }
36
+ return res.json();
37
+ },
38
+ /**
39
+ * Get current user's profile and preferences
40
+ */
41
+ async getUser() {
42
+ const res = await fetch(`${apiUrl}/users/me`, {
43
+ headers: getHeaders(true),
44
+ });
45
+ return res.json();
46
+ },
47
+ /**
48
+ * Get current user's notification history
49
+ */
50
+ async getHistory(appId, limit = 100) {
51
+ const params = new URLSearchParams();
52
+ if (appId)
53
+ params.append("appId", appId);
54
+ params.append("limit", limit.toString());
55
+ const res = await fetch(`${apiUrl}/users/me/history?${params}`, {
56
+ headers: getHeaders(true),
57
+ });
58
+ return res.json();
59
+ },
60
+ // ===== CHANNELS =====
61
+ /**
62
+ * Add a notification channel for current user
63
+ */
64
+ async addChannel(channelType, channelIdentifier, metadata) {
65
+ const res = await fetch(`${apiUrl}/users/me/channels`, {
66
+ method: "POST",
67
+ headers: getHeaders(true),
68
+ body: JSON.stringify({
69
+ channelType,
70
+ channelIdentifier,
71
+ enabled: true,
72
+ metadata,
73
+ }),
74
+ });
75
+ return res.json();
76
+ },
77
+ /**
78
+ * Connect email for current user
79
+ */
80
+ async connectEmail(email) {
81
+ return this.addChannel("email", email);
82
+ },
83
+ /**
84
+ * Update a notification channel
85
+ */
86
+ async updateChannel(channelId, updates) {
87
+ const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
88
+ method: "PUT",
89
+ headers: getHeaders(true),
90
+ body: JSON.stringify(updates),
91
+ });
92
+ return res.json();
93
+ },
94
+ /**
95
+ * Delete a notification channel
96
+ */
97
+ async deleteChannel(channelId) {
98
+ const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
99
+ method: "DELETE",
100
+ headers: getHeaders(true),
101
+ });
102
+ return res.json();
103
+ },
104
+ // ===== TELEGRAM =====
105
+ /**
106
+ * Get Telegram deep link for current user
107
+ */
108
+ async getTelegramLink() {
109
+ const res = await fetch(`${apiUrl}/telegram/request-link`, {
110
+ method: "POST",
111
+ headers: getHeaders(true),
112
+ });
113
+ return res.json();
114
+ },
115
+ /**
116
+ * Check current user's Telegram connection status
117
+ */
118
+ async checkTelegramStatus() {
119
+ const res = await fetch(`${apiUrl}/telegram/status/me`, {
120
+ headers: getHeaders(true),
121
+ });
122
+ return res.json();
123
+ },
124
+ // ===== APP PREFERENCES =====
125
+ /**
126
+ * Save notification preferences for an app
127
+ * @param appId - The application ID
128
+ * @param settings - Notification preferences including channels, type, and enabled status (defaults to true)
129
+ */
130
+ async savePreferences(appId, settings) {
131
+ const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
132
+ method: "POST",
133
+ headers: getHeaders(true),
134
+ body: JSON.stringify({ enabled: true, ...settings }),
135
+ });
136
+ return res.json();
137
+ },
138
+ /**
139
+ * Get notification settings for an app
140
+ */
141
+ async getAppSettings(appId) {
142
+ const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
143
+ headers: getHeaders(true),
144
+ });
145
+ return res.json();
146
+ },
147
+ // ===== IN-APP NOTIFICATIONS =====
148
+ /**
149
+ * Get current user's in-app notifications
150
+ */
151
+ async getInAppNotifications() {
152
+ const res = await fetch(`${apiUrl}/users/me/notifications`, {
153
+ headers: getHeaders(true),
154
+ });
155
+ return res.json();
156
+ },
157
+ /**
158
+ * Mark a notification as read
159
+ */
160
+ async markNotificationAsRead(notificationId) {
161
+ const res = await fetch(`${apiUrl}/users/me/notifications/${notificationId}/read`, {
162
+ method: "PUT",
163
+ headers: getHeaders(true),
164
+ });
165
+ return res.json();
166
+ },
167
+ // ===== SENDING NOTIFICATIONS =====
168
+ /**
169
+ * Send a notification (requires auth)
170
+ */
171
+ async sendNotification(data) {
172
+ const res = await fetch(`${apiUrl}/send`, {
173
+ method: "POST",
174
+ headers: getHeaders(true),
175
+ body: JSON.stringify(data),
176
+ });
177
+ return res.json();
178
+ },
179
+ };
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1 @@
1
+ export * from "./api.js";