New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

axios-master

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-master

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

latest
Source
npmnpm
Version
2.0.7
Version published
Weekly downloads
70
-92.1%
Maintainers
1
Weekly downloads
 
Created
Source

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

OptionTypeDescription
namestringName to display in logs
logbooleanIf true, logs raw Axios request/response
timeoutnumberRequest timeout in milliseconds
logger(log: LogData) => voidCustom logger callback
shouldRetrybooleanWhether to retry the request on failure
shouldRetryStatusnumber[]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

Keywords

axios

FAQs

Package last updated on 28 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts