@b3dotfun/sdk 0.0.45 → 0.0.47-alpha.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.
Files changed (86) hide show
  1. package/README.md +3 -215
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +13 -14
  3. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -15
  4. package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -2
  5. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +6 -3
  6. package/dist/cjs/anyspend/types/api.d.ts +176 -0
  7. package/dist/cjs/anyspend/utils/chain.js +1 -1
  8. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
  9. package/dist/cjs/shared/utils/index.d.ts +0 -1
  10. package/dist/cjs/shared/utils/index.js +0 -1
  11. package/dist/esm/anyspend/react/components/AnySpend.js +14 -15
  12. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -16
  13. package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -2
  14. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +8 -5
  15. package/dist/esm/anyspend/types/api.d.ts +176 -0
  16. package/dist/esm/anyspend/utils/chain.js +1 -1
  17. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  18. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
  19. package/dist/esm/shared/utils/index.d.ts +0 -1
  20. package/dist/esm/shared/utils/index.js +0 -1
  21. package/dist/styles/index.css +1 -1
  22. package/dist/types/anyspend/types/api.d.ts +176 -0
  23. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  24. package/dist/types/shared/utils/index.d.ts +0 -1
  25. package/package.json +2 -21
  26. package/src/anyspend/react/components/AnySpend.tsx +21 -19
  27. package/src/anyspend/react/components/AnyspendDepositHype.tsx +21 -21
  28. package/src/anyspend/react/components/common/OrderHistory.tsx +11 -11
  29. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +124 -129
  30. package/src/anyspend/types/api.ts +176 -0
  31. package/src/anyspend/utils/chain.ts +1 -4
  32. package/src/shared/utils/index.ts +0 -1
  33. package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  34. package/dist/cjs/anyspend/react/components/common/ErrorSection.js +0 -12
  35. package/dist/cjs/notifications/index.d.ts +0 -4
  36. package/dist/cjs/notifications/index.js +0 -26
  37. package/dist/cjs/notifications/react/hooks/index.d.ts +0 -1
  38. package/dist/cjs/notifications/react/hooks/index.js +0 -17
  39. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +0 -42
  40. package/dist/cjs/notifications/react/hooks/useNotifications.js +0 -148
  41. package/dist/cjs/notifications/react/index.d.ts +0 -1
  42. package/dist/cjs/notifications/react/index.js +0 -17
  43. package/dist/cjs/notifications/services/api.d.ts +0 -65
  44. package/dist/cjs/notifications/services/api.js +0 -178
  45. package/dist/cjs/notifications/services/index.d.ts +0 -1
  46. package/dist/cjs/notifications/services/index.js +0 -17
  47. package/dist/cjs/notifications/types/index.d.ts +0 -50
  48. package/dist/cjs/notifications/types/index.js +0 -2
  49. package/dist/cjs/shared/utils/auth-token.d.ts +0 -7
  50. package/dist/cjs/shared/utils/auth-token.js +0 -17
  51. package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  52. package/dist/esm/anyspend/react/components/common/ErrorSection.js +0 -9
  53. package/dist/esm/notifications/index.d.ts +0 -4
  54. package/dist/esm/notifications/index.js +0 -8
  55. package/dist/esm/notifications/react/hooks/index.d.ts +0 -1
  56. package/dist/esm/notifications/react/hooks/index.js +0 -1
  57. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +0 -42
  58. package/dist/esm/notifications/react/hooks/useNotifications.js +0 -145
  59. package/dist/esm/notifications/react/index.d.ts +0 -1
  60. package/dist/esm/notifications/react/index.js +0 -1
  61. package/dist/esm/notifications/services/api.d.ts +0 -65
  62. package/dist/esm/notifications/services/api.js +0 -173
  63. package/dist/esm/notifications/services/index.d.ts +0 -1
  64. package/dist/esm/notifications/services/index.js +0 -1
  65. package/dist/esm/notifications/types/index.d.ts +0 -50
  66. package/dist/esm/shared/utils/auth-token.d.ts +0 -7
  67. package/dist/esm/shared/utils/auth-token.js +0 -11
  68. package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  69. package/dist/types/notifications/index.d.ts +0 -4
  70. package/dist/types/notifications/react/hooks/index.d.ts +0 -1
  71. package/dist/types/notifications/react/hooks/useNotifications.d.ts +0 -42
  72. package/dist/types/notifications/react/index.d.ts +0 -1
  73. package/dist/types/notifications/services/api.d.ts +0 -65
  74. package/dist/types/notifications/services/index.d.ts +0 -1
  75. package/dist/types/notifications/types/index.d.ts +0 -50
  76. package/dist/types/shared/utils/auth-token.d.ts +0 -7
  77. package/src/anyspend/react/components/common/ErrorSection.tsx +0 -21
  78. package/src/notifications/index.ts +0 -11
  79. package/src/notifications/react/hooks/index.ts +0 -1
  80. package/src/notifications/react/hooks/useNotifications.ts +0 -153
  81. package/src/notifications/react/index.ts +0 -1
  82. package/src/notifications/services/api.ts +0 -211
  83. package/src/notifications/services/index.ts +0 -1
  84. package/src/notifications/types/index.ts +0 -57
  85. package/src/shared/utils/auth-token.ts +0 -13
  86. /package/dist/{esm/notifications/types/index.js → cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts} +0 -0
@@ -1,211 +0,0 @@
1
- import { getAuthToken } from "@b3dotfun/sdk/shared/utils/auth-token";
2
- import type {
3
- NotificationHistory,
4
- NotificationPreferences,
5
- SendNotificationRequest,
6
- TelegramLinkResponse,
7
- TelegramStatusResponse,
8
- UserData,
9
- } from "../types";
10
-
11
- const DEFAULT_API_URL = "https://notifications.b3.fun";
12
-
13
- let apiUrl: string = DEFAULT_API_URL;
14
-
15
- export function setApiUrl(url: string) {
16
- apiUrl = url;
17
- }
18
-
19
- export function getApiUrl(): string {
20
- return apiUrl;
21
- }
22
-
23
- function getHeaders(includeAuth = false): HeadersInit {
24
- const headers: HeadersInit = {
25
- "Content-Type": "application/json",
26
- };
27
-
28
- if (includeAuth) {
29
- const token = getAuthToken();
30
- if (token) {
31
- headers["Authorization"] = `Bearer ${token}`;
32
- }
33
- }
34
-
35
- return headers;
36
- }
37
-
38
- export const notificationsAPI = {
39
- // ===== USER MANAGEMENT =====
40
-
41
- /**
42
- * Register the current user (userId extracted from JWT)
43
- */
44
- async registerUser() {
45
- const res = await fetch(`${apiUrl}/users`, {
46
- method: "POST",
47
- headers: getHeaders(true),
48
- });
49
- return res.json();
50
- },
51
-
52
- /**
53
- * Get current user's profile and preferences
54
- */
55
- async getUser(): Promise<UserData> {
56
- const res = await fetch(`${apiUrl}/users/me`, {
57
- headers: getHeaders(true),
58
- });
59
- return res.json();
60
- },
61
-
62
- /**
63
- * Get current user's notification history
64
- */
65
- async getHistory(appId?: string, limit = 100): Promise<NotificationHistory[]> {
66
- const params = new URLSearchParams();
67
- if (appId) params.append("appId", appId);
68
- params.append("limit", limit.toString());
69
-
70
- const res = await fetch(`${apiUrl}/users/me/history?${params}`, {
71
- headers: getHeaders(true),
72
- });
73
- return res.json();
74
- },
75
-
76
- // ===== CHANNELS =====
77
-
78
- /**
79
- * Add a notification channel for current user
80
- */
81
- async addChannel(channelType: string, channelIdentifier: string, metadata?: Record<string, any>) {
82
- const res = await fetch(`${apiUrl}/users/me/channels`, {
83
- method: "POST",
84
- headers: getHeaders(true),
85
- body: JSON.stringify({
86
- channelType,
87
- channelIdentifier,
88
- enabled: true,
89
- metadata,
90
- }),
91
- });
92
- return res.json();
93
- },
94
-
95
- /**
96
- * Connect email for current user
97
- */
98
- async connectEmail(email: string) {
99
- return this.addChannel("email", email);
100
- },
101
-
102
- /**
103
- * Update a notification channel
104
- */
105
- async updateChannel(
106
- channelId: string,
107
- updates: { enabled?: boolean; channelIdentifier?: string; metadata?: Record<string, any> },
108
- ) {
109
- const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
110
- method: "PUT",
111
- headers: getHeaders(true),
112
- body: JSON.stringify(updates),
113
- });
114
- return res.json();
115
- },
116
-
117
- /**
118
- * Delete a notification channel
119
- */
120
- async deleteChannel(channelId: string) {
121
- const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
122
- method: "DELETE",
123
- headers: getHeaders(true),
124
- });
125
- return res.json();
126
- },
127
-
128
- // ===== TELEGRAM =====
129
-
130
- /**
131
- * Get Telegram deep link for current user
132
- */
133
- async getTelegramLink(): Promise<TelegramLinkResponse> {
134
- const res = await fetch(`${apiUrl}/telegram/request-link`, {
135
- method: "POST",
136
- headers: getHeaders(true),
137
- });
138
- return res.json();
139
- },
140
-
141
- /**
142
- * Check current user's Telegram connection status
143
- */
144
- async checkTelegramStatus(): Promise<TelegramStatusResponse> {
145
- const res = await fetch(`${apiUrl}/telegram/status/me`, {
146
- headers: getHeaders(true),
147
- });
148
- return res.json();
149
- },
150
-
151
- // ===== APP PREFERENCES =====
152
-
153
- /**
154
- * Save notification preferences for an app
155
- */
156
- async savePreferences(appId: string, settings: NotificationPreferences) {
157
- const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
158
- method: "POST",
159
- headers: getHeaders(true),
160
- body: JSON.stringify({ ...settings, enabled: true }),
161
- });
162
- return res.json();
163
- },
164
-
165
- /**
166
- * Get notification settings for an app
167
- */
168
- async getAppSettings(appId: string) {
169
- const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
170
- headers: getHeaders(true),
171
- });
172
- return res.json();
173
- },
174
-
175
- // ===== IN-APP NOTIFICATIONS =====
176
-
177
- /**
178
- * Get current user's in-app notifications
179
- */
180
- async getInAppNotifications() {
181
- const res = await fetch(`${apiUrl}/users/me/notifications`, {
182
- headers: getHeaders(true),
183
- });
184
- return res.json();
185
- },
186
-
187
- /**
188
- * Mark a notification as read
189
- */
190
- async markNotificationAsRead(notificationId: string) {
191
- const res = await fetch(`${apiUrl}/users/me/notifications/${notificationId}/read`, {
192
- method: "PUT",
193
- headers: getHeaders(true),
194
- });
195
- return res.json();
196
- },
197
-
198
- // ===== SENDING NOTIFICATIONS =====
199
-
200
- /**
201
- * Send a notification (requires auth)
202
- */
203
- async sendNotification(data: SendNotificationRequest) {
204
- const res = await fetch(`${apiUrl}/send`, {
205
- method: "POST",
206
- headers: getHeaders(true),
207
- body: JSON.stringify(data),
208
- });
209
- return res.json();
210
- },
211
- };
@@ -1 +0,0 @@
1
- export * from "./api";
@@ -1,57 +0,0 @@
1
- export type ChannelType = "email" | "telegram" | "discord" | "sms" | "whatsapp" | "in_app";
2
-
3
- export interface NotificationChannel {
4
- id: number;
5
- channel_type: ChannelType;
6
- enabled: number;
7
- channel_identifier: string;
8
- }
9
-
10
- export interface UserData {
11
- user: {
12
- id: number;
13
- user_id: string;
14
- };
15
- channels: NotificationChannel[];
16
- appSettings: Array<{
17
- app_id: string;
18
- notification_type: string;
19
- enabled: number;
20
- channels: string;
21
- }>;
22
- }
23
-
24
- export interface NotificationHistory {
25
- id: string;
26
- app_id: string;
27
- notification_type: string;
28
- title: string;
29
- message: string;
30
- created_at: string;
31
- read: boolean;
32
- }
33
-
34
- export interface TelegramLinkResponse {
35
- deepLink: string;
36
- verificationCode: string;
37
- botUsername: string;
38
- }
39
-
40
- export interface TelegramStatusResponse {
41
- connected: boolean;
42
- chatId?: string;
43
- }
44
-
45
- export interface NotificationPreferences {
46
- notificationType: string;
47
- channels: string[];
48
- }
49
-
50
- export interface SendNotificationRequest {
51
- userId: string;
52
- appId: string;
53
- notificationType: string;
54
- message: string;
55
- title?: string;
56
- data?: Record<string, any>;
57
- }
@@ -1,13 +0,0 @@
1
- import Cookies from "js-cookie";
2
-
3
- const B3_AUTH_COOKIE_NAME = "b3-auth";
4
-
5
- /**
6
- * Get the authentication token from the B3 auth cookie
7
- * This token is managed by the B3 Global Account authentication system
8
- *
9
- * @returns The JWT token string or null if not found
10
- */
11
- export function getAuthToken(): string | null {
12
- return Cookies.get(B3_AUTH_COOKIE_NAME) || null;
13
- }