UNPKG

npm-registry-sdk

Version:

A fully type-safe client library for the npm registry API.

84 lines (83 loc) 3.29 kB
import type { DistTags, DownloadPeriod, PackageInfo, PackageMetadata, RegistryDownloads, RegistryKeys, RegistryMetadata, SearchOptions, SearchResults } from './types/index.ts'; import { type RequestInitOptions } from './utils/request.ts'; interface NpmRegistryOptions extends RequestInitOptions { /** * The base URL of the NPM Registry. * @default 'https://registry.npmjs.org' */ registry?: string; /** * The base URL of the NPM Registry API. * @default 'https://api.npmjs.org' */ api?: string; } export default class NpmRegistry { private registry; private api; private request; constructor({ api, registry, ...request }?: NpmRegistryOptions); /** * Get the registry metadata * @returns The registry metadata * @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md#get */ getRegistryMetadata(): Promise<RegistryMetadata>; /** * Get the public signing keys used by the registry. * @returns The registry keys * @see https://docs.npmjs.com/about-registry-signatures */ getRegistryKeys(): Promise<RegistryKeys>; /** * Get the download statistics for the registry * @param period The download period (e.g., 'last-day', 'last-week', 'last-month', 'last-year', 'yyyy-mm-dd:yyyy-mm-dd') * @param packageName The package name (optional) * @returns The download statistics * @see https://github.com/npm/registry/blob/master/docs/download-counts.md#point-values */ getRegistryDownloads(period: DownloadPeriod, packageName?: string): Promise<RegistryDownloads>; /** * Get package information from the registry * @param packageName The package name * @returns The package information * @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md#getpackage */ getPackage(packageName: string): Promise<PackageInfo>; /** * Get package metadata for a specific version * @param packageName The package name * @param version The package version * @returns Package metadata * @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md#getpackageversion */ getPackageVersion(packageName: string, version: string): Promise<PackageMetadata>; /** * Get the latest version of a package * @param packageName The package name * @returns The latest version metadata */ getLatestVersion(packageName: string): Promise<PackageMetadata>; /** * Search for packages in the registry * @param query The search query * @param options The search options * @returns The search results * @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md#get-v1search */ search(query: string, options?: SearchOptions): Promise<SearchResults>; /** * Get the dist-tags for a package * @param packageName The package name * @returns The dist-tags */ getDistTags(packageName: string): Promise<DistTags>; /** * Download a package tarball * @param packageName The package name * @param version The package version * @returns The tarball as an ArrayBuffer */ downloadTarball(packageName: string, version: string): Promise<ArrayBuffer>; } export {};