Two real defects in the repo I can actually reach, found by auditing my own
work rather than someone else's.
formatPrice divided by 100 unconditionally. That assumes every currency has two
decimals, and several have none: with NEXT_PUBLIC_APP_CURRENCY=JPY a 2999-unit
product rendered as ¥30 instead of ¥2,999 — a hundredfold error, silently, on
every price in the shop. KRW, VND and ISK behave the same way, and KWD errs in
the other direction with three decimals. APP_CURRENCY is an environment
variable, so this was one deployment away from being real.
It now delegates to commercekit's money module, which takes the exponent from
the currency. That also removes a second money formatter from a repo that had
just adopted the first — exactly the duplication this whole exercise is about,
introduced by me.
TEMPLATE_MAP typed its payload as `any`, so the cron dispatching welcome emails
could hand a template the wrong shape and the compiler would agree — on mail
that goes to real users, built from a jsonb column nothing else validates. All
four templates take the same WelcomePayload, so the `any` bought nothing.
Typing it immediately produced an error, which turned out to be a typing gap
rather than a live bug: the cron spread `item.payload as object`, erasing the
shape, while enqueueWelcomeSequence does write { name, email }. So the emails
were correct and the types were lying about why. The cast now narrows to
WelcomePayload and the compiler can see it.
Verification: lint, tsc, css-vars, 901 tests / 87 files (8 new, including the
JPY case that would have caught the price bug).
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
SIGNAL_TEXT_CLASSES: add to pet-signal.ts config; replace duplicated
ternary (sig==="concern" ? danger-text : warn-text) in dashboard,
health, and checkin pages — was 3 identical inline mappings
formatPrice: admin overview was computing revenue inline
($${(revenue/100).toLocaleString(...)}) — now uses shared formatPrice()
formatDateShort: extend to accept full ISO timestamps (not just
date-only strings); admin users page was calling toLocaleDateString
inline — now uses formatDateShort()
User role colors: veterinarian/pet_sitter/admin used Tailwind named
colors (text-blue-700 etc.) while pet_owner used CSS vars — inconsistent
within the SSOT config; added --role-vet/sitter/admin CSS vars to
globals.css and updated lib/config/users.ts to reference them
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
formatPrice and formatAdoptionFee now use Intl.NumberFormat(locale, { style: "currency",
currency: APP_CURRENCY }) so the symbol and number formatting are locale-aware.
APP_CURRENCY reads from NEXT_PUBLIC_APP_CURRENCY env (default "USD"), making the
deployment currency a single config value rather than a hardcoded symbol.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
formatPetAge and formatPetAgeShort now accept a t() function so callers
pass their locale context instead of receiving hardcoded English. Adds 7
translation keys to the public namespace (petAgeMonths, petAgeYears,
petAgeYearsMonths, petAgeShortMonths, etc.) with proper plural forms and
natural phrasing for DE/FR/ES/JA/ZH/KO/TR/AR. Also adds unnamedPet key
to eliminate the last hardcoded English fallback in the booking modal,
and routes OG image price/fee strings through formatPrice/formatAdoptionFee
instead of inline $ calculations.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the hardcoded English strings ("Today", "Tomorrow", "In 7 days")
in formatRelativeDate with Intl.RelativeTimeFormat, so German users see
"heute/morgen/gestern", French see "aujourd'hui/demain/hier", etc.
Updates all call sites (pets list, health log, vaccinations) to pass
locale. Also routes sitter per-day price through formatAdoptionFee to
eliminate a rogue inline $-calculation in the Find page.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add formatAdoptionFee(feeCents: number | null): string — returns "Free"
for null/0, whole-dollar amount ("$25") otherwise. Eliminates 7 copies
of the same null-check + division + toFixed pattern scattered across
adoption pages and the admin panel.
Also wire formatPrice() in orders/route.ts and orders/[orderId]/route.ts
(5 instances) instead of inlining the dollar/cent division idiom.
No behavior change; all 534 tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Portal routes live outside next-intl's [locale] segment, so server
pages couldn't get the user's locale via getLocale() — date helpers
fell back to en. Non-English users saw English dates on the pet
profile and health page despite the language switcher.
- New lib/i18n/portal-locale.ts: getPortalLocale() reads the
NEXT_LOCALE cookie, validates it against routing.locales, falls
back to defaultLocale. The portal layout now uses this helper
instead of inlining the cookie read.
- formatIsoDate / formatIsoDateTime: accept optional locale (matches
the formatDateShort signature shipped last commit).
- Pet profile + health pages: resolve locale via getPortalLocale()
and pass it to all formatDateShort calls.
- SignalHistoryTimeline: accept optional locale prop, threaded from
the pet profile.
Client-side date callers (orders, bookings, etc.) intentionally
left as-is — they get the user's browser locale via undefined.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SignalHistoryTimeline hardcoded 'en-US', so non-English users on
the pet profile saw English dates regardless of their locale.
- SignalHistoryTimeline: route through formatIsoDate (uses runtime
locale) for consistency with the rest of the app
- formatDateShort: accept optional locale param so localized server
components can pass the resolved locale; default unchanged
- Public pet profile (under /[locale]/): pass locale to formatDateShort
so 'Born …' renders in the visitor's language
- Tests: cover both en and ja explicitly so a non-en CI runtime
doesn't break them (the prior implicit dependency on en-locale
CI is what made the suite fragile)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Four copies of formatPrice() and three copies of formatDate() were scattered
across portal and admin pages. Centralising eliminates future drift (e.g. a
currency symbol change or locale preference would previously require updating
4 files). Added formatIsoDate() and formatIsoDateTime() alongside the existing
domain formatters; updated all call-sites.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
formatRelativeDate used local midnight for the target date but all other
date operations in the codebase use UTC. For users in non-UTC timezones,
"today" could show as "yesterday". Fixed by using UTC midnight on both
sides of the comparison.
Also adds 11 unit tests for formatDateShort, formatWeight,
formatTemperature, and formatRelativeDate; and 2 missing pet-signal
cases (no metrics + overdue vaccinations → concern; high anxiety →
out-of-range watch).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Full Phase 1 scaffold:
- Next.js 16 + TypeScript strict + Tailwind 4 + Neon/Drizzle + NextAuth 5
- 9-language i18n (EN DE FR ES JA ZH KO TR AR) with RTL support for Arabic
- SSOT config: species (10 types), health metrics (7 KPIs), pet signal system
- DB schema: pets, healthMetrics (unique per pet+day), vaccinations, medications,
healthRecords, emailQueue
- Numeric storage: weight=grams, temperature=centidegrees (no float drift)
- computePetSignal() — pure domain function, 9 unit tests passing
- API routes: auth, account, pets CRUD, health metrics (upsert), records,
vaccinations, medications, public pet profiles (no auth)
- Cron: health-alerts, vaccination-reminders, email queue (all Bearer-protected)
- Portal UI: dashboard, pet list, add pet, health tracking, log page, vaccinations
- Public influencer pet profiles at /[locale]/pets/[handle]
- Email templates: welcome sequence, health alert, vaccination reminder
pnpm build ✓ pnpm test ✓ (9/9)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>