fix: restore backward-compatible header constants #616
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.
What is the purpose of this pull request?
This PR restores backward compatibility for individual header constant exports (e.g.,
TENANT_HEADER,BINDING_HEADER,LOCALE_HEADER,SEGMENT_HEADER) that were removed in #579, causing breaking changes for apps that depend on@vtex/api. It also enhances test coverage for the introduced changes in #579.src/constants.tsHeaderKeyscounterpart (single source of truth)@deprecatednotices to guide developers toward the modernHeaderKeysAPIHeaderKeysobjectWhat problem is this solving?
PR #579 (commit b1952ce) migrated from individual header constant exports to a
HeaderKeysobject for standardization. This introduced a breaking change because:@vtex/apiundefinedinstead of header string valuesundefinedas header keys, silently failing to set/read critical headersx-vtex-tenant)ctx.vtex.tenantbecomesundefined, causing runtime errors when destructured without guardsThis led to errors like:
TypeError: Cannot read property 'locale' of undefinedwhen destructuring tenantctx.vtex.binding?.localeandctx.vtex.tenant?.localeare missingIn order to fix this, we re-export individual constants alongside the new
HeaderKeysobject, maintaining both APIs.The test suite now includes additional tests that validate real-world usage patterns observed in VTEX IO apps:
src/constants.test.ts:539-562): tests the pattern where constants are used as computed property keys in header objectsundefinedkeys are created, which was the root cause of the bugsrc/constants.test.ts:564-587): validates CommonJS if destructuring work correctlyundefinedafter destructuring (the exact bug we're fixing)src/constants.test.ts:589-615): verifies that individual constants work with theVaryHeaderstype that changed in Add diagnostics-semconv to standardize some attributes and headers #579VaryHeadersis expectedsrc/constants.test.ts:617-669): comprehensive test covering patterns observed in internal GraphQL apps. This ensures to test the full workflow: set headers → send request → read headers.src/service/worker/runtime/utils/context.ts(context preparation)src/HttpClient/HttpClient.ts(HTTP client header building)service-examplerepositoryHow should this be manually tested?
Build and test the package:
Screenshots or example usage
Types of changes