Add package toggles and move config to ottabase.config.ts - #123
Conversation
…ute guards The shareable monorepo config migration was incomplete in two key areas: 1. Config pipeline gap: email and authBehavior settings defined in ottabase.config.ts were silently ignored because AppConfig, ConfigOptions, createAppConfig(), and userConfigToOptions() all lacked support for these fields. Now the full chain works: ottabase.config.ts → userConfigToOptions → createAppConfig → AppConfig with env var overrides for backward compat. 2. Package route guarding: disabling a package via packages.ottablog: false only removed its DB tables from migrations but left API routes active, causing 500 errors on access. Now all package-specific routes in the worker router check PACKAGES toggles and return a clear 404 with PACKAGE_DISABLED code when the package is off. Additional fixes: - Migrate queue/handlers.ts from raw env vars to worker-config imports - Update bootstrap wizard to reflect EMAIL_FROM moving to ottabase.config.ts - Update email route provider info to reference config instead of env vars - Add DEFAULT_EMAIL_CONFIG, DEFAULT_AUTH_BEHAVIOR_CONFIG constants - Export AUTH_BEHAVIOR_CONFIG and EMAIL_CONFIG from app.config.ts - Add PACKAGES toggle export to worker-config.ts https://claude.ai/code/session_01VrsgTM282BW4TFws7ZfnkE
Framework files contained 'Ottabase' and 'ottabase-template-app-tanstack'
literals that forced users to hand-edit framework code to rebrand — exactly
what the shareable monorepo design was meant to avoid.
Changes:
- log.config.ts: 3 occurrences of hardcoded app name → APP_ID from config
- appState.ts: hardcoded appName 'Ottabase' → APP_NAME from config
- router.ts: /api/health name + analytics defaultAppId → APP_NAME/APP_ID
- BrandFooter.tsx: 'Built with Ottabase' → 'Built with {APP_NAME}'
- docs.config.ts: 'Ottabase Docs' → '{APP_NAME} Docs'
Now users only edit ottabase.config.ts to rebrand the entire app.
https://claude.ai/code/session_01VrsgTM282BW4TFws7ZfnkE
There was a problem hiding this comment.
Pull request overview
This PR introduces package-level feature toggles (to enable/disable built-in Ottabase packages) and migrates non-secret email/auth behavior settings from runtime environment variables into ottabase.config.ts, while also standardizing usage of APP_ID/APP_NAME constants across the app.
Changes:
- Added
cfg.packages-driven package toggles and enforced them via route guards (plus conditional shortlink fallback handling). - Added
emailandfeatures.authBehaviorconfiguration to@ottabase/configtypes + config creation/merging (with env var overrides increateAppConfig()). - Replaced hardcoded app identifiers/names in several server + client locations with shared config constants.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/config/src/types.ts | Adds EmailConfig/AuthBehaviorConfig and wires them into AppConfig/OttabaseUserConfig. |
| packages/config/src/index.ts | Introduces defaults + env key constants for email/auth behavior. |
| packages/config/src/createAppConfig.ts | Merges new email and features.authBehavior sections (with env overrides) and maps user config into options. |
| apps/ottabase-template-app-tanstack/worker/routes/router.ts | Adds package guards for blog/shortlinks/referrals/brandEngine and standardizes health/appId usage. |
| apps/ottabase-template-app-tanstack/worker/routes/email.ts | Updates provider metadata and switches sender/region sourcing to build-time config constants. |
| apps/ottabase-template-app-tanstack/worker/lib/worker-config.ts | Adds PACKAGES toggle object and centralizes build-time config access for worker/server. |
| apps/ottabase-template-app-tanstack/worker/bootstrap/pages.ts | Updates bootstrap wizard guidance for email config location. |
| apps/ottabase-template-app-tanstack/src/pages/docs/docs.config.ts | Uses APP_NAME in docs title. |
| apps/ottabase-template-app-tanstack/src/ottabase/state/appState.ts | Uses APP_NAME for app state initialization. |
| apps/ottabase-template-app-tanstack/src/ottabase/config/log.config.ts | Uses APP_ID in log context instead of a hardcoded string. |
| apps/ottabase-template-app-tanstack/src/ottabase/config/app.config.ts | Exposes AUTH_BEHAVIOR_CONFIG and EMAIL_CONFIG from computed app config. |
| apps/ottabase-template-app-tanstack/src/ottabase/components/layout/BrandFooter.tsx | Uses APP_NAME in the footer text. |
| apps/ottabase-template-app-tanstack/ottabase/queue/handlers.ts | Switches queue mailer config to use build-time email config constants. |
| apps/ottabase-template-app-tanstack/cloudflare-worker.ts | Conditionally enables shortlink fallback behavior based on package toggle. |
| trackClicks: getBoolEnv('REFERRALS_TRACK_CLICKS', defaults.features?.referrals?.trackClicks ?? true), | ||
| expiryDays: getNumberEnv('REFERRALS_EXPIRY_DAYS', defaults.features?.referrals?.expiryDays ?? 30), | ||
| }, | ||
| authBehavior: { | ||
| sessionMaxAge: getNumberEnv( | ||
| 'AUTH_SESSION_MAX_AGE', | ||
| defaults.features?.authBehavior?.sessionMaxAge ?? 30 * 24 * 60 * 60, | ||
| ), | ||
| requireEmailVerified: getBoolEnv( | ||
| 'AUTH_REQUIRE_EMAIL_VERIFIED', | ||
| defaults.features?.authBehavior?.requireEmailVerified ?? false, | ||
| ), | ||
| disableCredentials: getBoolEnv( | ||
| 'AUTH_DISABLE_CREDENTIALS', | ||
| defaults.features?.authBehavior?.disableCredentials ?? false, | ||
| ), | ||
| verbose: getBoolEnv('AUTH_VERBOSE', defaults.features?.authBehavior?.verbose ?? false), | ||
| }, | ||
| }, | ||
|
|
||
| email: { | ||
| from: getEnv('EMAIL_FROM', defaults.email?.from ?? 'noreply@example.com'), | ||
| sesRegion: getEnv('AWS_REGION', defaults.email?.sesRegion ?? 'us-east-1'), | ||
| }, |
There was a problem hiding this comment.
New config-merging logic was added for features.authBehavior and email (including env var overrides), but the existing config tests don’t assert these fields. Adding tests that cover defaults and env override behavior for these new sections would help prevent regressions.
|
@copilot open a new pull request to apply changes based on the comments in this thread. Once done, ensure tests are up to date and pass 100%, |
…uthBehavior/email config tests (#124) * fix: address PR review comments - unused imports, email API backward compat, add config tests
…)" This reverts commit 2e116c1.
Summary
This PR introduces package-level feature toggles and migrates email and auth behavior configuration from environment variables to
ottabase.config.ts. It enables users to selectively enable/disable built-in packages (ottablog, shortlinks, referrals, brandEngine) and centralize non-secret configuration in the config file.Key Changes
Package Toggles
PACKAGESconstant inworker/lib/worker-config.tsthat reads fromcfg.packagesconfigurationworker/routes/router.ts) that return a 404 withPACKAGE_DISABLEDerror code when a disabled package is accessedcloudflare-worker.tsto conditionally enable shortlink fallback handlingConfiguration Migration
EMAIL_FROMandAWS_REGION(SES) from environment variables toottabase.config.tsunderemailsection with defaultsAUTH_SESSION_MAX_AGE,AUTH_REQUIRE_EMAIL_VERIFIED,AUTH_DISABLE_CREDENTIALS, andAUTH_VERBOSEtoottabase.config.tsunderfeatures.authBehaviorcreateAppConfig()to read these values from config with environment variable overridesDEFAULT_EMAIL_CONFIGandDEFAULT_AUTH_BEHAVIOR_CONFIGconstantspackages/config/src/types.tsto includeEmailConfigandAuthBehaviorConfigCode Consolidation
'ottabase-template-app-tanstack') withAPP_IDandAPP_NAMEconstants throughout:Implementation Details
PACKAGE_DISABLEDcodehttps://claude.ai/code/session_01VrsgTM282BW4TFws7ZfnkE