Skip to content

Latest commit

 

History

History
123 lines (95 loc) · 7.16 KB

README.md

File metadata and controls

123 lines (95 loc) · 7.16 KB

npm Registry API Client

npm version npm downloads bundle License

@yorganci/npm-registry-api is a fully typesafe npm registry API client with optional caching.

Features

  • Validates registry responses using zod.
  • Supports response caching with unstorage.
  • Compatible with both Node.js and browser environments.
  • Works seamlessly with third-party npm-compatible registries.

Useful Links

Usage

Install @yorganci/npm-registry-api npm package:

# yarn
yarn add @yorganci/npm-registry-api

# npm
npm install @yorganci/npm-registry-api

# pnpm
pnpm add @yorganci/npm-registry-api

Basic usage

import { Client } from "@yorganci/npm-registry-api";

const client = new Client();

await client.searchPackages({ text: "react", size: 1 });

npm Registry API

Function Name Description
getAbbreviatedPackument Fetches abbreviated packument (package document) containing only the metadata necessary to install a package.
getBulkDailyPackageDownloads Retrieves the total number of downloads for each day for some packages in the given time period.
getBulkPackageDownloads Fetches the total number of downloads for the given packages in the given time period.
getDailyPackageDownloads Retrieves the total number of downloads for each day for a package in the given time period.
getDailyRegistryDownloads Gets the total number of downloads for each day for all packages in the registry in the given time period.
getPackageDownloads Fetches total number of downloads for a package in the given time period.
getPackageManifest Retrieves the manifest describing a specific version of a package (e.g., foo@1.0.0).
getPackageVersionsDownloads Gets the total number of downloads for each version of a package in the previous 7 days.
getPackument Fetches full packument (package document) containing all the metadata available about a package.
getRegistryDownloads Retrieves total number of downloads for all packages in the registry in the given time period.
getRegistryMetadata Fetches metadata describing the registry itself.
getRegistrySigningKeys Retrieves public signing keys used by the registry.
searchPackages Searches packages corresponding to a given query.

Caching API

@yorganci/npm-registry-api/cache module provides basic factory function to create Cache object to be used by Client. By default createCache, uses ohash under the hood to generate cache keys from URL and HTTP headers and any Driver implementation from unstorage can be used for persistance the default is unstorage/drivers/memory.

Basic usage with default options.

import { Client } from "@yorganci/npm-registry-api";
import { createCache } from "@yorganci/npm-registry-api/cache";

// By default `Map<string, unknown>` is used as caching layer
const cachedClient = new Client({
  cache: createCache(),
});

Create a file-system backed cache client.

import { Client } from "@yorganci/npm-registry-api";
import { createCache } from "@yorganci/npm-registry-api/cache";
import fs from "unstorage/drivers/fs";

const cachedClient = new Client({
  cache: createCache({
    storage: fs({
      base: "./data",
    }),
  }),
});

License

MIT