Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return libaccess.lsPackages(username, opts).then(access => {
// do a bit of filtering at this point, so that we don't need
// to fetch versions for more than one thing, but also don't
// accidentally a whole project.
let pkgs = Object.keys(access)
if (!cliOpts.partialWord || !pkgs.length) { return pkgs }
const pp = npa(cliOpts.partialWord).name
pkgs = pkgs.filter(p => !p.indexOf(pp))
if (pkgs.length > 1) return pkgs
return npmFetch.json(npa(pkgs[0]).escapedName, opts).then(doc => {
const vers = Object.keys(doc.versions)
if (!vers.length) {
return pkgs
} else {
return vers.map(v => `${pkgs[0]}@${v}`)
}
})
})
}).nodeify(cb)
const body = {
_id: 'org.couchdb.user:' + username,
name: username,
password: password,
type: 'user',
roles: [],
date: new Date().toISOString()
}
const logObj = {}
Object.keys(body).forEach(k => {
logObj[k] = k === 'password' ? 'XXXXX' : body[k]
})
process.emit('log', 'verbose', 'login', 'before first PUT', logObj)
const target = '-/user/org.couchdb.user:' + encodeURIComponent(username)
return fetch.json(target, opts.concat({
method: 'PUT',
body
})).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 fetch.json(target, opts.concat({
query: {write: true}
})).then(result => {
Object.keys(result).forEach(function (k) {
if (!body[k] || k === 'roles') {
body[k] = result[k]
}
})
_id: 'org.couchdb.user:' + username,
name: username,
password: password,
email: email,
type: 'user',
roles: [],
date: new Date().toISOString()
}
const logObj = {}
Object.keys(body).forEach(k => {
logObj[k] = k === 'password' ? 'XXXXX' : body[k]
})
process.emit('log', 'verbose', 'adduser', 'before first PUT', logObj)
const target = '/-/user/org.couchdb.user:' + encodeURIComponent(username)
return fetch.json(target, opts.concat({
method: 'PUT',
body
})).then(result => {
result.username = username
return result
})
}
return new opts.Promise((resolve, reject) => {
validate('SSSO|SSZO', [org, user, role, opts])
user = user.replace(/^@?/, '')
org = org.replace(/^@?/, '')
fetch.json(`/-/org/${eu(org)}/user`, opts.concat({
method: 'PUT',
body: { user, role }
})).then(resolve, reject)
}).then(ret => Object.assign(new MembershipDetail(), ret))
}
function get (opts) {
validate('O', arguments)
return fetch.json('/-/npm/v1/user', opts)
}
cmd.find = (id, opts) => {
opts = HooksConfig(opts)
validate('SO', [id, opts])
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, opts)
}
function untilLastPage (href, objects) {
return fetch.json(href, opts).then(result => {
objects = objects ? objects.concat(result.objects) : result.objects
if (result.urls.next) {
return untilLastPage(result.urls.next, objects)
} else {
return objects
}
})
}
}
cmd.rm = (id, opts) => {
opts = HooksConfig(opts)
validate('SO', [id, opts])
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, opts.concat({
method: 'DELETE'
}, opts)).catch(err => {
if (err.code === 'E404') {
return null
} else {
throw err
}
})
}
})).then(result => {
Object.keys(result).forEach(function (k) {
if (!body[k] || k === 'roles') {
body[k] = result[k]
}
})
return fetch.json(`${target}/-rev/${body._rev}`, opts.concat({
method: 'PUT',
body,
forceAuth: {
username,
password: Buffer.from(password, 'utf8').toString('base64'),
otp: opts.otp
}
}))
})
}).then(result => {