tia/src/app/api
Mannu 0c7f37fd12 feat(quota): storage quota + family-member limits for free tier
Feature A — Storage quota (1 GiB per family):
- src/lib/quota.ts: enforcement library with pure functions (fully unit-tested)
  and DB-bound helpers; isPaidFamily() is the single payment abstraction gate
- src/lib/format-bytes.ts: extracted formatBytes() — safe for client imports
- POST /api/upload: quota check before presigned URL issuance (HTTP 402 + reason code)
- POST /api/memories/[id]/confirm: HeadObject reconciles actual R2 size; deletes
  over-quota objects and marks row failed rather than silently exceeding limit
- GET /api/storage-usage: storage info endpoint for UI meter
- src/components/StorageMeter.tsx: meter bar + StorageQuotaBanner + MemberLimitBanner
- memories/page.tsx: quota banner, FAB disabled (⊘) when exceeded, compact meter in header
- settings/page.tsx: always-visible StorageMeter + MemberLimitBanner in invite section

Feature B — Member limit (2 per family, free tier):
- invites/route.ts: replaced ad-hoc inline check with checkMemberLimit() from quota lib
  Structured 403 response: { reason, currentCount, limit }
- Freeze rule: paid→free downgrade leaves all members intact; only new invites blocked

Migration:
- drizzle/0007_subscription_status.sql: ADD COLUMN subscription_status varchar(20)
- debug-migration/route.ts: step added for hot-apply without full redeploy
- src/db/schema/family.ts: subscriptionStatus field added to Drizzle schema

Tests: 44 unit tests in src/__tests__/quota.test.ts, all passing
- Pure function tests (no DB): isPaidFamily, wouldExceedQuota, isAtMemberLimit, formatBytes
- DB-bound tests (mocked @/db): getFamilyStorageUsage, checkStorageQuota,
  checkMemberLimit, getStorageInfo, tenant isolation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 23:21:11 +05:30
..
admin feat: admin orphaned family management + user journey analytics 2026-05-24 09:38:34 +05:30
ai feat(g1-g4): design system, memories pipeline, medical tracking, AI brain 2026-05-17 17:48:34 +05:30
allergies Security hardening: auth, bcrypt, rate-limiting, RLS, audit 2026-05-16 23:11:01 +05:30
auth fix(profile): use correct image column on users table (not avatar_url) 2026-05-24 14:07:49 +05:30
chat Security hardening - all 8 patches applied 2026-05-16 23:59:43 +05:30
children feat(homepage): remove baby photo option + fix R2 orphan cleanup 2026-05-24 13:44:10 +05:30
circle/join/[token] Circle feature: C0–C9 multi-tenant social groups (Sprint 9 + 10) 2026-05-24 01:04:50 +05:30
circles fix: post menu clipping, add edit post, fix image display + fullscreen 2026-05-24 07:56:10 +05:30
cron/backup Add security libs: auth, audit, rate-limit, scoped db 2026-05-16 23:10:56 +05:30
debug-migration feat(quota): storage quota + family-member limits for free tier 2026-05-27 23:21:11 +05:30
families Security hardening - all 8 patches applied 2026-05-16 23:59:43 +05:30
family Security hardening - all 8 patches applied 2026-05-16 23:59:43 +05:30
garments feat(wardrobe): add complete wardrobe feature (W0–W9) 2026-05-23 18:09:22 +05:30
growth fix(growth): convert dates to strings before SQL query 2026-05-17 14:00:42 +05:30
history Security hardening - all 8 patches applied 2026-05-16 23:59:43 +05:30
illnesses Security hardening: auth, bcrypt, rate-limiting, RLS, audit 2026-05-16 23:11:01 +05:30
invites feat(quota): storage quota + family-member limits for free tier 2026-05-27 23:21:11 +05:30
logs Activity page overhaul — 9 UX improvements 2026-05-23 23:07:02 +05:30
medicines feat(g1-g4): design system, memories pipeline, medical tracking, AI brain 2026-05-17 17:48:34 +05:30
memories feat(quota): storage quota + family-member limits for free tier 2026-05-27 23:21:11 +05:30
milestones feat(g5-g6): age-aware UX + mama affiliate page 2026-05-18 00:59:17 +05:30
notifications fix: notifications IDOR — verify child belongs to caller's family 2026-05-17 11:57:57 +05:30
onboarding Fix onboarding schema 2026-05-17 00:25:56 +05:30
profile feat(g5-g6): age-aware UX + mama affiliate page 2026-05-18 00:59:17 +05:30
storage-usage feat(quota): storage quota + family-member limits for free tier 2026-05-27 23:21:11 +05:30
upload feat(quota): storage quota + family-member limits for free tier 2026-05-27 23:21:11 +05:30
vaccinations feat(g1-g4): design system, memories pipeline, medical tracking, AI brain 2026-05-17 17:48:34 +05:30
visits Security hardening: auth, bcrypt, rate-limiting, RLS, audit 2026-05-16 23:11:01 +05:30