Skip to content

Commit 08a62b0

Browse files
authored
Merge pull request #110 from zotoio/feature/projects
feat(projects): exposed the project capability from the Launch Darkly APIs
2 parents 7b494d4 + 9f7132c commit 08a62b0

File tree

10 files changed

+3914
-1581
lines changed

10 files changed

+3914
-1581
lines changed

API.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<dd></dd>
1212
<dt><a href="#LaunchDarklyUtilsMembers">LaunchDarklyUtilsMembers</a></dt>
1313
<dd></dd>
14+
<dt><a href="#LaunchDarklyUtilsProjects">LaunchDarklyUtilsProjects</a></dt>
15+
<dd></dd>
1416
<dt><a href="#LaunchDarklyUtilsRoles">LaunchDarklyUtilsRoles</a></dt>
1517
<dd></dd>
1618
</dl>
@@ -377,6 +379,125 @@ Invite a New Team Member by their Email Address
377379
| emailAddress | <code>String</code> | | Email Address of New Member |
378380
| initialRoleKey | <code>String</code> | <code>reader</code> | Default Role for New Member |
379381

382+
<a name="LaunchDarklyUtilsProjects"></a>
383+
384+
## LaunchDarklyUtilsProjects
385+
**Kind**: global class
386+
387+
* [LaunchDarklyUtilsProjects](#LaunchDarklyUtilsProjects)
388+
* [new LaunchDarklyUtilsProjects(apiClient, log, ldUtils)](#new_LaunchDarklyUtilsProjects_new)
389+
* [.API_GROUP](#LaunchDarklyUtilsProjects+API_GROUP) ⇒ <code>string</code>
390+
* [.getProjects()](#LaunchDarklyUtilsProjects+getProjects) ⇒ <code>Promise</code>
391+
* [.getProject(projectKey)](#LaunchDarklyUtilsProjects+getProject) ⇒ <code>Promise</code>
392+
* [.createProject(projectName, projectKey, includeInSnippetByDefault, tags, environments, defaultClientSideAvailability)](#LaunchDarklyUtilsProjects+createProject) ⇒ <code>Promise</code>
393+
* [.updateProject(projectKey, jsonPatch)](#LaunchDarklyUtilsProjects+updateProject) ⇒ <code>Promise</code>
394+
* [.deleteProject(projectKey)](#LaunchDarklyUtilsProjects+deleteProject)
395+
396+
<a name="new_LaunchDarklyUtilsProjects_new"></a>
397+
398+
### new LaunchDarklyUtilsProjects(apiClient, log, ldUtils)
399+
Projects specific api functions attached as 'LaunchDarklyUtils.projects'
400+
401+
**Returns**: [<code>LaunchDarklyUtilsMembers</code>](#LaunchDarklyUtilsMembers) - team member api functions
402+
403+
| Param | Type | Description |
404+
| --- | --- | --- |
405+
| apiClient | <code>Swagger</code> | generated launchdarkly apiClient |
406+
| log | <code>Object</code> | logger implementation, or 'console' |
407+
| ldUtils | [<code>LaunchDarklyUtils</code>](#LaunchDarklyUtils) | primary utils class |
408+
409+
<a name="LaunchDarklyUtilsProjects+API_GROUP"></a>
410+
411+
### launchDarklyUtilsProjects.API\_GROUP ⇒ <code>string</code>
412+
Api group object key in LD api
413+
414+
**Kind**: instance property of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
415+
<a name="LaunchDarklyUtilsProjects+getProjects"></a>
416+
417+
### launchDarklyUtilsProjects.getProjects() ⇒ <code>Promise</code>
418+
Get all projects in account
419+
420+
**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
421+
**Fulfil**: <code>Object</code> List of projects JSON
422+
**Reject**: <code>Error</code> object with message
423+
**Example**
424+
```js
425+
ldutils getProjects
426+
```
427+
<a name="LaunchDarklyUtilsProjects+getProject"></a>
428+
429+
### launchDarklyUtilsProjects.getProject(projectKey) ⇒ <code>Promise</code>
430+
get a single project by project key
431+
432+
**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
433+
**Fulfil**: <code>Object</code> project object json
434+
**Reject**: <code>Error</code> object with message
435+
436+
| Param | Description |
437+
| --- | --- |
438+
| projectKey | _id field of team member |
439+
440+
**Example**
441+
```js
442+
ldutils getProject new-project
443+
```
444+
<a name="LaunchDarklyUtilsProjects+createProject"></a>
445+
446+
### launchDarklyUtilsProjects.createProject(projectName, projectKey, includeInSnippetByDefault, tags, environments, defaultClientSideAvailability) ⇒ <code>Promise</code>
447+
Create a project in the account
448+
449+
**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
450+
**Fulfil**: <code>Object</code> project object json
451+
**Reject**: <code>Error</code> object with message
452+
453+
| Param | Type | Description |
454+
| --- | --- | --- |
455+
| projectName | <code>\*</code> | the name of the project |
456+
| projectKey | <code>\*</code> | the key that identifies the project |
457+
| includeInSnippetByDefault | <code>\*</code> | boolean true / false of whether should include a snippet |
458+
| tags | <code>\*</code> | arrays of tags that can be associated with the project |
459+
| environments | <code>\*</code> | an array of environments that are associated with the account |
460+
| defaultClientSideAvailability | <code>\*</code> | An object that defines wether the SDK and / or mobile flags are available |
461+
462+
**Example**
463+
```js
464+
ldutils createProject new-project 'New Project' 'false' dev,Development,#41705:test,Test,f5a623 'true' 'false' marketing,online
465+
```
466+
<a name="LaunchDarklyUtilsProjects+updateProject"></a>
467+
468+
### launchDarklyUtilsProjects.updateProject(projectKey, jsonPatch) ⇒ <code>Promise</code>
469+
Patch a single project using jsonPatch notation
470+
471+
**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
472+
**Fulfil**: <code>Object</code> an empty project
473+
**Reject**: <code>Error</code> object with message
474+
475+
| Param | Type | Description |
476+
| --- | --- | --- |
477+
| projectKey | <code>\*</code> | projectKey a key that identifies the project |
478+
| jsonPatch | <code>\*</code> | an array of string using the JSON patch notation https://tools.ietf.org/html/rfc6902 |
479+
480+
**Example**
481+
```js
482+
ldutils updateProject new-project [{ op: 'replace', path: '/name', value: 'New project name' }]
483+
```
484+
<a name="LaunchDarklyUtilsProjects+deleteProject"></a>
485+
486+
### launchDarklyUtilsProjects.deleteProject(projectKey)
487+
Delete a project
488+
489+
**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
490+
**Fulfil**: <code>Object</code> an empty project
491+
**Reject**: <code>Error</code> object with message
492+
493+
| Param | Type | Description |
494+
| --- | --- | --- |
495+
| projectKey | <code>\*</code> | projectKey a key that identifies the project |
496+
497+
**Example**
498+
```js
499+
ldutils deleteProject new-project
500+
```
380501
<a name="LaunchDarklyUtilsRoles"></a>
381502

382503
## LaunchDarklyUtilsRoles

ldutils

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,55 @@ process.on('unhandledRejection', (reason, p) => {
2222
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

25+
program
26+
.command('getProjects')
27+
.description('get all the projects associated with the account')
28+
.action(() => {
29+
ldUtils.projects.getProjects().then(response => {
30+
console.log(json.plain(reponse));
31+
});
32+
});
33+
34+
program
35+
.command('getProject <projectKey>')
36+
.description('get a project for the specified projectKey')
37+
.action(projectKey => {
38+
ldUtils.projects.getProject(projectKey).then(response => {
39+
console.log(json.plain(response));
40+
});
41+
});
42+
43+
program
44+
.command(
45+
'createProject <projectKey> <projectName> [includeInSnippetByDefault] [environments] [defaultClientSideAvailability] [tags]'
46+
)
47+
.description('Create a new project')
48+
.action(
49+
(projectKey, projectName, includeInSnippetByDefault, tags, environments, defaultClientSideAvailability) => {
50+
ldUtils.projects
51+
.createProject(
52+
projectKey,
53+
projectName,
54+
includeInSnippetByDefault,
55+
tags,
56+
environments,
57+
defaultClientSideAvailability
58+
)
59+
.then(response => {
60+
console.log(json.plain(reponse));
61+
});
62+
}
63+
);
64+
65+
program
66+
.command('deleteProject <projectKey>')
67+
.description('delete a project by the specified projectKey')
68+
.action(projectKey => {
69+
ldUtils.projects.deleteProject(projectKey).then(response => {
70+
console.log(json.plain(reponse));
71+
});
72+
});
73+
2574
program
2675
.command('getFeatureFlags <projectKey>')
2776
.description('get all flags for a given project')

src/LaunchDarklyUtils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LaunchDarklyUtilsRoles } from './LaunchDarklyUtilsRoles';
44
import { LaunchDarklyApiClient } from './LaunchDarklyApiClient';
55
import { LaunchDarklyLogger } from './LaunchDarklyLogger';
66
import { default as dotenv } from 'dotenv';
7+
import { LaunchDarklyUtilsProjects } from './LaunchDarklyUtilsProjects';
78
dotenv.config();
89

910
/**
@@ -34,6 +35,7 @@ export class LaunchDarklyUtils {
3435
this.flags = new LaunchDarklyUtilsFlags(this.apiClient, this.log, this);
3536
this.roles = new LaunchDarklyUtilsRoles(this.apiClient, this.log, this);
3637
this.members = new LaunchDarklyUtilsMembers(this.apiClient, this.log, this);
38+
this.projects = new LaunchDarklyUtilsProjects(this.apiClient, this.log, this);
3739
this.log.debug(`utils ready.`);
3840
} catch (e) {
3941
this.log.error(e);

0 commit comments

Comments
 (0)