1
1
'use strict'
2
2
3
3
const eu = encodeURIComponent
4
- const figgyPudding = require ( 'figgy-pudding' )
5
4
const getStream = require ( 'get-stream' )
6
5
const npmFetch = require ( 'npm-registry-fetch' )
7
6
const validate = require ( 'aproba' )
8
7
9
- const TeamConfig = figgyPudding ( {
10
- description : { } ,
11
- Promise : { default : ( ) => Promise }
12
- } )
13
-
14
8
const cmd = module . exports = { }
15
9
16
- cmd . create = ( entity , opts ) => {
17
- opts = TeamConfig ( opts )
10
+ cmd . create = ( entity , opts = { description : undefined } ) => {
18
11
return pwrap ( opts , ( ) => {
19
12
const { scope, team } = splitEntity ( entity )
20
13
validate ( 'SSO' , [ scope , team , opts ] )
21
- return npmFetch . json ( `/-/org/${ eu ( scope ) } /team` , opts . concat ( {
14
+ const uri = `/-/org/${ eu ( scope ) } /team`
15
+ return npmFetch . json ( uri , {
16
+ ...opts ,
22
17
method : 'PUT' ,
23
18
scope,
24
19
body : { name : team , description : opts . description }
25
- } ) )
20
+ } )
26
21
} )
27
22
}
28
23
29
- cmd . destroy = ( entity , opts ) => {
30
- opts = TeamConfig ( opts )
24
+ cmd . destroy = ( entity , opts = { } ) => {
31
25
return pwrap ( opts , ( ) => {
32
26
const { scope, team } = splitEntity ( entity )
33
27
validate ( 'SSO' , [ scope , team , opts ] )
34
- return npmFetch . json ( `/-/team/${ eu ( scope ) } /${ eu ( team ) } ` , opts . concat ( {
28
+ const uri = `/-/team/${ eu ( scope ) } /${ eu ( team ) } `
29
+ return npmFetch . json ( uri , {
30
+ ...opts ,
35
31
method : 'DELETE' ,
36
32
scope
37
- } ) )
33
+ } )
38
34
} )
39
35
}
40
36
41
- cmd . add = ( user , entity , opts ) => {
42
- opts = TeamConfig ( opts )
37
+ cmd . add = ( user , entity , opts = { } ) => {
43
38
return pwrap ( opts , ( ) => {
44
39
const { scope, team } = splitEntity ( entity )
45
40
validate ( 'SSO' , [ scope , team , opts ] )
46
- return npmFetch . json ( `/-/team/${ eu ( scope ) } /${ eu ( team ) } /user` , opts . concat ( {
41
+ const uri = `/-/team/${ eu ( scope ) } /${ eu ( team ) } /user`
42
+ return npmFetch . json ( uri , {
43
+ ...opts ,
47
44
method : 'PUT' ,
48
45
scope,
49
46
body : { user }
50
- } ) )
47
+ } )
51
48
} )
52
49
}
53
50
54
- cmd . rm = ( user , entity , opts ) => {
55
- opts = TeamConfig ( opts )
51
+ cmd . rm = ( user , entity , opts = { } ) => {
56
52
return pwrap ( opts , ( ) => {
57
53
const { scope, team } = splitEntity ( entity )
58
54
validate ( 'SSO' , [ scope , team , opts ] )
59
- return npmFetch . json ( `/-/team/${ eu ( scope ) } /${ eu ( team ) } /user` , opts . concat ( {
55
+ const uri = `/-/team/${ eu ( scope ) } /${ eu ( team ) } /user`
56
+ return npmFetch . json ( uri , {
57
+ ...opts ,
60
58
method : 'DELETE' ,
61
59
scope,
62
60
body : { user }
63
- } ) )
61
+ } )
64
62
} )
65
63
}
66
64
67
- cmd . lsTeams = ( scope , opts ) => {
68
- opts = TeamConfig ( opts )
69
- return pwrap ( opts , ( ) => getStream . array ( cmd . lsTeams . stream ( scope , opts ) ) )
65
+ cmd . lsTeams = ( scope , opts = { } ) => {
66
+ return pwrap ( opts , ( ) => {
67
+ return getStream . array ( cmd . lsTeams . stream ( scope , { ...opts } ) )
68
+ } )
70
69
}
71
- cmd . lsTeams . stream = ( scope , opts ) => {
72
- opts = TeamConfig ( opts )
70
+ cmd . lsTeams . stream = ( scope , opts = { } ) => {
73
71
validate ( 'SO' , [ scope , opts ] )
74
- return npmFetch . json . stream ( `/-/org/${ eu ( scope ) } /team` , '.*' , opts . concat ( {
72
+ const uri = `/-/org/${ eu ( scope ) } /team`
73
+ return npmFetch . json . stream ( uri , '.*' , {
74
+ ...opts ,
75
75
query : { format : 'cli' }
76
- } ) )
76
+ } )
77
77
}
78
78
79
- cmd . lsUsers = ( entity , opts ) => {
80
- opts = TeamConfig ( opts )
81
- return pwrap ( opts , ( ) => getStream . array ( cmd . lsUsers . stream ( entity , opts ) ) )
79
+ cmd . lsUsers = ( entity , opts = { } ) => {
80
+ return pwrap ( opts , ( ) => {
81
+ return getStream . array ( cmd . lsUsers . stream ( entity , { ...opts } ) )
82
+ } )
82
83
}
83
- cmd . lsUsers . stream = ( entity , opts ) => {
84
- opts = TeamConfig ( opts )
84
+ cmd . lsUsers . stream = ( entity , opts = { } ) => {
85
85
const { scope, team } = splitEntity ( entity )
86
86
validate ( 'SSO' , [ scope , team , opts ] )
87
87
const uri = `/-/team/${ eu ( scope ) } /${ eu ( team ) } /user`
88
- return npmFetch . json . stream ( uri , '.*' , opts . concat ( {
88
+ return npmFetch . json . stream ( uri , '.*' , {
89
+ ...opts ,
89
90
query : { format : 'cli' }
90
- } ) )
91
+ } )
91
92
}
92
93
93
94
cmd . edit = ( ) => {
@@ -100,7 +101,7 @@ function splitEntity (entity = '') {
100
101
}
101
102
102
103
function pwrap ( opts , fn ) {
103
- return new opts . Promise ( ( resolve , reject ) => {
104
+ return new Promise ( ( resolve , reject ) => {
104
105
fn ( ) . then ( resolve , reject )
105
106
} )
106
107
}
0 commit comments