Add Nexus API integration for authentication and service calls
Introduces a NexusClient utility class to handle authentication (token, refresh) and service calls (scrub, IP check, activity log) to the configured NEXUS_AUTH_URL and NEXUS_SERVICE_URL environment variables. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 2b12c51b-1a80-4d39-bc90-8ff1008f2ba5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/5VMaR1q Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
09c7d84e58
commit
aa07eaa183
2 changed files with 144 additions and 0 deletions
2
.replit
2
.replit
|
|
@ -66,5 +66,7 @@ FOUNDATION_GUILD_ID = "1338564560277344287"
|
|||
WHITELISTED_USERS = "113472107526033408"
|
||||
ALERT_CHANNEL_ID = "1435905356932055233"
|
||||
BASE_URL = "https://bot.aethex.dev"
|
||||
NEXUS_AUTH_URL = "https://aethex.tech"
|
||||
NEXUS_SERVICE_URL = "https://aethex.cloud"
|
||||
|
||||
[userenv.production]
|
||||
|
|
|
|||
142
aethex-bot/utils/nexusClient.js
Normal file
142
aethex-bot/utils/nexusClient.js
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
const NEXUS_AUTH_URL = process.env.NEXUS_AUTH_URL || 'https://aethex.tech';
|
||||
const NEXUS_SERVICE_URL = process.env.NEXUS_SERVICE_URL || 'https://aethex.cloud';
|
||||
|
||||
class NexusClient {
|
||||
constructor() {
|
||||
this.authUrl = NEXUS_AUTH_URL;
|
||||
this.serviceUrl = NEXUS_SERVICE_URL;
|
||||
}
|
||||
|
||||
async getToken(credentials) {
|
||||
const response = await fetch(`${this.authUrl}/api/passport/token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(credentials)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Token request failed' }));
|
||||
throw new Error(error.error || 'Failed to get token');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async refreshToken(refreshToken) {
|
||||
const response = await fetch(`${this.authUrl}/api/passport/refresh`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ refresh_token: refreshToken })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Refresh failed' }));
|
||||
throw new Error(error.error || 'Failed to refresh token');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async scrubText(text, accessToken) {
|
||||
const response = await fetch(`${this.serviceUrl}/api/sentinel/scrub`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
},
|
||||
body: JSON.stringify({ text })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Scrub failed' }));
|
||||
throw new Error(error.error || 'Failed to scrub text');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async checkSelfIP(accessToken) {
|
||||
const response = await fetch(`${this.serviceUrl}/api/sentinel/check-self`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'IP check failed' }));
|
||||
throw new Error(error.error || 'Failed to check IP');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async logActivity(activityData, accessToken) {
|
||||
const response = await fetch(`${this.serviceUrl}/api/sentinel/activity/log`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
},
|
||||
body: JSON.stringify(activityData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Activity log failed' }));
|
||||
throw new Error(error.error || 'Failed to log activity');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async checkIP(ip, accessToken) {
|
||||
const response = await fetch(`${this.serviceUrl}/api/blacklist/check/${encodeURIComponent(ip)}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Blacklist check failed' }));
|
||||
throw new Error(error.error || 'Failed to check IP blacklist');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async getUserSnapshot(userId, accessToken) {
|
||||
const response = await fetch(`${this.serviceUrl}/api/activity/user-snapshot/${encodeURIComponent(userId)}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Snapshot fetch failed' }));
|
||||
throw new Error(error.error || 'Failed to get user snapshot');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async getPublicStats() {
|
||||
const response = await fetch(`${this.serviceUrl}/api/overview/public-stats`, {
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Stats fetch failed' }));
|
||||
throw new Error(error.error || 'Failed to get public stats');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { NexusClient };
|
||||
Loading…
Reference in a new issue