|
8 | 8 | [](http://commitizen.github.io/cz-cli/) |
9 | 9 | [](https://github.com/semantic-release/semantic-release) |
10 | 10 |
|
11 | | -LaunchDarkly (https://launchdarkly.com/) provides SaaS based Feature Flag management at scale, with SDKs for all major Languages. |
| 11 | +LaunchDarkly (https://launchdarkly.com/) provides SaaS based Feature Flag management at scale, with SDKs for all major languages. |
12 | 12 |
|
13 | 13 | This unofficial module provides NodeJs functions wrapping the LaunchDarkly API. This is not the sdk for implementing flags in your app - it is the api to manage your account/flags. |
14 | 14 |
|
15 | 15 | ## Why? |
16 | 16 | There does not appear to be a project currently providing a simple interface to manage flags in LaunchDarkly via API in nodejs. |
17 | 17 |
|
18 | 18 | ## How? |
19 | | -There is a swagger.yaml available to generate bindings (https://launchdarkly.github.io/ld-openapi/swagger.yaml). Uses the swagger-js module to generate a client (https://github.com/swagger-api/swagger-js), and adds some extra features around logging and input validation. |
| 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 and chaining of operations. |
20 | 20 |
|
21 | 21 | ## Install |
22 | | -`npm install launchdarkly-nodeutils --save` |
| 22 | +1. `npm install launchdarkly-nodeutils --save` |
| 23 | +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 | 24 |
|
24 | 25 | ## Example usage |
25 | | -Note that the api token is not the same as your sdk keys. You need to generate this for your account in LaunchDarkly console. |
| 26 | +Please note that the api token is not the same as your sdk keys. You need to generate this for your account in LaunchDarkly console as above, and set it as the LAUNCHDARKLY_API_TOKEN env var. |
26 | 27 |
|
27 | 28 | ### commandline usage |
| 29 | +Command line support is primarily for debugging api calls. |
28 | 30 | ``` |
29 | 31 | export LAUNCHDARKLY_API_TOKEN=<api-token> |
30 | | -npm run api getFlags <myProjectId> |
| 32 | +
|
| 33 | +// collect all flags for a project |
| 34 | +npm run api -- getFeatureFlags <myProjectId> |
| 35 | +
|
| 36 | +// update or create a customRole with array of policies |
| 37 | +npm run api -- upsertCustomRole <customRoleKey> <customRoleName> '[{"resources":["proj/*"],"actions":["*"],"effect":"allow"}]' |
31 | 38 | ``` |
32 | 39 |
|
33 | 40 | ### node app usage |
| 41 | +Assumes that you have set the LAUNCHDARKLY_API_TOKEN environment var. |
34 | 42 | ``` |
35 | 43 | let ldUtils = await new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN); |
36 | 44 |
|
37 | 45 | // get flag state |
38 | 46 | let flagEnabled = await ldUtils.getFeatureFlagState('myProject', 'feature-abc', 'dev'); |
39 | 47 |
|
40 | 48 | // update flag state to on=true |
41 | | -await ldUtils.toggleFeatureFlag(proj'myProject', 'feature-def', 'dev', true); |
| 49 | +await ldUtils.toggleFeatureFlag('myProject', 'feature-def', 'dev', true); |
42 | 50 | ``` |
| 51 | + |
| 52 | +## commandline modes and parameters |
| 53 | +The command line modes and parameters map directly to the functions exposed for use in nodejs apps. |
| 54 | + |
| 55 | +### Feature flags |
| 56 | + |
| 57 | +| Mode | parameters | |
| 58 | +| ---- | ---------- | |
| 59 | +| getFeatureFlags | projectKey | |
| 60 | +| getFeatureFlag | projectKey, featureFlagKey, environmentKeyQuery | |
| 61 | +| getFeatureFlagState | projectKey, featureFlagKey, environmentKeyQuery | |
| 62 | +| toggleFeatureFlag | projectKey, featureFlagKey, environmentKeyQuery, enabled | |
| 63 | + |
| 64 | +### Custom roles |
| 65 | + |
| 66 | +| Mode | parameters | |
| 67 | +| ---- | ---------- | |
| 68 | +| getCustomRoles | none | |
| 69 | +| getCustomRole | customRoleKey | |
| 70 | +| createCustomRole | createCustomRole | |
| 71 | +| updateCustomRole | customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription(optional) | |
| 72 | +| upsertCustomRole | customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription(optional) | |
| 73 | + |
| 74 | +For details on role policy object structures, please see: https://docs.launchdarkly.com/docs/custom-roles |
0 commit comments