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

@unmap/routing

v0.37.2

Published

Typed client for the unmap routing API (route + isochrone)

Readme

@unmap/routing

Typed client for the unmap routing API: point-to-point routes and travel-time isochrones over the Canadian road graph, for driving, trucking, cycling, and walking, plus the departure-time transit route contract. No map dependency; works in Node and the browser.

npm i @unmap/routing
import { Router } from '@unmap/routing'

const router = new Router({ key: 'um_live_...' })

const route = await router.route([-114.07, 51.05], [-113.99, 51.05], { mode: 'auto' })
route.distanceMeters   // integer metres
route.durationSeconds  // integer seconds
route.geometry         // GeoJSON LineString, [lng, lat] coordinates

const bands = await router.isochrone([-114.07, 51.05], { minutes: [10, 20], mode: 'pedestrian' })
bands.features         // one GeoJSON polygon per minute value

Coordinates are always [lng, lat]. mode is 'auto' | 'car' | 'bicycle' | 'pedestrian' | 'truck' | 'transit' and defaults to 'auto'; minutes is required and takes up to four values of at most 120 minutes. Driving modes accept useHighways (0 avoid motorways and trunks, 1 prefer); cycling and walking accept useHills (0 avoid climbs even for a longer route, 1 indifferent) and already account for terrain without it. Driving times do not vary with grade at all, which is Valhalla's model, so useHills on a driving mode is a 400 rather than a no-op. Both methods accept an AbortSignal as signal. A non-2xx response throws a RouterError carrying the HTTP status and, when the body has one, code. An endpoint outside Canada is 422 outside_coverage. A longitude or latitude outside WGS84 is 400 invalid_location, not that code. A Canadian trip the graph cannot connect, including Iqaluit to the mainland, is 422 no_route.

Transit requires departAt and works on route() and isochrone(); a transit band can be a MultiPolygon, and a centre with no scheduled transit nearby throws a RouterError with code outside_coverage. Production routes the agencies /coverage.json lists as routing-ready. There is no arriveBy, transit matrix, or realtime claim.

Optimize tours

optimizeTours() is Unmap Optimize (POST /optimize): it assigns shipments to vehicles and orders their visits under time windows, capacities, breaks and route limits. The request is Google Route Optimization's OptimizeToursRequest, camelCase or snake_case, and response is its OptimizeToursResponse, unchanged. It is not router.optimize(), which orders the stops of one vehicle.

import { optimizeTours, UnmapOptimizeError } from '@unmap/routing'

try {
  const { response, warnings, billableShipments } = await optimizeTours(
    {
      model: {
        shipments: [{ deliveries: [{ arrivalLocation: { latitude: 51.05, longitude: -114.07 } }] }],
        vehicles: [{ startLocation: { latitude: 51.04, longitude: -114.06 } }],
      },
    },
    { key: 'um_live_...' },
  )
  response.routes          // one ShipmentRoute per vehicle that was used
  response.skippedShipments
} catch (e) {
  if (e instanceof UnmapOptimizeError) console.error(e.googleStatus, e.details)
}

The same call is router.optimizeTours(request) on a Router, and unmap.router.optimizeTours(request) from @unmap/sdk. The key is sent in the X-API-Key header, not in the URL.

What Unmap knows beyond Google's response comes back beside it, never inside it:

  • warnings: the parsed X-Unmap-Optimize-Warnings header, an array of { code, field?, path?, count?, message } for fields Unmap accepts but cannot honour, road travel the routing budget decided, and route polylines that could not be drawn. Empty when there are none.
  • billableShipments: the shipments this request billed (the X-Unmap-Billable-Shipments header). 0 for solvingMode: 'VALIDATE_ONLY', for a shipment re-solved within 24 hours, and when the header is absent.
  • timeoutClamped and clampedTimeoutSeconds: whether your timeout was over the plan's cap, and the seconds the solve ran with instead.

A failure throws UnmapOptimizeError, which extends UnmapError. status is the HTTP status, code the gateway's string code (bad_request, rate_limited, quota_exceeded), retryAfterSeconds comes from Retry-After, googleStatus is Google's status name (INVALID_ARGUMENT, FAILED_PRECONDITION, RESOURCE_EXHAUSTED) and details is Google's error.details: a google.rpc.BadRequest lists each field violation, and a PreconditionFailure lists the mandatory shipments no vehicle can serve. Retries follow the retry option, on by default for 429, 502, 503 and transport failures. A failed request is never billed. Until Unmap Optimize is enabled on the gateway, every call is a 404 with code: 'not_found' and no googleStatus.

Parameters, response shapes, and error bodies are documented at unmap.dev/docs/apis/routing.