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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@grantex/gateway

v0.1.1

Published

Zero-code reverse-proxy gateway that enforces Grantex grant tokens via YAML config

Readme

@grantex/gateway

Zero-code reverse-proxy that enforces Grantex grant tokens in front of any API via YAML config.

Install

npm install @grantex/gateway @grantex/sdk

Quick Start

1. Create gateway.yaml:

upstream: https://api.internal.example.com
jwksUri: https://your-auth-server/.well-known/jwks.json
port: 8080
upstreamHeaders:
  X-Internal-Auth: "secret-key"
routes:
  - path: /calendar/**
    methods: [GET]
    requiredScopes: [calendar:read]
  - path: /calendar/**
    methods: [POST, PUT, PATCH]
    requiredScopes: [calendar:write]
  - path: /payments/**
    methods: [POST]
    requiredScopes: [payments:initiate]

2. Start the gateway:

npx @grantex/gateway --config gateway.yaml

3. Make requests with grant tokens:

curl -H "Authorization: Bearer <grant-token>" \
  http://localhost:8080/calendar/events

How It Works

Client → Gateway (verify token + check scopes) → Upstream API
  1. Route matching — finds the first route matching the request method + path
  2. Token verification — extracts Bearer token and verifies offline via JWKS
  3. Scope checking — ensures the grant includes all required scopes for the route
  4. Proxy — strips the Authorization header, adds upstream headers + X-Grantex-* context headers, forwards to upstream
  5. Response — returns the upstream response as-is

YAML Config Reference

| Field | Type | Required | Description | |-------|------|----------|-------------| | upstream | string | Yes | Base URL of the upstream API | | jwksUri | string | Yes | JWKS endpoint for offline token verification | | port | number | No | Listen port (default: 8080) | | upstreamHeaders | object | No | Headers added to every upstream request | | grantexApiKey | string | No | API key for audit logging | | routes | array | Yes | Route definitions (see below) |

Route Definition

| Field | Type | Description | |-------|------|-------------| | path | string | URL path pattern (* = single segment, ** = any depth) | | methods | string[] | HTTP methods (GET, POST, PUT, PATCH, DELETE) | | requiredScopes | string[] | Scopes that must be present in the grant token |

Context Headers

The gateway adds these headers to upstream requests:

| Header | Value | |--------|-------| | X-Grantex-Principal | Principal ID from the grant token | | X-Grantex-Agent | Agent DID from the grant token | | X-Grantex-GrantId | Grant ID from the grant token |

Error Responses

| Status | Error Code | When | |--------|-----------|------| | 404 | ROUTE_NOT_FOUND | No route matches the request | | 401 | TOKEN_MISSING | No Bearer token in Authorization header | | 401 | TOKEN_INVALID | Token signature verification failed | | 401 | TOKEN_EXPIRED | Token has expired | | 403 | SCOPE_INSUFFICIENT | Grant doesn't include required scopes | | 502 | UPSTREAM_ERROR | Upstream API is unreachable |

Library API

Use the gateway programmatically:

import { createGatewayServer, loadConfig } from '@grantex/gateway';

const config = loadConfig('./gateway.yaml');
const server = createGatewayServer(config);

await server.listen({ port: config.port });

Docker

docker build -t grantex-gateway packages/gateway/
docker run -p 8080:8080 -v ./gateway.yaml:/etc/grantex/gateway.yaml grantex-gateway

Requirements

  • Node.js 18+
  • @grantex/sdk >= 0.1.0

License

Apache-2.0