Skip to content

npm: parse contentPolicy field into Version.Metadata - #50

Merged
andrew merged 2 commits into
mainfrom
npm-content-policy
Jul 29, 2026
Merged

npm: parse contentPolicy field into Version.Metadata#50
andrew merged 2 commits into
mainfrom
npm-content-policy

Conversation

@andrew

@andrew andrew commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

npm now lets maintainers declare dual-use content via a contentPolicy object in package.json, which propagates into the packument version object. Parse it as a typed *ContentPolicy and expose it under Metadata["npm:contentPolicy"] alongside npm:attestations and npm:signatures.

Announcement: https://github.blog/changelog/2026-07-28-npm-publish-time-malware-scanning-and-dual-use-metadata/
Policy: https://docs.npmjs.com/policies/dual-use

The packageResponse struct hunk is gofmt re-aligning columns; the file had drifted.

npm now lets maintainers declare dual-use content via a contentPolicy
object in package.json, propagated into the packument version object.
Parse it as a typed *ContentPolicy and expose it under
Metadata["npm:contentPolicy"] alongside attestations and signatures.

https://docs.npmjs.com/policies/dual-use

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support in the npm registry implementation for npm’s new contentPolicy metadata by decoding it into a typed Go struct and exposing it via core.Version.Metadata under a namespaced key.

Changes:

  • Parse the npm packument contentPolicy field into a typed *ContentPolicy on versionInfo.
  • Expose the parsed value as Metadata["npm:contentPolicy"] alongside existing npm:attestations and npm:signatures.
  • Add a unit test covering the round-trip behavior for contentPolicy.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/npm/npm.go Adds ContentPolicy parsing to versionInfo and publishes it as npm:contentPolicy in version metadata.
internal/npm/npm_test.go Adds tests for npm:contentPolicy being nil when absent and correctly populated when present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/npm/npm_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@andrew
andrew merged commit 4bba503 into main Jul 29, 2026
5 checks passed
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