This is the standalone Egghead CourseBuilder integration app for the Rails-exit migration.
Canonical repo:
/Users/joel/Code/badass-courses/eggheadDuring migration work it is mirrored into:
/Users/joel/Code/skillrecordings/migrate-egghead/eggheadRuntime boundaries:
- published
@coursebuilder/*packages only - no
workspace:*CourseBuilder runtime reach-through - local web development writes to local Docker MySQL
- beta web runtime reads an explicitly approved PlanetScale database but blocks commerce writes
- production web database configuration requires PlanetScale; the subscription lifecycle capability remains local Docker and Stripe test mode only
- builder production runtime and production imports remain blocked
Run:
pnpm install
pnpm phase0:imports
pnpm --filter @egghead/web devThe subscription flow uses hosted Stripe Checkout. CourseBuilder verifies Stripe webhook
signatures and publishes the events to the app's Inngest endpoint; the Egghead handler then
creates the local subscription records and grants the all-access entitlement. A checkout quantity
of two or more creates a team subscription: the seat count and owner are stored on the local
subscription, and access is assigned from /team rather than granted to the purchaser implicitly.
Configure these values in apps/web/.env.local:
STRIPE_SECRET_TOKEN=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
INNGEST_EVENT_KEY=
INNGEST_SIGNING_KEY=Subscription checkout, webhook reconciliation, and team-seat mutations in this branch require
EGGHEAD_RUNTIME=local, a local Docker database, and a Stripe test key. The existing production
configuration checks remain, but they do not authorize these lifecycle writes. Production rollout
requires a separate review of writer ownership and native database evidence.
The pricing page discovers active CourseBuilder products whose type is membership. Each offered
recurring price must be connected through active MerchantProduct and MerchantPrice rows. The
price owns its billing interval and currency; the database owns offer visibility, label, order,
and default selection. Legacy single-price memberships remain readable.
Run the app and the Inngest dev server in separate terminals:
pnpm --filter @egghead/web dev
pnpm dlx inngest-cli@latest dev --no-discovery -u http://localhost:3008/api/inngestForward Stripe test-mode webhooks to the CourseBuilder endpoint:
stripe listen --events checkout.session.completed,customer.subscription.updated,customer.subscription.deleted,customer.deleted,invoice.payment_failed,charge.refunded,charge.dispute.created,charge.dispute.updated,charge.dispute.closed,charge.dispute.funds_withdrawn,charge.dispute.funds_reinstated \
--forward-to http://localhost:3008/api/coursebuilder/webhook/stripeCopy the whsec_... value printed by Stripe CLI into STRIPE_WEBHOOK_SECRET, restart the
web app, sign in, and open /pricing. Use the Seats input to select two or more seats, then
click Subscribe for {quantity} seats to send that quantity to Stripe Checkout. The checkout
success page waits for the durable webhook handler to create the
subscription, then links to /team, where the owner can claim, invite, remove, and add seats.
Ownership follows the Stripe customer's marker (docs/adr/0001-subscription-ownership-handover.md).
Checkout creates new Stripe customers as CourseBuilder-born (cb@0), so their events route to
this app. It refuses a reused customer that CourseBuilder does not own now and after every
scheduled flip, including any customer created before checkout stamped the marker, and the
pricing page says billing is managed elsewhere. To test locally with such an older test-mode
customer, use a fresh account or a new Stripe test customer.
Subscriptions keep a validated billing snapshot and a separate seat roster in
Subscription.fields.membershipState. Access entitlements are a derived projection,
updated atomically under the subscription row lock. Renewals and final cancellations
use the same reconciliation operation. Payment suspension retains the roster; recovery
restores only members who are still assigned. A team remains a team when its capacity
changes, including a reduction to one seat.
Before reducing seats, the owner selects the retained members and target capacity on
/team, then changes billing through /profile. The selection takes effect only when
Stripe reports that capacity. An unplanned reduction below the assigned roster pauses
team access until the owner selects retained members. Increasing capacity never restores
members removed by a prior reduction.
Checkout and webhook writes require local Docker and a Stripe test key. Published
CourseBuilder handles normal webhooks; the app intercepts verified final cancellation
events because the installed package only logs them. Refunds, disputes, dunning and customer
deletions always reach CourseBuilder (it marks refunded and disputed purchases); the subscription
seam handles them in addition. This does not activate production
commerce. pnpm subscription:behaviors runs lifecycle histories, signed-webhook checks,
blocked-checkout checks, and the Drizzle transaction/batching receipt tests offline.
Then from migrate-egghead:
bun tools/me.ts egghead standalone check --url http://localhost:3008 --json | jq .The configured collection selects the read contract explicitly: TYPESENSE_COLLECTION_NAME
takes precedence over NEXT_PUBLIC_TYPESENSE_COLLECTION_NAME, with
egghead_content_migration_v1 as the default. There is no schema guessing or field-name retry.
content_productionuses the existing legacy index without rewriting it. Queries searchtitle,description,summary, andinstructor_name; exact instructor filters use indexedinstructor_namevalues. App course filters selecttype=playlist, and playlist hits render as courses. IDs are preserved, recognized legacy paths such as/playlists/<slug>become app paths, and already-modern root/nested paths are retained. Results and instructor facets share the app-supported content-type scope. Publication eligibility relies on publisher-controlled index inclusion, not timestamp filtering: some published courses have zero publication timestamps. Legacy read errors propagate rather than silently switching to SQL or returning an unrelated catalog. No legacy reindex is required.- All other collection names use the canonical migration contract. Search documents include
body, every content contributor ininstructorNames, and a normalizedinstructorKeysfacet. Text queries search instructor display names, while instructor filters use normalized keys. SQL remains a search availability fallback when Typesense is not configured or a canonical Typesense read errors; it is not a fallback for configured legacy read errors.
Both default and typed dropdown suggestions use GET /api/instructors, which returns
{ "instructors": [{ "name": "John Lindquist", "resourceCount": 33 }] } (illustrative count).
With configured content_production, discovery reads instructor facets from that same index;
canonical and no-Typesense configurations retain SQL instructor discovery. Names are normalized,
encoding variants are merged, and name searches fold accents. The operation returns up to six
default suggestions, or up to eight matching suggestions for ?q=<name>. Unknown names return
an empty list. Lookup failures propagate as errors, not successful empty results; the dropdown
shows "Unable to load instructors." rather than retaining stale suggestions.
Existing canonical collections missing instructorNames/instructorKeys need schema provisioning
and a full reindex before indexed instructor search is available. Deploying source alone does
not create those fields or contributor data. For the guarded migration collection, recreation
and reindexing use:
EGGHEAD_TYPESENSE_INDEX_APPROVED=true pnpm search:typesense-index --recreateDo not run that command against a shared or production collection without explicit authorization.