1 Debug PDF Generation - Test Commands

1.1 1. Test Hook Service Directly

# Test the hook service is working
curl -X POST https://hook-typst-export.ethical-capital.workers.dev \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer kgE2fh/dns2mWmvI6Gm6MHfNXRqXWs/b920ISCXcO0U=" \
  -H "User-Agent: dryvestment-app/1.0" \
  -H "X-Request-Source: dryvestment-app" \
  -d '{
    "title": "Test Brief",
    "markdown": "# Test\nThis is a test brief.",
    "author": "Test Author"
  }' \
  --output test.pdf

Expected Result: Should create a test.pdf file If this fails: Hook service has issues

1.2 2. Test Dryvest API Endpoint

# Test dryvest's generate-pdf API
curl -X POST https://dryvest.ethicic.com/api/generate-pdf \
  -H "Content-Type: application/json" \
  -H "Origin: https://dryvest.ethicic.com" \
  -d '{
    "title": "Test Investment Brief",
    "content": "# Test Brief\n\nThis is a test investment brief.",
    "venue": "Investment Committee",
    "decisionMaker": "Board of Trustees"
  }' \
  --output dryvest-test.pdf

Expected Result: Should create a dryvest-test.pdf file If this fails: Dryvest environment variables not set

1.3 3. Test Email API Endpoint

# Test dryvest's send-pdf-email API
curl -X POST https://dryvest.ethicic.com/api/send-pdf-email \
  -H "Content-Type: application/json" \
  -H "Origin: https://dryvest.ethicic.com" \
  -d '{
    "title": "Test Email Brief",
    "content": "# Email Test\n\nThis is a test email brief.",
    "venue": "Investment Committee",
    "decisionMaker": "Board of Trustees",
    "recipientEmail": "test@example.com",
    "recipientName": "Test User"
  }'

Expected Result: JSON response {"success": true, ...} If this fails: Email functionality not working

1.4 4. Check Dryvest Environment Variables

# Check if dryvest has required environment variables
# (This requires access to Cloudflare dashboard or wrangler from dryvest repo)

# From dryvest repository:
npx wrangler secret list

# Should show:
# - TYPST_EXPORT_TOKEN
# - HOOK_TYPST_EXPORT_URL
# - ALLOWED_ORIGINS
# - BUTTONDOWN_API_KEY (optional)

1.5 5. Test Browser Console (Frontend Debugging)

Open dryvest.ethicic.com in browser and run in console:

// Test PDF generation from frontend
fetch('/api/generate-pdf', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    title: 'Browser Test Brief',
    content: '# Browser Test\n\nThis is from the browser console.',
    venue: 'Test Committee',
    decisionMaker: 'Test Board'
  })
}).then(response => {
  console.log('Response status:', response.status);
  console.log('Response headers:', [...response.headers.entries()]);
  if (response.ok) {
    return response.blob();
  } else {
    return response.text().then(text => {
      console.error('Error response:', text);
      throw new Error(text);
    });
  }
}).then(blob => {
  console.log('PDF blob size:', blob.size, 'bytes');
  // Download the PDF
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = 'console-test.pdf';
  a.click();
}).catch(error => {
  console.error('PDF generation failed:', error);
});

1.6 6. Check Cloudflare Logs

# View real-time logs for dryvest (from dryvest repo)
npx wrangler pages deployment tail

# Or view recent logs
npx wrangler pages deployment list

1.7 Common Error Patterns

1.7.1 Missing Environment Variables

{"error": "PDF generation temporarily unavailable", "statusCode": 500}

Fix: Set TYPST_EXPORT_TOKEN and HOOK_TYPST_EXPORT_URL

1.7.2 Wrong Origin

{"error": "Unauthorized origin"}

Fix: Set ALLOWED_ORIGINS with correct domains

1.7.3 Hook Service Rejection

{"error": "Invalid authorization"}

Fix: Ensure tokens match between dryvest and hook service

1.7.4 PDF Too Large

{"error": "PDF too large for email delivery", "maxSize": "2MB", "actualSize": "3.2MB"}

Fix: Content is too long, need to shorten the brief

1.8 Quick Diagnosis Commands

# 1. Check if hook service is alive
curl -X GET https://hook-typst-export.ethical-capital.workers.dev

# 2. Check dryvest site is alive
curl -X GET https://dryvest.ethicic.com

# 3. Test authentication without PDF generation
curl -X POST https://hook-typst-export.ethical-capital.workers.dev \
  -H "Authorization: Bearer kgE2fh/dns2mWmvI6Gm6MHfNXRqXWs/b920ISCXcO0U=" \
  -H "User-Agent: dryvestment-app/1.0" \
  -d '{"title":"Auth Test"}'

# 4. Test wrong token (should fail)
curl -X POST https://hook-typst-export.ethical-capital.workers.dev \
  -H "Authorization: Bearer wrong-token" \
  -H "User-Agent: dryvestment-app/1.0" \
  -d '{"title":"Wrong Token Test"}'

1.9 Environment Variables Checklist

For dryvest.ethicic.com, these must be set in Cloudflare:

1.10 Success Indicators

Hook Service Working: - GET request returns {"ok": true, "service": "hook-typst-export", "timestamp": "..."} - POST with auth returns PDF binary data

Dryvest API Working: - /api/generate-pdf returns PDF file - /api/send-pdf-email returns {"success": true, ...}

Frontend Working: - PDF export button works in browser - Email PDF modal accepts input and sends successfully