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

trustlyx

v1.1.0

Published

<p align="center"> <img src="https://capsule-render.vercel.app/api?type=waving&color=0:0f2027,50:203a43,100:2c5364&height=200&section=header&text=Trust&fontSize=50&fontColor=ffffff&animation=fadeIn" /> </p>

Downloads

228

Readme

🔐 Trustlyx — Production-Ready Authentication Engine


🧠 What is Trust?

Trust is a modular, multi-tenant authentication engine designed for real-world production systems.

It provides:

  • 🔑 Password auth
  • 🔗 Magic links
  • 🌐 OAuth (Google)
  • 🔁 Token-based sessions
  • 🧱 Adapter-based infrastructure
  • 🏢 Multi-tenant support (core feature)

✨ Features

🔐 Authentication Methods

  • Email + Password
  • Magic Link (passwordless)
  • Google OAuth

🧱 Architecture

  • Context-based execution (AuthContext)
  • Service-layer separation
  • Adapter pattern (email, cache)
  • Strategy-based auth flows

🛡️ Security

  • Password hashing (bcrypt)
  • Token hashing (SHA-256)
  • Brute-force protection
  • Rate limiting support
  • Refresh token sessions
  • One-time magic links

🏢 Multi-Tenancy

  • Tenant isolation at DB level
  • Context-driven tenant resolution

📦 Project Structure

sdk/
│
├── core/
│   ├── Trust.ts
│   ├── context.ts
│   ├── jwt.ts
│
├── services/
│   ├── AuthService.ts
│   ├── UserService.ts
│   ├── OAuthService.ts
│   ├── SecurityService.ts
│
├── strategies/
│   ├── magicLink.ts
│   ├── google.ts
│
├── adapters/
│   ├── email/
│   ├── cache/
│
├── models/
│   ├── User.ts
│

⚙️ Installation

npm install trustylyx

🚀 Quick Start

1. Initialize SDK

import { Trust } from "./sdk";

const sdk = new Trust({
  jwtSecret: "secret",
  refreshSecret: "refresh",
  appUrl: "http://localhost:3000",

  getTenant: (req) => req.headers["x-tenant-id"],

  adapters: {
    email: new MockEmailAdapter(),
    cache: new RedisAdapter(redisClient),
  },

  providers: {
    google: {
      clientId: "...",
      clientSecret: "...",
      redirectUri: "...",
    },
  },
});

2. Create Context (🔥 important)

const ctx = sdk.createContext(req);

3. Use Services

const auth = new AuthService(ctx);

await auth.signup(email, password);
await auth.login(email, password);

4. Magic Link

await sendMagicLink(ctx, email);
await verifyMagicLink(ctx, token);

🧩 Core Concepts

🔹 AuthContext

{
  sdk,
  tenantId
}
  • Eliminates passing sdk everywhere
  • Injects tenant automatically
  • Ensures isolation

🔹 Adapters

Plug in your own infrastructure:

email: EmailAdapter
cache: CacheAdapter

Examples:

  • Resend / SendGrid
  • Redis / Memory cache

🔹 Services vs Strategies

| Layer | Responsibility | | ---------- | ------------------------------ | | Services | Business logic | | Strategies | Auth flows (magic link, OAuth) |


🔐 Security Design

✅ Passwords

  • Hashed with bcrypt

✅ Tokens

  • Stored as SHA-256 hashes

✅ Magic Links

  • One-time use
  • Expire after 15 minutes
  • Deleted after verification

✅ Brute Force Protection

await security.recordFailedLogin(email, tenantId);

🔁 Session System

Each user stores:

refreshTokens: [
  {
    token,
    createdAt,
    expiresAt
  }
]

Supports:

  • Session tracking
  • Expiry validation
  • Future: rotation & reuse detection

🏢 Multi-Tenant Design

Every query is scoped:

{ email, tenantId }

Tenant comes from:

sdk.getTenant(req)

🧪 Development Mode

Use mock adapters:

new MockEmailAdapter()

Logs emails to console instead of sending.


🧠 Future Roadmap

  • 🔄 Refresh token rotation
  • 🚨 Reuse attack detection
  • 📧 Email verification flow
  • 🔌 Plugin system
  • 📊 Audit logs
  • 🪝 Hooks system

🎯 Philosophy

This is not just an auth system. It's an auth engine.

  • Composable
  • Framework-agnostic
  • Production-first
  • Security-focused

💡 Inspiration

Built with ideas inspired by:

  • Modern SaaS auth systems
  • Real-world backend architecture patterns
  • Scalable multi-tenant systems

Made By Dave