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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@distributed/amon

v0.0.10

Published

Small library exposing utility methods for GraphQL

Downloads

20

Readme

Small lib exposing reusable utility methods for JWT authentication, using @node-rs/bcrypt & jsonwebtoken under the hood.

Install

With yarn:

yarn add @distributed/amon

With npm:

npm install @distributed/amon

Usage

Auth

Requirements:

Use process.env.APP_SECRET or pass the appSecret into createAuthPayload / createJwtToken functions.

You can execute the following command to generate your secret:

node -e "console.log(crypto.randomBytes(32).toString('hex'))"
# .env
APP_SECRET="45e05712755026248ef0f8f9881182b2cc3db28e64fcc42fb19d3209f5f0d19c"

Create password hash

import { createPasswordHash } from '@distributed/amon';

const hashPassword = await createPasswordHash('foo');
// => $2a$10$2M95zVobIQOm9BgNmKh/gu7IkH/LM45ZqsySlUQaFLrqAhppvm5Ei

Password validation

import { isPasswordValid } from '@distributed/amon';

const hashPassword = await createPasswordHash('bar');
const valid = await isPasswordValid('bar', hashPassword);
// => true

Get userId

import { getUserId } from '@distributed/amon';
import fastify from 'fastify';

const app = fastify();

app.get('/', async (request, reply) => {
  const userId = getUserId(request.headers);

  reply.type('application/json').code(200);
  return { userId };
});

Create Authpayload

import { getUserId } from '@distributed/amon';
import fastify from 'fastify';

const app = fastify();

app.get('/', async (request, reply) => {
  type User = { username: 'batman' };

  const userId = getUserId(request.headers);

  const user = await db.findUnique({ where: { id: userId } });
  const authPayload = await createAuthPayload<User>(userId, user);

  reply.type('application/json').code(200);
  return authPayload;
});

Create Jwt Token

import { createJwtToken } from '@distributed/amon';

const userId = 'foo';

// JWT Signing options
const options = {};

// App Secret, if process.env.APP_SECREt is not set
const appSecret = 'bar';

const token = await createJwtToken({ userId, options, appSecret });

Development

  1. Install dependencies using yarn install or npm install
  2. Start development server using yarn watch