You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(server): analytics and limits as Effect service packages #73
apps/server/src/analytics.ts and rate-limit.ts are modules with two consumers each (auth and patches once they exist). They port before their first consumer so auth can depend on them.
Do
packages/analytics: an Analytics service (Context.Service, one file per the conventions) with a track interface the emitters use; a PostHog layer whose finalizer flushes and gives up under 3 s; a no-op layer for tests and when the key is unset. Config slice with the key as Redacted.
packages/limits: the fixed-window limiter as a Limits service whose interface mirrors RateLimiter.consume (returns remaining and a Retry-After), keeping today's semantics: fails closed at 10k tracked keys. Pure in-memory layer; the interface must allow a Redis-backed layer later with no consumer change.
The Fastify app consumes both through a thin Effect.runPromise seam (a ManagedRuntime built once in start.ts); the old modules and their tests are deleted, tests ported to @effect/vitest (TestClock for window expiry; fault injection by a failing PostHog layer, not a mock).
CONTEXT.md for each (analytics event; rate limit, window, fails closed); promote the language-service warnings to error for both packages.
Done when
No limiter or analytics code remains in apps/server/src; the limiter's Retry-After and fail-closed behaviour are tested through the service; the finalizer flush is tested with TestClock.
Activity