- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] launchdarkly - new components #14742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            105 changes: 105 additions & 0 deletions
          
          105 
        
  components/launchdarkly/actions/evaluate-feature-flag/evaluate-feature-flag.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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, | ||
| }, | ||
| }); | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", `Successfully evaluated feature flag with \`${response.items.length}\` item(s).`); | ||
|  | ||
| return response; | ||
| }, | ||
| }; | ||
        
          
          
            77 changes: 77 additions & 0 deletions
          
          77 
        
  components/launchdarkly/actions/toggle-feature-flag/toggle-feature-flag.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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; | ||
| }, | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }; | ||
        
          
          
            90 changes: 90 additions & 0 deletions
          
          90 
        
  components/launchdarkly/actions/update-feature-flag/update-feature-flag.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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", | ||
| }), | ||
| ], | ||
| }, | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| 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; | ||
| }, | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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, | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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); | ||
| } | ||
|         
                  jcortes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| 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), | ||
| }; | ||
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.