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

@justrelate/iam-client

v0.2.0

Published

Internal library for authenticating users via the JustRelate IAM service.

Readme

IAM Client

The @justrelate/iam-client library provides a simple and secure way to authenticate users via the JustRelate IAM service. It validates IAM tokens and retrieves user details for authorized services.

⚠️ Internal Use Only:
This library is intended for internal use only. It contains internal APIs and must not be used outside of JustRelate.

Installation

npm install @justrelate/iam-client

Quick Start

Authenticate a user with their IAM token:

import { authenticate } from '@justrelate/iam-client';

const result = await authenticate({
  instanceId: 'your-instance-id',
  authToken: 'your-bearer-token',
  service: 'https://api.justrelate.com/your-service',
});

if ('error' in result) {
  console.error('Authentication failed:', result.errorResponse);
} else {
  console.log('Authenticated user:', result.name);
}

API Reference

authenticate(params: AuthenticateParams): Promise<IAMAuthResponse>

Validates an IAM token using the JustRelate IAM service.

Parameters

| Name | Type | Required | Description | | ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------ | | authToken | String | Yes | The IAM bearer token used for authentication | | instanceId | String | Yes | The unique identifier of your JustRelate instance | | service | String | Yes | The URL of the service the token should authenticate (e.g., https://api.justrelate.com/your-service) | | baseAuthUrl | String | No | Custom IAM base URL (defaults to https://api.justrelate.com/iam/) |

Returns

A promise that resolves to one of the following:

Success (IAMAuthSuccess)
{
  account_id: string;
  email: string;
  name: string;
  picture: string;
  sub: string;
  team_ids: string[];
}
Failure (IAMAuthFailure)
{
  status: number;
  errorResponse: {
    error: string;
    code?: string;
    details?: object;
  };
}

Status Codes

  • 401 – Invalid authentication token
  • 403 – Insufficient permissions
  • 404 – Invalid instance ID

Exceptions

The authenticate function may throw an IAMAuthError if:

  • The IAM service does not respond within 10 seconds
  • There are network issues (e.g., DNS, CORS, blocked requests)
  • The response has an unexpected status code
  • The response body is not valid JSON

Usage Examples

Basic Authentication

import { authenticate } from '@justrelate/iam-client';

try {
  const result = await authenticate({
    instanceId: 'your-instance-id',
    authToken: 'your-token-here',
    service: 'https://api.justrelate.com/your-service',
  });

  if ('error' in result) {
    console.error('Auth failed:', result.errorResponse);
  } else {
    console.log('Welcome,', result.name);
    console.log('Team IDs:', result.team_ids);
  }
} catch (error) {
  console.error('Authentication error:', error.message);
}

Express.js Middleware

Integrate IAM authentication into your Express.js application:

import express from 'express';
import { authenticate } from '@justrelate/iam-client';

export async function withIAMAuth(req, res, next) {
  try {
    const token = req.headers.authorization?.replace('Bearer ', '') || '';

    const currentUser = await authenticate({
      instanceId: req.params.instanceId,
      authToken: token,
      service: 'https://api.justrelate.com/your-service',
    });

    if ('errorResponse' in currentUser) {
      return res.status(currentUser.status).json(currentUser.errorResponse);
    }

    res.locals.currentUser = currentUser;
    return next();
  } catch (error) {
    return res.status(500).json({ error: 'Internal Server Error' });
  }
}

const app = express();

app.get('/', (req, res) => {
  res.send('Hello from Express!');
});

app.get('/:instanceId/current-user', withIAMAuth, (req, res) => {
  res.json({ currentUser: res.locals.currentUser });
});

app.listen(3000, () => {
  console.log('Server is running at http://localhost:3000');
});

Testing the Endpoint

Use curl to test the protected route:

curl -X GET "http://localhost:3000/YOUR_INSTANCE_ID/current-user" \
     -H "Authorization: Bearer YOUR_TOKEN"

Available Routes:

  • GET / — Public endpoint
  • GET /:instanceId/current-user — Protected IAM-authenticated endpoint

License

UNLICENSED

Support

For help or questions, please contact the Scrivito team via the #dev-scrivito Slack channel.