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

@intelicity/gates-sdk

v0.2.0

Published

Simple SDK for authenticating users with AWS Cognito JWT tokens

Readme

Gates SDK

Node.js SDK for the Gates authentication system (AWS Cognito). Provides JWT token verification, group-based access control, admin user management, and framework-agnostic middleware.

Installation

npm install @intelicity/gates-sdk

Features

  • JWT verification for both access and id tokens
  • Admin user management (create + assign to client/group)
  • Framework-agnostic middleware (works with Fastify, Express, etc.)
  • Built-in JWKS caching (1h TTL)
  • Group-based access control (Cognito Groups)
  • Comprehensive error hierarchy

Usage

Token Verification

import { AuthService } from "@intelicity/gates-sdk";

const auth = new AuthService(
  "sa-east-1",           // AWS region
  "sa-east-1_xxxxxxxxx", // User Pool ID
  "your-client-id"       // Cognito App Client ID
);

const user = await auth.verifyToken(accessToken);
// user.user_id, user.groups, user.token_use, user.email?, user.name?

Supports both access_token (validates client_id claim) and id_token (validates aud claim). The token_use field on the returned user indicates which type was verified.

Middleware

Framework-agnostic functions for request authentication:

import { handleAuth, AuthService } from "@intelicity/gates-sdk";

const service = new AuthService(region, userPoolId, clientId);

// Fastify
app.addHook("preHandler", async (req) => {
  req.user = await handleAuth(req.headers.authorization, {
    service,
    requiredGroups: "GAIA",
  });
});

// Express
app.use(async (req, res, next) => {
  try {
    req.user = await handleAuth(req.headers.authorization, {
      service,
      requiredGroups: "GAIA",
    });
    next();
  } catch (e) { next(e); }
});

Individual functions are also available:

import { extractToken, authenticate, authorize } from "@intelicity/gates-sdk";

const token = extractToken(req.headers.authorization); // Bearer token extraction
const user = await authenticate(token, service);        // JWT verification
authorize(user, ["GAIA", "RECAPE"]);                    // Group check (throws if unauthorized)

Error Handling

import {
  TokenExpiredError,
  InvalidTokenError,
  UnauthorizedGroupError,
  GatesError,
} from "@intelicity/gates-sdk";

try {
  const user = await auth.verifyToken(token);
} catch (error) {
  if (error instanceof TokenExpiredError) {
    // error.code === "TOKEN_EXPIRED"
  } else if (error instanceof InvalidTokenError) {
    // error.code === "INVALID_TOKEN"
  } else if (error instanceof UnauthorizedGroupError) {
    // error.code === "UNAUTHORIZED_GROUP"
    // error.requiredGroups: string[]
  } else if (error instanceof GatesError) {
    // error.code, error.message
  }
}

Admin Service (User Management)

For creating users and managing system access (requires admin id_token):

import { GatesAdminService } from "@intelicity/gates-sdk";

const admin = new GatesAdminService({
  baseUrl: "https://abc123.execute-api.sa-east-1.amazonaws.com/prod",
});

// Create a new user and add to a client (group)
// Internally calls POST /create-user then PUT /update-user
const { sub } = await admin.createUser(adminIdToken, {
  email: "[email protected]",
  name: "New User",
  role: "CLIENT_USER",
  client: "GAIA",
});

// Later: add/remove user access to other systems
await admin.updateUser(adminIdToken, {
  user_id: sub,
  clients_to_add: ["RECAPE"],
  clients_to_remove: ["INFORMS"],
});

API Reference

AuthService

new AuthService(region: string, userPoolId: string, clientId: string)
  • verifyToken(token: string): Promise<GatesUser> — Verifies JWT, returns user

GatesAdminService

new GatesAdminService({ baseUrl: string })
  • createUser(idToken: string, params: CreateUserParams): Promise<CreateUserResponse> — Creates user in Gates
  • updateUser(idToken: string, params: UpdateUserParams): Promise<void> — Manages user's system access

Types

type GatesUser = {
  user_id: string;              // from 'sub'
  email?: string;               // only in id_tokens
  name?: string;                // only in id_tokens
  role?: string;                // from 'custom:general_role'
  groups: string[];             // from 'cognito:groups'
  token_use: "access" | "id";
  exp: number;
  iat: number;
};

type GatesRole = "INTERNAL_ADMIN" | "INTERNAL_USER" | "CLIENT_ADMIN" | "CLIENT_USER";

Error Codes

| Code | Class | Description | | -------------------------- | --------------------------- | ------------------------------- | | TOKEN_EXPIRED | TokenExpiredError | JWT has expired | | INVALID_TOKEN | InvalidTokenError | Invalid or malformed token | | MISSING_AUTHORIZATION | MissingAuthorizationError | Authorization header missing | | UNAUTHORIZED_GROUP | UnauthorizedGroupError | User not in required group | | API_REQUEST_ERROR | ApiRequestError | Gates API request failed | | MISSING_PARAMETER | MissingParameterError | Required parameter missing | | INVALID_PARAMETER | InvalidParameterError | Parameter has invalid value |

Development

npm install
npm run build       # tsc && tsc-alias → dist/
npm run typecheck   # tsc --noEmit
npm test            # vitest run
npm run test:watch  # vitest (watch mode)

License

MIT