managarten/services/mana-analytics/src/config.ts
Till JS dbe24acfc4 feat(feedback,credits): community-credit grants — +5 submit / +500 ship / +25 reaction-match
Phase 3.A des feedback-rewards-and-identity-Plans. Direkter Reziprozitäts-
Loop: User kriegt sofort etwas zurück fürs Mitwirken, Originalwunsch-
Eulen werden beim Ship belohnt, Reagierer kriegen einen Anteil.

mana-credits:
- Neuer Endpoint POST /api/v1/internal/credits/grant + grantCredits()
  Service-Methode mit Idempotency via metadata.referenceId.
- transaction_type-Enum erweitert um 'grant' (eigener Typ statt
  Mismatch mit 'refund').
- Migration 0001_grant_transaction_type.sql + partial-Index auf
  metadata->>'referenceId' für O(log n) Idempotency-Lookup.

mana-analytics:
- FeedbackService stempelt sofort +5 Credits beim createFeedback (top-
  level only, Replies bekommen nichts), wenn Mindest-20-Zeichen erfüllt
  und Rate-Limit (10/User/24h via feedback_grant_log) nicht überschritten.
- adminUpdate triggert beim FRISCHEN Übergang nach 'completed':
  +500 Credits an Original-Wisher + +25 an alle, die mit 👍 oder 🚀
  reagiert haben. Doppel-Pay strukturell unmöglich via referenceId
  (`<id>_shipped`, `<id>_reaction_<userId>`).
- Founder-Whitelist via FEEDBACK_FOUNDER_USER_IDS env (verhindert
  Self-Reward).
- Drop voteCount-Spalte (durch reactions/score seit 0002 ersetzt).
- Migration 0003_grant_log_drop_vote_count.sql idempotent, lokal +
  prod eingespielt.

Plan: docs/plans/feedback-rewards-and-identity.md (Phase 3.A-3.F).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:13:46 +02:00

41 lines
1.4 KiB
TypeScript

export interface Config {
port: number;
databaseUrl: string;
manaAuthUrl: string;
manaLlmUrl: string;
manaCreditsUrl: string;
serviceKey: string;
/**
* Secret seeded into the per-user display-hash for the public-community
* pseudonym ("Wachsame Eule #4528"). Rotating this re-keys all future
* pseudonyms — existing rows keep the old hash/name.
*/
pseudonymSecret: string;
/**
* UserIds that bypass the +5 / +500 community credit grants — they would
* otherwise self-reward when posting/shipping their own wishes. Comma-
* separated env, empty in dev.
*/
founderUserIds: Set<string>;
cors: { origins: string[] };
}
export function loadConfig(): Config {
const env = (key: string, fallback?: string) => process.env[key] || fallback || '';
return {
port: parseInt(env('PORT', '3064'), 10),
databaseUrl: env('DATABASE_URL', 'postgresql://mana:devpassword@localhost:5432/mana_platform'),
manaAuthUrl: env('MANA_AUTH_URL', 'http://localhost:3001'),
manaLlmUrl: env('MANA_LLM_URL', 'http://localhost:3025'),
manaCreditsUrl: env('MANA_CREDITS_URL', 'http://localhost:3061'),
serviceKey: env('MANA_SERVICE_KEY', 'dev-service-key'),
pseudonymSecret: env('FEEDBACK_PSEUDONYM_SECRET', 'dev-pseudonym-secret'),
founderUserIds: new Set(
env('FEEDBACK_FOUNDER_USER_IDS', '')
.split(',')
.map((s) => s.trim())
.filter(Boolean)
),
cors: { origins: env('CORS_ORIGINS', 'http://localhost:5173').split(',') },
};
}