# @yorganci/npm-registry-api

> Fully typesafe npm registry API client with optional caching.

Latest version **0.3.0** (published 2024-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yorganci/npm-registry-api
pnpm add @yorganci/npm-registry-api
yarn add @yorganci/npm-registry-api
bun add @yorganci/npm-registry-api
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2024-07-27 |
| First published | 2024-07-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 769 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Atahan Yorganci |
| Maintainers | atahanyorganci |
| Keywords | npm, registry, typescript, isomorphic-fetch, npm-registry, npm-search, npm-downloads, packument, npm-registry-api, zod-validation  |

## Links

- npm: https://www.npmjs.com/package/@yorganci/npm-registry-api
- Repository: https://github.com/atahanyorganci/npm-registry-api
- Homepage: https://github.com/atahanyorganci/npm-registry-api#readme
- Issues: https://github.com/atahanyorganci/npm-registry-api/issues
- npm.io page: https://npm.io/package/@yorganci/npm-registry-api

## Dependencies (5)

- [zod](https://npm.io/package/zod.md) ^3.23.8
- [ohash](https://npm.io/package/ohash.md) ^1.1.3
- [ofetch](https://npm.io/package/ofetch.md) ^1.3.4
- [unstorage](https://npm.io/package/unstorage.md) ^1.10.2
- [zod-package-json](https://npm.io/package/zod-package-json.md) ^1.0.3

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2024-07-27
- 0.2.0 — 2024-07-20
- 0.1.3 — 2024-07-20
- 0.1.0 — 2024-07-20
- 0.0.2 — 2024-07-19
- 0.0.1 — 2024-07-18

## README

# npm Registry API Client

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![License][license-src]][license-href]

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

## Features

- Validates registry responses using [`zod`](https://github.com/colinhacks/zod).
- Supports response caching with [`unstorage`](https://github.com/unjs/unstorage).
- Compatible with both Node.js and browser environments.
- Works seamlessly with third-party npm-compatible registries.

## Useful Links

- [npm registry API][npm-registry-api] for REST API docs.
- [`ohash` docs](https://github.com/unjs/ohash) for serializing cache keys.
- [`unstorage` drivers](https://unstorage.unjs.io/drivers) for caching layer.

## Usage

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

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

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

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

Basic usage

```ts
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`][get-abbreviated-packument]             | Fetches abbreviated packument (package document) containing only the metadata necessary to install a package. |
| [`getBulkDailyPackageDownloads`][get-bulk-daily-package-downloads] | Retrieves the total number of downloads for each day for some packages in the given time period.              |
| [`getBulkPackageDownloads`][get-bulk-package-downloads]            | Fetches the total number of downloads for the given packages in the given time period.                        |
| [`getDailyPackageDownloads`][get-daily-package-downloads]          | Retrieves the total number of downloads for each day for a package in the given time period.                  |
| [`getDailyRegistryDownloads`][get-daily-registry-downloads]        | Gets the total number of downloads for each day for all packages in the registry in the given time period.    |
| [`getPackageDownloads`][get-package-downloads]                     | Fetches total number of downloads for a package in the given time period.                                     |
| [`getPackageManifest`][get-package-manifest]                       | Retrieves the manifest describing a specific version of a package (e.g., `foo@1.0.0`).                        |
| [`getPackageVersionsDownloads`][get-package-versions-downloads]    | Gets the total number of downloads for each version of a package in the previous 7 days.                      |
| [`getPackument`][get-packument]                                    | Fetches full packument (package document) containing all the metadata available about a package.              |
| [`getRegistryDownloads`][get-registry-downloads]                   | Retrieves total number of downloads for all packages in the registry in the given time period.                |
| [`getRegistryMetadata`][get-registry-metadata]                     | Fetches metadata describing the registry itself.                                                              |
| [`getRegistrySigningKeys`][get-registry-signing-keys]              | Retrieves public signing keys used by the registry.                                                           |
| [`searchPackages`][search-packages]                                | 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.

```ts
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.

```ts
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](./LICENSE)

[npm-version-src]: https://img.shields.io/npm/v/@yorganci/npm-registry-api?style=for-the-badge&logo=git&label=release
[npm-version-href]: https://npmjs.com/package/@yorganci/npm-registry-api
[npm-downloads-src]: https://img.shields.io/npm/dm/@yorganci/npm-registry-api?style=for-the-badge&logo=npm
[npm-downloads-href]: https://npmjs.com/package/@yorganci/npm-registry-api
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@yorganci/npm-registry-api?style=for-the-badge
[bundle-href]: https://bundlephobia.com/result?p=%40yorganci%npm-registry-api
[license-src]: https://img.shields.io/github/license/atahanyorganci/npm-registry-api.svg?style=for-the-badge
[license-href]: https://github.com/atahanyorganci/npm-registry-api/blob/main/LICENSE
[npm-registry-api]: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md
[get-abbreviated-packument]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getBulkDailyPackageDownloads
[get-bulk-daily-package-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getBulkDailyPackageDownloads
[get-bulk-package-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getBulkPackageDownloads
[get-daily-package-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getDailyPackageDownloads
[get-daily-registry-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getDailyRegistryDownloads
[get-package-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getPackageDownloads
[get-package-manifest]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getPackageManifest
[get-package-versions-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getPackageVersionsDownloads
[get-packument]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getPackument
[get-registry-downloads]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getRegistryDownloads
[get-registry-metadata]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getRegistryMetadata
[get-registry-signing-keys]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.getRegistrySigningKeys
[search-packages]: https://jsr.io/@yorganci/npm-registry-api/doc/~/Client.prototype.searchPackages

---
_Source: https://npm.io/package/@yorganci/npm-registry-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
