Optimize env.ts and eliminate dependency cycles in webapp#151
Draft
seansica wants to merge 27 commits intohijohnnylin:mainfrom
Draft
Optimize env.ts and eliminate dependency cycles in webapp#151seansica wants to merge 27 commits intohijohnnylin:mainfrom
env.ts and eliminate dependency cycles in webapp#151seansica wants to merge 27 commits intohijohnnylin:mainfrom
Conversation
…orts
- Introduce ts-oss/ts-env for handling runtime environment variables
- Introduce Zod for parsing and validating runtime environment variables
BREAKING CHANGE: Individual environment variable exports are no longer available.
Import { env } instead and use env.VARIABLE_NAME to access values.
- lib/env.ts was refactored to stop exporting individual env variables
- Refactored all dependent modules to import { env } and use
env.VARIABLES_NAME pattern
Refactored remaining dependent modules to import { env } and use
env.VARIABLES_NAME pattern
This is the recommended setting in TypeScript 5.0+ for applications that use a bundler
…nstants - Declare config values which are derived in createEnv using Zod transforms - Migrate constants to separate module BREAKING CHANGE: Downstream services must update their imports
Change to in Session interface augmentation
Additionally remove old OPENROUTER_BASE_URL declaration in one of the routers
Resolves a linting error that came up during build
…ces to new module - Resolves linting error 'import/no-cycle' caused by a dependency loop between lib/with-user.ts and lib/db/user.ts - Decouples mutually dependent interfaces into new module, lib/types/auth.ts BREAKING CHANGE: Breaks a ton of downstream routers that rely on RequestOptionalUser, RequestAuthedUser, and RequestAuthedAdminUser. These will need to be refactored to import from the new lib/types/auth module.
…om new lib/types/auth.ts
- Resolves the following two linting errors in autointerp-shared.ts - Cannot find module '@anthropic-ai/sdk/resources' or its corresponding type declarations.ts(2307) - Cannot find module 'openai/resources' or its corresponding type declarations.ts(2307)
This popped up as a linting error at some point.
This popped up as a linting error at some point.
…and authOptions - Moved functions that were causing the cycle to a new module, lib/auth/utils.ts - Refactored all downstream/dependent modules to import from the new path Tested and confirmed app can be built via 'npm run build:localhost'
…ble-handling-improvements
- Update import paths for constants (some were still importing from env) - Add missing environment variables GRAPH_SERVER_QWEN3_4B and GRAPH_RUNPOD_SERVER_QWEN3_4B
…ble-handling-improvements
…ble-handling-improvements
…ports - Replace direct env var imports with centralized env object - Add missing import statements for error constants and types - Remove duplicate ASSET_BASE_URL import - Fix import organization and formatting inconsistencies - Remove trailing whitespace and formatting issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Today, the webapp does not properly handle environment variables at runtime. There is no clear line of separation between runtime variables intended for the client versus the server. Parsing and validation are missing or minimal, and each variable is independently exported which is tedious to maintain and difficult to read.
In addition, there exists several dependency cycles in the webapp. The linter will catch them lest they be ignored by in-line bypass statements. This PR resolves two of them. The following still remain:
Fix
t3-oss/env-nextjsand Zod for parsing and validating environment variables at runtime.NEXT_PUBLIC_. ships to the client). This will (hopefully) help to eventually eliminate server-side variables from shipping to the client altogether (just a best practice).lib/consants.tslib/env.ts.envobject; this way we don't have to export every environment variable individually (see screenshot)Testing
I can successfully build the app via
npm run build:localhoston an Ubuntu VM. There are no linting errors. However, given how many files are touched, additional, extensive testing is recommended.