Help us shape the future of Go! Take the 2026 Go Developer Survey

npm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package npm serves the npm registry of npm repositories at /artifactory/api/npm/{repoKey}/ (decision 0034), mounted through the router kit (decision 0032). Packuments and version manifests are built on each request from what the npm format keeps in the package index, and tarballs download through the item routes' download, so redirects and download counts apply to them as to any file. A publish stores the tarball through the item service, whose npm format indexes it as it indexes a REST deploy.

Index

Constants

View Source
const DefaultLoginTokenExpiry = 30 * 24 * time.Hour

DefaultLoginTokenExpiry is decision 0034's default npm.login_token_expiry: the month a token from npm login lasts on 7.x (KB 000006713).

View Source
const DefaultMaxPublishSize = 1 << 30

DefaultMaxPublishSize is decision 0034's default npm.max_publish_size.

Variables

This section is empty.

Functions

func AuthLines

func AuthLines(c Credential) string

AuthLines is GET /api/npm/auth's answer: _auth with the base64 of user:<encrypted password> for a Basic caller, as 7.x's documentation shows it, or _authToken for a token caller. 7.161.26 stopped sending the always-auth and email lines (RTDEV-96526).

func Protocol

func Protocol(o Options) pkgroute.Protocol

Protocol is npm's registry protocol.

func ScopeAuthLines

func ScopeAuthLines(scope, registry string, c Credential) string

ScopeAuthLines is GET /api/npm/{repoKey}/auth/{scope}'s answer: the scope mapped to registry, the repository's registry URL ending in a slash, then the credential keyed to that URL less its scheme, so npm sends it to that registry alone. A Basic caller gets _password, the base64 of the encrypted password, and username, as 7.x's documentation shows them; the email and always-auth lines went in 7.161.26.

func ValidScope

func ValidScope(scope string) bool

ValidScope reports whether scope, without its @, can name an npm scope: npm accepts it in a scoped name. A scope is written into .npmrc, so anything else, a line break among it, is refused.

Types

type Accounts

type Accounts struct {
	// Passwords verifies the user name and password a login sends. Nil
	// answers login 501.
	Passwords Passwords
	// Tokens issues a login's token and revokes the one a logout names.
	// Nil answers login 501, and logout revokes nothing.
	Tokens Tokens
	// TokenExpiry is how long a login's token lasts
	// (npm.login_token_expiry); zero means DefaultLoginTokenExpiry.
	TokenExpiry time.Duration
}

Accounts is what npm's legacy login and logout need from the server: the authenticator that checks every other password login, and the token service (decision 0005).

type Credential

type Credential struct {
	// User and Password are set for a Basic caller. Password is the
	// caller's encrypted password (DV-004) when it sent its password, and
	// the token it sent when it sent one as the password: never a password.
	User, Password string
	// Token is set for a token caller, to the token it sent.
	Token string
}

Credential is what GET /api/npm/auth and its scoped form write into .npmrc for a caller (decision 0034): a user name and the secret that stands for the password, for a caller that sent Basic credentials, or the token a caller sent as Bearer or X-JFrog-Art-Api.

type Options

type Options struct {
	// Accounts verifies the passwords npm login sends and keeps the tokens
	// it issues.
	Accounts Accounts
	// MaxPublishSize is the largest publish request accepted
	// (npm.max_publish_size); zero means DefaultMaxPublishSize.
	MaxPublishSize int64
	// Format are the npm format's settings, which a read applies when it
	// resolves latest itself, as the format would settle it.
	Format npmfmt.Settings
}

Options are the npm registry's settings.

type Passwords

type Passwords interface {
	Basic(ctx context.Context, name, password string) (auth.Principal, error)
	Token(ctx context.Context, raw, user string) (auth.Principal, error)
}

Passwords verifies credentials as the server's middleware does (*auth.Authenticator).

type Tokens

type Tokens interface {
	Issue(ctx context.Context, r token.Request) (token.Issued, error)
	RevokeValue(ctx context.Context, raw string) error
}

Tokens issues and revokes access tokens (*token.Service).

Jump to

Keyboard shortcuts

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