npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@upstash/edge-flags

v0.1.1

Published

<div align="center"> <h1 align="center">Edge Flags</h1> <h5>Feature Flags for the Edge</h5> </div>

Downloads

1,772

Readme

Arch

Edge 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 and Vercel but we will soon roll out support for other popular frameworks and platforms. Let us know what you are looking for!

Features

  • Global Low latency: Flags are stored in a global Redis database and are evaluated at the edge.
  • Environments: Flags have different environments to support your deployment process: production, preview and development
  • Flexible: Flags support geo targeting, percentage based rollouts and custom attributes
  • Manage: Flags can be created and managed using the SDK or our console.
  • Free: Edge Flags is free to use. You only pay for the Redis database.
  • Cache: Flags can be cached for a short period of time to reduce the required requests to redis, making it cheaper to use.

Docs

This readme provides a quickstart guide. For more information, see our docs.

Architecture

Arch

Quickstart

  1. Create a redis database

Go to console.upstash.com/redis and create a new global database.

After creating the db, copy the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN to your .env file.

  1. Go to console.upstash.com/edge-flags and create a flag.

    See our docs for more information.

  2. Install @upstash/edge-flags in your project

npm install @upstash/edge-flags
  1. Create an edge function in your project
// /api/edge-flags.ts
import { createEdgeHandler } from "@upstash/edge-flags";

export default createEdgeHandler({
  cacheMaxAge: 0, // cache time in seconds, 0 disables the cache
  redisUrl: process.env.UPSTASH_REDIS_REST_URL!, // omit to load from env automatically
  redisToken: process.env.UPSTASH_REDIS_REST_TOKEN!, // omit to load from env automatically
});

/**
 * Edge flags only works in edge functions, it will break if you do not set the runtime
 */
export const config = {
  runtime: "experimental-edge",
};
  1. Query the flag in your frontend
// /app/index.tsx
import { useFlag } from "@upstash/edge-flags";
export default function Example() {

  const { isEnabled, isLoading, error } = useFlag("flag-name");
  
  if (error) return <div>Error: {error}</div>;
  if (isLoading) return <div>Loading...</div>;
  
  return <div>Is my feature enabled: {isEnabled}</div>;
}

Custom attributes

useFlag accepts an optional object that can be used to pass custom attributes to be evaluated in the flag rules.

const attributes = {
  userId: "chronark",
  role: "admin",
};

useFlag("flag-name", attributes);

Development

This monorepo is managed by turborepo and uses pnpm for dependency management.

Install dependencies

pnpm install

Build

pnpm build

Database Schema

All configuration is stored in Redis String data types. Each flag is accessible through a key like

STRING
edge-flags:{TENANT}:flags:{FLAG_NAME}:{ENVIRONMENT}

In 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 SCAN operation.

SET 
edge-flags:{TENANT}:flags
  • TENANT is currently unused (set as default) but reserved for future use. ie for managing multiple projects int a single database
  • FLAG_NAME is the unique identifier for the flag
  • ENVIRONMENT is the environment the flag is targeting. ie production, preview, development

Packages

  • /packages/sdk: The SDK to be imported into your project
  • /examples/nextjs: An example Next.js app using the SDK

Authors

This project was originally created by