Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import app from "../../launchdarkly.app.mjs";

export default {
key: "launchdarkly-evaluate-feature-flag",
name: "Evaluate Feature Flag",
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).",
version: "0.0.1",
type: "action",
props: {
app,
projectKey: {
propDefinition: [
app,
"project",
],
},
environmentKey: {
propDefinition: [
app,
"environment",
({ projectKey }) => ({
projectKey,
}),
],
},
flagKey: {
propDefinition: [
app,
"flag",
({
projectKey, environmentKey,
}) => ({
projectKey,
environmentKey,
}),
],
},
contextKind: {
propDefinition: [
app,
"contextKind",
({ projectKey }) => ({
projectKey,
}),
],
},
contextKey: {
label: "Context Key",
description: "The key of the context to evaluate the feature flag against.",
propDefinition: [
app,
"context",
({
projectKey, environmentKey, flagKey, contextKind,
}) => ({
projectKey,
environmentKey,
key: flagKey,
kind: contextKind,
}),
],
},
otherAttributes: {
type: "object",
label: "Other Attributes",
description: "Additional attributes to include in the context.",
optional: true,
},
},
methods: {
evaluateFeatureFlag({
projectKey, environmentKey, ...args
}) {
return this.app.post({
path: `/projects/${projectKey}/environments/${environmentKey}/flags/evaluate`,
...args,
});
},
},
async run({ $ }) {
const {
evaluateFeatureFlag,
projectKey,
environmentKey,
contextKind,
contextKey,
otherAttributes,
} = this;

const response = await evaluateFeatureFlag({
$,
projectKey,
environmentKey,
data: {
key: contextKey,
kind: contextKind,
...otherAttributes,
},
});

$.export("$summary", `Successfully evaluated feature flag with \`${response.items.length}\` item(s).`);

return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import app from "../../launchdarkly.app.mjs";

export default {
key: "launchdarkly-toggle-feature-flag",
name: "Toggle Feature Flag",
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)",
version: "0.0.1",
type: "action",
props: {
app,
projectKey: {
propDefinition: [
app,
"project",
],
},
environmentKey: {
propDefinition: [
app,
"environment",
({ projectKey }) => ({
projectKey,
}),
],
},
featureFlagKey: {
propDefinition: [
app,
"flag",
({
projectKey, environmentKey,
}) => ({
projectKey,
environmentKey,
}),
],
},
},
async run({ $ }) {
const {
app,
projectKey,
environmentKey,
featureFlagKey,
} = this;

const { environments: { [environmentKey]: { on: isOn } } } =
await app.getFeatureFlag({
$,
projectKey,
featureFlagKey,
});

const response = await app.updateFeatureFlag({
$,
projectKey,
featureFlagKey,
headers: {
"Content-Type": "application/json; domain-model=launchdarkly.semanticpatch",
},
data: {
environmentKey,
instructions: [
{
kind: isOn
? "turnFlagOff"
: "turnFlagOn",
},
],
},
});

$.export("$summary", "Successfully toggled the feature flag.");

return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import app from "../../launchdarkly.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "launchdarkly-update-feature-flag",
name: "Update Feature Flag",
description: "Updates an existing feature flag using a JSON object. [See the documentation](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag)",
version: "0.0.1",
type: "action",
props: {
app,
projectKey: {
propDefinition: [
app,
"project",
],
},
environmentKey: {
propDefinition: [
app,
"environment",
({ projectKey }) => ({
projectKey,
}),
],
},
featureFlagKey: {
propDefinition: [
app,
"flag",
({
projectKey, environmentKey,
}) => ({
projectKey,
environmentKey,
}),
],
},
patch: {
type: "string[]",
label: "Patch",
description: "An array of JSON patch operations to apply to the feature flag. [See the documentation](https://apidocs.launchdarkly.com/#section/Overview/Updates).",
default: [
JSON.stringify({
op: "replace",
path: "/description",
value: "New description for this flag",
}),
],
},
ignoreConflicts: {
type: "boolean",
label: "Ignore Conflicts",
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`.",
optional: true,
},
comment: {
type: "string",
label: "Comment",
description: "A comment to associate with the flag update.",
optional: true,
},
},
async run({ $ }) {
const {
app,
projectKey,
featureFlagKey,
patch,
ignoreConflicts,
comment,
} = this;

const response = await app.updateFeatureFlag({
$,
projectKey,
featureFlagKey,
params: {
ignoreConflicts,
},
data: {
patch: utils.parseArray(patch),
comment,
},
});

$.export("$summary", "Successfully updated feature flag");
return response;
},
};
11 changes: 11 additions & 0 deletions components/launchdarkly/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const BASE_URL = "https://app.launchdarkly.com";
const VERSION_PATH = "/api/v2";
const WEBHOOK_ID = "webhookId";
const SECRET = "secret";

export default {
BASE_URL,
VERSION_PATH,
WEBHOOK_ID,
SECRET,
};
50 changes: 50 additions & 0 deletions components/launchdarkly/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ConfigurationError } from "@pipedream/platform";

function isJson(value) {
try {
JSON.parse(value);
} catch (e) {
return false;
}

return true;
}

function valueToObject(value) {
if (typeof(value) === "object") {
return value;
}

if (!isJson(value)) {
throw new ConfigurationError(`Make sure the custom expression contains a valid JSON object: \`${value}\``);
}

return JSON.parse(value);
}

function parseArray(value) {
try {
if (!value) {
return [];
}

if (Array.isArray(value)) {
return value;
}

const parsedValue = JSON.parse(value);

if (!Array.isArray(parsedValue)) {
throw new Error("Not an array");
}

return parsedValue;

} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
}
}

export default {
parseArray: (value) => parseArray(value).map(valueToObject),
};
Loading
Loading