Skip to content

Commit bba2951

Browse files
committed
[Components] launchdarkly - new components
1 parent e86f52d commit bba2951

File tree

12 files changed

+832
-6
lines changed

12 files changed

+832
-6
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import app from "../../launchdarkly.app.mjs";
2+
3+
export default {
4+
key: "launchdarkly-evaluate-feature-flag",
5+
name: "Evaluate Feature Flag",
6+
description: "Evaluates an existing feature flag for a specific user or in a general context. [See the documentation](https://apidocs.launchdarkly.com/tag/Contexts#operation/evaluateContextInstance).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
projectKey: {
12+
propDefinition: [
13+
app,
14+
"project",
15+
],
16+
},
17+
environmentKey: {
18+
propDefinition: [
19+
app,
20+
"environment",
21+
({ projectKey }) => ({
22+
projectKey,
23+
}),
24+
],
25+
},
26+
flagKey: {
27+
propDefinition: [
28+
app,
29+
"flag",
30+
({
31+
projectKey, environmentKey,
32+
}) => ({
33+
projectKey,
34+
environmentKey,
35+
}),
36+
],
37+
},
38+
contextKind: {
39+
propDefinition: [
40+
app,
41+
"contextKind",
42+
({ projectKey }) => ({
43+
projectKey,
44+
}),
45+
],
46+
},
47+
contextKey: {
48+
label: "Context Key",
49+
description: "The key of the context to evaluate the feature flag against.",
50+
propDefinition: [
51+
app,
52+
"context",
53+
({
54+
projectKey, environmentKey, flagKey, contextKind,
55+
}) => ({
56+
projectKey,
57+
environmentKey,
58+
key: flagKey,
59+
kind: contextKind,
60+
}),
61+
],
62+
},
63+
otherAttributes: {
64+
type: "object",
65+
label: "Other Attributes",
66+
description: "Additional attributes to include in the context.",
67+
optional: true,
68+
},
69+
},
70+
methods: {
71+
evaluateFeatureFlag({
72+
projectKey, environmentKey, ...args
73+
}) {
74+
return this.app.post({
75+
path: `/projects/${projectKey}/environments/${environmentKey}/flags/evaluate`,
76+
...args,
77+
});
78+
},
79+
},
80+
async run({ $ }) {
81+
const {
82+
evaluateFeatureFlag,
83+
projectKey,
84+
environmentKey,
85+
contextKind,
86+
contextKey,
87+
otherAttributes,
88+
} = this;
89+
90+
const response = await evaluateFeatureFlag({
91+
$,
92+
projectKey,
93+
environmentKey,
94+
data: {
95+
key: contextKey,
96+
kind: contextKind,
97+
...otherAttributes,
98+
},
99+
});
100+
101+
$.export("$summary", `Successfully evaluated feature flag with \`${response.items.length}\` item(s).`);
102+
103+
return response;
104+
},
105+
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import app from "../../launchdarkly.app.mjs";
2+
3+
export default {
4+
key: "launchdarkly-toggle-feature-flag",
5+
name: "Toggle Feature Flag",
6+
description: "Toggles the status of a feature flag, switching it from active to inactive, or vice versa. [See the documentation](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
projectKey: {
12+
propDefinition: [
13+
app,
14+
"project",
15+
],
16+
},
17+
environmentKey: {
18+
propDefinition: [
19+
app,
20+
"environment",
21+
({ projectKey }) => ({
22+
projectKey,
23+
}),
24+
],
25+
},
26+
featureFlagKey: {
27+
propDefinition: [
28+
app,
29+
"flag",
30+
({
31+
projectKey, environmentKey,
32+
}) => ({
33+
projectKey,
34+
environmentKey,
35+
}),
36+
],
37+
},
38+
},
39+
async run({ $ }) {
40+
const {
41+
app,
42+
projectKey,
43+
environmentKey,
44+
featureFlagKey,
45+
} = this;
46+
47+
const { environments: { [environmentKey]: { on: isOn } } } =
48+
await app.getFeatureFlag({
49+
$,
50+
projectKey,
51+
featureFlagKey,
52+
});
53+
54+
const response = await app.updateFeatureFlag({
55+
$,
56+
projectKey,
57+
featureFlagKey,
58+
headers: {
59+
"Content-Type": "application/json; domain-model=launchdarkly.semanticpatch",
60+
},
61+
data: {
62+
environmentKey,
63+
instructions: [
64+
{
65+
kind: isOn
66+
? "turnFlagOff"
67+
: "turnFlagOn",
68+
},
69+
],
70+
},
71+
});
72+
73+
$.export("$summary", "Successfully toggled the feature flag.");
74+
75+
return response;
76+
},
77+
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import app from "../../launchdarkly.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "launchdarkly-update-feature-flag",
6+
name: "Update Feature Flag",
7+
description: "Updates an existing feature flag using a JSON object. [See the documentation](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
projectKey: {
13+
propDefinition: [
14+
app,
15+
"project",
16+
],
17+
},
18+
environmentKey: {
19+
propDefinition: [
20+
app,
21+
"environment",
22+
({ projectKey }) => ({
23+
projectKey,
24+
}),
25+
],
26+
},
27+
featureFlagKey: {
28+
propDefinition: [
29+
app,
30+
"flag",
31+
({
32+
projectKey, environmentKey,
33+
}) => ({
34+
projectKey,
35+
environmentKey,
36+
}),
37+
],
38+
},
39+
patch: {
40+
type: "string[]",
41+
label: "Patch",
42+
description: "An array of JSON patch operations to apply to the feature flag. [See the documentation](https://apidocs.launchdarkly.com/#section/Overview/Updates).",
43+
default: [
44+
JSON.stringify({
45+
op: "replace",
46+
path: "/description",
47+
value: "New description for this flag",
48+
}),
49+
],
50+
},
51+
ignoreConflicts: {
52+
type: "boolean",
53+
label: "Ignore Conflicts",
54+
description: "If a flag configuration change made through this endpoint would cause a pending scheduled change or approval request to fail, this endpoint will return a 400. You can ignore this check by setting this parameter to `true`.",
55+
optional: true,
56+
},
57+
comment: {
58+
type: "string",
59+
label: "Comment",
60+
description: "A comment to associate with the flag update.",
61+
optional: true,
62+
},
63+
},
64+
async run({ $ }) {
65+
const {
66+
app,
67+
projectKey,
68+
featureFlagKey,
69+
patch,
70+
ignoreConflicts,
71+
comment,
72+
} = this;
73+
74+
const response = await app.updateFeatureFlag({
75+
$,
76+
projectKey,
77+
featureFlagKey,
78+
params: {
79+
ignoreConflicts,
80+
},
81+
data: {
82+
patch: utils.parseArray(patch),
83+
comment,
84+
},
85+
});
86+
87+
$.export("$summary", "Successfully updated feature flag");
88+
return response;
89+
},
90+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const BASE_URL = "https://app.launchdarkly.com";
2+
const VERSION_PATH = "/api/v2";
3+
const WEBHOOK_ID = "webhookId";
4+
const SECRET = "secret";
5+
6+
export default {
7+
BASE_URL,
8+
VERSION_PATH,
9+
WEBHOOK_ID,
10+
SECRET,
11+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
function isJson(value) {
4+
try {
5+
JSON.parse(value);
6+
} catch (e) {
7+
return false;
8+
}
9+
10+
return true;
11+
}
12+
13+
function valueToObject(value) {
14+
if (typeof(value) === "object") {
15+
return value;
16+
}
17+
18+
if (!isJson(value)) {
19+
throw new ConfigurationError(`Make sure the custom expression contains a valid JSON object: \`${value}\``);
20+
}
21+
22+
return JSON.parse(value);
23+
}
24+
25+
function parseArray(value) {
26+
try {
27+
if (!value) {
28+
return [];
29+
}
30+
31+
if (Array.isArray(value)) {
32+
return value;
33+
}
34+
35+
const parsedValue = JSON.parse(value);
36+
37+
if (!Array.isArray(parsedValue)) {
38+
throw new Error("Not an array");
39+
}
40+
41+
return parsedValue;
42+
43+
} catch (e) {
44+
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
45+
}
46+
}
47+
48+
export default {
49+
parseArray: (value) => parseArray(value).map(valueToObject),
50+
};

0 commit comments

Comments
 (0)