New:Socket for Asana Is Now Available.Learn more
Get Started

@grantex/gateway

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grantex/gateway

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

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
1
Created
Source

@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
  • Route matching — finds the first route matching the request method + path
  • Token verification — extracts Bearer token and verifies offline via JWKS
  • Scope checking — ensures the grant includes all required scopes for the route
  • Proxy — strips the Authorization header, adds upstream headers + X-Grantex-* context headers, forwards to upstream
  • Response — returns the upstream response as-is

YAML Config Reference

FieldTypeRequiredDescription
upstreamstringYesBase URL of the upstream API
jwksUristringYesJWKS endpoint for offline token verification
portnumberNoListen port (default: 8080)
upstreamHeadersobjectNoHeaders added to every upstream request
grantexApiKeystringNoAPI key for audit logging
routesarrayYesRoute definitions (see below)

Route Definition

FieldTypeDescription
pathstringURL path pattern (* = single segment, ** = any depth)
methodsstring[]HTTP methods (GET, POST, PUT, PATCH, DELETE)
requiredScopesstring[]Scopes that must be present in the grant token

Context Headers

The gateway adds these headers to upstream requests:

HeaderValue
X-Grantex-PrincipalPrincipal ID from the grant token
X-Grantex-AgentAgent DID from the grant token
X-Grantex-GrantIdGrant ID from the grant token

Error Responses

StatusError CodeWhen
404ROUTE_NOT_FOUNDNo route matches the request
401TOKEN_MISSINGNo Bearer token in Authorization header
401TOKEN_INVALIDToken signature verification failed
401TOKEN_EXPIREDToken has expired
403SCOPE_INSUFFICIENTGrant doesn't include required scopes
502UPSTREAM_ERRORUpstream 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

Keywords

grantex

FAQs

Package last updated on 25 Jun 2026

Related posts