@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.
- package/README.md +3 -215
- package/dist/cjs/anyspend/react/components/AnySpend.js +13 -14
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -15
- package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +6 -3
- package/dist/cjs/anyspend/types/api.d.ts +176 -0
- package/dist/cjs/anyspend/utils/chain.js +1 -1
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
- package/dist/cjs/shared/utils/index.d.ts +0 -1
- package/dist/cjs/shared/utils/index.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +14 -15
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -16
- package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +8 -5
- package/dist/esm/anyspend/types/api.d.ts +176 -0
- package/dist/esm/anyspend/utils/chain.js +1 -1
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
- package/dist/esm/shared/utils/index.d.ts +0 -1
- package/dist/esm/shared/utils/index.js +0 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/types/api.d.ts +176 -0
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/types/shared/utils/index.d.ts +0 -1
- package/package.json +2 -21
- package/src/anyspend/react/components/AnySpend.tsx +21 -19
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +21 -21
- package/src/anyspend/react/components/common/OrderHistory.tsx +11 -11
- package/src/anyspend/react/components/common/OrderHistoryItem.tsx +124 -129
- package/src/anyspend/types/api.ts +176 -0
- package/src/anyspend/utils/chain.ts +1 -4
- package/src/shared/utils/index.ts +0 -1
- package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +0 -6
- package/dist/cjs/anyspend/react/components/common/ErrorSection.js +0 -12
- package/dist/cjs/notifications/index.d.ts +0 -4
- package/dist/cjs/notifications/index.js +0 -26
- package/dist/cjs/notifications/react/hooks/index.d.ts +0 -1
- package/dist/cjs/notifications/react/hooks/index.js +0 -17
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/cjs/notifications/react/hooks/useNotifications.js +0 -148
- package/dist/cjs/notifications/react/index.d.ts +0 -1
- package/dist/cjs/notifications/react/index.js +0 -17
- package/dist/cjs/notifications/services/api.d.ts +0 -65
- package/dist/cjs/notifications/services/api.js +0 -178
- package/dist/cjs/notifications/services/index.d.ts +0 -1
- package/dist/cjs/notifications/services/index.js +0 -17
- package/dist/cjs/notifications/types/index.d.ts +0 -50
- package/dist/cjs/notifications/types/index.js +0 -2
- package/dist/cjs/shared/utils/auth-token.d.ts +0 -7
- package/dist/cjs/shared/utils/auth-token.js +0 -17
- package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +0 -6
- package/dist/esm/anyspend/react/components/common/ErrorSection.js +0 -9
- package/dist/esm/notifications/index.d.ts +0 -4
- package/dist/esm/notifications/index.js +0 -8
- package/dist/esm/notifications/react/hooks/index.d.ts +0 -1
- package/dist/esm/notifications/react/hooks/index.js +0 -1
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/esm/notifications/react/hooks/useNotifications.js +0 -145
- package/dist/esm/notifications/react/index.d.ts +0 -1
- package/dist/esm/notifications/react/index.js +0 -1
- package/dist/esm/notifications/services/api.d.ts +0 -65
- package/dist/esm/notifications/services/api.js +0 -173
- package/dist/esm/notifications/services/index.d.ts +0 -1
- package/dist/esm/notifications/services/index.js +0 -1
- package/dist/esm/notifications/types/index.d.ts +0 -50
- package/dist/esm/shared/utils/auth-token.d.ts +0 -7
- package/dist/esm/shared/utils/auth-token.js +0 -11
- package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +0 -6
- package/dist/types/notifications/index.d.ts +0 -4
- package/dist/types/notifications/react/hooks/index.d.ts +0 -1
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/types/notifications/react/index.d.ts +0 -1
- package/dist/types/notifications/services/api.d.ts +0 -65
- package/dist/types/notifications/services/index.d.ts +0 -1
- package/dist/types/notifications/types/index.d.ts +0 -50
- package/dist/types/shared/utils/auth-token.d.ts +0 -7
- package/src/anyspend/react/components/common/ErrorSection.tsx +0 -21
- package/src/notifications/index.ts +0 -11
- package/src/notifications/react/hooks/index.ts +0 -1
- package/src/notifications/react/hooks/useNotifications.ts +0 -153
- package/src/notifications/react/index.ts +0 -1
- package/src/notifications/services/api.ts +0 -211
- package/src/notifications/services/index.ts +0 -1
- package/src/notifications/types/index.ts +0 -57
- package/src/shared/utils/auth-token.ts +0 -13
- /package/dist/{esm/notifications/types/index.js → cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts} +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
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);
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
*/
|
|
48
|
-
savePreferences(appId: string, settings: NotificationPreferences): Promise<any>;
|
|
49
|
-
/**
|
|
50
|
-
* Get notification settings for an app
|
|
51
|
-
*/
|
|
52
|
-
getAppSettings(appId: string): Promise<any>;
|
|
53
|
-
/**
|
|
54
|
-
* Get current user's in-app notifications
|
|
55
|
-
*/
|
|
56
|
-
getInAppNotifications(): Promise<any>;
|
|
57
|
-
/**
|
|
58
|
-
* Mark a notification as read
|
|
59
|
-
*/
|
|
60
|
-
markNotificationAsRead(notificationId: string): Promise<any>;
|
|
61
|
-
/**
|
|
62
|
-
* Send a notification (requires auth)
|
|
63
|
-
*/
|
|
64
|
-
sendNotification(data: SendNotificationRequest): Promise<any>;
|
|
65
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.notificationsAPI = void 0;
|
|
4
|
-
exports.setApiUrl = setApiUrl;
|
|
5
|
-
exports.getApiUrl = getApiUrl;
|
|
6
|
-
const auth_token_1 = require("../../shared/utils/auth-token");
|
|
7
|
-
const DEFAULT_API_URL = "https://notifications.b3.fun";
|
|
8
|
-
let apiUrl = DEFAULT_API_URL;
|
|
9
|
-
function setApiUrl(url) {
|
|
10
|
-
apiUrl = url;
|
|
11
|
-
}
|
|
12
|
-
function getApiUrl() {
|
|
13
|
-
return apiUrl;
|
|
14
|
-
}
|
|
15
|
-
function getHeaders(includeAuth = false) {
|
|
16
|
-
const headers = {
|
|
17
|
-
"Content-Type": "application/json",
|
|
18
|
-
};
|
|
19
|
-
if (includeAuth) {
|
|
20
|
-
const token = (0, auth_token_1.getAuthToken)();
|
|
21
|
-
if (token) {
|
|
22
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return headers;
|
|
26
|
-
}
|
|
27
|
-
exports.notificationsAPI = {
|
|
28
|
-
// ===== USER MANAGEMENT =====
|
|
29
|
-
/**
|
|
30
|
-
* Register the current user (userId extracted from JWT)
|
|
31
|
-
*/
|
|
32
|
-
async registerUser() {
|
|
33
|
-
const res = await fetch(`${apiUrl}/users`, {
|
|
34
|
-
method: "POST",
|
|
35
|
-
headers: getHeaders(true),
|
|
36
|
-
});
|
|
37
|
-
return res.json();
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
* Get current user's profile and preferences
|
|
41
|
-
*/
|
|
42
|
-
async getUser() {
|
|
43
|
-
const res = await fetch(`${apiUrl}/users/me`, {
|
|
44
|
-
headers: getHeaders(true),
|
|
45
|
-
});
|
|
46
|
-
return res.json();
|
|
47
|
-
},
|
|
48
|
-
/**
|
|
49
|
-
* Get current user's notification history
|
|
50
|
-
*/
|
|
51
|
-
async getHistory(appId, limit = 100) {
|
|
52
|
-
const params = new URLSearchParams();
|
|
53
|
-
if (appId)
|
|
54
|
-
params.append("appId", appId);
|
|
55
|
-
params.append("limit", limit.toString());
|
|
56
|
-
const res = await fetch(`${apiUrl}/users/me/history?${params}`, {
|
|
57
|
-
headers: getHeaders(true),
|
|
58
|
-
});
|
|
59
|
-
return res.json();
|
|
60
|
-
},
|
|
61
|
-
// ===== CHANNELS =====
|
|
62
|
-
/**
|
|
63
|
-
* Add a notification channel for current user
|
|
64
|
-
*/
|
|
65
|
-
async addChannel(channelType, channelIdentifier, metadata) {
|
|
66
|
-
const res = await fetch(`${apiUrl}/users/me/channels`, {
|
|
67
|
-
method: "POST",
|
|
68
|
-
headers: getHeaders(true),
|
|
69
|
-
body: JSON.stringify({
|
|
70
|
-
channelType,
|
|
71
|
-
channelIdentifier,
|
|
72
|
-
enabled: true,
|
|
73
|
-
metadata,
|
|
74
|
-
}),
|
|
75
|
-
});
|
|
76
|
-
return res.json();
|
|
77
|
-
},
|
|
78
|
-
/**
|
|
79
|
-
* Connect email for current user
|
|
80
|
-
*/
|
|
81
|
-
async connectEmail(email) {
|
|
82
|
-
return this.addChannel("email", email);
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* Update a notification channel
|
|
86
|
-
*/
|
|
87
|
-
async updateChannel(channelId, updates) {
|
|
88
|
-
const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
|
|
89
|
-
method: "PUT",
|
|
90
|
-
headers: getHeaders(true),
|
|
91
|
-
body: JSON.stringify(updates),
|
|
92
|
-
});
|
|
93
|
-
return res.json();
|
|
94
|
-
},
|
|
95
|
-
/**
|
|
96
|
-
* Delete a notification channel
|
|
97
|
-
*/
|
|
98
|
-
async deleteChannel(channelId) {
|
|
99
|
-
const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
|
|
100
|
-
method: "DELETE",
|
|
101
|
-
headers: getHeaders(true),
|
|
102
|
-
});
|
|
103
|
-
return res.json();
|
|
104
|
-
},
|
|
105
|
-
// ===== TELEGRAM =====
|
|
106
|
-
/**
|
|
107
|
-
* Get Telegram deep link for current user
|
|
108
|
-
*/
|
|
109
|
-
async getTelegramLink() {
|
|
110
|
-
const res = await fetch(`${apiUrl}/telegram/request-link`, {
|
|
111
|
-
method: "POST",
|
|
112
|
-
headers: getHeaders(true),
|
|
113
|
-
});
|
|
114
|
-
return res.json();
|
|
115
|
-
},
|
|
116
|
-
/**
|
|
117
|
-
* Check current user's Telegram connection status
|
|
118
|
-
*/
|
|
119
|
-
async checkTelegramStatus() {
|
|
120
|
-
const res = await fetch(`${apiUrl}/telegram/status/me`, {
|
|
121
|
-
headers: getHeaders(true),
|
|
122
|
-
});
|
|
123
|
-
return res.json();
|
|
124
|
-
},
|
|
125
|
-
// ===== APP PREFERENCES =====
|
|
126
|
-
/**
|
|
127
|
-
* Save notification preferences for an app
|
|
128
|
-
*/
|
|
129
|
-
async savePreferences(appId, settings) {
|
|
130
|
-
const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
|
|
131
|
-
method: "POST",
|
|
132
|
-
headers: getHeaders(true),
|
|
133
|
-
body: JSON.stringify({ ...settings, enabled: true }),
|
|
134
|
-
});
|
|
135
|
-
return res.json();
|
|
136
|
-
},
|
|
137
|
-
/**
|
|
138
|
-
* Get notification settings for an app
|
|
139
|
-
*/
|
|
140
|
-
async getAppSettings(appId) {
|
|
141
|
-
const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
|
|
142
|
-
headers: getHeaders(true),
|
|
143
|
-
});
|
|
144
|
-
return res.json();
|
|
145
|
-
},
|
|
146
|
-
// ===== IN-APP NOTIFICATIONS =====
|
|
147
|
-
/**
|
|
148
|
-
* Get current user's in-app notifications
|
|
149
|
-
*/
|
|
150
|
-
async getInAppNotifications() {
|
|
151
|
-
const res = await fetch(`${apiUrl}/users/me/notifications`, {
|
|
152
|
-
headers: getHeaders(true),
|
|
153
|
-
});
|
|
154
|
-
return res.json();
|
|
155
|
-
},
|
|
156
|
-
/**
|
|
157
|
-
* Mark a notification as read
|
|
158
|
-
*/
|
|
159
|
-
async markNotificationAsRead(notificationId) {
|
|
160
|
-
const res = await fetch(`${apiUrl}/users/me/notifications/${notificationId}/read`, {
|
|
161
|
-
method: "PUT",
|
|
162
|
-
headers: getHeaders(true),
|
|
163
|
-
});
|
|
164
|
-
return res.json();
|
|
165
|
-
},
|
|
166
|
-
// ===== SENDING NOTIFICATIONS =====
|
|
167
|
-
/**
|
|
168
|
-
* Send a notification (requires auth)
|
|
169
|
-
*/
|
|
170
|
-
async sendNotification(data) {
|
|
171
|
-
const res = await fetch(`${apiUrl}/send`, {
|
|
172
|
-
method: "POST",
|
|
173
|
-
headers: getHeaders(true),
|
|
174
|
-
body: JSON.stringify(data),
|
|
175
|
-
});
|
|
176
|
-
return res.json();
|
|
177
|
-
},
|
|
178
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./api";
|
|
@@ -1,17 +0,0 @@
|
|
|
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("./api"), exports);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export type ChannelType = "email" | "telegram" | "discord" | "sms" | "whatsapp" | "in_app";
|
|
2
|
-
export interface NotificationChannel {
|
|
3
|
-
id: number;
|
|
4
|
-
channel_type: ChannelType;
|
|
5
|
-
enabled: number;
|
|
6
|
-
channel_identifier: string;
|
|
7
|
-
}
|
|
8
|
-
export interface UserData {
|
|
9
|
-
user: {
|
|
10
|
-
id: number;
|
|
11
|
-
user_id: string;
|
|
12
|
-
};
|
|
13
|
-
channels: NotificationChannel[];
|
|
14
|
-
appSettings: Array<{
|
|
15
|
-
app_id: string;
|
|
16
|
-
notification_type: string;
|
|
17
|
-
enabled: number;
|
|
18
|
-
channels: string;
|
|
19
|
-
}>;
|
|
20
|
-
}
|
|
21
|
-
export interface NotificationHistory {
|
|
22
|
-
id: string;
|
|
23
|
-
app_id: string;
|
|
24
|
-
notification_type: string;
|
|
25
|
-
title: string;
|
|
26
|
-
message: string;
|
|
27
|
-
created_at: string;
|
|
28
|
-
read: boolean;
|
|
29
|
-
}
|
|
30
|
-
export interface TelegramLinkResponse {
|
|
31
|
-
deepLink: string;
|
|
32
|
-
verificationCode: string;
|
|
33
|
-
botUsername: string;
|
|
34
|
-
}
|
|
35
|
-
export interface TelegramStatusResponse {
|
|
36
|
-
connected: boolean;
|
|
37
|
-
chatId?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface NotificationPreferences {
|
|
40
|
-
notificationType: string;
|
|
41
|
-
channels: string[];
|
|
42
|
-
}
|
|
43
|
-
export interface SendNotificationRequest {
|
|
44
|
-
userId: string;
|
|
45
|
-
appId: string;
|
|
46
|
-
notificationType: string;
|
|
47
|
-
message: string;
|
|
48
|
-
title?: string;
|
|
49
|
-
data?: Record<string, any>;
|
|
50
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAuthToken = getAuthToken;
|
|
7
|
-
const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
8
|
-
const B3_AUTH_COOKIE_NAME = "b3-auth";
|
|
9
|
-
/**
|
|
10
|
-
* Get the authentication token from the B3 auth cookie
|
|
11
|
-
* This token is managed by the B3 Global Account authentication system
|
|
12
|
-
*
|
|
13
|
-
* @returns The JWT token string or null if not found
|
|
14
|
-
*/
|
|
15
|
-
function getAuthToken() {
|
|
16
|
-
return js_cookie_1.default.get(B3_AUTH_COOKIE_NAME) || null;
|
|
17
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CircleAlert } from "lucide-react";
|
|
3
|
-
export function ErrorSection({ error, message }) {
|
|
4
|
-
if (!error && !message) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const errorMessage = message || error?.message || "An error occurred";
|
|
8
|
-
return (_jsxs("div", { className: "error-section bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2", children: [_jsx(CircleAlert, { className: "bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" }), _jsx("div", { className: "text-as-red text-sm", children: errorMessage })] }));
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const VERSION = "1.0.0";
|
|
2
|
-
// Export types
|
|
3
|
-
export * from "./types/index.js";
|
|
4
|
-
// Export services
|
|
5
|
-
export * from "./services/index.js";
|
|
6
|
-
// Re-export auth token getter from shared for convenience
|
|
7
|
-
// Note: Auth token is managed by B3 Global Account authentication
|
|
8
|
-
export { getAuthToken } from "../shared/utils/auth-token.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./useNotifications";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./useNotifications.js";
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,145 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./hooks";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./hooks/index.js";
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
*/
|
|
48
|
-
savePreferences(appId: string, settings: NotificationPreferences): Promise<any>;
|
|
49
|
-
/**
|
|
50
|
-
* Get notification settings for an app
|
|
51
|
-
*/
|
|
52
|
-
getAppSettings(appId: string): Promise<any>;
|
|
53
|
-
/**
|
|
54
|
-
* Get current user's in-app notifications
|
|
55
|
-
*/
|
|
56
|
-
getInAppNotifications(): Promise<any>;
|
|
57
|
-
/**
|
|
58
|
-
* Mark a notification as read
|
|
59
|
-
*/
|
|
60
|
-
markNotificationAsRead(notificationId: string): Promise<any>;
|
|
61
|
-
/**
|
|
62
|
-
* Send a notification (requires auth)
|
|
63
|
-
*/
|
|
64
|
-
sendNotification(data: SendNotificationRequest): Promise<any>;
|
|
65
|
-
};
|