@b3dotfun/sdk 0.0.46 → 0.0.47-alpha.1

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