Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-registry-client

Package Overview
Dependencies
Maintainers
2
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-registry-client - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

.eslintrc

86

lib/adduser.js

@@ -32,11 +32,9 @@ module.exports = adduser

// same as the user we're becoming now. replace them on error.
var pre = { username: this.conf.get('username')
, password: this.conf.get('_password')
, auth: this.conf.get('_auth')
var c = this.conf.getCredentialsByURI(base)
var pre = { username: c.username
, password: c.password
, email: c.email
, token: this.conf.get('_token') }
this.conf.del('_token')
this.conf.del('username')
this.conf.del('_auth')
this.conf.del('_password')
if (this.couchLogin) {

@@ -65,9 +63,11 @@ this.couchLogin.token = null

// but if we're updating a current record, then it'll 409 first
if (error && !this.conf.get('_auth')) {
var c = this.conf.getCredentialsByURI(base)
if (error && !c.auth) {
// must be trying to re-auth on a new machine.
// use this info as auth
var b = new Buffer(username + ":" + password)
this.conf.set('_auth', b.toString("base64"))
this.conf.set('username', username)
this.conf.set('_password', password)
this.conf.setCredentialsByURI(base, {
username : username,
password : password,
email : email
})
}

@@ -99,37 +99,41 @@

}.bind(this))
}
function done (cb, pre) {
return function (error, data, json, response) {
if (!error && (!response || response.statusCode === 201)) {
return cb(error, data, json, response)
}
function done (cb, pre) {
return function (error, data, json, response) {
if (!error && (!response || response.statusCode === 201)) {
return cb(error, data, json, response)
}
// there was some kind of error, re-instate previous auth/token/etc.
this.conf.set('_token', pre.token)
if (this.couchLogin) {
this.couchLogin.token = pre.token
if (this.couchLogin.tokenSet) {
this.couchLogin.tokenSet(pre.token)
// there was some kind of error, re-instate previous auth/token/etc.
this.conf.set('_token', pre.token)
if (this.couchLogin) {
this.couchLogin.token = pre.token
if (this.couchLogin.tokenSet) {
this.couchLogin.tokenSet(pre.token)
}
}
}
this.conf.set('username', pre.username)
this.conf.set('_password', pre.password)
this.conf.set('_auth', pre.auth)
this.conf.setCredentialsByURI(base, {
username : pre.username,
password : pre.password,
email : pre.email
})
this.log.verbose("adduser", "back", [error, data, json])
if (!error) {
error = new Error( (response && response.statusCode || "") + " "+
"Could not create user\n"+JSON.stringify(data))
}
if (response
&& (response.statusCode === 401 || response.statusCode === 403)) {
this.log.warn("adduser", "Incorrect username or password\n"
+"You can reset your account by visiting:\n"
+"\n"
+" https://npmjs.org/forgot\n")
}
this.log.verbose("adduser", "back", [error, data, json])
if (!error) {
error = new Error(
(response && response.statusCode || "") + " " +
"Could not create user\n" + JSON.stringify(data)
)
}
return cb(error)
}.bind(this)
if (response && (response.statusCode === 401 || response.statusCode === 403)) {
this.log.warn("adduser", "Incorrect username or password\n" +
"You can reset your account by visiting:\n" +
"\n" +
" https://npmjs.org/forgot\n")
}
return cb(error)
}.bind(this)
}
}

@@ -7,3 +7,4 @@ module.exports = deprecate

function deprecate (uri, ver, message, cb) {
if (!this.conf.get('username')) {
var c = this.conf.getCredentialsByURI(uri)
if (!(c.token || c.auth)) {
return cb(new Error("Must be logged in to deprecate a package"))

@@ -10,0 +11,0 @@ }

@@ -8,9 +8,11 @@

, fs = require("fs")
, fixNameField = require("normalize-package-data/lib/fixer.js").fixNameField
function escaped(name) {
return name.replace("/", "%2f")
}
function publish (uri, data, tarball, cb) {
var email = this.conf.get('email')
var auth = this.conf.get('_auth')
var username = this.conf.get('username')
if (!email || !auth || !username) {
var c = this.conf.getCredentialsByURI(uri)
if (!(c.token || (c.auth && c.username && c.email))) {
var er = new Error("auth and email required for publishing")

@@ -21,4 +23,8 @@ er.code = 'ENEEDAUTH'

if (data.name !== encodeURIComponent(data.name))
return cb(new Error('invalid name: must be url-safe'))
try {
fixNameField(data, true)
}
catch (er) {
return cb(er)
}

@@ -35,3 +41,3 @@ var ver = semver.clean(data.version)

if (er) return cb(er)
putFirst.call(self, uri, data, tarbuffer, s, username, email, cb)
putFirst.call(self, uri, data, tarbuffer, s, c, cb)
})

@@ -41,3 +47,3 @@ })

function putFirst (registry, data, tarbuffer, stat, username, email, cb) {
function putFirst (registry, data, tarbuffer, stat, creds, cb) {
// optimistically try to PUT all in one single atomic thing.

@@ -54,11 +60,10 @@ // If 409, then GET and merge, try again.

, readme: data.readme || ""
, maintainers :
[ { name : username
, email : email
}
]
}
if (!creds.token) {
root.maintainers = [{name : creds.username, email : creds.email}]
data.maintainers = JSON.parse(JSON.stringify(root.maintainers))
}
root.versions[ data.version ] = data
data.maintainers = JSON.parse(JSON.stringify(root.maintainers))
var tag = data.tag || this.conf.get('tag') || "latest"

@@ -81,5 +86,5 @@ root["dist-tags"][tag] = data.version

length: stat.size
};
}
var fixed = url.resolve(registry, data.name)
var fixed = url.resolve(registry, escaped(data.name))
this.request("PUT", fixed, { body : root }, function (er, parsed, json, res) {

@@ -142,3 +147,3 @@ var r409 = "must supply latest _rev to update existing package"

case 'maintainers':
break;
break

@@ -153,3 +158,4 @@ // copy

this.request("PUT", url.resolve(registry, root.name), { body : current }, cb)
var uri = url.resolve(registry, escaped(root.name))
this.request("PUT", uri, { body : current }, cb)
}

@@ -156,0 +162,0 @@

@@ -11,4 +11,4 @@ module.exports = regRequest

, crypto = require("crypto")
, pkg = require("../package.json")
var pkg = require("../package.json")

@@ -69,10 +69,9 @@ // npm: means

, uc = where.match(adduserChange)
, alwaysAuth = this.conf.get('always-auth')
, alwaysAuth = this.conf.get("always-auth")
, isDel = method === "DELETE"
, isWrite = what || isDel
, authRequired = (authThis || alwaysAuth || isWrite) && !nu || uc || isDel
// resolve to a full url on the registry
if (!where.match(/^https?:\/\//)) {
this.log.verbose("url raw", where)
this.log.verbose("request", "url raw", where)

@@ -89,8 +88,8 @@ var q = where.split("?")

}
return encodeURIComponent(p)
return p
}).join("/")
if (q) where += "?" + q
this.log.verbose("url resolving", [registry, where])
this.log.verbose("request", "url resolving", [registry, where])
where = url.resolve(registry, where)
this.log.verbose("url resolved", where)
this.log.verbose("request", "url resolved", where)
}

@@ -100,27 +99,38 @@ this.log.verbose("request", "where is", where)

var remote = url.parse(where)
, auth = this.conf.get('_auth')
if ((authThis || alwaysAuth || isWrite) && !nu || uc || isDel) {
this.log.verbose("request", "setting basic auth")
if (authRequired && !auth) {
var un = this.conf.get('username')
var pw = this.conf.get('_password')
if (un && pw)
auth = new Buffer(un + ':' + pw).toString('base64')
var c = this.conf.getCredentialsByURI(where)
if (c) {
if (!c.token) {
if (c.username && c.password) {
remote.auth = c.username + ":" + c.password
}
else {
return cb(new Error(
"This request requires auth credentials. Run `npm login` and repeat the request."
))
}
}
else {
this.log.verbose("request", "using bearer token for auth")
}
}
else {
return cb(new Error(
"This request requires auth credentials. Run `npm login` and repeat the request."
))
}
}
if (authRequired && !auth) {
return cb(new Error(
"This request requires auth credentials. Run `npm login` and repeat the request."))
else {
this.log.verbose("request", "no basic auth needed")
}
if (auth && authRequired) {
remote.auth = new Buffer(auth, "base64").toString("utf8")
}
// Tuned to spread 3 attempts over about a minute.
// See formula at <https://github.com/tim-kos/node-retry>.
var operation = retry.operation({
retries: this.conf.get('fetch-retries') || 2,
factor: this.conf.get('fetch-retry-factor'),
minTimeout: this.conf.get('fetch-retry-mintimeout') || 10000,
maxTimeout: this.conf.get('fetch-retry-maxtimeout') || 60000
retries: this.conf.get("fetch-retries") || 2,
factor: this.conf.get("fetch-retry-factor"),
minTimeout: this.conf.get("fetch-retry-mintimeout") || 10000,
maxTimeout: this.conf.get("fetch-retry-maxtimeout") || 60000
})

@@ -136,3 +146,3 @@

if (er)
er.code = 'ESSL'
er.code = "ESSL"
return cb(er, parsed, raw, response)

@@ -149,3 +159,3 @@ }

self.log.info("retry", "will retry, error on last attempt: " + er)
return
return undefined
}

@@ -167,3 +177,3 @@ if (response)

var strict = this.conf.get('strict-ssl')
var strict = this.conf.get("strict-ssl")
if (strict === undefined) strict = true

@@ -173,6 +183,6 @@ var opts = { url: remote

, encoding: null // tell request let body be Buffer instance
, ca: this.conf.get('ca')
, localAddress: this.conf.get('local-address')
, cert: this.conf.get('cert')
, key: this.conf.get('key')
, ca: this.conf.get("ca")
, localAddress: this.conf.get("local-address")
, cert: this.conf.get("cert")
, key: this.conf.get("key")
, strictSSL: strict }

@@ -185,3 +195,3 @@ , headers = opts.headers = {}

headers['npm-session'] = this.sessionToken
headers["npm-session"] = this.sessionToken
headers.version = this.version || pkg.version

@@ -194,12 +204,15 @@

headers.accept = "application/json"
headers['accept-encoding'] = 'gzip'
headers["accept-encoding"] = "gzip"
headers["user-agent"] = this.conf.get('user-agent') ||
'node/' + process.version
headers["user-agent"] = this.conf.get("user-agent") ||
"node/" + process.version
var p = this.conf.get('proxy')
var sp = this.conf.get('https-proxy') || p
var c = this.conf.getCredentialsByURI(url.format(remote))
if (c.token) headers.authorization = "Bearer " + c.token
var p = this.conf.get("proxy")
var sp = this.conf.get("https-proxy") || p
opts.proxy = remote.protocol === "https:" ? sp : p
// figure out wth 'what' is
// figure out wth "what" is
if (what) {

@@ -248,3 +261,3 @@ if (Buffer.isBuffer(what) || typeof what === "string") {

if (response.headers['content-encoding'] !== 'gzip') return cb(er, response, data)
if (response.headers["content-encoding"] !== "gzip") return cb(er, response, data)

@@ -266,3 +279,3 @@ zlib.gunzip(data, function (er, buf) {

if (urlObj.auth)
urlObj.auth = '***'
urlObj.auth = "***"
this.log.http(response.statusCode, url.format(urlObj))

@@ -308,3 +321,3 @@

name = w[w.indexOf("_rewrite") + 1]
er = new Error("404 Not Found: "+name)
er = new Error("404 Not Found: " + name)
er.code = "E404"

@@ -311,0 +324,0 @@ er.pkgid = name

@@ -5,6 +5,11 @@

function star (uri, starred, cb) {
if (!this.conf.get('username')) return cb(new Error(
"Must be logged in to star/unstar packages"))
var c = this.conf.getCredentialsByURI(uri)
if (c.token) {
return cb(new Error("This operation is unsupported for token-based auth"))
}
else if (!c.auth) {
return cb(new Error("Must be logged in to star/unstar packages"))
}
this.request("GET", uri+"?write=true", null, function (er, fullData) {
this.request("GET", uri + "?write=true", null, function (er, fullData) {
if (er) return cb(er)

@@ -18,6 +23,6 @@

this.log.info("starring", fullData._id)
fullData.users[this.conf.get('username')] = true
fullData.users[c.username] = true
this.log.verbose("starring", fullData)
} else {
delete fullData.users[this.conf.get('username')]
delete fullData.users[c.username]
this.log.info("unstarring", fullData._id)

@@ -24,0 +29,0 @@ this.log.verbose("unstarring", fullData)

@@ -5,3 +5,3 @@ {

"description": "Client for the npm registry",
"version": "2.0.2",
"version": "3.0.0",
"repository": {

@@ -18,2 +18,3 @@ "url": "git://github.com/isaacs/npm-registry-client"

"mkdirp": "~0.3.3",
"normalize-package-data": "^0.4.0",
"npm-cache-filename": "^1.0.0",

@@ -20,0 +21,0 @@ "request": "2 >=2.25.0",

@@ -5,9 +5,3 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username : "username",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var client = common.freshClient()

@@ -27,3 +21,4 @@ tap.test("get the URL for the bugs page on a package", function (t) {

client.bugs("http://localhost:1337/sample", function (error, info) {
t.notOk(error, "no errors")
t.ifError(error)
t.ok(info.url, "got the URL")

@@ -30,0 +25,0 @@ t.ok(info.email, "got the email address")

@@ -5,10 +5,10 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username : "username",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "_authToken"] = "not-bad-meaning-bad-but-bad-meaning-wombat"
var client = common.freshClient(configuration)
var cache = require("./fixtures/underscore/cache.json")

@@ -61,4 +61,4 @@

client.deprecate("http://localhost:1337/underscore", VERSION, MESSAGE, function (error, data) {
t.notOk(error, "no errors")
client.deprecate(common.registry + "/underscore", VERSION, MESSAGE, function (er, data) {
t.ifError(er)
t.ok(data.deprecated, "was deprecated")

@@ -65,0 +65,0 @@

@@ -13,5 +13,5 @@ var tap = require("tap")

client.get("http://localhost:1337/-/all", null, function (er) {
t.notOk(er, "no error")
t.ifError(er, "no error")
t.end()
})
})

@@ -19,3 +19,7 @@ var tap = require("tap")

t.plan(2)
server.expect("/@bigco%2funderscore", function (req, res) {
res.json(usroot)
})
t.plan(3)
client.get("http://localhost:1337/underscore/1.3.3", null, function (er, data) {

@@ -28,2 +32,6 @@ t.deepEqual(data, us)

})
client.get("http://localhost:1337/@bigco%2funderscore", null, function (er, data) {
t.deepEqual(data, usroot)
})
})
var resolve = require("path").resolve
var server = require('./server.js')
var RC = require('../../')
var server = require("./server.js")
var RC = require("../../")
var toNerfDart = require("../../lib/util/nerf-dart.js")
var REGISTRY = "http://localhost:" + server.port
module.exports = {
port : server.port,
registry : REGISTRY,
freshClient : function freshClient(config) {
config = config || {}
config.cache = resolve(__dirname, '../fixtures/cache')
config.registry = 'http://localhost:' + server.port
config.cache = resolve(__dirname, "../fixtures/cache")
config.registry = REGISTRY
var container = {
get: function (k) { return config[k] },
set: function (k, v) { config[k] = v },
del: function (k) { delete config[k] },
getCredentialsByURI: function(uri) {
var nerfed = toNerfDart(uri)
var c = {scope : nerfed}
var client = new RC(config)
if (this.get(nerfed + ":_authToken")) {
c.token = this.get(nerfed + ":_authToken")
// the bearer token is enough, don't confuse things
return c
}
if (this.get(nerfed + ":_password")) {
c.password = new Buffer(this.get(nerfed + ":_password"), "base64").toString("utf8")
}
if (this.get(nerfed + ":username")) {
c.username = this.get(nerfed + ":username")
}
if (this.get(nerfed + ":email")) {
c.email = this.get(nerfed + ":email")
}
if (c.username && c.password) {
c.auth = new Buffer(c.username + ":" + c.password).toString("base64")
}
return c
},
setCredentialsByURI: function (uri, c) {
var nerfed = toNerfDart(uri)
if (c.token) {
this.set(nerfed + ":_authToken", c.token, "user")
this.del(nerfed + ":_password", "user")
this.del(nerfed + ":username", "user")
this.del(nerfed + ":email", "user")
}
else if (c.username || c.password || c.email) {
this.del(nerfed + ":_authToken", "user")
var encoded = new Buffer(c.password, "utf8").toString("base64")
this.set(nerfed + ":_password", encoded, "user")
this.set(nerfed + ":username", c.username, "user")
this.set(nerfed + ":email", c.email, "user")
}
else {
throw new Error("No credentials to set.")
}
}
}
var client = new RC(container)
server.log = client.log
client.log.level = 'silent'
client.log.level = "silent"

@@ -15,0 +75,0 @@ return client

@@ -6,12 +6,19 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username: "username",
password: "password",
email: "i@izs.me",
_auth: new Buffer("username:password").toString("base64"),
"always-auth": true
})
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "username"] = "username"
configuration[nerfed + "_password"] = new Buffer("password").toString("base64")
configuration[nerfed + "email"] = "i@izs.me"
var client = common.freshClient(configuration)
tap.test("publish again", function (t) {
// not really a tarball, but doesn't matter
var tarball = require.resolve("../package.json")
var pd = fs.readFileSync(tarball, "base64")
var pkg = require("../package.json")
var lastTime = null
server.expect("/npm-registry-client", function (req, res) {

@@ -70,7 +77,2 @@ t.equal(req.method, "PUT")

// not really a tarball, but doesn't matter
var tarball = require.resolve("../package.json")
var pd = fs.readFileSync(tarball, "base64")
var pkg = require("../package.json")
client.publish("http://localhost:1337/", pkg, tarball, function (er, data) {

@@ -77,0 +79,0 @@ if (er) throw er

@@ -7,12 +7,18 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username: "username",
password: "password",
email: "i@izs.me",
_auth: new Buffer("username:password").toString("base64"),
"always-auth": true
})
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "username"] = "username"
configuration[nerfed + "_password"] = new Buffer("password").toString("base64")
configuration[nerfed + "email"] = "i@izs.me"
var client = common.freshClient(configuration)
tap.test("publish", function (t) {
// not really a tarball, but doesn't matter
var tarball = require.resolve("../package.json")
var pd = fs.readFileSync(tarball, "base64")
var pkg = require("../package.json")
server.expect("/npm-registry-client", function (req, res) {

@@ -42,6 +48,2 @@ t.equal(req.method, "PUT")

// not really a tarball, but doesn't matter
var tarball = require.resolve("../package.json")
var pd = fs.readFileSync(tarball, "base64")
var pkg = require("../package.json")
client.publish("http://localhost:1337/", pkg, tarball, function (er, data) {

@@ -48,0 +50,0 @@ if (er) throw er

@@ -5,14 +5,16 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username : "othiym23",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var DEP_USER = "othiym23"
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "username"] = DEP_USER
configuration[nerfed + "_password"] = new Buffer("password").toString("base64")
configuration[nerfed + "email"] = "i@izs.me"
var client = common.freshClient(configuration)
var cache = require("./fixtures/underscore/cache.json")
var DEP_USER = "othiym23"
tap.test("star a package", function (t) {

@@ -56,3 +58,3 @@ server.expect("GET", "/underscore?write=true", function (req, res) {

client.star("http://localhost:1337/underscore", true, function (error, data) {
t.notOk(error, "no errors")
t.ifError(error, "no errors")
t.ok(data.starred, "was starred")

@@ -59,0 +61,0 @@

@@ -5,9 +5,3 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username : "username",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var client = common.freshClient()

@@ -28,3 +22,3 @@ var users = [

client.stars("http://localhost:1337/", "sample", function (error, info) {
t.notOk(error, "no errors")
t.ifError(error, "no errors")
t.deepEqual(info, users, "got the list of users")

@@ -31,0 +25,0 @@

@@ -5,10 +5,12 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username : "username",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "username"] = "username"
configuration[nerfed + "_password"] = new Buffer("password").toString("base64")
configuration[nerfed + "email"] = "i@izs.me"
var client = common.freshClient(configuration)
tap.test("tag a package", function (t) {

@@ -35,3 +37,3 @@ server.expect("PUT", "/underscore/not-lodash", function (req, res) {

client.tag("http://localhost:1337/underscore", {"1.3.2":{}}, "not-lodash", function (error, data) {
t.notOk(error, "no errors")
t.ifError(error, "no errors")
t.ok(data.tagged, "was tagged")

@@ -38,0 +40,0 @@

@@ -5,10 +5,10 @@ var tap = require("tap")

var common = require("./lib/common.js")
var client = common.freshClient({
username : "othiym23",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "_authToken"] = "of-glad-tidings"
var client = common.freshClient(configuration)
var cache = require("./fixtures/underscore/cache.json")

@@ -56,3 +56,3 @@

client.unpublish("http://localhost:1337/underscore", VERSION, function (error) {
t.notOk(error, "no errors")
t.ifError(error, "no errors")

@@ -59,0 +59,0 @@ t.end()

@@ -10,10 +10,9 @@ var tap = require("tap")

var client = common.freshClient({
username : "othiym23",
password : "password",
email : "ogd@aoaioxxysz.net",
_auth : new Buffer("username : password").toString("base64"),
"always-auth" : true
})
var nerfed = "//localhost:" + server.port + "/:"
var configuration = {}
configuration[nerfed + "_authToken"] = "of-glad-tidings"
var client = common.freshClient(configuration)
function OneA() {

@@ -26,3 +25,3 @@ Readable.call(this)

tap.test("unpublish a package", function (t) {
tap.test("uploading a tarball", function (t) {
server.expect("PUT", "/underscore", function (req, res) {

@@ -35,3 +34,3 @@ t.equal(req.method, "PUT")

client.upload("http://localhost:1337/underscore", new OneA(), "daedabeefa", true, function (error) {
t.notOk(error, "no errors")
t.ifError(error, "no errors")

@@ -38,0 +37,0 @@ t.end()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc