import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { BaseRequestOptions, GitlabAPIResponse, OneOf, OneOrNoneOf, PaginationRequestOptions, PaginationTypes, ShowExpanded, Sudo, } from '../infrastructure'; export type DeployTokenScope = | 'read_repository' | 'read_registry' | 'write_registry' | 'read_package_registry' | 'write_package_registry'; export interface DeployTokenSchema extends Record { id: number; name: string; username: string; expires_at: string; revoked: boolean; expired: boolean; scopes?: DeployTokenScope[]; } export interface NewDeployTokenSchema extends DeployTokenSchema { token: string; } export class DeployTokens extends BaseResource { all( { projectId, groupId, ...options }: OneOrNoneOf<{ projectId: string | number; groupId: string | number }> & { active?: boolean; } & PaginationRequestOptions

& BaseRequestOptions = {} as any, ): Promise> { let url: string; if (projectId) url = endpoint`projects/${projectId}/deploy_tokens`; else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens`; else url = 'deploy_tokens'; return RequestHelper.get()(this, url, options); } create( name: string, scopes: DeployTokenScope[], { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & { expires_at?: string; username?: string; } & Sudo & ShowExpanded = {} as any, ): Promise> { let url: string; if (projectId) url = endpoint`projects/${projectId}/deploy_tokens`; else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens`; else { throw new Error( 'Missing required argument. Please supply a projectId or a groupId in the options parameter.', ); } return RequestHelper.post()(this, url, { name, scopes, ...options, }); } remove( tokenId: number, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & Sudo & ShowExpanded = {} as any, ): Promise> { let url: string; if (projectId) url = endpoint`projects/${projectId}/deploy_tokens/${tokenId}`; else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens/${tokenId}`; else { throw new Error( 'Missing required argument. Please supply a projectId or a groupId in the options parameter.', ); } return RequestHelper.del()(this, url, options as any as Sudo & ShowExpanded); } show( tokenId: number, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & Sudo & ShowExpanded = {} as any, ): Promise> { let url: string; if (projectId) url = endpoint`projects/${projectId}/deploy_tokens/${tokenId}`; else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens/${tokenId}`; else { throw new Error( 'Missing required argument. Please supply a projectId or a groupId in the options parameter.', ); } return RequestHelper.get()( this, url, options as any as Sudo & ShowExpanded, ); } }