summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/lib/dist-tags/update.js
blob: 07ec3e5e75f0f6ba602f635c115d7ab33a9d4518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module.exports = update

var assert = require('assert')
var url = require('url')

var npa = require('npm-package-arg')

function update (uri, params, cb) {
  assert(typeof uri === 'string', 'must pass registry URI to distTags.update')
  assert(
    params && typeof params === 'object',
    'must pass params to distTags.update'
  )
  assert(typeof cb === 'function', 'muss pass callback to distTags.update')

  assert(
    typeof params.package === 'string',
    'must pass package name to distTags.update'
  )
  assert(
    params.distTags && typeof params.distTags === 'object',
    'must pass distTags map to distTags.update'
  )
  assert(
    params.auth && typeof params.auth === 'object',
    'must pass auth to distTags.update'
  )

  var p = npa(params.package)
  var pkg = p.scope ? params.package.replace('/', '%2f') : params.package
  var rest = '-/package/' + pkg + '/dist-tags'

  var options = {
    method: 'POST',
    body: JSON.stringify(params.distTags),
    auth: params.auth
  }
  this.request(url.resolve(uri, rest), options, cb)
}