0.3.0 • Published 10 months ago

@yorganci/npm-registry-api v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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 NameDescription
getAbbreviatedPackumentFetches abbreviated packument (package document) containing only the metadata necessary to install a package.
getBulkDailyPackageDownloadsRetrieves the total number of downloads for each day for some packages in the given time period.
getBulkPackageDownloadsFetches the total number of downloads for the given packages in the given time period.
getDailyPackageDownloadsRetrieves the total number of downloads for each day for a package in the given time period.
getDailyRegistryDownloadsGets the total number of downloads for each day for all packages in the registry in the given time period.
getPackageDownloadsFetches total number of downloads for a package in the given time period.
getPackageManifestRetrieves the manifest describing a specific version of a package (e.g., foo@1.0.0).
getPackageVersionsDownloadsGets the total number of downloads for each version of a package in the previous 7 days.
getPackumentFetches full packument (package document) containing all the metadata available about a package.
getRegistryDownloadsRetrieves total number of downloads for all packages in the registry in the given time period.
getRegistryMetadataFetches metadata describing the registry itself.
getRegistrySigningKeysRetrieves public signing keys used by the registry.
searchPackagesSearches 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