Commit graph

29 commits

Author SHA1 Message Date
Randall Stillwell
0e47fb883f Purge direct @neondatabase/serverless dependency from operational scripts.
Migrate setup-neon-db.js and reset-db.js to @vercel/postgres tagged templates so the runtime uses a single SQL client; historical add-*/fix-*/seed-* scripts remain unchanged per no-go-zone.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 00:37:27 -05:00
varutasu
d798e284c3
feat(scanner): AI Gateway vision + Layer-1 Tesseract/pg_trgm OCR (#38)
Route Layer-2 identification through Vercel AI Gateway (AI_GATEWAY_API_KEY,
default google/gemini-2.5-flash-lite). Add Layer-1 browser Tesseract name-strip
OCR with pg_trgm fuzzy catalog match via /api/cards/identify-by-text before
escalating to vision.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-27 12:59:59 -05:00
varutasu
de9f3348f6
feat(infra): adopt node-pg-migrate + backfill initial schema migration (#32)
Closes P1 #11 of .convoys/ship-readiness.md (launch sequence step 7) —
"No migration tool — scripts/add-*.js graveyard". Schema changes
post-this-convoy ship as node-pg-migrate migrations under migrations/
at the repo root; the legacy 27 scripts/add-*.js / scripts/fix-*.js /
scripts/seed-*.js jobs remain append-only history per the no-go-zones
rule.

Decisions (full record in .convoys/migration-tool.md § Decisions):

D1 — Tool: node-pg-migrate@^8. Rejected drizzle-kit / prisma migrate /
kysely because each forces broader TypeScript surface than AGENTS.md
Gotcha #9 allows (TS is a devDep only). node-pg-migrate is
JavaScript-native, raw-SQL-friendly via pgm.sql(), and ESM-clean for
the post-bump-next-js "type": "module" repo. Brings pg@^8.21.0 as a
peer dep (dev-only; never loaded in the Next.js bundle).

D2 — Migrations directory: migrations/ at the repo root. Separates
the tool-wrapped artifacts from the historical scripts/migrations/
placeholder folder (which housed the lone pre-tool
2026-05-24-rename-admin-email.js migration and remains preserved for
the audit trail). Matches node-pg-migrate's default flag.

D3 — Tracking table: default pgmigrations (no name collision with
the existing 7-table bootstrap; zero CLI noise).

D4 — Backfill strategy: hand-translate scripts/setup-neon-db.js's
DDL into the initial migration verbatim. Each await sql`...` block
becomes one pgm.sql(`...`) call. Each CREATE uses IF NOT EXISTS, so
the migration is idempotent against fresh AND pre-existing envs —
re-running setup-db on an env that already has the schema is a no-op
DDL-wise (only records the pgmigrations row). Documented assumption:
prod has drifted via the 27 historical add-*.js scripts; reconciling
those into the migration history is the queued
reconcile-historical-add-scripts follow-up convoy.

D5 — Bootstrap reconciliation: split. setup-neon-db.js now (1)
validates ADMIN_INITIAL_PASSWORD + POSTGRES_URL, (2) spawns
`npm run migrate up` via child_process with stdio inherited, (3)
seeds the admin row with ON CONFLICT (email) DO NOTHING. The seven
DDL blocks are deleted from setup-neon-db.js; success/error message
copy is updated to mention the migration step explicitly.

D6 — CI integration: defer. Wiring a CI job that runs migrate up
against a test DB needs either a dedicated Neon branch + secret OR a
Postgres service container; both are real work. Surface as
wire-migrate-into-ci follow-up. Risk acknowledged in
.convoys/migration-tool.md § R3.

D7 — Down-migration on the initial backfill: hard stub. Rolling back
the initial schema would drop every user / card / collection / deck
row in the DB. The stub throws with a long-form error pointing at
the recommended alternative (branch the Neon database + forward-apply).
Future migrations that touch one of the seven bootstrap tables write
their own dated migration with a real down().

Verification (pre-PR):
- npm run lint → 128 problems (baseline preserved, zero regression;
  migration file is lint-clean, no new ignore patterns)
- npm run test:run → 21/21 pass
- node --check on migrations/1779853647564_initial-schema.js + on
  scripts/setup-neon-db.js → exit 0
- Module load + down() throw verified via dynamic import
- npm run migrate -- --help reaches the node-pg-migrate CLI through
  the wrapper

Live verification against a Neon branch is deferred (no throwaway
branch available); the operator's optional post-merge sequence is
documented in .convoys/migration-tool.md § Operator runbook.

See .convoys/migration-tool.md § Follow-ups for the queued
wire-migrate-into-ci / reconcile-historical-add-scripts /
retire-graveyard-scripts-after-audit / audit-node-pg-migrate-transitive-deps
/ add-migration-template follow-up convoys.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 23:01:58 -05:00
varutasu
9abbab6c21
feat(brand): unify on Deck Hearth across in-repo strings + infra (P1 brand decision)
Resolves the launch-blocking 'TCG Vault vs Deck Hearth' inconsistency called out in AGENTS.md line 5 since project setup. Operator gate-0 decision: Deck Hearth wins. Two briefs applied serially. B1 (mechanical): 7-file display + comment sweep. B2 (infrastructure): Redis prefix rename in lib/rate-limit.js (5 prefixes, accept one-time counter reset), package.json + lockfile regen (STOP-on-churn confirmed only name lines changed), admin/alice/bob email rename in seed scripts + login pre-fill + NEW idempotent migration script scripts/migrations/2026-05-24-rename-admin-email.js. Risk 4 PRESERVE applied: test/lib/permission-middleware.test.js retains admin@tcgvault.com literal with 7-line architect-authored why comment (documents pre-fix-auth-bypass bug shape; preserves historical truth per project's gotcha-documentation convention). All 5 D-decisions ratified at gate-1 (Deck Hearth / deck-hearth / deckhearth / admin@deckhearth.com / full deckhearth Redis prefix). Local: lint 128 baseline (B1 + B2), vitest 21/21 (B1 + B2). CI all green: Playwright smoke 3/3 against rebranded preview in 1m4s, forbidden-cors-headers pass, forbidden-endpoints pass, Screenshot diff pass, Vercel deployment complete. Cross-validation lineage: 4th convoy where the same 3-test smoke spec defends auth surface through sweeping change (after PR #15 Layout default-user, PR #19 CORS, PR #20 rate-limit, now this PR #21 brand rename). OPERATOR POST-MERGE ACTION REQUIRED: run 'node scripts/migrations/2026-05-24-rename-admin-email.js' against prod Neon DB before next admin login (ordering: migration FIRST, then any subsequent setup-db invocation). Migration is ESM, idempotent, UNIQUE-collision-safe. PR #21 architect-commit 50ce9ab, B1 ac8c998, B2 1c18d21.
2026-05-25 02:28:29 -05:00
varutasu
7b6f7519b2
feat(test): adopt @playwright/test + ship playwright.config.js + visual scaffold (P1 #10 step 2)
Closes P1 #10 step 2. Adds @playwright/test@^1.60.0, playwright.config.js (CI fail-loud / dev warn-and-continue for missing VERCEL_AUTOMATION_BYPASS_SECRET, two projects partitioned by testMatch, snapshotPathTemplate aligned with workflow upload path), tests/visual/homepage.spec.ts (1 test, no baseline committed per architect Boot-the-brief Finding 7), 3 npm scripts, and 3 .gitignore entries. Smoke tests now run end-to-end against Vercel preview with x-vercel-protection-bypass header: 3/3 passed in 2.9s, total workflow 59s. Zero secret leaks in log. PR #18 architect-commit 3ac527e, implementer-commit c72d006.
2026-05-24 19:25:18 -05:00
varutasu
ca302a89c1
fix(layout+pages): default user=null + page audit sweep (P0 #7) (#15)
* convoy: scope fix-layout-default-user (P0 #7 — Layout maintainer-email leak)

The last remaining P0 ship-blocker from .convoys/ship-readiness.md.
components/Layout.js line 562 defaults the user prop to a real email
address (me@randallstillwell.com); any page that renders Layout without
passing user explicitly impersonates the maintainer.

Scope: components/Layout.js + audit of 17 pages that import Layout
(grep-confirmed list in convoy file). Single PR likely. Auditor cohort
skipped (no design-system, IA, or browser-smoke surface).

Architect to address:
  - Q1: logged-out rendering branch design (navbar, mobile-nav,
        auth-only items treatment)
  - Q2: page audit triage into always-auth / public-or-auth /
        anonymous-allowed buckets
  - Q3: brief decomposition (single brief / 2 briefs in 1 PR / fan-out)
  - Q4: whether to add vitest coverage for the logged-out branch
        (recommend yes — small surface, high regression protection)

Hard out-of-scope: branding (pick-a-name), auth-provider collapse
(single-auth-provider), Layout god-component split (god-component-split).

depends_on: bump-next-js (shipped), fix-auth-bypass (shipped),
            drop-public-setup (shipped)
addresses: P0 #7 from .convoys/ship-readiness.md
parent: ship-readiness

Co-authored-by: Cursor <cursoragent@cursor.com>

* architect(fix-layout-default-user): plan + briefs 1-2 (Layout fix + page audit)

2 briefs, single PR. ~12 files net (down from the 18 in the original scope —
10 of the 17 Layout-importing pages already pass user explicitly).

Brief 1: components/Layout.js default user=null + Sign-in CTA branch in
  UserProfileDropdown when logged out. Adds first jsdom test in the repo
  at test/components/Layout.test.js (Decision D2) with 5 regression-lock
  assertions. devDeps: jsdom@^29, @testing-library/react@^16.

Brief 2: page audit sweep — 7 pages need code changes:
  - Pass user={user} to Layout: scanner.js, deck-builder.js (×4),
    deck/[id].js (×3), decks.js (×3)
  - Replace page-level useState({email: 'me@...'}) → useState(null) +
    null-guards: profile.js, settings.js
  - Replace hardcoded const user = {email: 'me@...'} with useAuth():
    card/[id].js

Discovered second anti-pattern: profile.js, settings.js, card/[id].js
seed page-level state with the maintainer email. Folded into Brief 2 since
success metric "no real email address remains in any component default-prop"
reads naturally to include page-level seed values.

Decisions:
  A1 — Sign-in CTA replaces avatar+email+dropdown when user===null;
       hides auth-only dropdown (Profile/Settings/Logout/Admin);
       keeps public + community nav visible
  B  — Per-page bucket assignment (10 already correct, 7 need fix);
       full per-page table with justification in convoy file
  C2 — Two briefs in one PR (Brief 1 = Layout + test; Brief 2 = page
       sweep depends on Brief 1). C1 buries the conceptual change under
       mechanical edits; C3 is over-orchestrated for this scope
  D2 — vitest lock-in; first jsdom test in repo; same negative-regression
       style as test/lib/permission-middleware.test.js (synthetic-admin
       shape). devDeps jsdom + @testing-library/react

Risks tracked R1-R8. Biggest: R2 (useState(null) null-deref in 3 leaky
pages — mitigated by audit-pass mandate + manual smoke).

MobileNavigation deliberately NOT folded in: its user prop is dead code
(never reads user.*); different bug class; cleanup queued separately to
avoid scope expansion.

Flagged-but-deferred:
  - 4 pages still import useAuth from lib/auth-context.js
    → single-auth-provider (queued P1 #9)
  - Layout headers still render "Deck Hearth" / "DH" branding
    → pick-a-name (queued P1 #12)
  - MobileNavigation dead user prop → cleanup-mobile-nav-dead-props
    or fold into god-component-split

addresses: P0 #7 from .convoys/ship-readiness.md (last P0 ship-blocker)
parent: ship-readiness
Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(layout): default user=null + Sign-in CTA when logged out (Brief 1 of fix-layout-default-user)

Closes the source-side half of P0 #7 from .convoys/ship-readiness.md.
The page-side sweep (Brief 2) follows in a separate commit.

components/Layout.js:
  - Default user prop is now null (was hardcoded to
    { email: 'me@randallstillwell.com', role: 'user' })
  - UserProfileDropdown renders a "Sign in" link to /login when
    user === null instead of the maintainer's email + auth-only menu
    items (Decision A1)
  - All user.* accesses guarded with optional chaining or null checks
  - useState hook stays above the new null-user early return to satisfy
    rules-of-hooks (boot-the-brief caught this on the first try;
    see AGENTS.md Gotcha #11.5)

test/components/Layout.test.js (new):
  - First jsdom test in the repo (Decision D2)
  - 5 regression-lock assertions: no maintainer email ever rendered
    (prop omitted, prop=null), Sign-in link exists with href=/login,
    supplied email renders when prop is set, no "Guest" placeholder
    (locks A1 copy choice)
  - Mocks next/link, next/router (prefetch, replace, events, query),
    and theme-context.useTheme for jsdom safety under Next 16

package.json + package-lock.json:
  - Add jsdom@^29 and @testing-library/react@^16 to devDependencies
  - @testing-library/dom@^10 added explicitly (peer auto-install
    skipped it under npm 11; brief anticipated this fallback)

vitest.config.js (deviation from brief — see PR description):
  - Add esbuild { loader: 'jsx', jsx: 'automatic' } so vitest can
    parse JSX in .js files. Required to import any React component
    written in the repo's Next.js pages-router .js convention
    (AGENTS.md Gotcha #9). The brief said "no change" to this file,
    but JSX-in-.js parsing is a hard prerequisite for the new test
    to import components/Layout.js — the alternatives (rename test
    to .test.jsx; rewrite test in React.createElement) either break
    the test glob or still hit the same Layout.js parse failure.
    Other tests are unaffected (they import non-JSX modules).

Smoke output: see PR description.

addresses: P0 #7 from .convoys/ship-readiness.md (last P0 ship-blocker)
Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(pages): pass user explicitly + null-guard leaky page seeds (Brief 2 of fix-layout-default-user)

Closes the page-side half of P0 #7 from .convoys/ship-readiness.md.
Brief 1 (commit ddf8fd2) handled the Layout-side fix.

Per the architect's per-page bucket table (Decision B in
.convoys/fix-layout-default-user.md), 7 pages needed code changes;
the other 10 of 17 Layout-importing pages already pass `user` correctly.

Pass user={user} to Layout (4 pages, 11 call sites):
  - pages/scanner.js (1 call)
  - pages/decks.js (3 calls)
  - pages/deck-builder.js (4 calls)
  - pages/deck/[id].js (3 calls)
  (All four still import useAuth from lib/auth-context.js — that's
   intentional and stays as-is until the single-auth-provider convoy
   collapses the three parallel auth surfaces.)

Replace leaky page-level seed values with useState(null) + null guards
(2 pages, R2 mitigation):
  - pages/profile.js: useState({email: 'me@...', role: 'user', ...})
                     → useState(null) + ?. on every sync user.* read
                     + early-return guards in getDisplayName/getInitials
                     + conditional render around the "Member since" block
                       so formatDate(undefined) never runs
  - pages/settings.js: same pattern (single user.email reader guarded)

Replace hardcoded const with useAuth from lib/use-auth.js (1 page):
  - pages/card/[id].js: const user = {email: 'me@...'}
                       → const { user } = useAuth() (called unconditionally
                       at the top of the component; rules-of-hooks safe)

Verification:
  - grep 'me@randallstillwell.com' pages/ → 0 hits
  - 21/21 vitest tests pass (16 pre-existing + 5 from Brief 1)
  - npm run lint matches baseline (128 problems pre, 128 post; verified
    via git stash before/after)
  - Manual static read-through of every diff; ReadLints clean on the 7
    files
  - Dev-server smoke: /cards anonymous returned HTTP 200 with 0
    'me@randallstillwell' matches before the user's shared dev server
    became unresponsive mid-session (same dev-server-shared-by-user
    constraint flagged in Brief 1); interactive logged-in smoke is
    parent/operator gated

Flagged-but-deferred (untouched per scope):
  - 4 pages still import useAuth from lib/auth-context.js
    → single-auth-provider (queued P1 #9)
  - components/MobileNavigation.js still receives dead user prop
    → cleanup-mobile-nav-dead-props (or fold into god-component-split)

addresses: P0 #7 from .convoys/ship-readiness.md (last P0 ship-blocker)
Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:31:37 -05:00
Randall Stillwell
1629afbb76 test(auth): add vitest harness + 16 auth-focused unit tests (Brief 5 of fix-auth-bypass)
Closes AGENTS.md gotcha #11 (well, the relevant half of it — "Testing:
None yet" line in §6 is now stale).

Installs vitest@^3.2.4 (single devDep, no UI / coverage / jsdom) and
adds 16 unit tests across 3 files that lock in post-Brief-1/2/4
behavior:

  test/lib/auth-secret.test.js (3 tests)
    - JWT_SECRET exports the env value
    - JWT_TOKEN_TTL is canonical 24h
    - Module throws at load when JWT_SECRET is empty

  test/lib/permission-middleware.test.js (8 tests)
    - getUserFromRequest returns null for: missing header, non-Bearer
      scheme, malformed token, wrong-secret token, expired token,
      valid-token-no-user-row
    - Returns user object for valid token + user row
    - Brief 2 regression lock: does NOT return the synthetic admin
      shape { userId: 1, email: 'admin@tcgvault.com', role: 'admin' }
      when no Authorization header is present

  test/api/auth-utils.test.js (5 tests)
    - generateToken issues 24h JWT (exp - iat === 86400)
    - Payload includes userId, email, role
    - verifyToken round-trips valid tokens
    - Returns null for malformed / wrong-secret tokens

CI: re-enabled the previously commented-out test: job in
.github/workflows/ci.yml. Blocking (no || true wrapper) — vitest is
the first runner in this repo and we want CI red on test regression.
JWT_SECRET is set via a CI-only fake; production secret is unaffected.

Rate-limit (Brief 4) coverage deferred to a future expand-auth-tests
convoy per architect's call (R11). package.json has "type": "module"
so vitest's default Vite-based transform handles .js ESM out of the
box — no transform config needed.

Convoy: fix-auth-bypass / Brief 5 (last brief)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 11:12:15 -05:00
Randall Stillwell
297afca1ae fix(auth): tighten public auth surface — CORS + rate limit (Brief 4 of fix-auth-bypass)
Adds rate limiting to /api/auth/login and /api/auth/register and removes
their wide-open CORS allowlist.

Rate limiting (@upstash/ratelimit + @upstash/redis):
  - 5 attempts per 15-minute sliding window per IP, prefix "tcgvault:auth"
  - new lib/rate-limit.js, lazy singleton, single source of truth
  - reads KV_REST_API_URL / KV_REST_API_TOKEN (Vercel Upstash Marketplace
    convention — auto-provisioned, no manual env-var setup needed)
  - fail-closed in production if env vars are missing (better to error
    one login than silently disable brute-force protection on live)
  - fail-open in dev/test if env vars are missing (single console.warn)
  - fail-open on Upstash backend outage (defense-in-depth — don't lock
    the entire userbase out if Upstash is down)
  - IP extracted from x-forwarded-for first hop, with socket fallback;
    NOT req.body.email (rotates) or Authorization header (absent on
    unauthenticated login)

CORS:
  - Removed Access-Control-Allow-Origin: * + companion headers + OPTIONS
    preflight from login.js and register.js
  - These are first-party endpoints called from the same-origin SPA; the
    "*" allowlist was a development convenience that shipped to prod
  - verify.js is OUT OF SCOPE per architect's "cors-tighten" deferral
    (see convoy plan § Architect's calls)

Other handler ordering preserved verbatim per brief: method gate first,
then rate-limit check (returns 429 with Retry-After header), then the
existing try/catch + body parsing + DB work.

Pre-merge requirements: KV_REST_API_URL + KV_REST_API_TOKEN must be set
in Vercel Production (already done — Upstash marketplace integration
auto-provisioned both, confirmed by maintainer 2026-05-23).

Convoy: fix-auth-bypass / Brief 4
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 10:57:49 -05:00
Randall Stillwell
e57ea17579 bump: next 15.4.3 -> 16.2.6, ESLint flat config (v9 fallback), typescript devDep
Closes P0 ship-blocker #8 from .convoys/ship-readiness.md. Vercel has
been refusing every deployment since 2025-08-01 with "Vulnerable version
of Next.js detected, please update immediately" — this bump clears
that platform gate and unblocks every downstream preview-smoke and
visual-diff gate that depends on a live preview URL.

Changes (per Brief 1 acceptance criteria, all four gate-1 decisions
applied — see .convoys/bump-next-js.md § Decisions for the audit trail):

- next: ^15.4.2 -> ^16.2.6 (resolves next@16.2.6)
- eslint: ^8 -> ^9.39.4 (Decision D fallback; v10 surfaced Risk R15
  empirically — @typescript-eslint/scope-manager@8.59.4 bundled by
  eslint-config-next@16 doesn't implement v10's new addGlobals API)
- eslint-config-next: 15.4.2 -> ^16.2.6
- typescript: newly added at ^5.9.3 as a devDep (Decision C; required
  by typescript-eslint chain regardless of ESLint major)
- scripts.lint: "next lint" -> "eslint ." (next lint removed in 16)
- next.config.js: images.domains -> images.remotePatterns (deprecated
  and removed in Next 16; preserves the three CDN hosts Scryfall,
  Pokemon TCG, Lorcana API for eventual next/image adoption)
- .eslintrc.json deleted (eslint-config-next@16 is flat-config-only)
- eslint.config.mjs added (verbatim shape from Next docs; verified
  forward-compatible with v10 so bump-eslint-10 will not need to
  touch this file)

Out of scope (deferred to dedicated convoys):
- React 18 -> 19 (bump-react)
- App Router migration (multi-month effort)
- Test runner adoption (adopt-vitest, adopt-playwright-smoke)
- Lint baseline cleanup (fix-lint-baseline) — new v9 baseline is
  128 problems (81 errors, 47 warnings), up from prior ~100 due to
  eslint-plugin-react-hooks@7.1.1 + @next/eslint-plugin-next@16.2.6
  rule additions
- ESLint v10 adoption (bump-eslint-10) — upstream-blocked on
  typescript-eslint shipping a v10-tested release that
  eslint-config-next then bundles
- TypeScript 6 adoption (bump-typescript-6) — same upstream block

Local verification:
- npm install: clean, no ERESOLVE warnings
- npm run build: exit 0, Next 16.2.6 (Turbopack), ~1.4s compile,
  23 static pages + 47 API routes, no images.domains deprecation
- npm run lint: exit 1, 128 problems, runs to completion (tolerated
  by CI's `|| true` wrapper; new baseline for fix-lint-baseline)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 02:31:26 -05:00
Randall Stillwell
308d2de365 🧹 Major Codebase Cleanup: Remove Legacy React Code
🗑️ Removed Unused Files (11 files):
- 6 temporary import result JSON files
- 3 placeholder pages (community.js, analytics.js, decks.js)
- 3 unused components (CollaborationManager, ActivityLog, BulkInviteModal)
- 2 TypeScript config files (tsconfig.json, next-env.d.ts)

📦 Cleaned Up Dependencies:
- Removed 5 unused TypeScript packages
- Kept resend for future invite/notification features
- Removed 8 packages total, reduced bundle size

 Benefits:
- Cleaner codebase with only active files
- Reduced build time and bundle size
- Eliminated TypeScript overhead (project uses only JS)
- Removed legacy React patterns and unused components
- Better maintainability and clarity

The codebase is now lean and focused on active features
2025-07-28 09:07:36 -05:00
Randall Stillwell
a7ee884d02 🖼️ Complete Avatar Upload System with Vercel Blob
📤 Avatar Upload API (/api/user/avatar):
- File upload with multipart form data parsing
- Comprehensive validation (file type, size limits)
- Support for JPEG, PNG, GIF, WebP images up to 5MB
- Automatic cleanup of old avatars before new uploads
- Vercel Blob integration with public access
- Database tracking in user_avatars table
- Error handling for upload failures

🎨 Avatar Generation API (/api/user/avatar/generate):
- Custom avatar generation using DiceBear API
- Fire-themed color scheme (matching app branding)
- Personalized based on user initials/username/email
- SVG format for crisp display at any size
- Automatic fallback if generation fails
- Same cleanup and storage workflow as uploads

🗑️ Account Deletion API (/api/user/delete):
- Complete user data cleanup including Vercel Blob files
- Cascading deletion respecting foreign key constraints
- Admin account protection (prevents self-deletion)
- Comprehensive cleanup order:
  * User avatars from Vercel Blob storage
  * Deck cards, decks, collection cards, collections
  * User cards, avatar records, settings
  * Finally the user account itself
- Detailed logging for audit trail
- Graceful error handling with specific error messages

🔧 Technical Features:
- Custom multipart form data parser for file uploads
- Vercel Blob put/del operations with error handling
- Unique filename generation with timestamps
- Database transaction-like cleanup for deletions
- File type validation and size limits
- Proper CORS headers for all endpoints

🎯 Integration Ready:
- Works seamlessly with existing profile page UI
- Supports both upload and generate avatar buttons
- Returns avatar URLs for immediate display
- Database consistency with user profile system
- Production-ready error handling and validation

The avatar system is now fully functional with Vercel Blob! 📸
2025-07-26 21:39:42 -05:00
Randall Stillwell
23d995102f 🎉 COMPLETED: Full Collaborative Collections System
 ALL FEATURES IMPLEMENTED:

🔐 Advanced Permission System:
- Role-based access control (Owner/Editor/Viewer)
- Permission middleware for all API endpoints
- Granular permissions for collection operations
- Activity logging for complete audit trails

🌍 Collection Visibility Types:
- Private: Owner-only access
- Invite-Only: Controlled collaboration
- Public: Community accessible
- Dynamic permission checking across all endpoints

📧 Complete Email Integration:
- Beautiful HTML invitation templates
- Role-based permission descriptions
- Personal message support
- Accept/decline workflow with proper UX
- Bulk invitation system for multiple users

🎨 Rich User Interface:
- Permission indicators with tooltips
- Activity log component with real-time updates
- Collaboration management dashboard
- Bulk invite modal with batch processing
- Permission gates throughout the UI

 Performance & Security:
- Database indexes for optimal queries
- Comprehensive error handling
- CORS headers and preflight support
- JWT-based authentication integration
- Cascading deletes and data integrity

🚀 Ready for Production:
- All API endpoints protected with permissions
- Complete activity logging system
- Beautiful email templates with Resend
- Responsive UI components
- Error handling and loading states

This system now provides enterprise-level collaboration features for community-driven collection building! 🎯
2025-07-25 08:34:28 -05:00
Randall Stillwell
be67815cab Added comprehensive user management scripts
- Created list-users.js to display all users with roles and details
- Added promote-user-to-admin.js to elevate regular users to admin
- Added demote-admin-to-user.js with safety check for last admin
- All scripts use proper ES modules and dotenv for environment loading
- Scripts validate user existence and current roles before operations
- Added detailed documentation to scripts/README.md
- Includes user-friendly output with emojis and clear status messages
- Tested promotion functionality successfully
- Maintains database integrity with proper error handling
2025-07-24 20:03:31 -05:00
Randall Stillwell
e75a4a6649 Major redesign: Enhanced card display with particle effects, improved filters, and search functionality
- Redesigned card display with 2.5:3.5 aspect ratio and image-only view
- Added infinite scroll to replace pagination
- Implemented authentic card back placeholders for MTG, Pokemon, and Lorcana
- Added rarity-based particle effects with tiered intensity (mythic/enchanted/rare/uncommon)
- Enhanced hover details panel with structured card information
- Fixed search functionality with debouncing and Enter key support
- Improved filter system with working TCG, rarity, set, and price filters
- Added favorite system for cards in both hover and detail views
- Updated card detail page with comprehensive metadata and actions
- Fixed API filtering with proper Vercel Postgres implementation
- Added particle animations and rarity glow effects
- Improved overall UX with better visual hierarchy and interactions
2025-07-23 21:26:54 -05:00
Randall Stillwell
7be41b4490 Clean slate: Remove React traces and create pure Next.js setup 2025-07-23 09:32:31 -05:00
Randall Stillwell
339fb6f910 Update @vercel/postgres to latest version and add test APIs 2025-07-23 08:49:05 -05:00
Randall Stillwell
873f4592c2 Convert from React to Next.js for proper API route support 2025-07-23 08:25:58 -05:00
Randall Stillwell
0bc3e854fb Fix build compatibility issues
🔧 Build Fixes:
- Downgrade TypeScript from ^5.7.3 to ^4.9.5 for react-scripts compatibility
- Add .npmrc with legacy-peer-deps=true to handle dependency conflicts
- Ensure compatibility with react-scripts@5.0.1 requirements

This resolves the ERESOLVE error:
 react-scripts@5.0.1 expects typescript ^3.2.1 || ^4
 Now using typescript ^4.9.5 (compatible)

Build should now succeed on Vercel.
2025-07-22 10:32:15 -05:00
Randall Stillwell
2c1e9bbb79 🚀 Replace Tesseract with AI-powered OCR
🤖 AI OCR Implementation:
- Replace poor-performing Tesseract.js with OpenAI Vision API
- Add Ollama Vision support for local/private scanning
- Structured JSON output with card details (name, set, type, rarity, etc.)
- Much higher accuracy and faster processing
- Intelligent game detection (MTG, Pokemon, Lorcana)

⚙️ OCR Settings Panel:
- Configure OpenAI API key or Ollama server URL
- Test API connectivity before scanning
- Choose preferred OCR service
- Settings persist in localStorage

 Enhanced Card Data:
- Extract card name, set, type, rarity, HP, attacks, abilities
- Better game detection and set code identification
- Structured data for improved database matching
- Higher confidence scores (85%+ vs 37% with Tesseract)

🎯 For your Frosmoth card, this should extract:
- Card Name: 'Frosmoth'
- Game: 'POKEMON'
- HP: '90'
- Set: Proper set identification
- Confidence: 90%+ instead of 37%
2025-07-22 10:30:07 -05:00
Randall Stillwell
7dc8718512 Fix build issues and update dependencies
🔧 Build Fixes:
- Update Node.js version from 18.x to 22.x (required by Vercel)
- Remove debug endpoints to get under 12 function limit for Hobby plan
- Downgrade React from 19.x to 18.x for better compatibility
- Update react-router-dom to v6.28.0 (compatible with Node 22)
- Update TypeScript to v5.7.3
- Update React types to match React version

Functions count: 12/12 (at limit for Hobby plan)

Core API endpoints:
 auth/login.js, auth/register.js
 collections/index.js, collections/add-card.js
 cards/find-or-create.js
 admin/users.js, admin/promote-user.js
 setup-auth.js, simple.js
 Legacy: migrate.ts, v1/cards/[id].ts, v1/cards/index.ts
2025-07-22 08:18:51 -05:00
Randall Stillwell
b462010434 Add proper Next.js API routes and install Next.js types
🔧 API Route Format:
- Add /api/simple.js using standard Vercel function format
- Add /api/hello.ts using proper Next.js API route format
- Install Next.js and types for proper API route support

🧪 Testing Multiple Formats:
- JavaScript endpoint: /api/simple.js
- TypeScript endpoint: /api/hello.ts
- Both use traditional req/res pattern instead of NextRequest/NextResponse

This should help identify the correct API format for Vercel functions.
2025-07-22 06:43:39 -05:00
Randall Stillwell
dc95d0d76d Implement complete user authentication and admin panel system
 Features Added:
- User registration and login with JWT authentication
- Role-based access control (user/admin)
- Comprehensive admin panel with user management
- Password hashing with bcrypt
- Session management and token storage
- Protected routes and public routes
- Modern login/register forms with validation

🗄️ Database Schema:
- Users table with profile information
- Roles and permissions system
- User-role junction tables
- Session management tables
- Database triggers and indexes

🎨 UI/UX Improvements:
- Updated navigation with user menu
- Admin badge and access controls
- Responsive authentication forms
- Loading states and error handling
- Role-based UI elements

🔧 API Endpoints:
- /api/auth/login - User authentication
- /api/auth/register - User registration
- /api/admin/users - User management (admin only)
- /api/setup-auth - Database schema setup

🚀 Admin Panel Features:
- User listing with search and pagination
- Role assignment (user/admin)
- User activation/deactivation
- System dashboard with stats
- Card management placeholder
- Real-time user management
2025-07-21 21:06:38 -05:00
Randall Stillwell
6f40a5058d Fix Node.js 18 compatibility for Vercel deployment
- Switch from @neondatabase/serverless to standard 'pg' client for Node.js 18 support
- Update Node.js version to 18.x as required by Vercel
- Replace Neon template literals with standard parameterized queries
- Add proper connection pooling and SSL configuration for production
- All API endpoints updated: /api/v1/cards/, /api/v1/cards/[id], /api/migrate
- Build tested and working successfully
2025-07-21 16:08:45 -05:00
Randall Stillwell
bdaa257c88 Fix Vercel Node.js compatibility issues
- Downgrade Node.js version from 22.x to 20.x (Vercel supported)
- Downgrade @neondatabase/serverless from 1.0.1 to 0.10.4 for Node.js 20 compatibility
- Resolve 'Invalid Node.js Version' deployment error
- Build tested locally and working successfully
2025-07-21 16:00:17 -05:00
Randall Stillwell
33345a9f51 Fix Vercel deployment issues
- Update Node.js version from 18.x to 22.x for Neon compatibility
- Fix TypeScript errors by properly typing error objects as Error
- Resolve engine compatibility issues with @neondatabase/serverless and react-router
- Add proper error type casting in all API endpoints
- Fix FUNCTION_INVOCATION_FAILED crashes
2025-07-21 15:56:26 -05:00
Randall Stillwell
4fea3d287e Add Neon database integration and migration scripts
- Install @neondatabase/serverless, @vercel/blob, @stackframe/stack
- Add database schema setup script (scripts/setup-database.sql)
- Add JSON to Neon migration script (scripts/migrate-json-to-neon.ts)
- Prepare for user collections, decks, and authentication
- Ready for Neon database population with existing card data
2025-07-21 15:06:43 -05:00
Randall Stillwell
df4cd86d90 Add Vercel Analytics and Speed Insights for comprehensive tracking
- Install @vercel/analytics and @vercel/speed-insights packages
- Integrate Analytics component for user behavior tracking
- Add SpeedInsights component for Core Web Vitals monitoring
- Track page views, user interactions, and performance metrics
2025-07-21 14:34:34 -05:00
Randall Stillwell
baeddb575b Specify Node.js 18.x for Vercel compatibility 2025-07-21 14:15:36 -05:00
Randall Stillwell
6b81ed38b0 🚀 TCG Vault - Complete All-Vercel Setup
 Features:
- Camera OCR card scanning with Tesseract.js
- Beautiful glowing card effects and animations
- Intelligent card matching and recognition
- Mobile-responsive design with Tailwind CSS

🏗️ Architecture:
- Frontend: React TypeScript application
- Backend: Vercel Functions (replacing FastAPI)
- Database: JSON file with exported card data
- Deployment: Single Vercel project

📁 Structure:
- api/ - Vercel Functions backend endpoints
- src/ - React frontend components and logic
- src/data/cards.json - Card database (12 cards)
- vercel.json - Optimized Vercel configuration

💰 Cost: /bin/zsh additional (uses existing Vercel Pro)
🚀 Ready for immediate Vercel deployment
2025-07-21 13:53:06 -05:00