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

alvys-sdk

v0.1.2

Published

Typed JavaScript/TypeScript client for the Alvys REST API.

Readme

Alvys REST API

Typed, ESM-first JavaScript/TypeScript client for the Alvys REST API, generated directly from the public OpenAPI specification.

Features

  • Dual ESM/CJS builds with bundled declaration files targeting ES2020 runtimes.
  • Typed client built on openapi-fetch covering every endpoint from the latest spec.
  • Configurable auth & headers via createAlvysClient() options.
  • Zero runtime dependencies beyond the Fetch API; bring your own fetch in Node.js environments.

Installation

npm install alvys-sdk
# or yarn/pnpm/bun

Usage

import { createAlvysClient } from 'alvys-sdk';

const alvys = createAlvysClient({
  accessToken: async () => {
    // fetch a token via your auth flow
    return process.env.ALVYS_TOKEN!;
  },
});

const response = await alvys.POST('/api/s/v1/shipments', {
  body: {
    shipmentNumber: 'SH-1001',
    // ...rest of the typed payload
  },
});

if (response.data) {
  console.log('Shipment:', response.data);
} else {
  console.error('API error:', response.error);
}

Token helper

Tokens issued by https://auth.alvys.com/oauth/token expire after 60 minutes. The SDK now ships a helper that caches and refreshes them automatically while keeping the .env fallback for manually generated tokens.

import { createAlvysAccessTokenProvider, createAlvysClient } from 'alvys-sdk';

const getAccessToken = createAlvysAccessTokenProvider({
  clientId: process.env.ALVYS_CLIENT_ID!,
  clientSecret: process.env.ALVYS_CLIENT_SECRET!,
  // Optional: scope, custom audience, or fetch implementation
});

const alvys = createAlvysClient({
  accessToken: getAccessToken,
});

createAlvysAccessTokenProvider()

  • Caches the last token and refreshes it one minute before expiration.
  • Uses the official audience https://api.alvys.com/public/ by default.
  • Falls back to process.env.ALVYS_TOKEN when no client credentials are available.
  • Accepts async clientId/clientSecret/fallbackToken factories plus a custom fetch implementation if needed.

Endpoint examples (Drivers, Loads, Trucks, Trailers)

Each helper returns the typed response from the OpenAPI spec. Path params (such as {version}) are passed via params.path, while filters go in params.query, and search payloads are fully typed via the exported components schema map.

Drivers

import { createAlvysClient, type components } from 'alvys-sdk';

const alvys = createAlvysClient();

const drivers = await alvys.GET('/api/p/v{version}/drivers', {
  params: { path: { version: '1' } },
});

const driverSearch = await alvys.POST('/api/p/v{version}/drivers/search', {
  params: { path: { version: '1' } },
  body: {
    Page: 1,
    PageSize: 25,
    Status: ['Active'],
    Name: 'Smith',
  } satisfies components['schemas']['Alvys.Models.Users.DriverSearchRequest'],
});

if (driverSearch.data) {
  driverSearch.data.Items.forEach(driver => console.log(driver.Name));
}

Loads

const loadByNumber = await alvys.GET('/api/p/v{version}/loads', {
  params: {
    path: { version: '2' },
    query: { loadNumber: 'L-10001' },
  },
});

const loadSearch = await alvys.POST('/api/p/v{version}/loads/search', {
  params: { path: { version: '2' } },
  body: {
    Page: 1,
    PageSize: 50,
    Status: ['Dispatched', 'Delivered'],
    DateRange: {
      Start: '2024-01-01T00:00:00Z',
      End: '2024-01-31T23:59:59Z',
    },
    IncludeDeleted: false,
  } satisfies components['schemas']['Alvys.Models.Loads.LoadSearchRequest'],
});

Trucks

const trucks = await alvys.GET('/api/p/v{version}/trucks', {
  params: { path: { version: '1' } },
});

const truckSearch = await alvys.POST('/api/p/v{version}/trucks/search', {
  params: { path: { version: '1' } },
  body: {
    Page: 1,
    PageSize: 25,
    TruckNumber: '1205',
    Status: ['Active'],
  } satisfies components['schemas']['Alvys.Models.Users.TruckSearchRequest'],
});

Trailers

const trailer = await alvys.GET('/api/p/v{version}/trailers/{id}', {
  params: {
    path: { version: '1', id: 'uuid-of-trailer' },
  },
});

const trailerSearch = await alvys.POST('/api/p/v{version}/trailers/search', {
  params: { path: { version: '1' } },
  body: {
    Page: 1,
    PageSize: 25,
    TrailerNumber: 'TR-4200',
    Status: ['Active'],
  } satisfies components['schemas']['Alvys.Models.Trailers.TrailerSearchRequest'],
});

Node.js

This SDK expects a global Fetch API. Node 18+ exposes fetch/Headers natively. For older versions, install a polyfill such as undici:

import { fetch, Headers, Request, Response } from 'undici';

globalThis.fetch = fetch;
globalThis.Headers = Headers;
globalThis.Request = Request;
globalThis.Response = Response;

Alternatively, pass the implementation explicitly:

import { fetch as undiciFetch } from 'undici';

const alvys = createAlvysClient({ fetch: undiciFetch });

Custom headers & base URL

const alvys = createAlvysClient({
  baseUrl: 'https://integrations.alvys.com',
  accessToken: () => getTokenFromSomewhere(),
  defaultHeaders: async () => ({
    'x-my-app-version': '1.2.3',
  }),
});

Per-request headers (including overriding Authorization) can still be supplied via the second argument to GET/POST/... calls.

API typings

All OpenAPI types live in src/types/alvys.ts. You can import any of them:

import type { paths } from 'alvys-sdk';

Local development

  • npm run generate – regenerate src/types/alvys.ts from the public swagger document.
  • npm run build – produce the dual ESM/CJS bundle in dist/.
  • npm run dev – watch-mode build via tsup.

The generated types are committed so the SDK can be used without running the generator, but make sure to re-run it before publishing when the upstream API changes.