Skip to content

Add package toggles and move config to ottabase.config.ts - #123

Merged
thinkdj merged 3 commits into
copilot/make-monorepo-flexiblefrom
claude/shareable-monorepo-BvhnT
Feb 26, 2026
Merged

thinkdj merged 3 commits into
copilot/make-monorepo-flexiblefrom
claude/shareable-monorepo-BvhnT

Conversation

@thinkdj

@thinkdj thinkdj commented Feb 26, 2026

Copy link
Copy Markdown
Owner

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

  • Added PACKAGES constant in worker/lib/worker-config.ts that reads from cfg.packages configuration
  • Implemented package guards throughout the router (worker/routes/router.ts) that return a 404 with PACKAGE_DISABLED error code when a disabled package is accessed
  • Protected routes for: ottablog, shortlinks, referrals, and brandEngine across GET, POST, PATCH, DELETE, and PUT handlers
  • Added package check in cloudflare-worker.ts to conditionally enable shortlink fallback handling

Configuration Migration

  • Email Configuration: Moved EMAIL_FROM and AWS_REGION (SES) from environment variables to ottabase.config.ts under email section with defaults
  • Auth Behavior: Moved AUTH_SESSION_MAX_AGE, AUTH_REQUIRE_EMAIL_VERIFIED, AUTH_DISABLE_CREDENTIALS, and AUTH_VERBOSE to ottabase.config.ts under features.authBehavior
  • Updated createAppConfig() to read these values from config with environment variable overrides
  • Added DEFAULT_EMAIL_CONFIG and DEFAULT_AUTH_BEHAVIOR_CONFIG constants
  • Updated type definitions in packages/config/src/types.ts to include EmailConfig and AuthBehaviorConfig

Code Consolidation

  • Replaced hardcoded app name strings ('ottabase-template-app-tanstack') with APP_ID and APP_NAME constants throughout:
    • Health check endpoint
    • Log configuration (dev and prod)
    • App state initialization
    • Footer component
    • Docs page title
    • Analytics tracking
  • Updated email provider documentation to reference the new config location instead of environment variables

Implementation Details

  • Package guards are checked at route entry points before handler execution
  • All disabled package responses use consistent error format with PACKAGE_DISABLED code
  • Configuration maintains backward compatibility with environment variable overrides
  • Email configuration is now centralized but still respects provider-specific env vars (API keys, credentials)

https://claude.ai/code/session_01VrsgTM282BW4TFws7ZfnkE

…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
Copilot AI review requested due to automatic review settings February 26, 2026 13:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 email and features.authBehavior configuration to @ottabase/config types + config creation/merging (with env var overrides in createAppConfig()).
  • 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.

Comment thread packages/config/src/createAppConfig.ts Outdated
Comment on lines 156 to 179
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'),
},

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 uses AI. Check for mistakes.
Comment thread apps/ottabase-template-app-tanstack/worker/routes/email.ts
@thinkdj

thinkdj commented Feb 26, 2026

Copy link
Copy Markdown
Owner Author

@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%,

Copilot AI commented Feb 26, 2026

Copy link
Copy Markdown

@thinkdj I've opened a new pull request, #124, to work on those changes. Once the pull request is ready, I'll request review from you.

…uthBehavior/email config tests (#124)

* fix: address PR review comments - unused imports, email API backward compat, add config tests
@thinkdj
thinkdj merged commit 2e116c1 into copilot/make-monorepo-flexible Feb 26, 2026
5 checks passed
thinkdj added a commit that referenced this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants