npm

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package npm transforms registry metadata without storage or network access.

Index

Constants

This section is empty.

Variables

View Source
var ErrVersionDenied = errors.New("package version blocked by denylist")
View Source
var ErrVersionNotFound = errors.New("version not found")

Functions

func Abbreviated

func Abbreviated(body []byte) bool

Abbreviated reports whether body is an abbreviated packument: one with the top-level "modified" field the abbreviated format carries and no "time" map, which cooldown needs. A full document without a time map, as some registries serve, is not abbreviated, and neither is anything that is not a JSON object.

func AttestationsURL

func AttestationsURL(proxyURL, packageName, version string) string

AttestationsURL returns the proxy URL that serves the attestations of a version, in the form the npm registry uses: the package name with its scope slash encoded, "@", and the version.

func Rewrite

func Rewrite(packageName string, body []byte, options Options) ([]byte, []string, error)

Rewrite filters upstream versions and points their tarball and attestation URLs at the proxy, preserving untouched JSON values verbatim. Hosted entries override upstream versions. The returned version set is unordered. The document, denylist and hosted entries are not modified.

func TarballURL

func TarballURL(proxyURL, packageName, version, tarball string) string

TarballURL returns the proxy URL that serves the tarball upstream lists at tarball for this version.

func Version

func Version(packageName, specifier string, packument []byte, options Options) ([]byte, error)

Version resolves a version or dist-tag through the filtered packument.

func VersionFromFilename

func VersionFromFilename(packageName, filename string) string

VersionFromFilename extracts a version from an npm tarball filename.

Types

type CooldownPolicy

type CooldownPolicy interface {
	Enabled() bool
	Evaluate(ecosystem, packagePURL string, publishedAt, evaluatedAt time.Time) cooldown.Decision
}

CooldownPolicy evaluates version age at the caller's supplied time.

type LocalVersion

type LocalVersion struct {
	Version     string
	Entry       json.RawMessage
	PublishedAt string
}

LocalVersion is an already approved hosted version and its publication time.

type Options

type Options struct {
	ProxyURL       string
	Cooldown       CooldownPolicy
	DeniedVersions map[string]bool
	EvaluatedAt    time.Time
	LocalVersions  []LocalVersion
	// Optional callbacks report changes synchronously without retaining events.
	// OnTarballsRewritten is called at most once per document, with how many
	// tarball URLs it pointed at the proxy, and not at all when none.
	OnTarballsRewritten func(count int)
	OnCooldownFilter    func(version, publishedAt string)
}

Options supplies the public URL, policy and hosted versions for a rewrite. EvaluatedAt is used as given; the transformation never reads the clock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL