Skip to content

Commit

Permalink
Merge pull request #110 from zotoio/feature/projects
Browse files Browse the repository at this point in the history
feat(projects): exposed the project capability from the Launch Darkly APIs
  • Loading branch information
Younis-NAB authored Feb 21, 2021
2 parents 7b494d4 + 9f7132c commit 08a62b0
Show file tree
Hide file tree
Showing 10 changed files with 3,914 additions and 1,581 deletions.
121 changes: 121 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<dd></dd>
<dt><a href="#LaunchDarklyUtilsMembers">LaunchDarklyUtilsMembers</a></dt>
<dd></dd>
<dt><a href="#LaunchDarklyUtilsProjects">LaunchDarklyUtilsProjects</a></dt>
<dd></dd>
<dt><a href="#LaunchDarklyUtilsRoles">LaunchDarklyUtilsRoles</a></dt>
<dd></dd>
</dl>
Expand Down Expand Up @@ -377,6 +379,125 @@ Invite a New Team Member by their Email Address
| emailAddress | <code>String</code> | | Email Address of New Member |
| initialRoleKey | <code>String</code> | <code>reader</code> | Default Role for New Member |

<a name="LaunchDarklyUtilsProjects"></a>

## LaunchDarklyUtilsProjects
**Kind**: global class

* [LaunchDarklyUtilsProjects](#LaunchDarklyUtilsProjects)
* [new LaunchDarklyUtilsProjects(apiClient, log, ldUtils)](#new_LaunchDarklyUtilsProjects_new)
* [.API_GROUP](#LaunchDarklyUtilsProjects+API_GROUP) ⇒ <code>string</code>
* [.getProjects()](#LaunchDarklyUtilsProjects+getProjects) ⇒ <code>Promise</code>
* [.getProject(projectKey)](#LaunchDarklyUtilsProjects+getProject) ⇒ <code>Promise</code>
* [.createProject(projectName, projectKey, includeInSnippetByDefault, tags, environments, defaultClientSideAvailability)](#LaunchDarklyUtilsProjects+createProject) ⇒ <code>Promise</code>
* [.updateProject(projectKey, jsonPatch)](#LaunchDarklyUtilsProjects+updateProject) ⇒ <code>Promise</code>
* [.deleteProject(projectKey)](#LaunchDarklyUtilsProjects+deleteProject)

<a name="new_LaunchDarklyUtilsProjects_new"></a>

### new LaunchDarklyUtilsProjects(apiClient, log, ldUtils)
Projects specific api functions attached as 'LaunchDarklyUtils.projects'

**Returns**: [<code>LaunchDarklyUtilsMembers</code>](#LaunchDarklyUtilsMembers) - team member api functions

| Param | Type | Description |
| --- | --- | --- |
| apiClient | <code>Swagger</code> | generated launchdarkly apiClient |
| log | <code>Object</code> | logger implementation, or 'console' |
| ldUtils | [<code>LaunchDarklyUtils</code>](#LaunchDarklyUtils) | primary utils class |

<a name="LaunchDarklyUtilsProjects+API_GROUP"></a>

### launchDarklyUtilsProjects.API\_GROUP ⇒ <code>string</code>
Api group object key in LD api

**Kind**: instance property of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
<a name="LaunchDarklyUtilsProjects+getProjects"></a>

### launchDarklyUtilsProjects.getProjects() ⇒ <code>Promise</code>
Get all projects in account

**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
**Fulfil**: <code>Object</code> List of projects JSON
**Reject**: <code>Error</code> object with message
**Example**
```js
ldutils getProjects
```
<a name="LaunchDarklyUtilsProjects+getProject"></a>

### launchDarklyUtilsProjects.getProject(projectKey) ⇒ <code>Promise</code>
get a single project by project key

**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
**Fulfil**: <code>Object</code> project object json
**Reject**: <code>Error</code> object with message

| Param | Description |
| --- | --- |
| projectKey | _id field of team member |

**Example**
```js
ldutils getProject new-project
```
<a name="LaunchDarklyUtilsProjects+createProject"></a>

### launchDarklyUtilsProjects.createProject(projectName, projectKey, includeInSnippetByDefault, tags, environments, defaultClientSideAvailability) ⇒ <code>Promise</code>
Create a project in the account

**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
**Fulfil**: <code>Object</code> project object json
**Reject**: <code>Error</code> object with message

| Param | Type | Description |
| --- | --- | --- |
| projectName | <code>\*</code> | the name of the project |
| projectKey | <code>\*</code> | the key that identifies the project |
| includeInSnippetByDefault | <code>\*</code> | boolean true / false of whether should include a snippet |
| tags | <code>\*</code> | arrays of tags that can be associated with the project |
| environments | <code>\*</code> | an array of environments that are associated with the account |
| defaultClientSideAvailability | <code>\*</code> | An object that defines wether the SDK and / or mobile flags are available |

**Example**
```js
ldutils createProject new-project 'New Project' 'false' dev,Development,#41705:test,Test,f5a623 'true' 'false' marketing,online
```
<a name="LaunchDarklyUtilsProjects+updateProject"></a>

### launchDarklyUtilsProjects.updateProject(projectKey, jsonPatch) ⇒ <code>Promise</code>
Patch a single project using jsonPatch notation

**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
**Fulfil**: <code>Object</code> an empty project
**Reject**: <code>Error</code> object with message

| Param | Type | Description |
| --- | --- | --- |
| projectKey | <code>\*</code> | projectKey a key that identifies the project |
| jsonPatch | <code>\*</code> | an array of string using the JSON patch notation https://tools.ietf.org/html/rfc6902 |

**Example**
```js
ldutils updateProject new-project [{ op: 'replace', path: '/name', value: 'New project name' }]
```
<a name="LaunchDarklyUtilsProjects+deleteProject"></a>

### launchDarklyUtilsProjects.deleteProject(projectKey)
Delete a project

**Kind**: instance method of [<code>LaunchDarklyUtilsProjects</code>](#LaunchDarklyUtilsProjects)
**Fulfil**: <code>Object</code> an empty project
**Reject**: <code>Error</code> object with message

| Param | Type | Description |
| --- | --- | --- |
| projectKey | <code>\*</code> | projectKey a key that identifies the project |

**Example**
```js
ldutils deleteProject new-project
```
<a name="LaunchDarklyUtilsRoles"></a>

## LaunchDarklyUtilsRoles
Expand Down
49 changes: 49 additions & 0 deletions ldutils
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,55 @@ process.on('unhandledRejection', (reason, p) => {
new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(ldUtils => {
program.version('1.0.0').description('Manage LaunchDarkly flags and other assets from the command line.');

program
.command('getProjects')
.description('get all the projects associated with the account')
.action(() => {
ldUtils.projects.getProjects().then(response => {
console.log(json.plain(reponse));
});
});

program
.command('getProject <projectKey>')
.description('get a project for the specified projectKey')
.action(projectKey => {
ldUtils.projects.getProject(projectKey).then(response => {
console.log(json.plain(response));
});
});

program
.command(
'createProject <projectKey> <projectName> [includeInSnippetByDefault] [environments] [defaultClientSideAvailability] [tags]'
)
.description('Create a new project')
.action(
(projectKey, projectName, includeInSnippetByDefault, tags, environments, defaultClientSideAvailability) => {
ldUtils.projects
.createProject(
projectKey,
projectName,
includeInSnippetByDefault,
tags,
environments,
defaultClientSideAvailability
)
.then(response => {
console.log(json.plain(reponse));
});
}
);

program
.command('deleteProject <projectKey>')
.description('delete a project by the specified projectKey')
.action(projectKey => {
ldUtils.projects.deleteProject(projectKey).then(response => {
console.log(json.plain(reponse));
});
});

program
.command('getFeatureFlags <projectKey>')
.description('get all flags for a given project')
Expand Down
2 changes: 2 additions & 0 deletions src/LaunchDarklyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LaunchDarklyUtilsRoles } from './LaunchDarklyUtilsRoles';
import { LaunchDarklyApiClient } from './LaunchDarklyApiClient';
import { LaunchDarklyLogger } from './LaunchDarklyLogger';
import { default as dotenv } from 'dotenv';
import { LaunchDarklyUtilsProjects } from './LaunchDarklyUtilsProjects';
dotenv.config();

/**
Expand Down Expand Up @@ -34,6 +35,7 @@ export class LaunchDarklyUtils {
this.flags = new LaunchDarklyUtilsFlags(this.apiClient, this.log, this);
this.roles = new LaunchDarklyUtilsRoles(this.apiClient, this.log, this);
this.members = new LaunchDarklyUtilsMembers(this.apiClient, this.log, this);
this.projects = new LaunchDarklyUtilsProjects(this.apiClient, this.log, this);
this.log.debug(`utils ready.`);
} catch (e) {
this.log.error(e);
Expand Down
Loading

0 comments on commit 08a62b0

Please sign in to comment.