]> 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/team.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 / team.js
1 module.exports = team
2
3 var assert = require('assert')
4 var url = require('url')
5
6 var subcommands = {}
7
8 function team (sub, uri, params, cb) {
9   teamAssertions(sub, uri, params, cb)
10   return subcommands[sub].call(this, uri, params, cb)
11 }
12
13 subcommands.create = function (uri, params, cb) {
14   return this.request(apiUri(uri, 'org', params.scope, 'team'), {
15     method: 'PUT',
16     auth: params.auth,
17     body: JSON.stringify({
18       name: params.team
19     })
20   }, cb)
21 }
22
23 subcommands.destroy = function (uri, params, cb) {
24   return this.request(apiUri(uri, 'team', params.scope, params.team), {
25     method: 'DELETE',
26     auth: params.auth
27   }, cb)
28 }
29
30 subcommands.add = function (uri, params, cb) {
31   return this.request(apiUri(uri, 'team', params.scope, params.team, 'user'), {
32     method: 'PUT',
33     auth: params.auth,
34     body: JSON.stringify({
35       user: params.user
36     })
37   }, cb)
38 }
39
40 subcommands.rm = function (uri, params, cb) {
41   return this.request(apiUri(uri, 'team', params.scope, params.team, 'user'), {
42     method: 'DELETE',
43     auth: params.auth,
44     body: JSON.stringify({
45       user: params.user
46     })
47   }, cb)
48 }
49
50 subcommands.ls = function (uri, params, cb) {
51   var uriParams = '?format=cli'
52   if (params.team) {
53     var reqUri = apiUri(
54       uri, 'team', params.scope, params.team, 'user') + uriParams
55     return this.request(reqUri, {
56       method: 'GET',
57       auth: params.auth
58     }, cb)
59   } else {
60     return this.request(apiUri(uri, 'org', params.scope, 'team') + uriParams, {
61       method: 'GET',
62       auth: params.auth
63     }, cb)
64   }
65 }
66
67 // TODO - we punted this to v2
68 // subcommands.edit = function (uri, params, cb) {
69 //   return this.request(apiUri(uri, 'team', params.scope, params.team, 'user'), {
70 //     method: 'POST',
71 //     auth: params.auth,
72 //     body: JSON.stringify({
73 //       users: params.users
74 //     })
75 //   }, cb)
76 // }
77
78 function apiUri (registryUri) {
79   var path = Array.prototype.slice.call(arguments, 1)
80     .map(encodeURIComponent)
81     .join('/')
82   return url.resolve(registryUri, '-/' + path)
83 }
84
85 function teamAssertions (subcommand, uri, params, cb) {
86   assert(subcommand, 'subcommand is required')
87   assert(subcommands.hasOwnProperty(subcommand),
88          'team subcommand must be one of ' + Object.keys(subcommands))
89   assert(typeof uri === 'string', 'registry URI is required')
90   assert(typeof params === 'object', 'params are required')
91   assert(typeof params.auth === 'object', 'auth is required')
92   assert(typeof params.scope === 'string', 'scope is required')
93   assert(!cb || typeof cb === 'function', 'callback must be a function')
94   if (subcommand !== 'ls') {
95     assert(typeof params.team === 'string', 'team name is required')
96   }
97   if (subcommand === 'rm' || subcommand === 'add') {
98     assert(typeof params.user === 'string', 'user is required')
99   }
100   if (subcommand === 'edit') {
101     assert(typeof params.users === 'object' &&
102            params.users.length != null,
103            'users is required')
104   }
105 }