Repository navigation
feat(registry): add onComponentRequest hook - #1602
Merged
Merged
Conversation
Lets registry owners apply their own per-request policy (e.g. rejecting outdated component versions) once the requested version has been resolved, without baking that policy into OC itself. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The hook's latestVersion getter re-ran semver over every published version on each read. Memoise it against the components cache's version array, which is replaced (not mutated) on publish/poll, so it is only recomputed when the list changes. Unversioned requests reuse the same cache. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
A nested renderComponent rejection (e.g. from onComponentRequest) reaches the parent data provider as a string, which produced an empty "Component execution error: " message. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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
Adds an
onComponentRequestregistry option so registry owners can apply their own policy to component requests after OC has resolved the version. The motivating case is rejecting outdated versions for security reasons. That policy belongs to each registry, not to OC, so this adds a generic hook rather than built-in version rules.name,requestedVersion, the resolvedversion,latestVersion,component(its package.json, includingallVersions),headers,parametersandaction.latestVersion: uses the same rule OC applies to unversioned requests, so pre-releases are excluded. It is computed only when the hook reads it, and the result is cached per component version list (aWeakMapkeyed on the list held by the components cache). It is recalculated only when that list changes after a publish or poll, which takes a read from ~190 µs to ~9 ns at 500 versions. Unversioned requests use the same cache, so they also stop recalculating the latest version on every request.{ status?, code?, error? }rejects it; the defaults are403andCOMPONENT_REQUEST_REJECTED. The hook may also return a Promise.500with codeCOMPONENT_REQUEST_HOOK_FAILED, and anerrorevent is fired. Requests are not let through when the hook fails.get-component.ts, so it coversGET /:name/:version, batchPOST /, actions, nestedrenderComponentcalls andaccept: application/vnd.oc.info+jsonrequests. If no hook is configured, nothing changes.renderComponentproduces, that string is now included in the error message. Previously the message wasComponent execution error:with nothing after it.detailsis unchanged.Not covered (open for discussion)
/:name/:version/~info,~previewand versioned static assets (component-static.ts) don't useget-component.ts, so the hook doesn't run for them.fallbackRegistryUrldon't go through the hook, because no local package.json is available for them.Test plan
npm run build(biome + tsc)npm run test-silent: 1175 passingregistry-routes-component.js): context contents, pass-through, sync and async rejection, default values, sync throw, async rejection, info-header requestsregistry.js): a real registry rejects onGET, rejects only the matching item in a batchPOST /, and runs the hook for nested rendersversion-handlerand repository tests for the cached latest version, including that changes to the per-requestallVersionscopy don't affect itGenerated with Devin