mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-20 07:03:36 +02:00
refactor(credits): route credit calls to mana-credits service
Update consumers to call the new standalone mana-credits service instead of the credit endpoints embedded in mana-core-auth. Changes: - CreditClientService: Add getCreditsUrl() reading MANA_CREDITS_URL (falls back to MANA_CORE_AUTH_URL for backward compatibility). All credit calls now use /api/v1/internal/* endpoints. - BetterAuthService: Replace direct DB inserts for credit balance and guild pool init with HTTP calls to mana-credits internal API. Replace local gift redemption with HTTP call. - .env.development: Add MANA_CREDITS_URL=http://localhost:3060 - CLAUDE.md: Add mana-credits to services list Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
64f7f768eb
commit
b0009c200b
4 changed files with 59 additions and 33 deletions
|
|
@ -35,6 +35,18 @@ export class CreditClientService {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credits service URL. Uses MANA_CREDITS_URL if available,
|
||||
* falls back to MANA_CORE_AUTH_URL for backward compatibility.
|
||||
*/
|
||||
private getCreditsUrl(): string {
|
||||
return (
|
||||
this.configService?.get<string>('MANA_CREDITS_URL') ||
|
||||
process.env.MANA_CREDITS_URL ||
|
||||
this.getAuthUrl()
|
||||
);
|
||||
}
|
||||
|
||||
private getServiceKey(): string {
|
||||
return (
|
||||
this.options?.serviceKey ||
|
||||
|
|
@ -76,7 +88,7 @@ export class CreditClientService {
|
|||
}
|
||||
|
||||
async getBalance(userId: string): Promise<CreditBalance> {
|
||||
const authUrl = this.getAuthUrl();
|
||||
const creditsUrl = this.getCreditsUrl();
|
||||
const serviceKey = this.getServiceKey();
|
||||
|
||||
if (!serviceKey) {
|
||||
|
|
@ -89,7 +101,7 @@ export class CreditClientService {
|
|||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${authUrl}/api/v1/credits/balance/${userId}`, {
|
||||
const response = await fetch(`${creditsUrl}/api/v1/internal/credits/balance/${userId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -127,7 +139,7 @@ export class CreditClientService {
|
|||
metadata?: Record<string, any>,
|
||||
creditSource?: { type: 'personal' } | { type: 'guild'; guildId: string }
|
||||
): Promise<boolean> {
|
||||
const authUrl = this.getAuthUrl();
|
||||
const creditsUrl = this.getCreditsUrl();
|
||||
const serviceKey = this.getServiceKey();
|
||||
|
||||
if (!serviceKey) {
|
||||
|
|
@ -136,7 +148,7 @@ export class CreditClientService {
|
|||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${authUrl}/api/v1/credits/use`, {
|
||||
const response = await fetch(`${creditsUrl}/api/v1/internal/credits/use`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -179,7 +191,7 @@ export class CreditClientService {
|
|||
description: string,
|
||||
metadata?: Record<string, any>
|
||||
): Promise<boolean> {
|
||||
const authUrl = this.getAuthUrl();
|
||||
const creditsUrl = this.getCreditsUrl();
|
||||
const serviceKey = this.getServiceKey();
|
||||
|
||||
if (!serviceKey) {
|
||||
|
|
@ -188,7 +200,7 @@ export class CreditClientService {
|
|||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${authUrl}/api/v1/credits/refund`, {
|
||||
const response = await fetch(`${creditsUrl}/api/v1/internal/credits/refund`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue