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 🙏

© 2025 – Pkg Stats / Ryan Hefner

axios-master

v2.0.7

Published

Axios wrapper for advanced response time logging, retries, and token refresh.

Readme

Axios Master

A powerful and flexible Axios wrapper that adds advanced features like:

  • ✅ Retry on specific HTTP status codes
  • 🔁 Automatic token refresh using a custom function
  • 🪵 Rich logging with response metadata
  • ⏱ Custom timeout
  • 🌐 HTTPS Agent support

📦 Installation

npm install axios-master

✨ Features

  • Easy-to-use Axios wrapper
  • Retry mechanism with token refresh
  • Customizable logger with timing, request, and response info
  • Optional verbose logging
  • Automatically handles 401 or any status you define

🚀 Basic Example

import axiosMaster from "axios-master";

async function fetchStatus(body: any) {
  try {
    const result = await axiosMaster(
      {
        method: "GET",
        url: `${config.host}/payment/status?value=${body.value}`,
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
          Authorization: `Bearer ${config.token}`,
        },
      },
      {
        name: "Payment Status",
        timeout: 20000,
        shouldRetry: true,
        shouldRetryStatus: [401],
        retryFunction: getNewToken,
        logger: (log) => {
          console.log("API LOG:", log);
        },
      },
    );

    console.log("Result:", result);
  } catch (error) {
    console.error("Request Failed:", error);
  }
}

🔄 Retry with Token Refresh (using axios-master itself)

import axiosMaster from "axios-master";

const getNewToken = async (): Promise<string> => {
  try {
    const tokenRes = await axiosMaster(
      {
        method: "POST",
        url: "https://api.example.com/auth/token",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          username: "your_username",
          password: "your_password",
        },
      },
      {
        name: "Get New Token",
        timeout: 10000,
        logger: (log) => {
          console.log("Token Fetch Log:", log);
        },
      },
    );

    config.token = tokenRes.accessToken;
    return config.token;
  } catch (error) {
    console.error("Token fetch failed:", error);
    return "";
  }
};

🧪 Function Signature

axiosMasterMain(
  default_config: AxiosRequestConfig,
  masterConfig: MasterConfig
): Promise<any>

⚙️ MasterConfig Options

| Option | Type | Description | | ------------------- | ------------------------ | ---------------------------------------------- | | name | string | Name to display in logs | | log | boolean | If true, logs raw Axios request/response | | timeout | number | Request timeout in milliseconds | | logger | (log: LogData) => void | Custom logger callback | | shouldRetry | boolean | Whether to retry the request on failure | | shouldRetryStatus | number[] | HTTP status codes to retry (e.g. [401, 500]) | | retryFunction | () => Promise<string> | Token refresh function to call before retrying |


📊 Logger Payload Structure

{
  log_levels: "INFO" | "DEBUG" | "WARN" | "ERROR" | "CRITICAL" | "TRACE",
  message: string,
  json: {
    time: number, // in seconds
    request: AxiosRequestConfig,
    response: any,
    responseBody: any,
    statusCode: number
  }
}

🌐 Advanced Options

  • Automatically retries failed requests if status code matches
  • Supports retry only once (for safety)
  • Useful for microservices, SDKs, or secure API clients

📃 License

MIT License © Buyantogtokh