Documentation
¶
Overview ¶
Package npm transforms registry metadata without storage or network access.
Index ¶
- Variables
- func Abbreviated(body []byte) bool
- func AttestationsURL(proxyURL, packageName, version string) string
- func Rewrite(packageName string, body []byte, options Options) ([]byte, []string, error)
- func TarballURL(proxyURL, packageName, version, tarball string) string
- func Version(packageName, specifier string, packument []byte, options Options) ([]byte, error)
- func VersionFromFilename(packageName, filename string) string
- type CooldownPolicy
- type LocalVersion
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrVersionDenied = errors.New("package version blocked by denylist")
var ErrVersionNotFound = errors.New("version not found")
Functions ¶
func Abbreviated ¶
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 ¶
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 ¶
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 ¶
TarballURL returns the proxy URL that serves the tarball upstream lists at tarball for this version.
func VersionFromFilename ¶
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.