{"id":18768718,"url":"https://github.com/get-convex/launchdarkly","last_synced_at":"2025-04-13T07:30:46.849Z","repository":{"id":258165762,"uuid":"842098778","full_name":"get-convex/launchdarkly","owner":"get-convex","description":"A Convex component that syncs LaunchDarkly feature flags","archived":false,"fork":false,"pushed_at":"2024-10-24T02:11:00.000Z","size":650,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-24T11:38:33.018Z","etag":null,"topics":["component","convex","feature-flags","launchdarkly"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/get-convex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-13T17:07:02.000Z","updated_at":"2024-10-24T02:07:50.000Z","dependencies_parsed_at":"2024-10-24T02:15:41.133Z","dependency_job_id":null,"html_url":"https://github.com/get-convex/launchdarkly","commit_stats":null,"previous_names":["get-convex/launchdarkly"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/get-convex%2Flaunchdarkly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/get-convex%2Flaunchdarkly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/get-convex%2Flaunchdarkly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/get-convex%2Flaunchdarkly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/get-convex","download_url":"https://codeload.github.com/get-convex/launchdarkly/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223573807,"owners_count":17167369,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["component","convex","feature-flags","launchdarkly"],"created_at":"2024-11-07T19:13:42.139Z","updated_at":"2025-04-13T07:30:46.820Z","avatar_url":"https://github.com/get-convex.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Convex Component: LaunchDarkly\n\n[![npm version](https://badge.fury.io/js/@convex-dev%2Flaunchdarkly.svg)](https://badge.fury.io/js/@convex-dev%2Flaunchdarkly)\n\n\u003c!-- START: Include on https://convex.dev/components --\u003e\n\nThis is a Convex component for feature flagging and experimentation using [LaunchDarkly](https://launchdarkly.com).\n\nIt syncs your LaunchDarkly environment to your Convex deployment, allowing you to use your feature flags in Convex.\n\n## Why use LaunchDarkly with Convex?\n\n- **Feature flags in your backend**: Use feature flags in your Convex functions to dynamically control the behavior of your app.\n- **Experimentation**: Run A/B tests and feature experiments in Convex using LaunchDarkly.\n- **Real-time updates**: Your LaunchDarkly flags and segments are synced to Convex in real-time, so you can use them in your app without needing to make additional API requests.\n\n## Prerequisites\n\n### LaunchDarkly account\n\nTo use this component you must have a LaunchDarkly account.\n\n### Convex App\n\nYou'll need an existing Convex project to use the component.\nConvex is a hosted backend platform, including a database, serverless functions,\nand a ton more you can learn about [here](https://docs.convex.dev/get-started).\n\nRun `npm create convex` or follow any of the [quickstarts](https://docs.convex.dev/home) to set one up.\n\n## Installation\n\n### Install and configure the component package\n\n```bash\nnpm install @convex-dev/launchdarkly\n```\n\nCreate a `convex.config.ts` file in your app's `convex/` folder and install the component by calling `use`:\n\n```typescript\n// convex/convex.config.ts\nimport { defineApp } from \"convex/server\";\nimport launchdarkly from \"@convex-dev/launchdarkly/convex.config\";\n\nconst app = defineApp();\n\napp.use(launchdarkly);\n\nexport default app;\n```\n\nOnce you've installed the component, make sure you push your changes to your Convex app:\n\n```bash\nnpx convex dev\n```\n\nRegister webhooks by creating an `http.ts` file in your `convex/` folder:\n\n```typescript\n// convex/http.ts\nimport { httpRouter } from \"convex/server\";\nimport { registerRoutes } from \"@convex-dev/launchdarkly\";\nimport { components } from \"./_generated/api\";\n\nconst http = httpRouter();\n\n// You may pass a third parameter here to override the default path of `/ld/webhook`\nregisterRoutes(components.launchdarkly, http);\n\nexport default http;\n```\n\nThis will register two webhook HTTP handlers in your your Convex app's deployment:\n\n- `GET YOUR_CONVEX_SITE_URL/ld/webhook` - LaunchDarkly will use this endpoint to verify the installation of your component.\n- `PUT YOUR_CONVEX_SITE_URL/ld/webhook` - LaunchDarkly will send your flag and segment data to this endpoint.\n\n### Configure the LaunchDarkly integration\n\nNow, you'll need to copy your LaunchDarkly environment's SDK Key and store it in the component. You can copy your LaunchDarkly SDK by loading the [LaunchDarkly dashboard](https://app.launchdarkly.com), selecting your environment, and pressing Cmd + K (or Ctrl + K) to open the command palette. Select the \"Copy SDK Key for the current environment\" option.\n\n![Copy SDK Key](./images/copy-sdk-key.png)\n\nThe value you copied should start with `sdk-`.\n\nStore the SDK key you copied as an environment variable named `LAUNCHDARKLY_SDK_KEY` in your Convex deployment. You can do so on the [environment variables](https://dashboard.convex.dev/deployment/settings/environment-variables) page or via `npx convex env set LAUNCHDARKLY_SDK_KEY sdk-***` from the CLI.\n\nYou can now configure the LaunchDarkly integration. On the [Integrations page](https://app.launchdarkly.com/settings/integrations/convex/new) of the LaunchDarkly dashboard, search for Convex and click \"Add Integration\".\n\nEach of your Convex deployments (e.g. Production and other developer's environments) will need their own integration configured in LaunchDarkly.\n\n![Add Integration](./images/launchdarkly-integration-configuration.png)\n\nSelect a name and environment for the integration.\n\nFor \"Webhook URL\", use your deployment's HTTP Actions URL suffixed with the path provided to the `registerRoutes` call in your `http.ts` file. By default, the path is `/ld/webhook`. You can retrieve your HTTP Actions URL on the [Deployment Settings page](https://dashboard.convex.dev/deployment/settings) of the Convex dashboard. Example: `https://techno-kitten-138.convex.site/ld/webhook`\n\nFor \"Component API Token\", generate a shared secret to be used by the LaunchDarkly integration. This will ensure the payloads sent to your webhook are coming from LaunchDarkly.\n\n```bash\nnpx convex run --component=launchdarkly tokens:generate --push\n```\n\nOnce you save, you can open the integration form again and click the Validate button to test the connection. If you encounter errors, check the logs page in the Convex dashboard for more information.\n\n### Using the LaunchDarkly component\n\nYou may initialize the LaunchDarkly class with the component configuration and use the LaunchDarkly SDK as you would in a normal JavaScript application.\n\n```typescript\nimport { LaunchDarkly } from \"@convex-dev/launchdarkly\";\nimport { components } from \"./_generated/api\";\nimport { query } from \"./_generated/server\";\n\nconst launchdarkly = new LaunchDarkly(components.launchdarkly);\n\nexport const myQuery = query({\n  args: {},\n  handler: async ({ ctx }) =\u003e {\n    const ld = launchdarkly.sdk(ctx);\n    const isFlagOn = await ld.boolVariation(\n      \"my-flag\",\n      { key: \"myUser\" },\n      false\n    );\n    if (isFlagOn) {\n      // Do something when flag is on\n    } else {\n      // Do something when flag is off\n    }\n  },\n});\n```\n\n## Example App\n\nYou can run the example in the [`examples`](./example/README.md) folder to see how the LaunchDarkly component works.\n\n## Production\n\nWhen you're ready to deploy your app to production with LaunchDarkly, be sure to follow all the setup steps for production, including adding the `LAUNCHDARKLY_SDK_KEY` evnironment variable and configuring an additional shared secret and integration for Production. You'll want this to be configured before any of your code relies on the LaunchDarkly flags.\n\nYou may use this command to generate your production secret:\n\n```bash\nnpx convex run --component=launchdarkly --prod tokens:generate\n```\n\n## Syncing multiple LaunchDarkly environments in one Convex app\n\nIf you have multiple LaunchDarkly environments, you can create a separate component configuration for each environment.\n\n```typescript\n// convex/convex.config.js\nimport { defineApp } from \"convex/server\";\nimport launchdarkly from \"@convex-dev/launchdarkly/convex.config\";\n\nconst app = defineApp();\n\napp.use(launchdarkly, {\n  name: \"first\",\n});\n\napp.use(launchdarkly, {\n  name: \"second\",\n});\n\nexport default app;\n```\n\nBe sure to also update your `http.ts` file to register the routes for each component:\n\n```typescript\n// convex/http.ts\nimport { httpRouter } from \"convex/server\";\nimport { registerRoutes } from \"@convex-dev/launchdarkly\";\nimport { components } from \"./_generated/api\";\n\nconst http = httpRouter();\n\nregisterRoutes(components.first, http, \"/ld/first\");\nregisterRoutes(components.second, http, \"/ld/second\");\n\nexport default http;\n```\n\nThen you can generate a separate shared secret for each environment:\n\n```bash\nnpx convex run --component=first tokens:generate\nnpx convex run --component=second tokens:generate\n```\n\nAlso, store the appropriate SDK keys in your Convex deployment for each LaunchDarkly environment:\n\nThese secrets can be plugged into seperate integration configurations in LaunchDarkly.\n\nOnce configured, you may initialize `LaunchDarkly` with the appropriate component configuration:\n\n```typescript\nimport { LaunchDarkly } from \"@convex-dev/launchdarkly\";\n\nconst launchDarklyFirst = new LaunchDarkly(components.first, {\n  LAUNCHDARKLY_SDK_KEY: process.env.LAUNCHDARKLY_SDK_KEY_FIRST!,\n});\n\nconst launchDarklySecond = new LaunchDarkly(components.second, {\n  LAUNCHDARKLY_SDK_KEY: process.env.LAUNCHDARKLY_SDK_KEY_SECOND!,\n});\n\nexport const myQuery = query({\n  args: {},\n  handler: async ({ ctx }) =\u003e {\n    const ldFirst = launchdarklyFirst.sdk(ctx);\n\n    const ldSecond = launchDarklySecond.sdk(ctx);\n\n    ...\n  },\n});\n```\n\n## Unsupported LaunchDarkly features\n\nThe LaunchDarkly component for Convex is in beta, and may not support all functionality available in the LaunchDarkly SDK.\nIf you encounter any issues or need help with a specific feature, please file an issue in the [GitHub repository](https://github.com/get-convex/launchdarkly/issues).\n\n- Sending events in Convex queries is not supported. If you would like to have the SDK send events to LaunchDarkly (e.g. flag evaluation insights and for experimentation), you should use LaunchDarkly in a mutation or action instead.\n- Big segments\n- Diagnostic events\n\n\u003c!-- END: Include on https://convex.dev/components --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fget-convex%2Flaunchdarkly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fget-convex%2Flaunchdarkly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fget-convex%2Flaunchdarkly/lists"}