Skip to content

Commit cc7a4cb

Browse files
GeneAIclaude
authored andcommitted
feat: Add database and automated fulfillment system
- Add PostgreSQL database schema (customers, purchases, licenses, downloads) - Add license key generation (EMPATHY-XXXX-XXXX-XXXX-XXXX format) - Add Resend email integration for automated fulfillment - Update webhook to handle full purchase flow - Add /api/db/init endpoint for one-time schema setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3a980ed commit cc7a4cb

File tree

9 files changed

+1101
-50
lines changed

9 files changed

+1101
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ website/out/
6666
website/.env.local
6767
website/.env.production.local
6868
website/build/
69+
!website/lib/
6970

7071
# Working files (reminders, drafts, planning docs)
7172
BADGES_REMINDER.md

website/.env.example

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,67 @@
1-
# Email Service Configuration
2-
# Choose one: SendGrid, Mailchimp, or custom SMTP
1+
# ===========================================
2+
# Empathy Framework Website Environment Config
3+
# ===========================================
34

4-
# SendGrid (Recommended for transactional emails)
5-
SENDGRID_API_KEY=your_sendgrid_api_key_here
6-
SENDGRID_FROM_EMAIL=[email protected]
7-
CONTACT_EMAIL=[email protected]
8-
9-
# Mailchimp (Alternative for newsletter)
10-
# MAILCHIMP_API_KEY=your_mailchimp_api_key_here
11-
# MAILCHIMP_LIST_ID=your_mailchimp_list_id_here
12-
# MAILCHIMP_SERVER_PREFIX=us1
13-
14-
# Custom SMTP (Alternative)
15-
# SMTP_HOST=smtp.gmail.com
16-
# SMTP_PORT=587
17-
18-
# SMTP_PASS=your_app_password
19-
20-
# Analytics
21-
NEXT_PUBLIC_PLAUSIBLE_DOMAIN=smartaimemory.com
22-
# Optional: Self-hosted Plausible
23-
# NEXT_PUBLIC_PLAUSIBLE_API_HOST=https://plausible.io
5+
# Deployment
6+
NODE_ENV=production
7+
NEXT_PUBLIC_SITE_URL=https://smartaimemory.com
248

25-
# GitHub API (for stats)
26-
# Optional: Add token for higher rate limits
27-
# GITHUB_TOKEN=your_github_personal_access_token
9+
# ===========================================
10+
# Database (Railway PostgreSQL)
11+
# ===========================================
12+
# Get from Railway: Project → PostgreSQL → Connect → Connection URL
13+
DATABASE_URL=postgresql://user:password@host:5432/railway
2814

29-
# Database (if needed for newsletter/contact storage)
30-
# DATABASE_URL=postgresql://user:password@localhost:5432/smartaimemory
15+
# Admin secret for database initialization (generate a random string)
16+
ADMIN_SECRET=your_random_admin_secret_here
3117

18+
# ===========================================
3219
# Stripe Configuration
20+
# ===========================================
3321
# Get keys from: https://dashboard.stripe.com/apikeys
3422
STRIPE_SECRET_KEY=sk_live_...
3523
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_...
24+
3625
# Get from: Developers → Webhooks → [Your endpoint] → Signing secret
3726
STRIPE_WEBHOOK_SECRET=whsec_...
3827

3928
# Stripe Product Price IDs (get from Dashboard after creating products)
4029
# These need NEXT_PUBLIC_ prefix to be accessible in client components
41-
NEXT_PUBLIC_STRIPE_PRICE_BOOK=price_...
42-
NEXT_PUBLIC_STRIPE_PRICE_LICENSE=price_...
30+
NEXT_PUBLIC_STRIPE_PRICE_BOOK=price_1Sbf3xAbABKRT84gGn7yaivw
31+
NEXT_PUBLIC_STRIPE_PRICE_LICENSE=price_1SbfCjAbABKRT84gSh7BoLAl
32+
4333
# Contribution tiers (optional)
4434
NEXT_PUBLIC_STRIPE_PRICE_CONTRIB_5=price_...
4535
NEXT_PUBLIC_STRIPE_PRICE_CONTRIB_25=price_...
4636
NEXT_PUBLIC_STRIPE_PRICE_CONTRIB_100=price_...
4737
NEXT_PUBLIC_STRIPE_PRICE_CONTRIB_500=price_...
4838

49-
# Deployment
50-
NODE_ENV=production
51-
NEXT_PUBLIC_SITE_URL=https://smartaimemory.com
39+
# ===========================================
40+
# Email Service (Resend - Recommended)
41+
# ===========================================
42+
# Get from: https://resend.com/api-keys
43+
RESEND_API_KEY=re_...
44+
45+
# Email addresses
46+
FROM_EMAIL=Empathy Framework <[email protected]>
47+
SUPPORT_EMAIL=[email protected]
48+
49+
# ===========================================
50+
# Legacy Email (Optional - SendGrid)
51+
# ===========================================
52+
# SENDGRID_API_KEY=your_sendgrid_api_key_here
53+
54+
CONTACT_EMAIL=[email protected]
55+
56+
# ===========================================
57+
# Analytics
58+
# ===========================================
59+
NEXT_PUBLIC_PLAUSIBLE_DOMAIN=smartaimemory.com
60+
# Optional: Self-hosted Plausible
61+
# NEXT_PUBLIC_PLAUSIBLE_API_HOST=https://plausible.io
62+
63+
# ===========================================
64+
# GitHub API (for stats - optional)
65+
# ===========================================
66+
# Add token for higher rate limits
67+
# GITHUB_TOKEN=your_github_personal_access_token

website/app/api/db/init/route.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { initializeDatabase } from '@/lib/db';
3+
4+
// This endpoint initializes the database schema
5+
// Should only be called once during setup, protected by a secret
6+
export async function POST(req: NextRequest) {
7+
try {
8+
// Check for admin secret
9+
const { secret } = await req.json();
10+
11+
if (secret !== process.env.ADMIN_SECRET) {
12+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
13+
}
14+
15+
if (!process.env.DATABASE_URL) {
16+
return NextResponse.json(
17+
{ error: 'DATABASE_URL is not configured' },
18+
{ status: 500 }
19+
);
20+
}
21+
22+
await initializeDatabase();
23+
24+
return NextResponse.json({
25+
success: true,
26+
message: 'Database schema initialized successfully',
27+
});
28+
} catch (error) {
29+
console.error('Database initialization error:', error);
30+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
31+
return NextResponse.json({ error: errorMessage }, { status: 500 });
32+
}
33+
}

0 commit comments

Comments
 (0)