diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 26f14e5..258bb93 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: diff --git a/README.md b/README.md index e580e24..b54309e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@

-Node.js SDK to fetch data from the npm API. +Node.js SDK to fetch data from the npm API (with up to date TypeScript types) ## Getting Started @@ -35,9 +35,14 @@ $ yarn add @nodesecure/npm-registry-sdk ## Usage example ```ts -import Registry from "@nodesecure/npm-registry-sdk"; +import * as Npm from "@nodesecure/npm-registry-sdk"; + +const packument: Npm.Packument = await Npm.packument("express"); +console.log(packument); ``` +packument and packumentVersion take an optional payload options which can be used to provide an NPM token. + ## API ### getNpmRegistryURL(): string @@ -72,15 +77,62 @@ interface NpmRegistryMetadata { } ``` -### packument(name: string, options?: PackumentOptions): Promise\ +### packument(name: string, options?: PackumentOptions): Promise\ ```ts -interface PackumentOptions { - token: string; +interface Packument { + _id: string; + _rev: string; + name: string; + readme?: string; + description?: string; + 'dist-tags': { latest?: string } & ObjectOfStrings; + versions: { + [key: string]: PackumentVersion + }; + maintainers: Maintainer[]; + time: { + modified: string, + created: string, + [key: string]: string + }; + users?: { + [key: string]: boolean; + } + contributors?: Maintainer[]; + homepage?: string; + keywords?: string[]; + repository?: Repository; + author?: Maintainer; + bugs?: { url: string }; + license: string; + // left out users (stars) deprecated, and attachments (does nothing) + readmeFilename?: string; } ``` -### packumentVersion(name: string, version: string, options?: packumentOptions): Promise\ +### packumentVersion(name: string, version: string, options?: PackumentOptions): Promise\ + +```ts +type PackumentVersion = PackageJson & { + gitHead?: string; + maintainers: Maintainer[]; + dist: Dist; + types?: string; + deprecated?: string; + _id: string; + _npmVersion: string; + _nodeVersion: string; + _npmUser: Maintainer; + _hasShrinkwrap?: boolean; + _engineSupported?: boolean; + _defaultsLoaded?: boolean; + _npmOperationalInternal?: { + host: string; + tmp: string; + } +}; +``` ### downloads(pkgName: string, period: Period = "last-week"): Promise< NpmPackageDownload > diff --git a/src/api/packument.ts b/src/api/packument.ts index 784a544..a0fa916 100644 --- a/src/api/packument.ts +++ b/src/api/packument.ts @@ -1,11 +1,13 @@ // Import Third-party Dependencies -import * as npm from "@npm/types"; +import type { PackageJson, Maintainer, Dist, Repository, ObjectOfStrings } from "@npm/types"; import * as httpie from "@myunisoft/httpie"; // Import Internal Dependencies import { getLocalRegistryURL } from "../registry.js"; import { getHttpAgent } from "../http.js"; +export type { PackageJson, Maintainer, Dist, Repository }; + export interface PackumentOptions { /** Npm API Token **/ token: string; @@ -17,11 +19,11 @@ export interface Packument { name: string; readme?: string; description?: string; - 'dist-tags': { latest?: string } & npm.ObjectOfStrings; + 'dist-tags': { latest?: string } & ObjectOfStrings; versions: { [key: string]: PackumentVersion }; - maintainers: npm.Maintainer[]; + maintainers: Maintainer[]; time: { modified: string, created: string, @@ -30,27 +32,27 @@ export interface Packument { users?: { [key: string]: boolean; } - contributors?: npm.Maintainer[]; + contributors?: Maintainer[]; homepage?: string; keywords?: string[]; - repository?: npm.Repository; - author?: npm.Maintainer; + repository?: Repository; + author?: Maintainer; bugs?: { url: string }; license: string; // left out users (stars) deprecated, and attachments (does nothing) readmeFilename?: string; } -export type PackumentVersion = npm.PackageJson & { +export type PackumentVersion = PackageJson & { gitHead?: string; - maintainers: npm.Maintainer[]; - dist: npm.Dist; + maintainers: Maintainer[]; + dist: Dist; types?: string; deprecated?: string; _id: string; _npmVersion: string; _nodeVersion: string; - _npmUser: npm.Maintainer; + _npmUser: Maintainer; _hasShrinkwrap?: boolean; _engineSupported?: boolean; _defaultsLoaded?: boolean;