refactor: unify the request pipeline in VaultClient#118
Merged
Conversation
Extend __resolveAndRequest(op, method, path, data, extraHeaders, options)
into the single entry point for the auth-token -> headers -> resolve-mount
-> rewrite-path -> make-request pipeline:
- update() delegates with the merge-patch Content-Type header and
{ wrapData: true }, keeping its always-on { data } envelope on every
engine version
- __v2Only() delegates with { v2Only: true }, keeping the KV v2 version
assertion ahead of any HTTP request
- request() routes through { raw: true }, which skips mount resolution
and path rewriting for literal passthrough
resolver.resolve() now has exactly one call site in VaultClient (down
from three). Pure refactor with zero behavior change: the pre-existing
unit suite passes unmodified, and new characterization tests pin the
pipeline behavior across v1/v2 mounts x namespace x extra headers,
including the byte-for-byte v1 path passthrough and the exact
UnsupportedOperationError message.
The ~8x copy-pasted catch/log/rethrow in the public methods is left
untouched on purpose; extracting it is a follow-up (see #110).
Closes #110
Signed-off-by: Yuriy R <22548029+kurok@users.noreply.github.com>
072fc66 to
e0c2ec3
Compare
m2broth
approved these changes
Jul 2, 2026
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.
Summary
Fixes #110. The resolve-mount → rewrite-path → make-request pipeline was implemented three times in
src/VaultClient.js(__resolveAndRequest,update(),__v2Only()), withrequest()carrying a partial fourth copy. Any cross-cutting change (retries, per-request headers, a new engine version) had to be applied identically in each copy. This PR extends__resolveAndRequest(op, method, path, data, extraHeaders, options)into the single entry point and makes the other three delegate to it. Pure refactor — zero behavior change.Changes
src/VaultClient.js__resolveAndRequestgains anoptionsparameter:{ raw }(skip resolution/rewriting — literal passthrough),{ v2Only }(KV v2 version assertion before any HTTP request),{ wrapData }(force the{ data }envelope on every engine version — merge-patch semantics)update()is now a delegation passing theapplication/merge-patch+jsonheader and{ wrapData: true }(its envelope has always applied on v1 too — preserved)__v2Only()delegates with{ v2Only: true }, keeping the exactUnsupportedOperationErrormessage and its assert-before-request orderingrequest()routes through{ raw: true }grep -c "resolver.resolve(" src/VaultClient.jsdrops to 1 (was 3)test/VaultClient.pipeline.test.mjs(new) — 21 characterization tests written before the refactor and verified green against the old code, pinning v1/v2 × namespace × extra-headers behavior: byte-for-byte v1 path passthrough (incl. trailing slash),update()'s always-on envelope on v1, rawrequest()never consulting the resolver, exact v2-only error message, noX-Vault-Namespaceleakage into per-request headersCHANGELOG.md— bullet under a new# Unreleasedheading (no version bump)Note: sibling PRs (#116 and the in-flight PRs for #109/#111) also add
# Unreleasedbullets, so a trivial CHANGELOG rebase conflict is possible.Verification
npm run lint— cleannpm run test:unit— 276 passing (255 pre-existing tests unmodified + 21 new)npm run coverage— 98.5% statements / 95.57% branches / 100% functions / 98.5% lines (thresholds 97/93/100/97)npm run test:e2eagainst a real Vault 1.17.6 dev server (KV v1) — 6 passing, 1 pendingnpm run test:e2e:kv2against a real Vault dev server (KV v2) — 10 passingType of change
Checklist
npm run lint && npm testpasses locally# UnreleasedinCHANGELOG.mdSigned-off-by:trailer (git commit -s)