
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
**hs-fetch** is a TypeScript-based HTTP client library offering features like token management, retry logic, and timeout settings. It is designed to integrate seamlessly with frameworks like Next.js 14, supporting modern server and client-side rendering u
hs-fetch is a TypeScript-based HTTP client library offering features like token management, retry logic, and timeout settings. It is designed to integrate seamlessly with frameworks like Next.js 14, supporting modern server and client-side rendering use cases.
Note: Comprehensive E2E testing has been conducted using Cypress to ensure reliability and stability across various scenarios.
401 Unauthorized
responses with a limit to prevent infinite loops.revalidate
and tags
for compatibility with Next.js ISR (Incremental Static Regeneration).npm install hs-fetch
import Api from "hs-fetch";
// Create an API instance
const api = new Api({
baseUrl: "https://api.example.com",
getToken: () => localStorage.getItem("token"),
onRefreshToken: async () => {
// Implement token refresh logic
},
onRefreshTokenFailed: () => {
// Handle token refresh failure
},
authorizationType: "Bearer",
});
// Example GET request
const fetchData = async () => {
try {
const data = await api.get({
url: "/data",
query: { page: 1 },
revalidate: 60, // ISR revalidation
tags: ["data"], // ISR tags
});
console.log(data);
} catch (error) {
console.error("Error fetching data:", error);
}
};
// Example POST request
const postData = async () => {
try {
const response = await api.post({
url: "/data",
body: { name: "John Doe" },
onSuccess: (data) => {
console.log("Data posted successfully:", data);
},
onError: (error) => {
console.error("Error posting data:", error);
},
});
} catch (error) {
console.error("Error posting data:", error);
}
};
Api
ClassThe Api
class manages HTTP requests, handles token refresh, and implements retry logic.
constructor(config: Partial<ApiConfig>)
get<T>(options: FetchOptions<T>): Promise<T>
post<T>(options: FetchOptions<T>): Promise<T>
put<T>(options: FetchOptions<T>): Promise<T>
patch<T>(options: FetchOptions<T>): Promise<T>
delete<T>(options: FetchOptions<T>): Promise<T>
These methods perform HTTP requests for their respective verbs, using FetchOptions for configuration.
FetchOptions
Interface
FetchOptions
allows you to customize your requests with various options.
interface FetchOptions<T = unknown> {
method?: string;
body?: T;
query?: Record<string, unknown>;
url: string;
headers?: Record<string, string>;
revalidate?: number;
tags?: string[];
retryCount?: number;
retryDelay?: number;
timeout?: number;
onSuccess?: (data: T) => void;
onError?: (error: Error) => void;
beforeRequest?: (url: string, options: RequestInit) => void;
afterResponse?: (response: Response) => void;
useToken?: boolean;
}
FAQs
**hs-fetch** is a TypeScript-based HTTP client library offering features like token management, retry logic, and timeout settings. It is designed to integrate seamlessly with frameworks like Next.js 14, supporting modern server and client-side rendering u
The npm package hs-fetch receives a total of 28 weekly downloads. As such, hs-fetch popularity was classified as not popular.
We found that hs-fetch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.