feat(selfhost): NEW_ORG_TRIAL_DAYS sets the new-org trial length (default 15)

Merged
WC
2d ago
+108-7

Summary

Self-hosted installs have no billing, so a new organization should never leave its free trial. This makes the trial length a Worker setting, NEW_ORG_TRIAL_DAYS.

  • resolveNewOrgTrialEnd() reads NEW_ORG_TRIAL_DAYS: whole days from 1 to 36500 (100 years).
  • Unset or empty: 15 days, exactly as today. Capgo Cloud does not set it, so nothing changes there.
  • An invalid value (0, negative, not a number, a decimal, above 36500) is logged as an error and also gives 15 days.
  • Direct-offer creators still get no trial, whatever the value.
  • The capgo-workers image passes the variable to the Workers (OPTIONAL_ENV); without that the container would drop it.
  • Documented in docs/selfhost-workers.md.

No Cloud env, wrangler or deploy change.

Known limit

The database trigger generate_org_user_stripe_info_on_org_create() still writes NOW() + 15 days on the temporary pending_<org> row at signup. The on_organization_create job then writes the final row with the trial end from this setting and deletes the pending one. So a self-hosted org shows 15 days until that job has run. Changing the trigger needs a migration and is left out of this PR.

Test plan

  • bunx vitest run tests/direct-offer.unit.test.ts: unset, 36500, invalid values, direct offer
  • bunx vitest run tests/*.unit.test.ts (8507 passed)
  • bunx tsc --noEmit -p tsconfig.backend.json, eslint, bun run check:plugin-runtime
  • CI