UNPKG

verdaccio

Version:

A lightweight private npm proxy registry

143 lines (142 loc) 6.93 kB
import { AbbreviatedManifest, DistFile, Manifest, Version } from '@verdaccio/types'; import LocalStorage from './local-storage'; /** * Create an empty package manifest with all the internal bookkeeping * sections (`_uplinks`, `_distfiles`, `_attachments`, `_rev`) initialized. * Used as the starting point when a package is seen for the first time. * @param name package name * @return an empty manifest for the given package */ export declare function generatePackageTemplate(name: string): Manifest; /** * Normalize a manifest read from storage: ensure the object sections * (`versions`, `dist-tags`, `_distfiles`, `_attachments`, `_uplinks`, `time`) * exist, default the revision and `_id`, and normalize the dist-tags shape. * The manifest is mutated in place. * @param pkg package manifest reference * @return the same manifest, normalized */ export declare function normalizePackage(pkg: Manifest): Manifest; /** * Produce the next revision id in the `<counter>-<hash>` format used by the * storage layer, incrementing the counter of the previous revision. * @param rev previous revision id, eg. `2-a1b2c3` * @return the next revision id */ export declare function generateRevision(rev: string): string; /** * Pick the most relevant readme for a package: the manifest readme or the * `latest` version readme first, otherwise the first readme found across the * `next`, `beta`, `alpha`, `test`, `dev` and `canary` dist-tags, in that order. * @param pkg package manifest * @return the readme content, or an empty string when none is available */ export declare function getLatestReadme(pkg: Manifest): string; /** * Remove the readme from a version object: only one readme is kept per * package (see getLatestReadme), never one per version. The version is * mutated in place. * @param version version metadata * @return the same version without its readme */ export declare function cleanUpReadme(version: Version): Version; /** * Manifest properties allowed in responses served to clients; everything * else is verdaccio-internal bookkeeping and is stripped by cleanUpLinksRef. */ export declare const WHITELIST: string[]; /** * Strip verdaccio-internal sections (`_distfiles`, `_attachments`, ...) from * a manifest before serving it to a client. The manifest is mutated in place. * @param keepUpLinkData whether the `_uplinks` section should be preserved * @param result manifest to clean up * @return the same manifest with only whitelisted properties */ export declare function cleanUpLinksRef(keepUpLinkData: boolean, result: Manifest): Manifest; /** * Verify a package does not exist locally yet; part of the publish flow. * @param name package name * @param localStorage local storage instance * @throws conflict error when the package already exists locally */ export declare function checkPackageLocal(name: string, localStorage: LocalStorage): Promise<void>; /** * Create a new package in the local storage and register its latest version * in the in-memory search indexer. * @param name package name * @param metadata package manifest to store * @param localStorage local storage instance */ export declare function publishPackage(name: string, metadata: any, localStorage: LocalStorage): Promise<void>; /** * Verify a package does not exist on any uplink yet; part of the publish * flow. Uplink failures other than 404 reject the publish, unless * `publish.allow_offline` is enabled in the configuration. * @param name package name * @param isAllowPublishOffline whether publishing with unreachable uplinks is allowed * @param syncMetadata bound Storage._syncUplinksMetadata function * @throws conflict error when the package exists upstream, service unavailable when uplinks are offline */ export declare function checkPackageRemote(name: string, isAllowPublishOffline: boolean, syncMetadata: any): Promise<void>; /** * Merge the `time` field of a remote manifest into the cached one; remote * entries win on conflicts. Returns a new manifest, the inputs are untouched. * @param cacheManifest local cached manifest * @param remoteManifest manifest fetched from an uplink * @return the cached manifest with the merged time field */ export declare function mergeUplinkTimeIntoLocal(cacheManifest: Manifest, remoteManifest: Manifest): any; /** * Build the search item emitted for a local package during a search stream, * based on its latest version: npm-search compatible maintainers * (`{ username, email }`), publisher (from `_npmUser`, falling back to the * first maintainer), license and links. * @param data package manifest * @param time modified time attached to the search item * @return the search item, or undefined when the package has no usable latest version */ export declare function prepareSearchPackage(data: Manifest, time: unknown): any; /** * Whether the tarball url path ends with the given file name * (any query string or fragment is ignored, like the path parsing * in updateVersions). */ export declare function tarballMatchesFilename(tarball: string, filename: string): boolean; /** * Build a distfile record from a version's dist metadata when its tarball * url matches the given file name. */ export declare function distFileFromVersion(version: Version | undefined, filename: string): DistFile | null; /** * Resolve the distfile record for a tarball filename. Prefers the * `_distfiles` bookkeeping, but falls back to the version metadata when the * record is missing (storages written by other verdaccio versions cache * versions without their distfile records, which made those tarballs * permanently unavailable). * @param manifest cached manifest * @param filename tarball file name, eg. pkg-1.0.0.tgz */ export declare function lookupDistFile(manifest: Manifest, filename: string): DistFile | null; /** * Check whether the package metadata has enough data to be published. * @param pkg package manifest * @return true when the manifest carries a versions section */ export declare function isPublishablePackage(pkg: Manifest): boolean; /** * Whether a version declares an install lifecycle script (`install`, * `preinstall` or `postinstall`); surfaced in abbreviated manifests as * `hasInstallScript` so clients can warn about script execution. * @param version version metadata * @return true when an install script is present */ export declare function hasInstallScript(version: Version): boolean; /** * Convert a full manifest into the abbreviated format served when the client * requests `application/vnd.npm.install-v1+json` (npm install), keeping only * the fields the npm registry contract defines for installation. * https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md * @param manifest full package manifest * @return the abbreviated manifest */ export declare function convertAbbreviatedManifest(manifest: Manifest): AbbreviatedManifest;