]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/lib/star.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / lib / star.js
1 module.exports = star
2
3 var assert = require('assert')
4
5 function star (uri, params, cb) {
6   assert(typeof uri === 'string', 'must pass registry URI to star')
7   assert(params && typeof params === 'object', 'must pass params to star')
8   assert(typeof cb === 'function', 'must pass callback to star')
9
10   var starred = !!params.starred
11
12   var auth = params.auth
13   assert(auth && typeof auth === 'object', 'must pass auth to star')
14   if (!(auth.token || (auth.password && auth.username && auth.email))) {
15     var er = new Error('Must be logged in to star/unstar packages')
16     er.code = 'ENEEDAUTH'
17     return cb(er)
18   }
19
20   var client = this
21   this.request(uri + '?write=true', { auth: auth }, function (er, fullData) {
22     if (er) return cb(er)
23
24     client.whoami(uri, params, function (er, username) {
25       if (er) return cb(er)
26
27       var data = {
28         _id: fullData._id,
29         _rev: fullData._rev,
30         users: fullData.users || {}
31       }
32
33       if (starred) {
34         client.log.info('starring', data._id)
35         data.users[username] = true
36         client.log.verbose('starring', data)
37       } else {
38         delete data.users[username]
39         client.log.info('unstarring', data._id)
40         client.log.verbose('unstarring', data)
41       }
42
43       var options = {
44         method: 'PUT',
45         body: data,
46         auth: auth
47       }
48       return client.request(uri, options, cb)
49     })
50   })
51 }