Spaces:
Sleeping
Sleeping
File size: 1,559 Bytes
5743bc2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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,
};
}
|