npm

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AbbreviatedContentType = "application/vnd.npm.install-v1+json"

AbbreviatedContentType is the media type of the install-v1 (abbreviated) packument.

View Source
const AttachmentContentType = "application/octet-stream"

AttachmentContentType is the only content type npm publishes tarballs with.

View Source
const UpstreamAccept = AbbreviatedContentType + "; q=1.0, application/json; q=0.8, */*"

UpstreamAccept is the Accept header OpenArtifact sends upstream for an abbreviated packument (the value npm itself sends).

Variables

View Source
var ErrAllVersionsHidden = errors.New("every version of the packument is hidden")

ErrAllVersionsHidden is returned by HideVersions when it would hide every version of a packument that had some.

View Source
var ErrIntegrityMismatch = errors.New("npm tarball integrity mismatch")

ErrIntegrityMismatch reports tarball bytes that do not match the digest the packument advertises.

View Source
var ErrInvalidAttachment = errors.New("invalid npm attachment")

ErrInvalidAttachment reports a malformed _attachments entry of a publish body.

View Source
var ErrInvalidPackageName = errors.New("invalid npm package name")
View Source
var ErrInvalidPath = errors.New("not an npm registry path")

ErrInvalidPath reports a path that is not a registry packument, version or tarball path.

View Source
var ErrInvalidSemver = errors.New("invalid semver")
View Source
var ErrNotObject = errors.New("npm packument is not a JSON object")

ErrNotObject reports a packument that is not a JSON object.

Functions

func CheckAttachmentContentType added in v0.6.0

func CheckAttachmentContentType(ct string, ok bool) error

CheckAttachmentContentType validates the content_type of an attachment; ok is false when the field was absent or not a string.

func CheckAttachmentLength added in v0.6.0

func CheckAttachmentLength(declared int64, ok bool, actual int64) error

CheckAttachmentLength validates that the declared attachment length matches the number of decoded bytes; ok is false when the field was absent or invalid.

func ComparePrerelease added in v0.15.0

func ComparePrerelease(a, b string) int

ComparePrerelease orders two semver prerelease identifiers (semver 2.0.0, section 11): numeric identifiers numerically and below alphanumeric ones, alphanumeric ones lexically in ASCII order.

func ComputeIntegrity

func ComputeIntegrity(r io.Reader) (string, string, string, int64, error)

func HideVersions added in v0.16.0

func HideVersions(doc []byte, hide func(version string, published time.Time) bool) ([]byte, error)

HideVersions removes from a full packument every version hide reports true for. hide is asked about every version with its time entry (the zero time when the entry is absent or not an RFC 3339 time, so a rule that needs no date still applies): the version and its time entry go ("created" and "modified" stay), and a dist-tag that pointed at a removed version moves ("latest": to the highest remaining version that is not a prerelease, or the highest remaining one when only prereleases are left) or goes (every other tag). doc is returned as is when nothing is hidden; ErrAllVersionsHidden when nothing would be left of a packument that had versions.

func MergePackuments added in v0.6.0

func MergePackuments(docs [][]byte) ([]byte, error)

MergePackuments merges packuments of the same package in member priority order: versions are the union (the first member that has a version wins), each dist-tag comes from the first member that has it, time entries and every other top-level field likewise come from the first member that has them. A single document is returned unchanged.

func PublishedAt added in v0.16.0

func PublishedAt(doc []byte, version string) (time.Time, bool, error)

PublishedAt is the packument's time entry of version; ok is false when the packument has none for it or it is not an RFC 3339 time.

func RewriteTarballs added in v0.6.0

func RewriteTarballs(doc []byte, pkg, tarballBase string) ([]byte, error)

RewriteTarballs returns doc with every version's dist.tarball replaced by tarballBase + "/" + pkg + "/-/" + <filename of the old URL>, where tarballBase is "<server>/repos/<repo>". Integrity fields are untouched.

func TarballFileOf added in v0.6.0

func TarballFileOf(tarballURL string) string

TarballFileOf returns the filename of an upstream dist.tarball URL.

func ValidatePackageName

func ValidatePackageName(name string) error

func ValidateSemver

func ValidateSemver(v string) error

func VerifyDist added in v0.6.0

func VerifyDist(r io.Reader, d Dist) (bool, error)

VerifyDist hashes r and compares it with the digest in dist: dist.integrity (strongest listed SRI algorithm, any of its digests may match) or, when that is absent, dist.shasum. verified is false when dist advertises neither, in which case nothing was compared. A mismatch is ErrIntegrityMismatch.

func VersionManifest added in v0.6.0

func VersionManifest(doc []byte, versionOrTag string) ([]byte, bool, error)

VersionManifest extracts one version's manifest from a packument; versionOrTag is an exact version or a dist-tag.

func WantsAbbreviated added in v0.6.0

func WantsAbbreviated(accept string) bool

WantsAbbreviated reports whether the Accept header asks for the install-v1 (abbreviated) packument.

Types

type Dist added in v0.6.0

type Dist struct {
	Tarball   string `json:"tarball"`
	Integrity string `json:"integrity"`
	Shasum    string `json:"shasum"`
}

Dist is the dist object of one version.

type Path added in v0.6.0

type Path struct {
	Kind PathKind
	// Package is the decoded package name ("lodash", "@scope/name").
	Package string
	// Version is the version or dist-tag of a KindVersion path.
	Version string
	// File is the tarball filename of a KindTarball path.
	File string
}

Path is a parsed repository-relative registry path.

func ParsePath added in v0.6.0

func ParsePath(rel string) (Path, error)

ParsePath classifies a repository-relative path. The scope separator may be a literal "/" or an escaped %2f (npm sends "@scope%2fname" for packuments).

type PathKind added in v0.6.0

type PathKind int

PathKind classifies a registry request path.

const (
	// KindPackument is GET /<pkg>.
	KindPackument PathKind = iota + 1
	// KindVersion is GET /<pkg>/<version-or-tag>.
	KindVersion
	// KindTarball is GET /<pkg>/-/<file>.
	KindTarball
)

type Release added in v0.16.0

type Release struct {
	Version string
	// Published is the packument's time[Version]; zero when it is absent or
	// not an RFC 3339 time.
	Published time.Time
	Dist      Dist
}

Release is one version of a packument as a tarball lookup finds it.

func FindRelease added in v0.16.0

func FindRelease(doc []byte, pkg, file string) (Release, bool, error)

FindRelease locates the version whose dist.tarball has the given filename and returns that version's upstream tarball URL, integrity and shasum and its publish time. The version named by the conventional filename is tried first.

type VersionTime added in v0.16.0

type VersionTime struct {
	Version string
	// Published is the zero time when the packument has no RFC 3339 time entry for it.
	Published time.Time
}

VersionTime is one version of a packument with its time entry.

func Versions added in v0.16.0

func Versions(doc []byte) ([]VersionTime, error)

Versions lists the versions of a full packument with their time entries, in no particular order.

Jump to

Keyboard shortcuts

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