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

moshimoshi-react

v0.0.1

Published

`moshimoshi-react` is a lightweight and extendable HTTP client wrapper around Axios with automatic token handling, tailored for React applications. It manages login, token storage, access token refresh, and secured/unsecured API calls in a clean and reusa

Readme

moshimoshi-react

moshimoshi-react is a lightweight and extendable HTTP client wrapper around Axios with automatic token handling, tailored for React applications. It manages login, token storage, access token refresh, and secured/unsecured API calls in a clean and reusable way.

🚀 Features

  • 🔒 Access and refresh token management
  • 🔄 Auto-refresh access tokens on 401 responses
  • 🔐 Authenticated and public API requests
  • ⚙️ Customizable endpoints and token storage
  • 🔁 Singleton pattern to keep one global instance
  • 🪝 React-friendly with browser redirect on auth failures
  • 📦 Tree-shakable and optimized for bundlers

📦 Installation

npm install moshimoshi-react
# or
yarn add moshimoshi-react

🔧 Setup

1. Initialize the singleton client

import { Moshimoshi } from 'moshimoshi-react';
import { LocalStorageAdapter } from './storage/LocalStorageAdapter';
import { Endpoint } from './entity/Endpoint';

const storage = new LocalStorageAdapter();

const loginEndpoint = new Endpoint('/api/login', 'POST');
const refreshEndpoint = new Endpoint('/api/refresh', 'POST');

const api = Moshimoshi.getInstance(storage, loginEndpoint, refreshEndpoint);

2. Logging in

await api.login({
  username: '[email protected]',
  password: 'securepassword',
});

3. Making requests

Authenticated

const securedEndpoint = new Endpoint('/api/private', 'GET');
const result = await api.loadAuthorized(securedEndpoint);

Public

const publicEndpoint = new Endpoint('/api/public', 'GET');
const result = await api.load(publicEndpoint);

4. Logging out

await api.logout(); // Will clear all tokens and redirect to /login

🧱 Core Concepts

Endpoint

Encapsulates API endpoint details:

const endpoint = new Endpoint('/api/users/:id', 'GET', {
  parameters: { id: '123' },
  query: { include: 'details' },
  headers: { 'X-Custom': 'value' },
});

Token

Represents access/refresh tokens with optional expiration.

Storage

You can plug in your own Storage implementation (e.g., localStorage, sessionStorage, SecureStore) using the interface provided.


🧪 Example Storage Adapter

export class LocalStorageAdapter implements Storage {
  save(token: Token, type: TokenType): void {
    localStorage.setItem(type, JSON.stringify(token));
  }

  retrieve(type: TokenType): Token | undefined {
    const raw = localStorage.getItem(type);
    return raw ? Token.fromJSON(JSON.parse(raw)) : undefined;
  }

  deleteAll(): void {
    localStorage.clear();
  }
}

💡 Notes

  • If the access token is expired and no refresh token is available, the user is redirected to /login.
  • loadAuthorized() automatically attaches the Bearer token.
  • You can add a logoutEndpoint for server-side session clearing.

🔗 Peer Dependencies

This package expects react, react-dom, and react-router-dom to be present in your project.

"peerDependencies": {
  "react": "^19.0.0",
  "react-dom": "^19.0.0",
  "react-router-dom": "^7.4.0"
}

📁 Project Structure

  • Written in TypeScript
  • Bundled with Rollup
  • Output formats: CommonJS and ESModule
  • Supports tree-shaking

📜 License

MIT


✨ Contributing

Feel free to open issues or submit PRs to improve the library. Feedback is always welcome!


🧠 TODO

  • [ ] React hook integration (useMoshimoshi)
  • [ ] Token expiration countdown utility
  • [ ] SSR support