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

@0xzahed/geotrack-client

v0.1.0

Published

Client for consuming a Django geotrack backend (IP-based login location) from Next.js/React apps

Readme

@0xzahed/geotrack-client

TypeScript client for consuming a django-geotrack backend from Next.js / React apps.

The Django app records IP-derived location (country / division / district / city) on every user login automatically — no browser permission popup needed. This package is the frontend half: fetch that data back and display it.

Install

npm install @0xzahed/geotrack-client

Works with plain fetch (Node 18+, browsers) — React is only needed if you use the optional useLoginLocation hook.

Quick start

import { GeotrackClient, formatLocation } from "@0xzahed/geotrack-client";

const client = new GeotrackClient({
  baseUrl: "https://your-django-api.com/api/geotrack",
  getAuthHeaders: () => ({
    Authorization: `Bearer ${yourAccessToken}`,
  }),
});

const latest = await client.getLatestLocation();
console.log(formatLocation(latest)); // "Dhaka, Dhaka Division, Bangladesh"

React hook

"use client";
import { GeotrackClient } from "@0xzahed/geotrack-client";
import { useLoginLocation } from "@0xzahed/geotrack-client/react";

const client = new GeotrackClient({
  baseUrl: process.env.NEXT_PUBLIC_API_URL + "/api/geotrack",
  getAuthHeaders: () => ({ Authorization: `Bearer ${getToken()}` }),
});

export default function LastLoginBadge() {
  const { location, loading, error } = useLoginLocation(client);

  if (loading) return <span>Loading location…</span>;
  if (error) return null;

  return (
    <span>
      Last login from {location?.city}, {location?.division}, {location?.country}
    </span>
  );
}

API

new GeotrackClient(options)

| Option | Type | Description | |---|---|---| | baseUrl | string | Base URL of the geotrack API, e.g. https://api.example.com/api/geotrack | | getAuthHeaders | () => Record<string, string> | Optional. Called per request — return auth headers | | fetchImpl | typeof fetch | Optional. Custom fetch implementation (defaults to global fetch) |

Methods

| Method | Returns | Endpoint | |---|---|---| | getLatestLocation() | Promise<LoginLocation> | GET /latest-location/ | | getLoginHistory() | Promise<{ results: LoginLocation[]; count: number }> | GET /login-history/ |

formatLocation(loc)

Joins city, division, country into a readable string — "Dhaka, Dhaka Division, Bangladesh", or "Unknown location" when empty.

LoginLocation

interface LoginLocation {
  id: number;
  ip_address: string;
  country: string | null;
  country_code: string | null;
  division: string | null;   // state / region
  district: string | null;
  city: string | null;
  latitude: number | null;
  longitude: number | null;
  user_agent: string | null;
  created_at: string;        // ISO 8601
}

Both endpoints require authentication (IsAuthenticated on the Django side) — pass credentials via getAuthHeaders.

Dual ESM + CJS

Ships both module formats — import gets ESM (dist/esm/), require gets CommonJS (dist/). No configuration needed; works with Next.js, Vite, webpack, and plain Node.

Backend

Requires the companion Django app: https://github.com/0xzahed/django-geotrack

License

MIT