{"id":15288631,"url":"https://github.com/upstash/edge-flags","last_synced_at":"2025-04-15T19:32:14.461Z","repository":{"id":65357207,"uuid":"571674026","full_name":"upstash/edge-flags","owner":"upstash","description":"Feature flags for serverless functions","archived":false,"fork":false,"pushed_at":"2024-09-27T15:52:46.000Z","size":1879,"stargazers_count":86,"open_issues_count":5,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-10T06:54:12.097Z","etag":null,"topics":["edge","feature-flags","nextjs","redis","upstash","upstash-sdk","vercel"],"latest_commit_sha":null,"homepage":"https://edge-flags.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upstash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-11-28T16:32:12.000Z","updated_at":"2025-03-15T21:08:17.000Z","dependencies_parsed_at":"2024-06-26T15:36:55.929Z","dependency_job_id":"96deb0d5-7836-4527-a366-2caf7ca0ed23","html_url":"https://github.com/upstash/edge-flags","commit_stats":{"total_commits":88,"total_committers":1,"mean_commits":88.0,"dds":0.0,"last_synced_commit":"5074a6fb4ba636baa5021bf30130bc58835fd8b6"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fedge-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fedge-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fedge-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fedge-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upstash","download_url":"https://codeload.github.com/upstash/edge-flags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249138823,"owners_count":21218953,"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":["edge","feature-flags","nextjs","redis","upstash","upstash-sdk","vercel"],"created_at":"2024-09-30T15:51:25.804Z","updated_at":"2025-04-15T19:32:14.440Z","avatar_url":"https://github.com/upstash.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1 align=\"center\"\u003eEdge Flags\u003c/h1\u003e\n    \u003ch5\u003eFeature Flags for the Edge\u003c/h5\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://edge-flags.vercel.app\"\u003eedge-flags.vercel.app\u003c/a\u003e\n\u003c/div\u003e\n\u003cbr/\u003e\n\n![Arch](/img/edge-flags/flag.png)\n\n\u003e [!NOTE]  \n\u003e **This project is a Community Project.**\n\u003e\n\u003e The project is maintained and supported by the community. Upstash may contribute but does not officially support or assume responsibility for it.\n\nEdge Flags is a low latency feature flagging solution running at the edge and storing data in a global Redis database. It is designed to be used with [Next.js](https://nextjs.org) and [Vercel](https://vercel.com) but we will soon roll out support for other popular frameworks and platforms. Let us know what you are looking for!\n\n## Features\n\n- **Global Low latency:** Flags are stored in a global Redis database and are evaluated at the edge.\n- **Environments:** Flags have different environments to support your deployment process: `production`, `preview` and `development`\n- **Flexible:** Flags support geo targeting, percentage based rollouts and custom attributes\n- **Manage:** Flags can be created and managed using the SDK or the self-hosted [dashboard](https://github.com/upstash/edge-flags/tree/main/packages/dashboard) in this repo.\n- **Free:** Edge Flags is free to use. You only pay for the Redis database.\n- **Cache:** Flags can be cached for a short period of time to reduce the required requests to redis, making it cheaper to use.\n\n\u003cbr/\u003e\n\n\n## Architecture\n\n![Arch](img/simple.png)\n\n## Quickstart\n\n1. Create a redis database\n\nGo to [console.upstash.com/redis](https://console.upstash.com/redis) and create\na new global database.\n\nAfter creating the db, copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` to your `.env` file.\n\n2.  Run `npx @upstash/edge-flags-dashboard` in your project to open the self-hosted dashboard.\n\n```bash\nnpx @upstash/edge-flags-dashboard\n```\n\nYou can also use the hosted version at https://edge-flags-dashboard.vercel.app.\n\n3.  Create a flag from the dashboard. See our [docs](https://upstash.com/docs/oss/sdks/ts/edge-flags/getstarted) for more information.\n\n4.  Install `@upstash/edge-flags` in your project\n\n```bash\nnpm install @upstash/edge-flags\n```\n\n4. Create an edge function in your project\n\n```ts\n// /app/api/edge-flags/route.ts\nimport { createEdgeHandler } from \"@upstash/edge-flags\";\n\nexport const GET = createEdgeHandler({\n  cacheMaxAge: 0, // cache time in seconds, 0 disables the cache\n  redisUrl: process.env.UPSTASH_REDIS_REST_URL!, // omit to load from env automatically\n  redisToken: process.env.UPSTASH_REDIS_REST_TOKEN!, // omit to load from env automatically\n});\n\nexport const runtime = \"edge\";\n```\n\n5. Query the flag in your frontend\n\n```tsx\n// /app/page.tsx\nimport { useFlag } from \"@upstash/edge-flags\";\n\nexport default function Example() {\n  const { isEnabled, isLoading, error } = useFlag(\"flag-name\");\n\n  if (error) return \u003cdiv\u003eError: {error}\u003c/div\u003e;\n  if (isLoading) return \u003cdiv\u003eLoading...\u003c/div\u003e;\n\n  return \u003cdiv\u003eIs my feature enabled: {isEnabled}\u003c/div\u003e;\n}\n```\n\n## Custom attributes\n\n`useFlag` accepts an optional object that can be used to pass custom attributes\nto be evaluated in the flag rules.\n\n```tsx\nconst attributes = {\n  userId: \"chronark\",\n  role: \"admin\",\n};\n\nuseFlag(\"flag-name\", attributes);\n```\n\n\n## Docs\n- [Overview](docs/overview.md)\n- [Getting Started](docs/getstarted.md)\n- [Environments](docs/environments.md)\n- [Percentage](docs/percentage.md)\n- [Rules](docs/rules.md)\n- [React Example](docs/react.md)\n\n\n## Development\n\nThis monorepo is managed by turborepo and uses `pnpm` for dependency management.\n\n#### Install dependencies\n\n```bash\npnpm install\n```\n\n#### Build\n\n```bash\npnpm build\n```\n\n## Database Schema\n\nAll configuration is stored in Redis `String` data types. Each flag is\naccessible through a key like\n\n```\nSTRING\nedge-flags:{TENANT}:flags:{FLAG_NAME}:{ENVIRONMENT}\n```\n\nIn addition to the flags, there will be a single set that contains all the flag IDs. We can not guarantee the database is only used for edge-flags so we need to keep track of the flags we have created instead of using a potentially expensive\n`SCAN` operation.\n\n```\nSET\nedge-flags:{TENANT}:flags\n```\n\n- `TENANT` is currently unused (set as `default`) but reserved for future use.\n  ie for managing multiple projects int a single database\n- `FLAG_NAME` is the unique identifier for the flag\n- `ENVIRONMENT` is the environment the flag is targeting. ie `production`,\n  `preview`, `development`\n\n### Packages\n\n- **/packages/sdk:** The SDK to be imported into your project\n- **/packages/dashboard:** A dashboard for creating and updating your flags\n- **/examples/nextjs:** An example Next.js app using the SDK\n\n## Authors\n\nThis project was originally created by\n\n- [@ademilter](https://twitter.com/ademilter)\n- [@chronark\\_](https://twitter.com/chronark_)\n- [@enesakar](https://twitter.com/enesakar)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupstash%2Fedge-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupstash%2Fedge-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupstash%2Fedge-flags/lists"}