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

@nextuneapps/geofencing

v0.1.8

Published

Express middleware and routes for NextUne location and exchange-rate data, with TypeScript types.

Readme

@nextuneapps/geofencing

Express (Node.js) library paired with the Django package nextune-geofencing: optional middleware that attaches location-related fields to each request, optional mounted routes, and TypeScript types for the payload shapes your app works with. Published on npm under the nextuneapps org.

Install

npm install @nextuneapps/geofencing

express is a peer dependency (v4 or v5). Node 18+ (uses fetch). Published dist/ is CommonJS so it loads with require() and works with typical Express setups; TypeScript and bundlers can still import it.

Types (IDE-friendly payloads)

Import types from the package root so handlers, serializers, and tests stay aligned with the JSON you handle:

import type {
  NextuneLocationPayload,
  NextuneGeo,
  NextuneGeofencing,
  ExchangeRatesResponse,
  ExchangeRatesBlock,
  GeofencingRouterErrorBody,
} from "@nextuneapps/geofencing";

Location (NextuneLocationPayload) — returned by the GET …/whoami route (caller IP), POST …/ip, and the same shape from your own proxies or clients. Narrow unknown bodies like this:

import type {
  NextuneLocationPayload,
  NextuneGeo,
  NextuneGeofencing,
} from "@nextuneapps/geofencing";

function summarizeLocation(body: unknown) {
  const data = body as NextuneLocationPayload;
  const geo: NextuneGeo | undefined = data.geo;
  const gf: NextuneGeofencing | null | undefined = data.geofencing;

  return {
    currency: gf?.currency ?? geo?.currency,
    country: gf?.country_code ?? geo?.country,
    payment_methods: data.payment_methods,
  };
}

Exchange rates — same idea for FX payloads:

import type { ExchangeRatesResponse, ExchangeRatesBlock } from "@nextuneapps/geofencing";

function ratesTable(body: unknown, baseCode: string) {
  const payload = body as ExchangeRatesResponse;
  const block: ExchangeRatesBlock | undefined = payload[baseCode.toUpperCase()];
  return block?.rates;
}

Middleware req — after geofencingMiddleware(), req.geofencing is typed (see the package’s Express module augmentation).

import express from "express";
import { geofencingMiddleware } from "@nextuneapps/geofencing";

const app = express();
app.use(geofencingMiddleware());

app.get("/checkout", (req, res) => {
  const gf = req.geofencing;
  res.json({
    country: req.country_code,
    country_name: req.country_name,
    currency: gf?.currency,
    payment_hint: gf?.currency_symbol,
  });
});

Router errors — treat error JSON from the package router consistently:

import type { GeofencingRouterErrorBody } from "@nextuneapps/geofencing";

function isRouterError(x: unknown): x is GeofencingRouterErrorBody {
  return typeof x === "object" && x !== null && "error" in x;
}

Middleware

Attaches req.geofencing, req.country_code, and req.country_name (same field names as the Django package).

import express from "express";
import { geofencingMiddleware } from "@nextuneapps/geofencing";

const app = express();
app.use(geofencingMiddleware());

app.get("/example", (req, res) => {
  res.json({
    country: req.country_code,
    name: req.country_name,
    geofencing: req.geofencing,
  });
});

Routes

Mount the router and JSON parsing for POST /ip:

import express from "express";
import { createGeofencingRouter } from "@nextuneapps/geofencing";

const app = express();
app.use(express.json());
app.use("/v1/geo", createGeofencingRouter());
  • GET /v1/geo/whoami — resolves the caller’s IP, then returns location JSON as NextuneLocationPayload. Commonly used for “current visitor” country, currency, and geofencing.
  • POST /v1/geo/ip — body { "ip": "203.0.113.1" } → same location JSON shape (NextuneLocationPayload).
  • GET /v1/geo/exchange-rates/:currency — three-letter ISO code (e.g. KES) → exchange-rate JSON (ExchangeRatesResponse).