import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, OneOf, ShowExpanded } from '../infrastructure'; export interface NuGetPackageIndexSchema extends Record { versions: string[]; } export interface NuGetResourceSchema extends Record { '@id': string; '@type': string; comment: string; } export interface NuGetServiceIndexSchema extends Record { version: string; resources: NuGetResourceSchema[]; } export interface NuGetServiceMetadataVersionSchema extends Record { '@id': string; packageContent: string; catalogEntry: { '@id': string; authors: string; dependencyGroups: unknown[]; id: string; version: string; tags: string; packageContent: string; summary: string; }; } export interface NuGetServiceMetadataItemSchema extends Record { '@id': string; lower: string; upper: string; count: number; items: NuGetServiceMetadataVersionSchema; } export interface NuGetServiceMetadataSchema extends Record { count: number; items: NuGetServiceMetadataItemSchema[]; resources: NuGetResourceSchema[]; } export interface NuGetSearchResultSchema extends Record { '@type': string; authors: string; id: string; title: string; version: string; verified: boolean; summary: string; totalDownloads: number; versions: { '@id': string; version: string; download: number; }[]; } export interface NuGetSearchResultsSchema extends Record { totalHits: number; data: NuGetSearchResultSchema[]; } function url({ projectId, groupId, }: { projectId?: string | number; groupId?: string | number } = {}): string { if (projectId) return endpoint`/projects/${projectId}/packages/nuget`; if (groupId) return endpoint`/groups/${groupId}/-/packages/nuget`; throw new Error( 'Missing required argument. Please supply a projectId or a groupId in the options parameter', ); } export class NuGet extends BaseResource { downloadPackageFile( projectId: string | number, packageName: string, packageVersion: string, filename: string, options?: ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/packages/nuget/download/${packageName}/${packageVersion}/${filename}`, options, ); } search( q: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & { skip?: number; take?: number; prerelease?: boolean; } & ShowExpanded, ): Promise> { const uri = url({ projectId, groupId }); return RequestHelper.get()(this, `${uri}/query`, { q, ...options }); } showMetadata( packageName: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded, ): Promise> { const uri = url({ projectId, groupId }); return RequestHelper.get()( this, `${uri}/metadata/${packageName}/index`, options as ShowExpanded, ); } showPackageIndex( projectId: string | number, packageName: string, options?: ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/packages/nuget/download/${packageName}/index`, options, ); } showServiceIndex({ projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded): Promise< GitlabAPIResponse > { const uri = url({ projectId, groupId }); return RequestHelper.get()( this, `${uri}/index`, options as ShowExpanded, ); } showVersionMetadata( packageName: string, packageVersion: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded, ): Promise> { const uri = url({ projectId, groupId }); return RequestHelper.get()( this, `${uri}/metadata/${packageName}/${packageVersion}`, options as ShowExpanded, ); } uploadPackageFile( projectId: string | number, packageName: string, packageVersion: string, packageFile: { content: Blob; filename: string }, options?: ShowExpanded, ): Promise> { return RequestHelper.put()(this, endpoint`projects/${projectId}/packages/nuget`, { isForm: true, ...options, packageName, packageVersion, file: [packageFile.content, packageFile.filename], }); } uploadSymbolPackage( projectId: string | number, packageName: string, packageVersion: string, packageFile: { content: Blob; filename: string }, options?: ShowExpanded, ): Promise> { return RequestHelper.put()( this, endpoint`projects/${projectId}/packages/nuget/symbolpackage`, { isForm: true, ...options, packageName, packageVersion, file: [packageFile.content, packageFile.filename], }, ); } }