UNPKG

fhir-package-installer

Version:

A utility module for downloading, indexing, caching, and managing FHIR packages from the FHIR Package Registry and Simplifier

134 lines (133 loc) 6.1 kB
/** * © Copyright Outburn Ltd. 2022-2025 All Rights Reserved * Project name: FHIR-Package-Installer */ import type { ILogger, FpiConfig, PackageIdentifier, PackageIndex, PackageManifest, DownloadPackageOptions, InstallPackageOptions } from './types'; export declare class FhirPackageInstaller { private logger; private registryUrl; private registryToken?; private fallbackUrlBase; /** * Path to the FHIR package cache directory. * This directory is used to store downloaded and extracted FHIR packages. * If the directory does not exist, it will be created. */ private cachePath; private skipExamples; private allowHttp; private prethrow; constructor(config?: FpiConfig); private withRetries; /** * Takes a PackageIdentifier Object and returns the corresponding directory name of the package * @param packageObject A PackageObject with both name and version keys * @returns (string) Directory name in the standard format `name#version` */ private toDirName; /** * Takes a PackageIdentifier Object and returns the path to the package folder in the cache * @param packageObject A PackageIdentifier Object with both name and version keys * @returns The full path to the package directory */ getPackageDirPath(packageId: PackageIdentifier | string): Promise<string>; /** * Get the full path to the .fpi.index.json file in the package folder * @param packageObject A PackageIdentifier Object with both name and version keys * @returns (string) The path to the package index file */ private getPackageIndexPath; /** * Scans a package folder and generates a new `.fpi.index.json` file * @param packageObject The package identifier object * @returns PackageIndex */ private generatePackageIndex; /** * Generates HTTP options including authorization header for registry requests * @param url The URL being requested * @returns HTTP options object with headers if needed */ private getHttpOptions; private fetchJson; private fetchStream; private getPackageDataFromRegistry; private getTarballUrl; private downloadFile; private downloadTarball; /** * Extracts a tarball to a temporary directory and generates a new `.fpi.index.json` file. * The tarball can be a file path or a stream. * @param src The source tarball, either a file path or a Readable stream. * @returns The path to the temporary directory where the package was extracted. */ private extractTarball; private downloadAndExtractTarball; /** * Caches the package in the FHIR package cache directory. * If the package is already installed, it will not be reinstalled. * @param packageObject The package identifier object * @param src The source path of the package to be cached * @param move Whether to move the package to the cache or copy it. Defaults to **true**. * @returns The path to the cached package directory */ private cachePackage; /** * Extracts the version of the package from a raw package identifier string. * Supported formats: `name@version`, `name#version`, or just `name` * @param packageId Raw package identifier string * @returns The version part or 'latest' if not supplied */ private getVersionFromPackageString; isInstalled(packageId: PackageIdentifier | string): Promise<boolean>; getPackageIndexFile(packageId: PackageIdentifier | string): Promise<PackageIndex>; checkLatestPackageDist(packageName: string): Promise<string>; toPackageObject(packageId: string | PackageIdentifier): Promise<PackageIdentifier>; private readManifestFile; getManifest(packageId: string | PackageIdentifier): Promise<PackageManifest>; /** * Get the path to the FHIR package cache directory. * This directory is used to store downloaded and extracted FHIR packages. * If the directory does not exist, it will be created. * @returns {string} The path to the FHIR package cache directory */ getCachePath(): string; /** * Get the logger instance used by this FhirPackageInstaller. */ getLogger(): ILogger; getDependencies(packageObject: PackageIdentifier): Promise<{ [key: string]: string; }>; install(packageId: string | PackageIdentifier): Promise<boolean>; private installPackageDependencies; /** * Installs a package from a local file or directory. * The package can be a tarball file or a directory containing the package files. * @param src The path to the local package file or directory. * @param options Options for installing the package. * @returns A promise that resolves to true if the package was installed successfully, * or false if it was already installed. */ installLocalPackage(src: string, options?: InstallPackageOptions): Promise<boolean>; /** * Downloads a package tarball and optionally extracts it to a destination directory. * * Behavior: * - If `extract` is false or omitted: downloads the tarball as a .tgz file to the destination directory. * - If `extract` is true: downloads and extracts the package into a subdirectory of the destination path. * * @param packageId A package identifier string or a PackageIdentifier object. * @param options Options controlling the download and extraction behavior. * @returns * - If `extract` is false: the full path to the downloaded tarball file. * - If `extract` is true: the full path to the extracted package directory. */ downloadPackage(packageId: string | PackageIdentifier, options?: DownloadPackageOptions): Promise<string>; } /** * Default instance export for convenience */ declare const fpi: FhirPackageInstaller; export default fpi; export type { ILogger, PackageIdentifier, PackageIndex, PackageManifest, FileInPackageIndex, PackageResource, DownloadPackageOptions, InstallPackageOptions } from './types';