import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, ShowExpanded } from '../infrastructure'; export interface NPMVersionSchema { name: string; version: string; dist: { shasum: string; tarball: string; }; } export interface NPMPackageMetadataSchema extends Record { name: string; versions: { [version: string]: NPMVersionSchema; }; 'dist-tags': { [tag: string]: string; }; } function url(projectId?: string | number): string { return projectId ? endpoint`/projects/${projectId}/packages/npm` : 'packages/npm'; } export class NPM extends BaseResource { downloadPackageFile( projectId: string | number, packageName: string, filename: string, options?: ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/packages/npm/${packageName}/-/${filename}`, options, ); } removeDistTag( packageName: string, tag: string, options?: { projectId?: string | number } & ShowExpanded, ): Promise> { const prefix = url(options?.projectId); return RequestHelper.del()( this, `${prefix}/-/package/${packageName}/dist-tags/${tag}`, options, ); } setDistTag( packageName: string, tag: string, options?: { projectId?: string | number } & ShowExpanded, ): Promise> { const prefix = url(options?.projectId); return RequestHelper.put()( this, `${prefix}/-/package/${packageName}/dist-tags/${tag}`, options, ); } showDistTags( packageName: string, options?: { projectId?: string | number } & ShowExpanded, ): Promise, C, E, void>> { const prefix = url(options?.projectId); return RequestHelper.get>()( this, `${prefix}/-/package/${packageName}/dist-tags`, options, ); } showMetadata( packageName: string, options?: { projectId?: string | number } & ShowExpanded, ): Promise> { const prefix = url(options?.projectId); return RequestHelper.get()(this, `${prefix}/${packageName}`, options); } uploadPackageFile( projectId: string | number, packageName: string, versions: string, metadata: Record, options?: ShowExpanded, ): Promise, C, E, void>> { return RequestHelper.put>()( this, endpoint`projects/${projectId}/packages/npm/${packageName}`, { ...options, versions, ...metadata, }, ); } }