refactor(config): enhance config with @clevercloud/reglage - #1081
Open
pdesoyres-cc wants to merge 8 commits into
Open
refactor(config): enhance config with @clevercloud/reglage#1081pdesoyres-cc wants to merge 8 commits into
pdesoyres-cc wants to merge 8 commits into
Conversation
pdesoyres-cc
force-pushed
the
enhance-config
branch
2 times, most recently
from
April 10, 2026 14:34
13ca0ae to
763778f
Compare
|
🔎 A preview has been automatically published! If you created the alias to the preview script, you can run this command to download and install this preview: clever-preview update enhance-configYou can also run it from your local repository: ./scripts/preview.js update enhance-config
This preview will be deleted once this PR is closed. |
pdesoyres-cc
force-pushed
the
enhance-config
branch
from
April 10, 2026 14:38
763778f to
d169518
Compare
pdesoyres-cc
force-pushed
the
enhance-config
branch
from
May 4, 2026 17:20
d169518 to
4e095e6
Compare
added 8 commits
May 6, 2026 11:03
Introduce a Config class that holds the config data and exposes a typed `get()` method with proper Zod type inference. This replaces the previous mutate-in-place reload strategy (delete all keys + Object.assign) with a clean `reload()` that swaps the inner reference. This is needed for the integration of @clevercloud/reglage, which provides immutable config instances that cannot be mutated in place. The Config wrapper lets us swap the immutable inner object on reload while keeping the same singleton reference for all consumers.
Replace all direct property accesses (config.API_HOST, baseConfig.TOKEN, etc.)
with config.get('API_HOST'), baseConfig.get('TOKEN'), etc. across the codebase.
This ensures all consumers go through the Config class accessor, which is
required for the reglage integration where the underlying config object
is immutable and gets swapped on reload.
Split Config into BaseConfig (Zod-validated config values) and Config
(extends BaseConfig with profiles/activeProfile as dedicated properties).
Profiles are auth-related runtime state, not configuration values —
they no longer pass through the Zod schema. loadConfig() now returns
{ data, profiles } separately, and reloadConfig() updates each independently.
Update all consumers to use the new Config properties instead of
config.get('profiles'), config.get('token'), config.get('secret').
Profiles and auth credentials are now accessed through config.profiles,
config.activeProfile, and config.activeProfile?.token/secret.
Replace the hand-rolled Zod schema + safeParse approach with @clevercloud/reglage's createConfigBuilder, gaining named sources, refine-based derived keys, secret marking, and structured toString output. Remove now-unnecessary test helpers and add coverage for explicit CONSOLE_TOKEN_URL / GOTO_URL overrides
pdesoyres-cc
force-pushed
the
enhance-config
branch
from
May 6, 2026 09:03
4e095e6 to
0fa8935
Compare
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.
Context
The config module was hand-rolled around a Zod schema plus
safeParse, with a few sharp edges thatmade it awkward to extend:
deleteevery key, thenObject.assign) so consumers thatimported
configsaw fresh values. Fragile, and incompatible with any immutable config object.auth-related runtime state, not user-facing config.
reaching for ad hoc.
@clevercloud/reglageis a purpose-built config builder that gives us all of the above out of thebox. Adopting it lets us delete the bespoke validation/merge code and gain better diagnostics
(per-source error attribution, structured
toString, secret redaction) for free.Changes
Configclass exposing a typedget(key)accessor.reload()now swaps theinner config reference instead of mutating fields in place.
config.API_HOST/config.TOKEN/ etc. toconfig.get('API_HOST'),config.activeProfile?.token, and so on.BaseConfig(validated config values) fromConfig(addsprofilesandactiveProfileasdedicated properties). The
$envvirtual profile derived fromCLEVER_TOKEN/CLEVER_SECRETlives here too.
safeParsepipeline withcreateConfigBuilderfrom@clevercloud/reglage.CONSOLE_TOKEN_URLandGOTO_URLbecomerefine-based derived keys offCONSOLE_URL; OAuthconsumer key/secret are marked
secret: true.priority, and reload semantics. Wire
npm testinto thevalidatescript and thecode-qualityCI workflow.Implementation notes
The
Configwrapper is the linchpin: reglage produces immutable config instances, so we cannotkeep mutating a shared object on reload. The wrapper lets every consumer hold a stable reference
to
configwhile the inner immutable object gets swapped onreloadConfig(). That is also whythe call-site migration to
get()is mandatory rather than cosmetic — direct property access onthe inner instance would skip the swap.
How to review
src/config/config.js— theBaseConfig/Configsplit,loadConfig(), andbuildConfig()are the load-bearing pieces.src/config/config.test.jsto see the contract that's now pinned down (defaults, envoverrides, derived keys, profile overrides, priority, reload).
npm testlocally to exercise the suite; CI now runs it via the new step in.github/workflows/code-quality.yml.src/models/send-to-api.js,src/commands/curl/curl.command.js,src/commands/login/login.command.js) to confirm theconfig.get(...)/config.activeProfilepattern reads cleanly.