feat(EL-1458): let the host supply the bearer token and extra headers per request - #38
Conversation
Review-with-friends-but-good —
|
p-bartosz
left a comment
There was a problem hiding this comment.
Review: APPROVE ✅
Adds two optional IConfiguratorOptions hooks — accessTokenProvider (host-supplied bearer, nullish falls back to existing resolution) and additionalHeaders (per-request headers applied last) — both no-ops when absent. No must-fix issues found.
Checked, not just read:
fetchRequestis the onlyfetchcall in the package (ConfiguratorContext.ts:449) and every caller builds a freshRequest, so both hooks apply to all traffic and nothing bleeds between requests.setvsappendis right in both new spots: the bearer replaces rather than stacks, andadditionalHeadersoverwriting library-set headers is the documented intent, asserted atConfiguratorContext.spec.ts:296.- Purely additive to a published interface — no signature or contract changes for existing consumers, and the
else ifonly diverts requests where a host opts in by returning a token. - On the PR head: 43/43 jest tests pass,
tsc --noEmitclean,eslintclean,webpackbuild succeeds.
Non-blocking, for the record: the constructor guard at ConfiguratorContext.ts:51-58 early-returns before the apiUrl default at :78-80, so a host passing only accessTokenProvider (no tenantId/tenantDomain) gets apiUrl === undefined. That guard is pre-existing and untouched here, and the consumer in Elfsquad/showroom#389 always passes apiUrl + tenantDomain, so nothing in this PR regresses — worth a separate ticket rather than a change request. Same for the x-elfsquad-id drop when a token is supplied: deliberate, tested, and cheap to add one sentence to the accessTokenProvider JSDoc whenever this file is next touched.
The package-lock.json version drift (3.6.9 vs 3.6.11) is pre-existing on main and npm ci passes in CI.
JIRA TASK: EL-1458 - JWT / tenant via query params
Important
Related PRs, in merge order:
WHAT
Two optional
IConfiguratorOptions, both no-ops when absent:accessTokenProvider— supplies the bearer for every request instead of theAuthenticationContext. Returningnull/undefinedfalls back to the existing resolution, so the host decides per request.additionalHeaders— headers resolved per request and applied last, overwriting what the library sets itself.HOW
fetchRequestgains one branch and one loop. A provided token takes the authenticated path even underANONYMOUS_AND_USER_LOGIN, because a host-supplied token stands in for a signed-in user — otherwise the request would go out anonymously withx-elfsquad-idand the token would be ignored.Showroom V2 needs both: EMS launches the showroom with
?jwt=…&tenantId=…&organizationId=…, and today none of it can reach configurator traffic.x-elf-orgid/x-elf-tenantiddecide which organization's pricing and assortment the configuration resolves against, so without this the SDK's requests answer for the wrong organization whileapiClient's answer for the right one.FOOTNOTES / CAVEATS / WEIRD STUFF
format:checkstill reportsConfiguratorContext.tsandConfiguratorHttpError.ts— pre-existing onmain, and reformatting them would bury this diff. The lines added here are prettier-clean.package.jsonis bumped to 3.6.11;package-lock.jsonstill says 3.6.9, which it already did onmain.