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

nfx-network

v1.1.1

Published

Modular, multi-platform network layer for Vite, Next.js, and React Native

Readme

@nickelfox/network

A modular, type-safe, multi-platform network layer for Vite, Next.js, and React Native. Built on Ky and TanStack Query v5.


Features

  • Single package, three platforms — Vite SPA, Next.js (client + SSR), React Native (bare + Expo)
  • TanStack Query v5 — cache, deduplication, background refetch, offline persistence
  • Cookie-based auth for web — httpOnly cookies + credentials: include, zero JS token handling
  • Bearer token auth for React Native — MMKV with device-ID-derived encryption key
  • Automatic token refresh — shared promise prevents concurrent refresh storms
  • Proactive token expiry check — refreshes before expiry, no wasted round-trips
  • Typed errors — discriminated ApiResult<T> union, canonical NetworkErrorCode registry
  • Retry with jitter — exponential backoff, Retry-After header respected
  • In-flight deduplication — concurrent identical GETs share one request
  • Content-Type negotiation — JSON, blob, text, and 204 No Content handled automatically
  • Structured logging — correlation IDs, pluggable Logger adapter, automatic redaction
  • Strict TypeScriptstrict, noUncheckedIndexedAccess, exactOptionalPropertyTypes
  • Tree-shakeable — platform adapters on separate entry points, sideEffects: false

Installation

# In your app (workspace or file reference)
npm install @nickelfox/network

# Required peer dependencies (all platforms)
npm install ky @tanstack/react-query

# Web only
npm install react

# React Native only
npm install react-native-mmkv react-native-device-info

# Next.js only — next is already in your project

Quick Start

Vite SPA

// main.tsx
import { networkLayerSetup, createNetworkConfig } from '@nickelfox/network'
import { LocalStorageAdapter } from '@nickelfox/network/adapters/web'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

const queryClient = new QueryClient({
  defaultOptions: {
    queries: { networkMode: 'offlineFirst', staleTime: 30_000 }
  }
})

networkLayerSetup({
  config: createNetworkConfig({
    baseURL: import.meta.env.VITE_API_URL,
    authMode: 'cookie',
  }),
  onLogout: () => {
    queryClient.clear()
    window.location.href = '/login'
  },
})

export function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <Router />
    </QueryClientProvider>
  )
}

Next.js

// app/providers.tsx (client component)
'use client'
import { networkLayerSetup, createNetworkConfig } from '@nickelfox/network'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { useRouter } from 'next/navigation'
import { useRef } from 'react'

export function Providers({ children }: { children: React.ReactNode }) {
  const router = useRouter()
  const queryClientRef = useRef(new QueryClient({
    defaultOptions: { queries: { networkMode: 'offlineFirst', staleTime: 30_000 } }
  }))

  useRef(() => {
    networkLayerSetup({
      config: createNetworkConfig({
        baseURL: process.env.NEXT_PUBLIC_API_URL!,
        serverBaseURL: process.env.INTERNAL_API_URL,
        authMode: 'cookie',
      }),
      onLogout: () => {
        queryClientRef.current.clear()
        router.push('/login')
      },
    })
  })

  return (
    <QueryClientProvider client={queryClientRef.current}>
      {children}
    </QueryClientProvider>
  )
}

React Native (bare + Expo)

// App.tsx
import { networkLayerSetup, createNetworkConfig } from '@nickelfox/network'
import { MMKVAdapter } from '@nickelfox/network/adapters/react-native'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { navigationRef } from './navigation/navigationRef'

const queryClient = new QueryClient({
  defaultOptions: {
    queries: { networkMode: 'offlineFirst', staleTime: 30_000 }
  }
})

networkLayerSetup({
  config: createNetworkConfig({
    baseURL: process.env.API_URL!,
    authMode: 'bearer',
    tokenKeys: {
      access: 'user-token',
      refresh: 'refresh-token',
      refreshEndpoint: '/auth/refresh-token/',
    },
  }),
  storage: new MMKVAdapter(),
  onLogout: () => {
    queryClient.clear()
    navigationRef.current?.navigate('Login')
  },
})

export default function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <RootNavigator />
    </QueryClientProvider>
  )
}

Usage at a Glance

// Define endpoints once
import { RouteDefinition } from '@nickelfox/network'

export const API = {
  DEALS: {
    LIST:   { endpoint: '/deals/', method: 'GET' } satisfies RouteDefinition,
    CREATE: { endpoint: '/deals/', method: 'POST' } satisfies RouteDefinition,
    DETAIL: (id: string) => ({ endpoint: `/deals/${id}/`, method: 'GET' }) satisfies RouteDefinition,
    UPDATE: (id: string) => ({ endpoint: `/deals/${id}/`, method: 'PATCH' }) satisfies RouteDefinition,
  }
}

// Query
const { data, isLoading, error } = useApiQuery<Deal[]>(API.DEALS.LIST)

// Query with params
const { data } = useApiQuery<Deal>(
  API.DEALS.DETAIL(dealId),
  { pathParams: { id: dealId } }
)

// Filtered query
const { data } = useApiQuery<Deal[]>(
  API.DEALS.LIST,
  { queryParams: { status: 'active', page: 1 } }
)

// Mutation
const { mutate, isPending } = useApiMutation<Deal, CreateDealPayload>(
  API.DEALS.CREATE,
  {},
  {
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['/deals/'] })
    }
  }
)

// Mutation with dynamic route
const { mutate } = useApiMutation<Deal, UpdateDealPayload>(
  (vars) => API.DEALS.UPDATE(vars.id),
)

Package Entry Points

| Import path | Contents | Use in | |---|---|---| | @nickelfox/network | Hooks, types, createNetworkConfig, networkLayerSetup | All platforms | | @nickelfox/network/adapters/web | LocalStorageAdapter, SessionStorageAdapter | Vite | | @nickelfox/network/adapters/next | NextServerCookieAdapter, LocalStorageAdapter | Next.js | | @nickelfox/network/adapters/react-native | MMKVAdapter | React Native | | @nickelfox/network/mocks | http, HttpResponse, delay from MSW | Tests / dev |

Adapters are on separate entry points so platform-specific code (MMKV, next/headers) never enters the wrong bundle.


Documentation