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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gatewaystack/request-context

v0.0.6

Published

Lightweight request-scoped context for GatewayStack.

Readme

@gatewaystack/request-context

Lightweight request-scoped context for GatewayStack.

@gatewaystack/request-context gives you a single place to hang identity, policy, routing, and audit metadata for each incoming request — without threading it through every function call.

It’s intentionally tiny: underneath, it’s just an async-context helper (Node AsyncLocalStorage / equivalent) plus a shared GatewayContext shape that the other layers (identifiabl, limitabl, proxyabl, explicabl, etc.) can read/write.


Install

npm install @gatewaystack/request-context
# or
pnpm add @gatewaystack/request-context

Core concepts

  • GatewayContext – a per-request object (e.g. { request, identity, authz, limits, routing }) that evolves as the request flows through the six layers.

  • runWithGatewayContext – wraps a request lifecycle so downstream code can call getGatewayContext() and read/write state.

  • getGatewayContext – reads the current context (or undefined if you’re outside a gateway scope).

The contract is:

  • Read-only from the perspective of business handlers (they can inspect but shouldn’t mutate identity/policy arbitrarily).

  • Layer-owned fields, e.g.:

-identity owned by identifiabl

-authz owned by validatabl

-limits owned by limitabl

-routing owned by proxyabl

-audit/eventIds observed by explicabl

Quickstart

In your Express app:

import express from "express";
import { runWithGatewayContext } from "@gatewaystack/request-context";

const app = express();

app.use((req, _res, next) => {
  // Seed the context once per request
  runWithGatewayContext(
    {
      request: {
        method: req.method,
        path: req.path,
        ip: (req as any).ip,
        userAgent: req.get("user-agent") ?? undefined,
      },
    },
    () => next()
  );
});

Downstream, other packages can do:

import { getGatewayContext } from "@gatewaystack/request-context";

function someMiddleware(_req, _res, next) {
  const ctx = getGatewayContext();

  // e.g. identifiabl may attach canonical identity:
  // ctx.identity = { sub, orgId, scopes, ... };

  next();
}

Usage with other GatewayStack layers

Typical flow:

1- runWithGatewayContext seeds ctx.request.

2- identifiabl verifies the JWT and writes ctx.identity.

3- validatabl reads ctx.identity and attaches ctx.authz (scopes, decisions).

4- limitabl reads ctx.identity and attaches ctx.limits (keys, decisions).

5- proxyabl reads ctx.identity / ctx.authz to route tools/models and inject headers.

6- explicabl reads the final context and emits an audit event.

You can also use it standalone in your own middleware, as long as you respect the “no breaking changes to existing fields” rule.