npm-profile
Advanced tools
Comparing version 2.0.2 to 2.0.3
32
index.js
'use strict' | ||
const fetch = require('make-fetch-happen') | ||
const fetch = require('make-fetch-happen').defaults({retry: false}) | ||
const validate = require('aproba') | ||
@@ -54,6 +54,24 @@ const url = require('url') | ||
const target = url.resolve(conf.registry, '-/user/org.couchdb.user:' + encodeURIComponent(username)) | ||
return fetchJSON(Object.assign({method: 'PUT', target: target, body: userobj}, conf)).catch(err => { | ||
if (err.code === 'E400') err.message = `There is no user with the username "${username}".` | ||
throw err | ||
if (err.code !== 'E409') throw err | ||
return fetchJSON(Object.assign({method: 'GET', target: target + '?write=true'}, conf)).then(result => { | ||
Object.keys(result).forEach(function (k) { | ||
if (!userobj[k] || k === 'roles') { | ||
userobj[k] = result[k] | ||
} | ||
}) | ||
const req = { | ||
method: 'PUT', | ||
target: target + '/-rev/' + userobj._rev, | ||
body: useroby, | ||
auth: { | ||
basic: { | ||
username: username, | ||
password: password | ||
} | ||
} | ||
} | ||
return fetchJSON(Object.assign({}, conf, req)) | ||
}) | ||
}) | ||
@@ -165,3 +183,9 @@ } | ||
} else { | ||
return res.buffer().then(content => [res, content]) | ||
return res.buffer().then(content => { | ||
try { | ||
return [res, JSON.parse(content)] | ||
} catch (_) { | ||
return [res, content] | ||
} | ||
}) | ||
} | ||
@@ -168,0 +192,0 @@ }).then(result => { |
{ | ||
"name": "npm-profile", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Library for updating an npmjs.com profile", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
# npm-profile | ||
Updating an npmjs.com profile | ||
Provides functions for fetching and updating an npmjs.com profile. | ||
@@ -12,2 +12,7 @@ ```js | ||
The API that this implements is documented here: | ||
* [authentication](https://github.com/npm/registry/blob/master/docs/user/authentication.md) | ||
* [profile editing](https://github.com/npm/registry/blob/master/docs/user/profile.md) (and two-factor authentication) | ||
## Functions | ||
@@ -14,0 +19,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22387
192
398