Skip to content

Commit 7b494d4

Browse files
authored
Merge pull request #107 from zotoio/fix/upgrade-deps
feat(upgrade): use latest swagger, and ..
2 parents 4253977 + d805ca1 commit 7b494d4

14 files changed

+5528
-3176
lines changed

.eslintrc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
"semi": [
2727
"error",
2828
"always"
29-
]
29+
],
30+
"comma-dangle": ["error", "never"],
31+
"arrow-parens": ["error", "as-needed"],
32+
"space-before-function-paren": ["error", {
33+
"anonymous": "never",
34+
"named": "never",
35+
"asyncArrow": "always"
36+
}],
37+
"keyword-spacing": ["error", { "before": true }]
3038
}
3139
}

.prettierrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"useTabs": false,
33
"printWidth": 120,
44
"tabWidth": 4,
5-
"singleQuote": true
5+
"singleQuote": true,
6+
"arrowParens": "avoid",
7+
"trailingComma": "none"
68
}

API.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ ldutils restoreFeatureFlags my-project my-flag,my-flag-two prod ./preReleaseBack
268268
* [LaunchDarklyUtilsMembers](#LaunchDarklyUtilsMembers)
269269
* [new LaunchDarklyUtilsMembers(apiClient, log, ldUtils)](#new_LaunchDarklyUtilsMembers_new)
270270
* [.API_GROUP](#LaunchDarklyUtilsMembers+API_GROUP) ⇒ <code>string</code>
271-
* [.getTeamMembers()](#LaunchDarklyUtilsMembers+getTeamMembers) ⇒ <code>Promise</code>
271+
* [.getTeamMembers(limit, offset, filter)](#LaunchDarklyUtilsMembers+getTeamMembers) ⇒ <code>Promise</code>
272272
* [.getTeamMember(memberId)](#LaunchDarklyUtilsMembers+getTeamMember) ⇒ <code>Promise</code>
273273
* [.getTeamMemberByEmail(emailAddress)](#LaunchDarklyUtilsMembers+getTeamMemberByEmail) ⇒ <code>Promise</code>
274274
* [.getTeamMemberCustomRoles(emailAddress)](#LaunchDarklyUtilsMembers+getTeamMemberCustomRoles) ⇒ <code>Promise</code>
@@ -295,12 +295,19 @@ Api group object key in LD api
295295
**Kind**: instance property of [<code>LaunchDarklyUtilsMembers</code>](#LaunchDarklyUtilsMembers)
296296
<a name="LaunchDarklyUtilsMembers+getTeamMembers"></a>
297297

298-
### launchDarklyUtilsMembers.getTeamMembers() ⇒ <code>Promise</code>
298+
### launchDarklyUtilsMembers.getTeamMembers(limit, offset, filter) ⇒ <code>Promise</code>
299299
Get all team members in account
300300

301301
**Kind**: instance method of [<code>LaunchDarklyUtilsMembers</code>](#LaunchDarklyUtilsMembers)
302302
**Fulfil**: <code>Object</code> team member list json
303303
**Reject**: <code>Error</code> object with message
304+
305+
| Param | Description |
306+
| --- | --- |
307+
| limit | max number of members to return (defaults to 20 per api) |
308+
| offset | starting offset to return |
309+
| filter | an optional filter https://apidocs.launchdarkly.com/reference#list-team-members |
310+
304311
**Example**
305312
```js
306313
ldutils getTeamMembers
@@ -450,7 +457,7 @@ Get a single role by _id
450457

451458
**Example**
452459
```js
453-
ldutils getCustomRoleById 5a554j890b575421b255d96e
460+
ldutils getCustomRoleById <id>
454461
```
455462
<a name="LaunchDarklyUtilsRoles+createCustomRole"></a>
456463

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LaunchDarkly nodejs utils
22

33
[![npm version](https://badge.fury.io/js/launchdarkly-nodeutils.svg)](https://badge.fury.io/js/launchdarkly-nodeutils)
4-
[![Build Status](https://travis-ci.org/zotoio/launchdarkly-nodeutils.svg?branch=master)](https://travis-ci.org/zotoio/launchdarkly-nodeutils)
4+
[![Build Status](https://travis-ci.com/zotoio/launchdarkly-nodeutils.svg?branch=master)](https://travis-ci.org/zotoio/launchdarkly-nodeutils)
55
[![Code Climate](https://img.shields.io/codeclimate/maintainability/zotoio/launchdarkly-nodeutils.svg)](https://codeclimate.com/github/zotoio/launchdarkly-nodeutils)
66
[![Test Coverage](https://codeclimate.com/github/zotoio/launchdarkly-nodeutils/badges/coverage.svg)](https://codeclimate.com/github/zotoio/launchdarkly-nodeutils/coverage)
77
[![Greenkeeper badge](https://badges.greenkeeper.io/zotoio/launchdarkly-nodeutils.svg)](https://greenkeeper.io/)
@@ -16,12 +16,33 @@ This unofficial module provides NodeJs functions wrapping the LaunchDarkly API.
1616
We need a way to manage flags as part of CI/CD pipelines, and there is not another project currently providing a simple interface to manage flags and other objects in LaunchDarkly via API in nodejs.
1717

1818
## How?
19-
There is a swagger.yaml available to generate bindings (https://launchdarkly.github.io/ld-openapi/swagger.yaml), so we use the swagger-js module to generate a client (https://github.com/swagger-api/swagger-js), and add some extra features around logging, error handling, and chaining of operations.
19+
There is an openapi spec available to generate bindings (https://launchdarkly.github.io/ld-openapi/openapi.yaml), so we use the swagger-js module to generate a client (https://github.com/swagger-api/swagger-js), and add some extra features around logging, error handling, and chaining of operations.
2020
In addition we expose apis as a commandline tool.
2121

2222
## Install
23-
1. `npm install launchdarkly-nodeutils --save` or clone this repo.
24-
2. Generate an access token with the permissions for the operations you will use. Please read: https://docs.launchdarkly.com/v2.0/docs/api-access-tokens
23+
1. `npm install launchdarkly-nodeutils -g` (this will install the `ldutils` command).
24+
1. Generate an access token with the permissions for the operations you will use. Please read: https://docs.launchdarkly.com/v2.0/docs/api-access-tokens
25+
1. export your api token `export LAUNCHDARKLY_API_TOKEN=<api-token>`
26+
1. run `ldutils` to confirm your installation was successful - you should see usage instructions.
27+
28+
The installation instructions above should be all you need to do. Alternatively, you can clone this repo and install manually.
29+
30+
After cloning this repo:
31+
1. run `yarn build`
32+
1. check that `ldutils` is executable and run it:
33+
```
34+
chmod 755 ./ldutils
35+
./ldutils
36+
```
37+
38+
The above will display a help screen of instructions, thanks to https://github.com/tj/commander.js/
39+
40+
Optionally you can add `ldutils` to your PATH, or symlink in a directory already in your path:
41+
42+
```
43+
sudo ln -s /<clonepath>/launchdarkly-nodeutils/ldutils /usr/local/bin/ldutils
44+
```
45+
> Make sure you have env var LAUNCHDARKLY_API_TOKEN set, and if piping output to another command, ensure that LAUNCHDARKLY_API_LOGLEVEL is not set to 'debug' to ensure only the json result of the command is returned.
2546
2647
## Use cases
2748
The command line tool or nodejs module can be used for many things. Here are some examples.
@@ -51,29 +72,8 @@ Copying flag attributes from prod back to preprod for testing. Also newly create
5172

5273

5374
## Command line usage
54-
After cloning this repo you can make `ldutils` executable, and use it to make api calls based on passed in parameters.
55-
56-
> please read the [API documentation](API.md) for examples.
57-
58-
```
59-
chmod 755 ./ldutils
60-
./ldutils
61-
```
62-
63-
The above will display a help screen of instructions, thanks to https://github.com/tj/commander.js/
64-
65-
Optionally you can add `ldutils` to your PATH:
66-
67-
```
68-
# cloned repo
69-
sudo ln -s /<clonepath>/launchdarkly-nodeutils/ldutils /usr/local/bin/ldutils
70-
71-
# or after 'npm install launchdarkly-nodeutils --save'
72-
sudo ln -s /<installpath>/node_modules/launchdarkly-nodeutils/ldutils /usr/local/bin/ldutils
73-
```
74-
> Make sure you have env var LAUNCHDARKLY_API_TOKEN set, and if piping output to another command, ensure that LAUNCHDARKLY_API_LOGLEVEL is not set to 'debug' to ensure only the json result of the command is returned.
7575

76-
Here are some examples of commandline usage (if you have not added ldutils to PATH, prefix with `./`:
76+
Here are some examples of commandline usage - see below for all available command modes:
7777
```
7878
export LAUNCHDARKLY_API_TOKEN=<api-token>
7979

ldutils

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,208 +19,206 @@ process.on('unhandledRejection', (reason, p) => {
1919
process.exit(1);
2020
});
2121

22-
new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(function(ldUtils) {
22+
new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(ldUtils => {
2323
program.version('1.0.0').description('Manage LaunchDarkly flags and other assets from the command line.');
2424

2525
program
2626
.command('getFeatureFlags <projectKey>')
2727
.description('get all flags for a given project')
28-
.action(function(projectKey) {
29-
ldUtils.flags.getFeatureFlags(projectKey).then(function(response) {
28+
.action(projectKey => {
29+
ldUtils.flags.getFeatureFlags(projectKey).then(response => {
3030
console.log(json.plain(response));
3131
});
3232
});
3333

3434
program
3535
.command(`getFeatureFlag <projectKey> <featureFlagKey> [environmentKeyQuery]`)
3636
.description('get a single flag - with optional env')
37-
.action(function(projectKey, featureFlagKey, environmentKeyQuery) {
38-
ldUtils.flags.getFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery).then(function(response) {
37+
.action((projectKey, featureFlagKey, environmentKeyQuery) => {
38+
ldUtils.flags.getFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery).then(response => {
3939
console.log(json.plain(response));
4040
});
4141
});
4242

4343
program
4444
.command(`getFeatureFlagState <projectKey> <featureFlagKey> <environmentKeyQuery>`)
4545
.description('get boolean flag state')
46-
.action(function(projectKey, featureFlagKey, environmentKeyQuery) {
47-
ldUtils.flags.getFeatureFlagState(projectKey, featureFlagKey, environmentKeyQuery).then(function(response) {
46+
.action((projectKey, featureFlagKey, environmentKeyQuery) => {
47+
ldUtils.flags.getFeatureFlagState(projectKey, featureFlagKey, environmentKeyQuery).then(response => {
4848
console.log(json.plain(response));
4949
});
5050
});
5151

5252
program
5353
.command(`toggleFeatureFlag <projectKey> <featureFlagKey> <environmentKeyQuery> <value>`)
5454
.description('set boolean flag state')
55-
.action(function(projectKey, featureFlagKey, environmentKeyQuery, value) {
55+
.action((projectKey, featureFlagKey, environmentKeyQuery, value) => {
5656
let enabled = value === 'true';
57-
ldUtils.flags
58-
.toggleFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery, enabled)
59-
.then(function(response) {
60-
console.log(json.plain(response));
61-
});
57+
ldUtils.flags.toggleFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery, enabled).then(response => {
58+
console.log(json.plain(response));
59+
});
6260
});
6361

6462
program
6563
.command(`migrateFeatureFlag <projectKey> <featureFlagKey> <fromEnv> <toEnv> (includeState)`)
6664
.description('migrate flag settings from one environment to another')
67-
.action(function(projectKey, featureFlagKey, fromEnv, toEnv, includeState) {
65+
.action((projectKey, featureFlagKey, fromEnv, toEnv, includeState) => {
6866
ldUtils.flags
6967
.migrateFeatureFlag(projectKey, featureFlagKey, fromEnv, toEnv, includeState)
70-
.then(function(response) {
68+
.then(response => {
7169
console.log(json.plain(response));
7270
});
7371
});
7472

7573
program
7674
.command(`bulkMigrateFeatureFlags <projectKey> <featureFlagKeys> <fromEnv> <toEnv> (includeState)`)
7775
.description('migrate multiple flag settings from one environment to another')
78-
.action(function(projectKey, featureFlagKeys, fromEnv, toEnv, includeState) {
76+
.action((projectKey, featureFlagKeys, fromEnv, toEnv, includeState) => {
7977
ldUtils.flags
8078
.bulkMigrateFeatureFlags(projectKey, featureFlagKeys, fromEnv, toEnv, includeState)
81-
.then(function(response) {
79+
.then(response => {
8280
console.log(json.plain(response));
8381
});
8482
});
8583

8684
program
8785
.command(`restoreFeatureFlags <projectKey> <featureFlagKeys> <targetEnv> <backupJsonFile> (includeState)`)
8886
.description('restore environment flag settings from a backup file - backup from getFeatureFlags')
89-
.action(function(projectKey, featureFlagKeys, targetEnv, backupJsonFile, includeState) {
87+
.action((projectKey, featureFlagKeys, targetEnv, backupJsonFile, includeState) => {
9088
ldUtils.flags
9189
.restoreFeatureFlags(projectKey, featureFlagKeys, targetEnv, backupJsonFile, includeState)
92-
.then(function(response) {
90+
.then(response => {
9391
console.log(json.plain(response));
9492
});
9593
});
9694

9795
program
9896
.command('getCustomRoles')
9997
.description('get all custom roles in account')
100-
.action(function() {
101-
ldUtils.roles.getCustomRoles().then(function(response) {
98+
.action(() => {
99+
ldUtils.roles.getCustomRoles().then(response => {
102100
console.log(json.plain(response));
103101
});
104102
});
105103

106104
program
107105
.command('getCustomRole <customRoleKey>')
108106
.description('get custom role by key')
109-
.action(function(customRoleKey) {
110-
ldUtils.roles.getCustomRole(customRoleKey).then(function(response) {
107+
.action(customRoleKey => {
108+
ldUtils.roles.getCustomRole(customRoleKey).then(response => {
111109
console.log(json.plain(response));
112110
});
113111
});
114112

115113
program
116114
.command('getCustomRoleById <customRoleId>')
117115
.description('get custom role by id')
118-
.action(function(customRoleId) {
119-
ldUtils.roles.getCustomRoleById(customRoleId).then(function(response) {
116+
.action(customRoleId => {
117+
ldUtils.roles.getCustomRoleById(customRoleId).then(response => {
120118
console.log(json.plain(response));
121119
});
122120
});
123121

124122
program
125123
.command(`createCustomRole <customRoleKey> <customRoleName> <customRolePolicyArray> [customRoleDescription]`)
126124
.description('create custom role')
127-
.action(function(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {
125+
.action((customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) => {
128126
customRolePolicyArray = JSON.parse(customRolePolicyArray);
129127
ldUtils.roles
130128
.createCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription)
131-
.then(function(response) {
129+
.then(response => {
132130
console.log(json.plain(response));
133131
});
134132
});
135133

136134
program
137135
.command(`updateCustomRole <customRoleKey> <customRoleName> <customRolePolicyArray> [customRoleDescription]`)
138136
.description('update custom role')
139-
.action(function(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {
137+
.action((customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) => {
140138
customRolePolicyArray = JSON.parse(customRolePolicyArray);
141139
ldUtils.roles
142140
.updateCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription)
143-
.then(function(response) {
141+
.then(response => {
144142
console.log(json.plain(response));
145143
});
146144
});
147145

148146
program
149147
.command(`upsertCustomRole <customRoleKey> <customRoleName> <customRolePolicyArray> [customRoleDescription]`)
150148
.description('create or update custom role')
151-
.action(function(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {
149+
.action((customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) => {
152150
customRolePolicyArray = JSON.parse(customRolePolicyArray);
153151
ldUtils.roles
154152
.upsertCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription)
155-
.then(function(response) {
153+
.then(response => {
156154
console.log(json.plain(response));
157155
});
158156
});
159157

160158
program
161159
.command('bulkUpsertCustomRoles <roleBulkLoadFile>')
162160
.description('path to a file containing array of role json')
163-
.action(function(roleBulkLoadFile) {
164-
ldUtils.roles.bulkUpsertCustomRoles(roleBulkLoadFile).then(function(response) {
161+
.action(roleBulkLoadFile => {
162+
ldUtils.roles.bulkUpsertCustomRoles(roleBulkLoadFile).then(response => {
165163
console.log(json.plain(response));
166164
});
167165
});
168166

169167
program
170168
.command('bulkUpsertCustomRoleFolder <roleFolder>')
171169
.description('path to a directory containing multiple files of role json')
172-
.action(function(roleFolder) {
173-
ldUtils.roles.bulkUpsertCustomRoleFolder(roleFolder).then(function(response) {
170+
.action(roleFolder => {
171+
ldUtils.roles.bulkUpsertCustomRoleFolder(roleFolder).then(response => {
174172
console.log(json.plain(response));
175173
});
176174
});
177175

178176
program
179177
.command('inviteTeamMember <emailAddress> <initialRoleName>')
180178
.description('Invite a New Team Member')
181-
.action(function(emailAddress, initialRoleName) {
182-
ldUtils.members.inviteTeamMember(emailAddress, initialRoleName).then(function(response) {
179+
.action((emailAddress, initialRoleName) => {
180+
ldUtils.members.inviteTeamMember(emailAddress, initialRoleName).then(response => {
183181
console.log(json.plain(response));
184182
});
185183
});
186184

187185
program
188-
.command('getTeamMembers')
186+
.command('getTeamMembers [limit] [offset] [filter]')
189187
.description('list all team members in account')
190-
.action(function() {
191-
ldUtils.members.getTeamMembers().then(function(response) {
188+
.action((limit, offset, filter) => {
189+
ldUtils.members.getTeamMembers(limit, offset, filter).then(response => {
192190
console.log(json.plain(response));
193191
});
194192
});
195193

196194
program
197195
.command('getTeamMember <memberId>')
198196
.description('get a team member by id')
199-
.action(function(memberId) {
200-
ldUtils.members.getTeamMember(memberId).then(function(response) {
197+
.action(memberId => {
198+
ldUtils.members.getTeamMember(memberId).then(response => {
201199
console.log(json.plain(response));
202200
});
203201
});
204202

205203
program
206204
.command('getTeamMemberByEmail <emailAddress>')
207205
.description('get a team member by email address')
208-
.action(function(emailAddress) {
209-
ldUtils.members.getTeamMemberByEmail(emailAddress).then(function(response) {
206+
.action(emailAddress => {
207+
ldUtils.members.getTeamMemberByEmail(emailAddress).then(response => {
210208
console.log(json.plain(response));
211209
});
212210
});
213211

214212
program
215213
.command('getTeamMemberCustomRoles <emailAddress>')
216214
.description('get a team members custom roles by email address')
217-
.action(function(emailAddress) {
218-
ldUtils.members.getTeamMemberCustomRoles(emailAddress).then(function(response) {
215+
.action(emailAddress => {
216+
ldUtils.members.getTeamMemberCustomRoles(emailAddress).then(response => {
219217
console.log(json.plain(response));
220218
});
221219
});
222220

223-
program.on('--help', function() {
221+
program.on('--help', () => {
224222
console.log('\n See https://github.com/zotoio/launchdarkly-nodeutils/API.md for examples.\n');
225223
});
226224

0 commit comments

Comments
 (0)