import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { BaseRequestOptions, GitlabAPIResponse, PaginationRequestOptions, PaginationTypes, ShowExpanded, Sudo, } from '../infrastructure'; import type { CondensedProjectSchema, ProjectSchema } from './Projects'; import type { SimpleUserSchema } from './Users'; import type { CustomAttributeSchema } from '../templates/ResourceCustomAttributes'; import { AccessLevel } from '../constants'; export interface GroupStatisticsSchema { storage_size: number; repository_size: number; wiki_size: number; lfs_objects_size: number; job_artifacts_size: number; pipeline_artifacts_size: number; packages_size: number; snippets_size: number; uploads_size: number; } export interface CondensedGroupSchema extends Record { id: number; web_url: string; name: string; } export interface SimpleGroupSchema extends CondensedGroupSchema { avatar_url: string | null; full_name: string; full_path: string; } export interface GroupSchema extends SimpleGroupSchema { path: string; description: string; visibility: 'public' | 'internal' | 'private'; share_with_group_lock: boolean; require_two_factor_authentication: boolean; two_factor_grace_period: number; project_creation_level: string; auto_devops_enabled?: boolean; subgroup_creation_level: string; emails_enabled?: boolean; mentions_disabled?: boolean; lfs_enabled: boolean; default_branch_protection: number; request_access_enabled: boolean; created_at: string; parent_id: number; ldap_cn?: string; ldap_access?: string; marked_for_deletion_on?: string; membership_lock?: boolean; } export interface ExpandedGroupSchema extends GroupSchema { runners_token: string; file_template_project_id: number; shared_with_groups: | { group_id: number; group_name: string; group_full_path: string; group_access_level: number; }[] | null; projects?: ProjectSchema[]; shared_projects?: ProjectSchema[]; } export type AllGroupsOptions = { skipGroups?: number[]; allAvailable?: boolean; search?: string; orderBy?: 'name' | 'path' | 'id'; sort?: 'asc' | 'desc'; visibility?: 'public' | 'internal' | 'private'; statistics?: boolean; withCustomAttributes?: boolean; owned?: boolean; minAccessLevel?: Exclude; topLevelOnly?: boolean; markedForDeletionOn?: string; active?: boolean; archived?: boolean; }; export type AllGroupProjectsOptions = { visibility?: 'public' | 'internal' | 'private'; orderBy?: | 'id' | 'name' | 'path' | 'created_at' | 'updated_at' | 'similarity' | 'last_activity_at'; topic?: string; sort?: 'asc' | 'desc'; archived?: boolean; search?: string; simple?: boolean; owned?: boolean; starred?: boolean; withIssuesEnabled?: boolean; withMergeRequestsEnabled?: boolean; withShared?: boolean; includeSubgroups?: boolean; minAccessLevel?: Exclude; withCustomAttributes?: boolean; withSecurityReports?: boolean; }; export type CreateGroupOptions = { autoDevopsEnabled?: boolean; avatar?: { content: Blob; filename: string }; defaultBranchProtection?: 0 | 1 | 2 | 3; description?: string; emailsDisabled?: boolean; lfsEnabled?: boolean; mentionsDisabled?: boolean; parentId?: number; projectCreationLevel?: 'noone' | 'maintainer' | 'developer'; requestAccessEnabled?: boolean; requireTwoFactorAuthentication?: boolean; shareWithGroupLock?: boolean; subgroupCreationLevel?: string; twoFactorGracePeriod?: number; visibility?: 'public' | 'internal' | 'private'; membershipLock?: boolean; extraSharedRunnersMinutesLimit?: number; sharedRunnersMinutesLimit?: number; }; export type EditGroupOptions = { name?: string; path?: string; autoDevopsEnabled?: boolean; avatar?: { content: Blob; filename: string }; defaultBranchProtection?: 0 | 1 | 2 | 3; description?: string; emailsDisabled?: boolean; lfsEnabled?: boolean; mentionsDisabled?: boolean; preventSharingGroupsOutsideHierarchy?: boolean; projectCreationLevel?: 'noone' | 'maintainer' | 'developer'; requestAccessEnabled?: boolean; requireTwoFactorAuthentication?: boolean; sharedRunnersSetting?: | 'enabled' | 'disabled_and_overridable' | 'disabled_and_unoverridable' | 'disabled_with_override'; shareWithGroupLock?: boolean; subgroupCreationLevel?: string; twoFactorGracePeriod?: number; visibility?: 'public' | 'internal' | 'private'; extraSharedRunnersMinutesLimit?: number; fileTemplateProjectId?: number; membershipLock?: boolean; preventForkingOutsideGroup?: boolean; sharedRunnersMinutesLimit?: number; uniqueProjectDownloadLimit?: number; uniqueProjectDownloadLimitIntervalInSeconds?: number; uniqueProjectDownloadLimitAllowlist?: string[]; uniqueProjectDownloadLimitAlertlist?: number[]; autoBanUserOnExcessiveProjectsDownload?: boolean; ipRestrictionRanges?: string; }; export type AllProvisionedUsersOptions = { username?: string; search?: string; active?: boolean; blocked?: boolean; createdAfter?: string; createdBefore?: string; }; export class Groups extends BaseResource { all( options: { withCustomAttributes: true } & AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise< GitlabAPIResponse<(GroupSchema & { custom_attributes: CustomAttributeSchema[] })[], C, E, P> >; all( options: { statistics: true } & AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; all( options?: AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; all( options?: AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()(this, 'groups', options); } allDescendantGroups( groupId: string | number, options: { statistics: true } & AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allDescendantGroups( groupId: string | number, options: AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allDescendantGroups( groupId: string | number, options?: AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`groups/${groupId}/descendant_groups`, options, ); } allProjects( groupId: string | number, options?: AllGroupProjectsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allProjects( groupId: string | number, options?: { simple: true } & AllGroupProjectsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allProjects( groupId: string | number, options?: AllGroupProjectsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`groups/${groupId}/projects`, options, ); } allSharedProjects( groupId: string | number, options?: { simple: true } & AllGroupProjectsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allSharedProjects( groupId: string | number, options?: AllGroupProjectsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allSharedProjects( groupId: string | number, options?: AllGroupProjectsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`groups/${groupId}/projects/shared`, options, ); } allSubgroups( groupId: string | number, options?: { statistics: true } & AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allSubgroups( groupId: string | number, options?: AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; allSubgroups( groupId: string | number, options?: AllGroupsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise< GitlabAPIResponse< GroupSchema[] | (GroupSchema & { statistics: GroupStatisticsSchema })[], C, E, P > > { return RequestHelper.get< GroupSchema[] | (GroupSchema & { statistics: GroupStatisticsSchema })[] >()(this, endpoint`groups/${groupId}/subgroups`, options); } allProvisionedUsers( groupId: string | number, options?: AllProvisionedUsersOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`groups/${groupId}/provisioned_users`, options, ); } allTransferLocations( groupId: string | number, options?: { search?: string } & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`groups/${groupId}/transfer_locations`, options, ); } create( name: string, path: string, { avatar, ...options }: CreateGroupOptions & Sudo & ShowExpanded = {} as any, ): Promise> { if (avatar) { return RequestHelper.post()(this, 'groups', { ...options, isForm: true, avatar: [avatar.content, avatar.filename], name, path, }); } return RequestHelper.post()(this, 'groups', { name, path, ...options }); } downloadAvatar( groupId: string | number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()(this, endpoint`groups/${groupId}/avatar`, options); } edit( groupId: string | number, { avatar, ...options }: EditGroupOptions & Sudo & ShowExpanded = {} as any, ): Promise> { if (avatar) { return RequestHelper.post()(this, endpoint`groups/${groupId}`, { ...options, isForm: true, avatar: [avatar.content, avatar.filename], }); } return RequestHelper.put()(this, endpoint`groups/${groupId}`, options); } remove( groupId: string | number, options?: { permanentlyRemove?: boolean | string; fullPath?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.del()(this, endpoint`groups/${groupId}`, options); } removeAvatar( groupId: string | number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.put()(this, endpoint`groups/${groupId}`, { ...options, avatar: '', }); } restore( groupId: string | number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()(this, endpoint`groups/${groupId}/restore`, options); } search( nameOrPath: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()(this, 'groups', { search: nameOrPath, ...options, }); } share( groupId: string | number, sharedGroupId: string | number, groupAccess: number, options: { expiresAt?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()(this, endpoint`groups/${groupId}/share`, { groupId: sharedGroupId, groupAccess, ...options, }); } show( groupId: string | number, options?: BaseRequestOptions, ): Promise> { return RequestHelper.get()(this, endpoint`groups/${groupId}`, options); } transfer( groupId: string | number, options?: { groupId?: number } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()(this, endpoint`groups/${groupId}/transfer`, options); } transferProject( groupId: string | number, projectId: string | number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`groups/${groupId}/projects/${projectId}`, options, ); } unshare( groupId: string | number, sharedGroupId: string | number, options: Sudo & ShowExpanded, ): Promise> { return RequestHelper.del()(this, endpoint`groups/${groupId}/share/${sharedGroupId}`, options); } uploadAvatar( groupId: string | number, content: Blob, { filename, ...options }: { filename?: string } & Sudo & ShowExpanded = {}, ): Promise> { return RequestHelper.put<{ avatar_url: string }>()(this, endpoint`groups/${groupId}/avatar`, { isForm: true, ...options, file: [content, filename], }); } }