From 698c5079bdfcffe3522cc6d1ef7ca2a0d36f5b5d Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 23 Jul 2012 11:18:47 -0700 Subject: [PATCH] npm-registry-client: Upgrade to 0.1.0 Fix isaacs/npmjs.org#73 --- .../npm-registry-client/lib/adduser.js | 40 +++++++++++++++++-- node_modules/npm-registry-client/package.json | 4 +- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/node_modules/npm-registry-client/lib/adduser.js b/node_modules/npm-registry-client/lib/adduser.js index 48a03595299..8f1912b3de5 100644 --- a/node_modules/npm-registry-client/lib/adduser.js +++ b/node_modules/npm-registry-client/lib/adduser.js @@ -39,9 +39,31 @@ function adduser (username, password, email, cb) { , date: new Date().toISOString() } - cb = done.call(this, cb) + // pluck off any other username/password/token. it needs to be the + // same as the user we're becoming now. replace them on error. + var pre = { username: this.username + , password: this.password + , auth: this.auth + , token: this.token } + + this.token = null + this.couchLogin.token = null + this.username = username + this.password = password + this.auth = new Buffer(username + ':' + password).toString('base64') + + cb = done.call(this, cb, pre) + + var logObj = Object.keys(userobj).map(function (k) { + if (k === 'salt' || k === 'password_sha') return [k, 'XXXXX'] + return [k, userobj[k]] + }).reduce(function (s, kv) { + s[kv[0]] = kv[1] + return s + }, {}) + + this.log.verbose("adduser", "before first PUT", logObj) - this.log.verbose("adduser", "before first PUT", userobj) this.request('PUT' , '/-/user/org.couchdb.user:'+encodeURIComponent(username) , userobj @@ -71,7 +93,7 @@ function adduser (username, password, email, cb) { userobj[k] = data[k] } }) - this.log.verbose("adduser", "userobj", userobj) + this.log.verbose("adduser", "userobj", logObj) this.request('PUT' , '/-/user/org.couchdb.user:'+encodeURIComponent(username) + "/-rev/" + userobj._rev @@ -81,11 +103,21 @@ function adduser (username, password, email, cb) { }.bind(this)) } -function done (cb) { +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.couchLogin.token = this.token = pre.token + if (this.couchLogin.tokenSet) { + this.couchLogin.tokenSet(pre.token) + } + this.username = pre.username + this.password = pre.password + this.auth = pre.auth + this.log.verbose("adduser", "back", [error, data, json]) if (!error) { error = new Error( (response && response.statusCode || "") + " "+ diff --git a/node_modules/npm-registry-client/package.json b/node_modules/npm-registry-client/package.json index ff9e6c3f102..e067a46d09e 100644 --- a/node_modules/npm-registry-client/package.json +++ b/node_modules/npm-registry-client/package.json @@ -6,7 +6,7 @@ }, "name": "npm-registry-client", "description": "Client for the npm registry", - "version": "0.0.11", + "version": "0.1.0", "repository": { "url": "git://github.com/isaacs/npm-registry-client" }, @@ -35,6 +35,6 @@ }, "license": "BSD", "readme": "# npm-registry-client\n\nThe code that npm uses to talk to the registry.\n\nIt handles all the caching and HTTP calls.\n\n## Usage\n\n```javascript\nvar RegClient = require('npm-registry-client')\nvar client = new RegClient(options)\n\nclient.get(\"npm\", \"latest\", 1000, function (er, data, raw, res) {\n // error is an error if there was a problem.\n // data is the parsed data object\n // raw is the json string\n // res is the response from couch\n})\n```\n\n# Options\n\n* `registry` **Required** {String} URL to the registry\n* `cache` **Required** {String} Path to the cache folder\n* `alwaysAuth` {Boolean} Auth even for GET requests.\n* `auth` {String} A base64-encoded `username:password`\n* `email` {String} User's email address\n* `tag` {String} The default tag to use when publishing new packages.\n Default = `\"latest\"`\n* `ca` {String} Cerficate signing authority certificates to trust.\n* `strictSSL` {Boolean} Whether or not to be strict with SSL\n certificates. Default = `true`\n* `userAgent` {String} User agent header to send. Default =\n `\"node/{process.version}\"`\n* `log` {Object} The logger to use. Defaults to `require(\"npmlog\")` if\n that works, otherwise logs are disabled.\n* `retries` {Number} Number of times to retry on GET failures.\n Default=2\n* `retryFactor` {Number} `factor` setting for `node-retry`. Default=10\n* `retryMinTimeout` {Number} `minTimeout` setting for `node-retry`.\n Default=10000 (10 seconds)\n* `retryMaxTimeout` {Number} `maxTimeout` setting for `node-retry`.\n Default=60000 (60 seconds)\n\n# client.request(method, where, [what], [etag], [nofollow], cb)\n\n* `method` {String} HTTP method\n* `where` {String} Path to request on the server\n* `what` {Stream | Buffer | String | Object} The request body. Objects\n that are not Buffers or Streams are encoded as JSON.\n* `etag` {String} The cached ETag\n* `nofollow` {Boolean} Prevent following 302/301 responses\n* `cb` {Function}\n * `error` {Error | null}\n * `data` {Object} the parsed data object\n * `raw` {String} the json\n * `res` {Response Object} response from couch\n\nMake a request to the registry. All the other methods are wrappers\naround this. one.\n\n# client.adduser(username, password, email, cb)\n\n* `username` {String}\n* `password` {String}\n* `email` {String}\n* `cb` {Function}\n\nAdd a user account to the registry, or verify the credentials.\n\n# client.get(url, [timeout], [nofollow], [staleOk], cb)\n\n* `url` {String} The url path to fetch\n* `timeout` {Number} Number of seconds old that a cached copy must be\n before a new request will be made.\n* `nofollow` {Boolean} Do not follow 301/302 responses\n* `staleOk` {Boolean} If there's cached data available, then return that\n to the callback quickly, and update the cache the background.\n\nFetches data from the registry via a GET request, saving it in\nthe cache folder with the ETag.\n\n# client.publish(data, tarball, [readme], cb)\n\n* `data` {Object} Package data\n* `tarball` {String | Stream} Filename or stream of the package tarball\n* `readme` {String} Contents of the README markdown file\n* `cb` {Function}\n\nPublish a package to the registry.\n\nNote that this does not create the tarball from a folder. However, it\ncan accept a gzipped tar stream or a filename to a tarball.\n\n# client.star(package, starred, cb)\n\n* `package` {String} Name of the package to star\n* `starred` {Boolean} True to star the package, false to unstar it.\n* `cb` {Function}\n\nStar or unstar a package.\n\nNote that the user does not have to be the package owner to star or\nunstar a package, though other writes do require that the user be the\npackage owner.\n\n# client.tag(project, version, tag, cb)\n\n* `project` {String} Project name\n* `version` {String} Version to tag\n* `tag` {String} Tag name to apply\n* `cb` {Function}\n\nMark a version in the `dist-tags` hash, so that `pkg@tag`\nwill fetch the specified version.\n\n# client.unpublish(name, [ver], cb)\n\n* `name` {String} package name\n* `ver` {String} version to unpublish. Leave blank to unpublish all\n versions.\n* `cb` {Function}\n\nRemove a version of a package (or all versions) from the registry. When\nthe last version us unpublished, the entire document is removed from the\ndatabase.\n\n# client.upload(where, file, [etag], [nofollow], cb)\n\n* `where` {String} URL path to upload to\n* `file` {String | Stream} Either the filename or a readable stream\n* `etag` {String} Cache ETag\n* `nofollow` {Boolean} Do not follow 301/302 responses\n* `cb` {Function}\n\nUpload an attachment. Mostly used by `client.publish()`.\n", - "_id": "npm-registry-client@0.0.11", + "_id": "npm-registry-client@0.1.0", "_from": "npm-registry-client@0" }