|
| 1 | +/** |
| 2 | + * Freebuff account standing ("Access Level") — the PRESENTATIONAL half. |
| 3 | + * |
| 4 | + * This file carries everything a client may see: the level names, their |
| 5 | + * user-facing labels and blurbs, and the wire shapes for standing info. The |
| 6 | + * actual limit matrix, thresholds and scorer live in |
| 7 | + * `./freebuff-trust.ts`, which is deliberately EXCLUDED from the public-repo |
| 8 | + * export (see scripts/public-export-manifest.txt) — a published limit is a |
| 9 | + * published target, so the numbers must never ship in a public file. Keep |
| 10 | + * that split when adding here: names, labels and shapes only, never numbers. |
| 11 | + */ |
| 12 | + |
| 13 | +import type { FreebuffAccessTier } from './freebuff-models' |
| 14 | + |
| 15 | +/** |
| 16 | + * Ordered least- to most-established. The order is load-bearing: |
| 17 | + * `FREEBUFF_TRUST_LEVELS.indexOf` is how "at least X" comparisons are done, so |
| 18 | + * inserting a level in the middle re-ranks every comparison in one edit rather |
| 19 | + * than requiring each call site to be found. |
| 20 | + */ |
| 21 | +export const FREEBUFF_TRUST_LEVELS = [ |
| 22 | + 'new', |
| 23 | + 'verified', |
| 24 | + 'established', |
| 25 | + 'core', |
| 26 | +] as const |
| 27 | + |
| 28 | +export type FreebuffTrustLevel = (typeof FREEBUFF_TRUST_LEVELS)[number] |
| 29 | + |
| 30 | +/** The level an account holds before anything is known about it. Every failure |
| 31 | + * path in the resolver must land somewhere DEFINITE, and this is not it — see |
| 32 | + * `FREEBUFF_TRUST_FALLBACK_LEVEL`. */ |
| 33 | +export const FREEBUFF_TRUST_MIN_LEVEL: FreebuffTrustLevel = 'new' |
| 34 | + |
| 35 | +/** |
| 36 | + * The level used when signals cannot be loaded (database error, timeout). |
| 37 | + * |
| 38 | + * `established` and NOT `new`, and this is the single most consequential |
| 39 | + * constant in the file. This resolver runs on the free-mode hot path; if a |
| 40 | + * Postgres hiccup dropped every caller to `new`, one degraded dependency would |
| 41 | + * throttle the entire product to a fifth of its capacity, and it would look |
| 42 | + * exactly like an outage nobody could attribute. Failing to the level that |
| 43 | + * reproduces roughly today's flat limits means a broken resolver costs us the |
| 44 | + * enforcement, never the users. Same reasoning as the signup gate's fail-open. |
| 45 | + */ |
| 46 | +export const FREEBUFF_TRUST_FALLBACK_LEVEL: FreebuffTrustLevel = 'established' |
| 47 | + |
| 48 | +export function isAtLeastTrustLevel( |
| 49 | + level: FreebuffTrustLevel, |
| 50 | + minimum: FreebuffTrustLevel, |
| 51 | +): boolean { |
| 52 | + return ( |
| 53 | + FREEBUFF_TRUST_LEVELS.indexOf(level) >= |
| 54 | + FREEBUFF_TRUST_LEVELS.indexOf(minimum) |
| 55 | + ) |
| 56 | +} |
| 57 | + |
| 58 | +/** User-facing name. Never says "trust", "risk" or "score" — a user reading |
| 59 | + * their own level is reading an explanation of their limits, not a verdict on |
| 60 | + * their character. */ |
| 61 | +export const FREEBUFF_TRUST_LEVEL_LABELS: Record<FreebuffTrustLevel, string> = { |
| 62 | + new: 'Getting started', |
| 63 | + verified: 'Verified', |
| 64 | + established: 'Established', |
| 65 | + core: 'Core member', |
| 66 | +} |
| 67 | + |
| 68 | +/** One line of user-facing copy per level, shown under the label. */ |
| 69 | +export const FREEBUFF_TRUST_LEVEL_BLURBS: Record<FreebuffTrustLevel, string> = { |
| 70 | + new: 'Welcome! Your account is brand new, so limits start small. They open up quickly — the steps below take a few minutes.', |
| 71 | + verified: |
| 72 | + 'Your account is verified. You have solid daily limits, and a bit of history unlocks the next level.', |
| 73 | + established: |
| 74 | + 'You are an established Freebuff user with generous limits on messages, spend and premium sessions.', |
| 75 | + core: 'You are a core member. You get the highest free limits we offer, in every region.', |
| 76 | +} |
| 77 | + |
| 78 | +/** A signal that moved the score, in user-facing language. */ |
| 79 | +export interface FreebuffTrustFactor { |
| 80 | + id: string |
| 81 | + label: string |
| 82 | + points: number |
| 83 | +} |
| 84 | + |
| 85 | +/** Something the user can do to move up, with what it is worth. */ |
| 86 | +export interface FreebuffTrustNextStep { |
| 87 | + id: string |
| 88 | + label: string |
| 89 | + detail: string |
| 90 | + points: number |
| 91 | + /** Where the UI should send them. Relative to the freebuff web app. */ |
| 92 | + href?: string |
| 93 | +} |
| 94 | + |
| 95 | +export interface FreebuffStandingHighlight { |
| 96 | + label: string |
| 97 | + value: string |
| 98 | +} |
| 99 | + |
| 100 | +/** |
| 101 | + * NOTE FOR CALLERS: `highlights` is what the level WOULD grant, which is only |
| 102 | + * what the account actually gets once `FREEBUFF_TRUST_LEVELS=enforce`. Both |
| 103 | + * producers gate on that (the Earn route and the session `standing` field), so |
| 104 | + * a client that receives this can render it as fact. A third producer must do |
| 105 | + * the same — see the comment in freebuff/web/src/app/api/web/standing/route.ts |
| 106 | + * for what happens otherwise. |
| 107 | + */ |
| 108 | +export interface FreebuffStandingInfo { |
| 109 | + level: FreebuffTrustLevel |
| 110 | + label: string |
| 111 | + blurb: string |
| 112 | + score: number |
| 113 | + /** Score at which the next level starts, or null at `core`. */ |
| 114 | + nextLevelAt: number | null |
| 115 | + nextLevel: FreebuffTrustLevel | null |
| 116 | + cappedBy: string | null |
| 117 | + cappedReason: string | null |
| 118 | + factors: FreebuffTrustFactor[] |
| 119 | + nextSteps: FreebuffTrustNextStep[] |
| 120 | + accessTier: FreebuffAccessTier |
| 121 | + /** Semantic, never numeric — see FreebuffStandingHighlight. */ |
| 122 | + highlights: FreebuffStandingHighlight[] |
| 123 | +} |
0 commit comments