return BB.try(() => { if (msg == null) throw new Error(`Usage: ${deprecate.usage}`) // fetch the data and make sure it exists. const p = npa(pkg) // npa makes the default spec "latest", but for deprecation // "*" is the appropriate default. const spec = p.rawSpec === '' ? '*' : p.fetchSpec if (semver.validRange(spec, true) === null) { throw new Error('invalid version range: ' + spec) } const uri = '/' + p.escapedName return fetch.json(uri, opts.concat({ spec: p, query: {write: true} })).then(packument => { // filter all the versions that match Object.keys(packument.versions) .filter(v => semver.satisfies(v, spec)) .forEach(v => { packument.versions[v].deprecated = msg }) return otplease(opts, opts => fetch(uri, opts.concat({ spec: p, method: 'PUT', body: packument, ignoreBody: true }))) }) }).nodeify(cb)
function fetchTags (spec, opts) { return regFetch.json( `/-/package/${spec.escapedName}/dist-tags`, opts.concat({ 'prefer-online': true, spec }) ).then(data => { if (data && typeof data === 'object') delete data._etag if (!data || !Object.keys(data).length) { throw new Error('No dist-tags found for ' + spec.name) } return data }) }
]).then(([username, fullData]) => { if (!username) { throw new Error('You need to be logged in!') } const body = { _id: fullData._id, _rev: fullData._rev, users: fullData.users || {} } if (using) { log.info('star', 'starring', body._id) body.users[username] = true log.verbose('star', 'starring', body) } else { delete body.users[username] log.info('star', 'unstarring', body._id) log.verbose('star', 'unstarring', body) } return fetch.json(pkg.escapedName, opts.concat({ spec: pkg, method: 'PUT', body })) }).then(data => {
}).then(({username, token}) => { if (username) { return username } else if (token) { return fetch.json('/-/whoami', opts.concat({ spec })).then(({username}) => { if (username) { return username } else { throw Object.assign(new Error( 'Your auth token is no longer valid. Please log in again.' ), {code: 'ENEEDAUTH'}) } }) } else { // At this point, if they have a credentials object, it doesn't have a // token or auth in it. Probably just the default registry. throw Object.assign(new Error( 'This command requires you to be logged in.' ), {code: 'ENEEDAUTH'}) } }).then(username => {
return BB.map(args.map(npa), pkg => { return BB.all([ whoami([pkg], true, () => {}), fetch.json(pkg.escapedName, opts.concat({ spec: pkg, query: {write: true}, 'prefer-online': true })) ]).then(([username, fullData]) => { if (!username) { throw new Error('You need to be logged in!') } const body = { _id: fullData._id, _rev: fullData._rev, users: fullData.users || {} } if (using) { log.info('star', 'starring', body._id) body.users[username] = true log.verbose('star', 'starring', body) } else { delete body.users[username] log.info('star', 'unstarring', body._id) log.verbose('star', 'unstarring', body) } return fetch.json(pkg.escapedName, opts.concat({ spec: pkg, method: 'PUT', body })) }).then(data => { output(s + ' ' + pkg.name) log.verbose('star', data) return data }) })
return (user ? BB.resolve(user) : whoami([], true, () => {})).then(usr => { return fetch.json('/-/_view/starredByUser', opts.concat({ query: {key: `"${usr}"`} // WHY. WHY THE ""?! })) }).then(data => data.rows).then(stars => {