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

@opens/accesshub-backend

v0.0.2

Published

Simple SDK for resource verification with cache and fallback

Downloads

3

Readme

AccessHub Backend SDK

A lightweight TypeScript SDK for company resource verification with memory caching and local fallback capabilities.

version license build typescript

Features

  • 🚀 Fast in-memory caching with TTL support
  • 💾 Persistent file-based fallback storage
  • 🔌 Pluggable cache providers (Redis, MongoDB, SQLite, etc.)
  • 🔄 Automatic fallback to local storage when API is unavailable
  • 🔒 Bearer token authentication support
  • 📦 Zero runtime dependencies beyond Axios and Keyv

Installation

npm install @opens/accesshub-backend

Quick Start

import { ResourceClient } from '@opens/accesshub-backend';

// Create client with minimal configuration
const client = new ResourceClient({
  accessHubURL: 'https://api.example.com',
  serviceToken: 'your-service-token',
});

// Get all company resources with automatic caching and fallback
const response = await client.getCompanyResources('company-id');
console.log(response.resources);

// Check if data came from cache or fallback storage
console.log(response._metadata.fromCache); // true/false
console.log(response._metadata.fromFallback); // true/false

// Get a specific resource by name
const resource = await client.getResource('company-id', 'resource1');

Configuration

import { ResourceClient } from '@opens/accesshub-backend';

const client = new ResourceClient({
  // Required: Base URL for the AccessHub API
  accessHubURL: 'https://api.example.com',

  // Optional: Authentication token for API requests
  serviceToken: 'your-service-token',

  // Optional: Cache TTL in milliseconds (default: 600000 = 10 minutes)
  cacheTTL: 300000,

  // Optional: Path for storing fallback JSON data
  dumpPath: './resource-data.json',

  // Optional: Custom cache implementation
  cache: customCacheImplementation,
});

Caching Options

The SDK supports various caching backends through Keyv adapters:

Default In-Memory Cache

// Uses built-in in-memory cache (default)
const client = new ResourceClient({
  accessHubURL: 'https://api.example.com',
});

Redis Cache

import { ResourceClient, KeyvCacheProvider } from '@opens/accesshub-backend';
// First: npm install @keyv/redis

const client = new ResourceClient({
  accessHubURL: 'https://api.example.com',
  cache: new KeyvCacheProvider({
    store: 'redis://localhost:6379',
    namespace: 'accesshub',
    ttl: 3600000, // 1 hour
  }),
});

Database Caching

import { ResourceClient, KeyvCacheProvider } from '@opens/accesshub-backend';

// MongoDB (requires @keyv/mongo)
const mongoCache = new KeyvCacheProvider({
  store: 'mongodb://user:pass@localhost:27017/database',
  namespace: 'resources',
});

// SQLite (requires @keyv/sqlite)
const sqliteCache = new KeyvCacheProvider({
  store: 'sqlite://path/to/database.sqlite',
});

const client = new ResourceClient({
  accessHubURL: 'https://api.example.com',
  cache: mongoCache,
});

Keyv Configuration Options

import { KeyvCacheProvider } from '@opens/accesshub-backend';

const cache = new KeyvCacheProvider({
  // Connection string or store instance
  store: 'redis://localhost:6379',

  // Namespace to prevent key collisions (default: 'accesshub')
  namespace: 'my-app',

  // Default TTL in milliseconds
  ttl: 3600000, // 1 hour
});

Supported Keyv adapters (install separately):

  • @keyv/redis - Redis adapter
  • @keyv/mongo - MongoDB adapter
  • @keyv/sqlite - SQLite adapter
  • @keyv/postgres - PostgreSQL adapter
  • @keyv/mysql - MySQL adapter

Custom Cache Implementation

You can create your own cache provider by implementing the CacheProvider interface:

import { ResourceClient, CacheProvider, ResourceResponse } from '@opens/accesshub-backend';

class CustomCache implements CacheProvider {
  async get(companyId: string): Promise<ResourceResponse | null> {
    // Retrieve data from your custom storage
    return null;
  }

  async set(companyId: string, data: ResourceResponse, ttl: number): Promise<void> {
    // Store data in your custom storage with TTL
  }

  async delete(companyId: string): Promise<void> {
    // Delete data for specific company
  }

  async clear(): Promise<void> {
    // Clear all cached data
  }
}

// Use your custom cache
const client = new ResourceClient({
  accessHubURL: 'https://api.example.com',
  cache: new CustomCache(),
});

Fallback Storage

The SDK automatically stores resource data to a local JSON file for offline access when the API is unavailable:

// Customize the fallback storage location
const client = new ResourceClient({
  accessHubURL: 'https://api.example.com',
  dumpPath: './custom/path/resources.json',
});

Response Types

// Full response structure
interface ResourceResponse {
  // Map of resource name to resource object
  resources: Record<string, Resource>;

  // Metadata about the response
  _metadata: {
    fromCache: boolean; // From cache?
    fromFallback: boolean; // From fallback storage?
    lastUpdated: string; // ISO timestamp
  };
}

// Individual resource structure
interface Resource {
  id: string;
  sequenceId: number;
  name: string;
  description: string;
  createdAt: string;
  updatedAt: string;
}