Skip to content

Metabase analytics integration and security improvements - #262

Merged
bokelley merged 2 commits into
mainfrom
membership-payment-flow
Dec 1, 2025
Merged

bokelley merged 2 commits into
mainfrom
membership-payment-flow

Conversation

@bokelley

@bokelley bokelley commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements a comprehensive membership and payment flow with integrated analytics, plus critical security fixes from code review.

Analytics Integration

  • Embedded Metabase dashboard at /admin/analytics
  • Revenue tracking with SQL views for analytics
  • Sample data seeding script for testing
  • Three-tab admin navigation (Members, Agreements, Analytics)
  • Documentation in README.md and ANALYTICS.md

Database Views Added

  • revenue_summary: Total revenue and transaction metrics
  • customer_health: Subscription status and health indicators
  • subscription_metrics: Billing interval breakdown and trends

Security Fixes (Critical)

All issues identified during code review have been addressed:

1. Admin Authentication via Environment Variable

  • File: server/src/middleware/auth.ts
  • Change: Replaced hardcoded email domain with ADMIN_EMAILS env var
  • Benefit: More flexible and secure admin access control

2. SQL Injection Protection

  • File: server/src/db/organization-db.ts
  • Change: Added column name whitelist in updateOrganization() method
  • Benefit: Prevents SQL injection through dynamic column names

3. Structured Logging

  • Files: server/src/billing/stripe-client.ts, server/src/http.ts
  • Change: Replaced all console.log/warn/error with structured logger (50+ instances)
  • Benefit: Eliminates JWT token logging risk, better production logging with context objects

4. Error Handling for Revenue Tracking

  • File: server/src/http.ts (webhook handlers)
  • Change: Added try-catch blocks around all revenue event database insertions
  • Benefit: Prevents webhook failures from cascading

Infrastructure Changes

  • Added Jest configuration for unit tests
  • Added billing/stripe-client tests
  • Added organization-db tests
  • Added webhook security tests
  • Metabase Docker Compose configuration
  • Database migrations for revenue tracking

Testing

✅ All 29 tests passing
✅ TypeScript compilation successful
✅ No secrets exposed in version control
✅ Schema validation passed (146 schemas)

Documentation

  • Updated README.md with Metabase setup instructions
  • Created ANALYTICS.md with:
    • Available analytics views
    • Example SQL queries
    • Dashboard templates
    • Troubleshooting guide

Notes

  • Empty changesets added (no API/schema changes, only implementation)
  • All commits squashed to keep history clean
  • Ready for review and merge

bokelley and others added 2 commits December 1, 2025 06:33
This PR implements a comprehensive membership and payment flow with
integrated analytics, plus critical security fixes from code review.

## Analytics Integration

- Embedded Metabase dashboard at /admin/analytics
- Revenue tracking with SQL views for analytics
- Sample data seeding script for testing
- Three-tab admin navigation (Members, Agreements, Analytics)
- Documentation in README.md and ANALYTICS.md

Database views added:
- revenue_summary: Total revenue and transaction metrics
- customer_health: Subscription status and health indicators
- subscription_metrics: Billing interval breakdown and trends

## Security Fixes (Critical)

1. **Admin authentication via environment variable**
   - Replaced hardcoded email domain with ADMIN_EMAILS env var
   - More flexible and secure admin access control
   - File: server/src/middleware/auth.ts

2. **SQL injection protection**
   - Added column name whitelist in updateOrganization()
   - Prevents injection through dynamic column names
   - File: server/src/db/organization-db.ts

3. **Structured logging**
   - Replaced all console.log/warn/error with structured logger
   - Eliminates JWT token logging risk
   - Better production logging with context objects
   - Files: server/src/billing/stripe-client.ts, server/src/http.ts

4. **Error handling for revenue tracking**
   - Added try-catch around revenue event insertions
   - Prevents webhook failures from cascading
   - File: server/src/http.ts (webhook handlers)

## Infrastructure Changes

- Added Jest configuration for unit tests
- Added billing/stripe-client tests
- Added organization-db tests
- Added webhook security tests
- Metabase Docker Compose configuration
- Database migrations for revenue tracking

## Testing

- All 29 tests passing
- TypeScript compilation successful
- No secrets exposed in version control

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Resolved conflicts by keeping security fixes from membership-payment-flow branch:
- Structured logging with Pino (stripe-client.ts, http.ts)
- ADMIN_EMAILS environment variable (auth.ts, .env.local.example)
- SQL injection protection (organization-db.ts)
- Error handling for revenue tracking (http.ts)
- Metabase analytics integration (README.md)

Also preserved Security Requirements section from main branch in README.md.
@bokelley
bokelley merged commit a443357 into main Dec 1, 2025
bmilekic pushed a commit to bmilekic/adcp that referenced this pull request Dec 5, 2025
…xtprotocol#262)

This PR implements a comprehensive membership and payment flow with
integrated analytics, plus critical security fixes from code review.

## Analytics Integration

- Embedded Metabase dashboard at /admin/analytics
- Revenue tracking with SQL views for analytics
- Sample data seeding script for testing
- Three-tab admin navigation (Members, Agreements, Analytics)
- Documentation in README.md and ANALYTICS.md

Database views added:
- revenue_summary: Total revenue and transaction metrics
- customer_health: Subscription status and health indicators
- subscription_metrics: Billing interval breakdown and trends

## Security Fixes (Critical)

1. **Admin authentication via environment variable**
   - Replaced hardcoded email domain with ADMIN_EMAILS env var
   - More flexible and secure admin access control
   - File: server/src/middleware/auth.ts

2. **SQL injection protection**
   - Added column name whitelist in updateOrganization()
   - Prevents injection through dynamic column names
   - File: server/src/db/organization-db.ts

3. **Structured logging**
   - Replaced all console.log/warn/error with structured logger
   - Eliminates JWT token logging risk
   - Better production logging with context objects
   - Files: server/src/billing/stripe-client.ts, server/src/http.ts

4. **Error handling for revenue tracking**
   - Added try-catch around revenue event insertions
   - Prevents webhook failures from cascading
   - File: server/src/http.ts (webhook handlers)

## Infrastructure Changes

- Added Jest configuration for unit tests
- Added billing/stripe-client tests
- Added organization-db tests
- Added webhook security tests
- Metabase Docker Compose configuration
- Database migrations for revenue tracking

## Testing

- All 29 tests passing
- TypeScript compilation successful
- No secrets exposed in version control

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant