feat: add remote Hyphen ENV loading - #151
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #151 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 8 9 +1
Lines 492 639 +147
Branches 105 146 +41
==========================================
+ Hits 492 639 +147 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces the Env service to securely fetch, decrypt, and load environment variables from Hyphen into process.env, along with corresponding documentation, integration into the main Hyphen class, and comprehensive unit tests. The review feedback highlights a critical compatibility issue: importing parseEnv directly from node:util will cause runtime crashes on Node.js versions prior to v20.12.0 (such as Node.js 18). To resolve this, it is recommended to import the util namespace dynamically and implement a lightweight fallback parser for older Node.js environments.
Summary
Envservice that fetches encrypted ENV data from Horizon and keys from VinzparseEnv, and updateprocess.envatomicallyhyphen.env, root exports, API-key propagation, and service event forwardingenv()andloadEnv()helpersUsage
Load through
HyphenA named load fetches both the default and named ENV documents. Named values win, and remote values overwrite matching
process.enventries after both documents have loaded, decrypted, and parsed successfully.Use load options to change those defaults:
includeDefault: falsefetches only the named environment.override: falsepreserves variables already present inprocess.env. The returned record still contains all fetched remote values.Use
EnvdirectlyConfigure from environment variables
Options can be omitted when these variables are available:
When running with Hyphen Deploy, the SDK also uses the automatically provided
HYPHEN_PROJECT_NAME,HYPHEN_APP_NAME, andHYPHEN_APP_ENVIRONMENTvariables as fallbacks. Explicit options and ID variables retain precedence, anddefaultis used when no environment is supplied.Bypass Vinz with an explicit decryption key
Providing
decryptionKeyskips the Vinz request, soprojectIdis not required.The synchronous local-file
env()andloadEnv()helpers remain unchanged.Testing
pnpm test— 295 tests passed with 100% statements, branches, functions, and linespnpm build— ESM, CJS, and type declarations built successfully