Skip to content

[Feature] vault refresh callback and helpers#55

Merged
thatkookooguy merged 4 commits into
betafrom
feature/vault-refresh-callback-and-helpers
Mar 7, 2026
Merged

[Feature] vault refresh callback and helpers#55
thatkookooguy merged 4 commits into
betafrom
feature/vault-refresh-callback-and-helpers

Conversation

@thatkookooguy

Copy link
Copy Markdown
Member

Description

  • onSecretRefreshed callback: New SecretRefreshEvent type and SecretRefreshCallback allowing consumers to react when Vault secrets are refreshed (e.g., reconnect a database pool). Can be registered via IVaultConfigOptions.onSecretRefreshed at construction or configService.onSecretRefreshed() at runtime.
  • Path-level atomic refresh: Refactored SecretRefreshManager so that all properties sharing the same Vault path (e.g., DB_USERNAME and DB_PASSWORD from database/creds/my-role) are updated from a single Vault read. This prevents credential mismatch where username comes from one lease and password from another. One callback event fires per path, listing all affected properties.
  • buildVaultConfigFromEnv() helper: New utility that builds IVaultConfigOptions from standard environment variables (VAULT_ADDR, VAULT_TOKEN, VAULT_GCP_ROLE). Returns undefined when Vault is not configured, so configit falls back to env vars/config files. Reduces boilerplate across microservices.
  • Bug fix: jest-stare 2.5.0 → 2.5.3 to fix util.isNullOrUndefined crash on Node 22+.
  • Test script fix: Corrected @VaultPath prefixes in test-vault-dynamic.ts that caused double-prefixed paths (secret/data/secret/data/...).

thatkookooguy and others added 3 commits February 3, 2026 15:50
## [2.12.2](v2.12.1...v2.12.2) (2026-02-03)

### Bug Fixes

* **vault:** register config instance for automatic refresh updates ([fe94863](fe94863))
- Add SecretRefreshEvent type and onSecretRefreshed callback to IVaultConfigOptions
- Refactor SecretRefreshManager to perform path-aware refresh: all properties
  sharing a Vault path are updated from a single read, preventing credential
  mismatch for database engine secrets (username/password)
- Fire one callback event per path refresh with affected properties list
- Wire callback through VaultIntegration and expose on ConfigService
- Add buildVaultConfigFromEnv() helper that builds IVaultConfigOptions from
  VAULT_ADDR, VAULT_TOKEN, and VAULT_GCP_ROLE environment variables
- Export new helpers and types from vault/index.ts
- Add unit tests for buildVaultConfigFromEnv (12 tests)
- Add integration tests for callback, path-level refresh, and dynamic secrets (7 tests)
- Fix test-vault-dynamic.ts VaultPath prefixes for correct Vault reads
- Update jest-stare 2.5.0 -> 2.5.3 to fix Node 22+ crash (util.isNullOrUndefined removed)

Made-with: Cursor
@codecov

codecov Bot commented Mar 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.69892% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.63%. Comparing base (109fd5e) to head (531be51).
⚠️ Report is 6 commits behind head on beta.

Files with missing lines Patch % Lines
src/vault/secret-refresh-manager.ts 94.02% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             beta      #55       +/-   ##
===========================================
+ Coverage   34.08%   47.63%   +13.55%     
===========================================
  Files          11       12        +1     
  Lines        1018     1079       +61     
  Branches      246      262       +16     
===========================================
+ Hits          347      514      +167     
+ Misses        610      565       -45     
+ Partials       61        0       -61     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- SecretRefreshManager: 19 tests covering path-level atomic
  refresh, callback registration, error handling, and status
- VaultIntegration callback wiring: 4 tests for constructor
  and runtime onSecretRefreshed delegation
- ConfigService.onSecretRefreshed: 2 tests for delegation
  and no-op when vault not configured

Raises secret-refresh-manager.ts from 0.81% to 95% coverage.

Made-with: Cursor
@thatkookooguy thatkookooguy merged commit 5306e8e into beta Mar 7, 2026
5 of 6 checks passed
@github-actions

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown

This PR is included in version 2.13.0-beta.1 🎉

The release is available on:

@github-actions

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown

This PR is included in version 2.13.0 🎉

The release is available on:

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.

2 participants