Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dist
dist-ssr
*.local
.wrangler
.cloudflare/
.dev.vars
.dev.vars.*
!*.example
Expand Down
12 changes: 6 additions & 6 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The Worker expects these secrets to be configured in Cloudflare:

Do not commit secret values. Local development secrets belong in `.dev.vars`, which is ignored by git.

## First Deploy of Magic-Link Auth (one-time sequence)
## Historical first-deploy instructions for magic-link auth

1. Snapshot: `npx wrangler d1 export cardcap-db --remote --output backup-2026-06-09.sql`
2. Fresh start (wipes pre-auth beta data): `npx wrangler d1 execute cardcap-db --remote --command "DELETE FROM extraction_jobs; DELETE FROM contacts; DELETE FROM users;"`
Expand Down Expand Up @@ -56,20 +56,20 @@ npm run lint
npm run build
```

The build script removes generated local env files from `dist/cardcap`.
The build script removes generated local env files from `.cloudflare/output`.

## Deploy

```powershell
npx wrangler whoami
npm run build
npx wrangler deploy
npx cf auth whoami
npm run deploy -- --dry-run
npm run deploy
```

If Cloudflare auth expires:

```powershell
npx wrangler login
npx cf auth login
```

## Production Smoke Test
Expand Down
27 changes: 5 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Invoke-WebRequest -UseBasicParsing http://127.0.0.1:5173/api/health
npm run lint
npm test
npm run build
npx wrangler deploy --dry-run
npm run deploy -- --dry-run
```

## Turn On OpenAI Extraction Locally
Expand All @@ -61,28 +61,11 @@ Restart the dev server after changing `.dev.vars`.
- Set `SESSION_SECRET` to any 32+ character string to exercise the real magic-link flow; with no `RESEND_API_KEY`, the sign-in link is printed to the dev-server console instead of emailed.
- `TURNSTILE_SECRET_KEY` unset means the Turnstile check is skipped locally.

## Cloudflare Setup Later
## Production deployment

Cloudflare can host the frontend, Worker API, database, and image storage for this version. No Supabase is needed for the first SaaS cut.

When you are ready to deploy:

```powershell
npx wrangler login
npx wrangler d1 create cardcap-local
npx wrangler r2 bucket create cardcap-card-images
npx wrangler d1 migrations apply cardcap-local --remote
npx wrangler secret put OPENAI_API_KEY
```

After `d1 create`, replace the placeholder `database_id` in `wrangler.jsonc`. For production AI extraction, change `AI_EXTRACTOR` from `mock` to `openai` in `wrangler.jsonc`, then deploy:
The `cardcap` Cloudflare Worker serves the app and API. Its production bindings are defined in `cloudflare.config.ts`. Contacts use D1 and photos use R2. The D1 CLI uses the existing `./migrations` directory.

```powershell
npm run build
npx wrangler deploy
npm run deploy -- --dry-run
npm run deploy
```

## Current Production Gaps

- Magic-link auth is implemented but not yet deployed: production still needs `SESSION_SECRET`, `RESEND_API_KEY`, and Turnstile keys (see DEPLOYMENT.md).
- The deployed database still holds pre-auth beta data; the deploy sequence snapshots then wipes it (fresh start).
34 changes: 34 additions & 0 deletions cloudflare.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { bindings, defineConfig } from 'cf/config'

export default defineConfig({
accountId: '584b3d4e1cb07efb65c315c7efcce589',
worker: {
name: 'cardcap',
entrypoint: './src/worker/index.ts',
compatibilityDate: '2026-06-07',
compatibilityFlags: ['nodejs_compat'],
assets: {
notFoundHandling: 'single-page-application',
runWorkerFirst: ['/api/*'],
},
observability: { enabled: true, redactQueryString: true, headSamplingRate: 1 },
env: {
AI_EXTRACTOR: bindings.text('openai'),
OPENAI_MODEL: bindings.text('gpt-5.4-mini'),
SENDER_EMAIL: bindings.text('cody@copperstateit.com'),
TURNSTILE_SITE_KEY: bindings.text('0x4AAAAAADix1GoVxjHxnCXP'),
OPENAI_API_KEY: bindings.secret(),
RESEND_API_KEY: bindings.secret(),
SESSION_SECRET: bindings.secret(),
TURNSTILE_SECRET_KEY: bindings.secret(),
// CF's D1 CLI reads ./migrations by default.
DB: bindings.d1({ name: 'cardcap-db', id: 'd3a74ece-fba4-4d92-a167-dfa21998c9ab' }),
CARD_IMAGES: bindings.r2({ name: 'cardcap-card-images' }),
RL_LINK_EMAIL: bindings.rateLimit({ namespace: '1001', simple: { limit: 2, period: 60 } }),
RL_LINK_IP: bindings.rateLimit({ namespace: '1002', simple: { limit: 5, period: 60 } }),
RL_UPLOAD: bindings.rateLimit({ namespace: '1003', simple: { limit: 10, period: 60 } }),
RL_PASSWORD_EMAIL: bindings.rateLimit({ namespace: '1004', simple: { limit: 2, period: 60 } }),
RL_PASSWORD_IP: bindings.rateLimit({ namespace: '1005', simple: { limit: 5, period: 60 } }),
},
},
})
4 changes: 2 additions & 2 deletions e2e/browser/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Serves the built SPA (dist/client) plus the real Worker on local Miniflare for browser tests.
// Serves the built SPA plus the real Worker on local Miniflare for browser tests.
// /__test/* are test-only controls; they are not part of the app.
// With ACCESS_SIM=1 the Worker runs in AUTH_MODE=access behind a SIMULATED Cloudflare Access edge: nothing is served without
// a simulated session cookie, unauthenticated requests (pages and API calls alike) are redirected to a fake sign-in page,
Expand All @@ -10,7 +10,7 @@ import { fileURLToPath } from 'node:url'
import { startHarness } from '../harness'

const port = Number(process.env.PORT || 5199)
const dist = resolve(process.env.CARDCAP_DIST || join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'dist', 'client'))
const dist = resolve(process.env.CARDCAP_DIST || join(dirname(fileURLToPath(import.meta.url)), '..', '..', '.cloudflare', 'output', 'v1', 'workers', 'default', 'assets'))
const accessSim = process.env.ACCESS_SIM === '1'
const types: Record<string, string> = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.png': 'image/png', '.woff2': 'font/woff2', '.txt': 'text/plain' }

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist', 'worker-configuration.d.ts', '.claude/**', 'test-results/**', 'playwright-report/**']),
globalIgnores(['dist', '.cloudflare/**', 'worker-configuration.d.ts', '.claude/**', 'test-results/**', 'playwright-report/**']),
{
files: ['**/*.{ts,tsx}'],
extends: [
Expand Down
Loading
Loading