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

@hostlink/light

v3.3.0

Published

A lightweight JavaScript/TypeScript client library for the **Light Framework**, providing an easy-to-use API for GraphQL queries/mutations, authentication, file management, user management, and more.

Readme

@hostlink/light

A lightweight JavaScript/TypeScript client library for the Light Framework, providing an easy-to-use API for GraphQL queries/mutations, authentication, file management, user management, and more.

Features

  • 🔐 Authentication - Login/logout, password management, OAuth (Google, Facebook, Microsoft), WebAuthn support
  • 📊 GraphQL Client - Simplified query and mutation APIs with automatic file upload handling
  • 📁 File System - Complete file and folder management operations
  • 👥 User Management - CRUD operations for users and roles
  • 📧 Email - Send emails via the backend
  • 🔄 Token Refresh - Automatic access token refresh with request queuing
  • 🌐 Universal - Works in both browser and Node.js environments

Installation

npm install @hostlink/light

Quick Start

import { createClient } from '@hostlink/light';

// Create a client instance
const api = createClient('https://your-api.com/graphql');

// Login
await api.auth.login('username', 'password');

// Query data
const users = await api.query({
  app: {
    users: {
      user_id: true,
      username: true,
      first_name: true
    }
  }
});

// Logout
await api.auth.logout();

API Reference

Creating a Client

import { createClient } from '@hostlink/light';

const api = createClient('https://your-api.com/graphql');

The client provides:

  • api.auth - Authentication methods
  • api.query - GraphQL queries
  • api.mutation - GraphQL mutations
  • api.users - User management
  • api.roles - Role management
  • api.mail - Email sending
  • api.config - Configuration access
  • api.collect - Collection builder
  • api.list - List builder

Authentication

Basic Login/Logout

// Login with username and password
await api.auth.login('username', 'password');

// Login with 2FA code
await api.auth.login('username', 'password', '123456');

// Logout
await api.auth.logout();

Get Current User

const user = await api.auth.getCurrentUser();
// Returns: { user_id, username, first_name, last_name, status }

// With custom fields
const user = await api.auth.getCurrentUser({
  user_id: true,
  username: true,
  email: true
});

Password Management

// Update password
await api.auth.updatePassword('oldPassword', 'newPassword');

// Change expired password
await api.auth.changeExpiredPassword('username', 'oldPassword', 'newPassword');

// Forgot password flow
const jwt = await api.auth.forgetPassword('username', '[email protected]');
await api.auth.verifyCode(jwt, '123456');
await api.auth.resetPassword(jwt, 'newPassword', '123456');

OAuth Providers

// Google
await api.auth.google.login(credential);
await api.auth.google.register(credential);
await api.auth.google.unlink();

// Facebook
await api.auth.facebook.login(accessToken);
await api.auth.facebook.register(accessToken);
await api.auth.facebook.unlink();

// Microsoft
await api.auth.microsoft.login(accessToken);
await api.auth.microsoft.register(accountId);
await api.auth.microsoft.unlink();

WebAuthn (Passkeys)

import { webAuthn } from '@hostlink/light';

// Register a new passkey
await webAuthn.register();

// Login with passkey
await webAuthn.login();

Permission Checking

// Check single permission
const canEdit = await api.auth.isGranted('edit_users');

// Check multiple permissions
const rights = await api.auth.grantedRights(['edit_users', 'delete_users']);

GraphQL Queries & Mutations

Query

const result = await api.query({
  app: {
    users: {
      user_id: true,
      username: true,
      profile: {
        avatar: true,
        bio: true
      }
    }
  }
});

Mutation

const result = await api.mutation({
  createPost: {
    __args: {
      title: 'Hello World',
      content: 'My first post'
    }
  }
});

File Upload

File uploads are automatically handled in mutations:

// Single file upload
await api.mutation({
  uploadAvatar: {
    __args: {
      file: fileInput.files[0]
    }
  }
});

// Multiple file upload
await api.mutation({
  uploadImages: {
    __args: {
      files: Array.from(fileInput.files)
    }
  }
});

Collection & List Builders

createList - Simple List Queries

import { createList } from '@hostlink/light';

// Create a list query
const users = await createList('Users', {
  user_id: true,
  username: true,
  first_name: true
})
  .where('status', 1)
  .where('role', 'admin')
  .sort('-created_at')
  .limit(10)
  .fetch();

// Get first item
const user = await createList('Users', { user_id: true, username: true })
  .where('username', 'john')
  .first();

Where Clauses

list
  .where('status', 1)              // Exact match
  .where('age', '>', 18)           // Greater than
  .where('age', '>=', 18)          // Greater than or equal
  .where('age', '<', 65)           // Less than
  .where('age', '<=', 65)          // Less than or equal
  .where('status', '!=', 0)        // Not equal
  .whereIn('role', ['admin', 'moderator'])  // In array
  .whereContains('name', 'john')   // Contains string
  .whereBetween('age', 18, 65)     // Between range

createCollection - Advanced Collection Operations

import { createCollection } from '@hostlink/light';

const collection = createCollection('Products', {
  id: true,
  name: true,
  price: true,
  category: true
});

// Filter and transform data
const result = await collection
  .where('category', '==', 'electronics')
  .where('price', '<', 1000)
  .sortBy('price')
  .map(item => ({ ...item, discounted: item.price * 0.9 }))
  .all();

// Aggregations
const avgPrice = await collection.avg('price');
const total = await collection.count();
const maxPrice = await collection.max('price');

User Management

// List users
const users = await api.users.list();

// Create user
await api.users.create({
  username: 'newuser',
  first_name: 'John',
  last_name: 'Doe',
  password: 'securepassword',
  join_date: '2024-01-01'
});

// Update user
await api.users.update(userId, {
  first_name: 'Jane'
});

// Delete user
await api.users.delete(userId);

Role Management

// List roles
const roles = await api.roles.list();

// Create role with child roles
await api.roles.create('admin', ['editor', 'viewer']);

// Delete role
await api.roles.delete('admin');

File System API

For direct filesystem access:

import { fs } from '@hostlink/light';

// Create folder
await fs.createFolder('local://path/to/folder');

// Delete folder
await fs.deleteFolder('local://path/to/folder');

// Rename folder
await fs.renameFolder('local://path/to/folder', 'newName');

// Write file
await fs.writeFile('local://path/to/file.txt', 'content');

// Upload file
await fs.uploadFile('local://path/to/destination', file);

// Delete file
await fs.deleteFile('local://path/to/file.txt');

// Check if exists
const exists = await fs.exists('local://path/to/file.txt');

// Move file/folder
await fs.move('local://from/path', 'local://to/path');

// Search files
const results = await fs.find('searchterm', 'document'); // labels: document, image, audio, video, archive

Email

await api.mail.send(
  '[email protected]',
  'Subject Line',
  'Email message body'
);

Model Helper

Create reusable model definitions:

import model from '@hostlink/light';

const Product = model('Product', {
  id: { name: 'product_id' },
  name: { gql: { name: true } },
  price: { gql: { price: true, currency: true } }
});

// CRUD operations
await Product.add({ name: 'New Product', price: 99.99 });
await Product.update(1, { price: 89.99 });
await Product.delete(1);
const product = await Product.get({ id: 1 }, { name: true, price: true });
const products = await Product.list({ name: true, price: true }).fetch();

Advanced Configuration

Direct API Client Access

import { setApiClient, getApiClient } from '@hostlink/light';

// Set a custom API client
setApiClient(customClient);

// Get the current API client
const client = getApiClient();

// Access the underlying axios instance
const { axios } = getApiClient();

Token Refresh

The client automatically handles token refresh when receiving TOKEN_EXPIRED errors. Failed requests are queued and retried after the token is refreshed.


TypeScript Support

This library is written in TypeScript and includes full type definitions.

import type { 
  UserFields, 
  CreateUserFields,
  QueryUserFieldsUserFields,
  RoleFields,
  FileFields,
  FolderFields,
  GraphQLQuery
} from '@hostlink/light';

License

MIT

Repository

https://github.com/HostLink/light