Guardian-Agent / artifacts /api-server /src /lib /trust-rating.ts
Prince9868's picture
Hackathon submission: Guardian OpenEnv
5743bc2
Raw
History Blame Contribute Delete
1.56 kB
export type TrustTier = "gold" | "clean" | "neutral" | "suspicious" | "high_manipulation";
type ExistingTrustRating = {
score: number;
totalScans: number;
patternsDetectedCount: number;
hiddenFeesCount: number;
};
export function computeTrustTier(score: number): TrustTier {
if (score >= 85) return "gold";
if (score >= 65) return "clean";
if (score >= 45) return "neutral";
if (score >= 25) return "suspicious";
return "high_manipulation";
}
export function computeTrustScoreDelta(patternsFound: number): number {
return patternsFound === 0 ? 5 : -(patternsFound * 8);
}
export function buildTrustRatingMutation(input: {
domain: string;
scoreDelta: number;
patternsFound: number;
hiddenFeesFound: number;
existing?: ExistingTrustRating | null;
now?: Date;
}) {
const now = input.now ?? new Date();
if (input.existing) {
const score = Math.max(0, Math.min(100, input.existing.score + input.scoreDelta));
return {
score,
tier: computeTrustTier(score),
totalScans: input.existing.totalScans + 1,
patternsDetectedCount: input.existing.patternsDetectedCount + input.patternsFound,
hiddenFeesCount: input.existing.hiddenFeesCount + input.hiddenFeesFound,
lastScannedAt: now,
};
}
const score = Math.max(0, Math.min(100, 70 + input.scoreDelta));
return {
domain: input.domain,
score,
tier: computeTrustTier(score),
totalScans: 1,
patternsDetectedCount: input.patternsFound,
hiddenFeesCount: input.hiddenFeesFound,
lastScannedAt: now,
};
}