npm

package
v0.15.21 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 10 Imported by: 0 modules, 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

Overview

Package npm is the npm registry credential provider: the access tokens npm has issued since 2021 (npm_…) and the UUID tokens before them.

Neither carries a checksum. The new format is matched on prefix, length and alphabet; a legacy UUID is only a token as the `_authToken` of an .npmrc line, since a bare UUID is anything. An .npmrc line also names the registry the token is for, which may be a private one: verification and revocation then go there instead of registry.npmjs.org. A token is revoked with itself, through the same endpoint `npm token revoke` uses.

Index

Constants

View Source
const (
	// KindAccessToken is an access token of the current format (npm_).
	KindAccessToken detect.Kind = "npm-access-token"
	// KindLegacyToken is a UUID token from before 2021, only recognised as
	// the _authToken of an .npmrc line.
	KindLegacyToken detect.Kind = "npm-legacy-token"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// RegistryURL is the public registry, https://registry.npmjs.org by
	// default; a token found in an .npmrc line for another registry is
	// checked against that one.
	RegistryURL string
	Client      *http.Client
	// Policy decides which private registries named in scanned content may
	// be contacted.
	Policy detect.ServerPolicy
}

Provider implements detect.Provider, detect.Revoker, detect.DryRunRevoker and detect.ServerVerifier for npm.

func New

func New() *Provider

New returns a Provider against the public npm registry.

func (*Provider) AllowPrivateServers

func (p *Provider) AllowPrivateServers(allow bool)

AllowPrivateServers implements detect.ServerVerifier.

func (*Provider) DryRunRevoke

func (p *Provider) DryRunRevoke(ctx context.Context, tok detect.Token) error

DryRunRevoke implements detect.DryRunRevoker: it authenticates with the token and looks it up in the account's list, exactly what Revoke does before deleting, and stops there. A registry that does not list the token (granular tokens are not listed) still accepts the deletion by value, so that is not a failure.

func (*Provider) Find

func (*Provider) Find(content []byte) []detect.Token

Find implements detect.Provider. One substring pass finds the npm_ prefix; each candidate is checked for 36 alphanumerics standing on their own. One more pass finds `_authToken`, whose value is a token whatever its shape: a UUID there is a legacy token, and an npm_ token there learns which registry the line is for.

func (*Provider) Kinds

func (*Provider) Kinds() []detect.KindInfo

Kinds implements detect.Provider. Both kinds revoke themselves through the registry's token API.

func (*Provider) LocalSources

func (*Provider) LocalSources() detect.LocalSources

LocalSources implements detect.Provider: the user's .npmrc, and the environment variables the npm CLI, setup-node and CI templates read. The project's .npmrc in the working directory is checked for every provider.

func (*Provider) Name

func (*Provider) Name() string

Name implements detect.Provider.

func (*Provider) Revoke

func (p *Provider) Revoke(ctx context.Context, tokens []detect.Token) error

Revoke implements detect.Revoker through the registry's token API, one DELETE per token, authenticated with the token itself: the endpoint `npm token revoke` uses accepts the token value as the key. A registry that only takes the record's key gets a second DELETE with the key the token list shows for it. A 200 or 204 means the token is gone; the caller confirms with Verify.

func (*Provider) Verify

func (p *Provider) Verify(ctx context.Context, tok detect.Token) detect.Verification

Verify implements detect.Provider with one GET /-/whoami on the token's registry, the public one unless the .npmrc line named another. A live token then looks itself up in the account's token list to say whether it can publish; a granular token may not list tokens, which changes nothing about it being live. Only a 401 is revoked.

Jump to

Keyboard shortcuts

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