From aa07eaa183ca8d853f371614844d5337d65b0353 Mon Sep 17 00:00:00 2001 From: sirpiglr <49359077-sirpiglr@users.noreply.replit.com> Date: Sun, 14 Dec 2025 03:56:59 +0000 Subject: [PATCH] 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 --- .replit | 2 + aethex-bot/utils/nexusClient.js | 142 ++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 aethex-bot/utils/nexusClient.js diff --git a/.replit b/.replit index 5fefc2d..4b02687 100644 --- a/.replit +++ b/.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] diff --git a/aethex-bot/utils/nexusClient.js b/aethex-bot/utils/nexusClient.js new file mode 100644 index 0000000..ea51a95 --- /dev/null +++ b/aethex-bot/utils/nexusClient.js @@ -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 };