UNPKG

cnpmcore

Version:

Private NPM Registry for Enterprise

68 lines (67 loc) 2.75 kB
import { AbstractService } from '../../common/AbstractService.ts'; import { LoginResultCode } from '../../common/enum/User.ts'; import type { Registry } from '../entity/Registry.ts'; import { Token as TokenEntity, type TokenType } from '../entity/Token.ts'; import { User as UserEntity } from '../entity/User.ts'; import { WebauthnCredential as WebauthnCredentialEntity } from '../entity/WebauthnCredential.ts'; type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>; interface CreateUser { name: string; email: string; password: string; ip: string; } interface LoginResult { code: LoginResultCode; user?: UserEntity; token?: TokenEntity; } type CreateTokenOption = CreateClassicTokenOptions | CreateGranularTokenOptions; interface CreateGranularTokenOptions { type: TokenType.granular; name: string; description?: string; allowedScopes?: string[]; allowedPackages?: string[]; isReadonly?: boolean; cidrWhitelist?: string[]; expires: number; } interface CreateClassicTokenOptions { isReadonly?: boolean; isAutomation?: boolean; cidrWhitelist?: string[]; } interface CreateWebauthnCredentialOptions { credentialId: string; publicKey: string; browserType?: string; } export declare class UserService extends AbstractService { private readonly userRepository; private readonly registryManagerService; checkPassword(user: UserEntity, password: string): boolean; findUserByNameOrDisplayName(name: string): Promise<UserEntity | null>; findInRegistry(registry: Registry, name: string): Promise<UserEntity | null>; findUserByName(name: string): Promise<UserEntity | null>; login(name: string, password: string): Promise<LoginResult>; findOrCreateUser({ name, email, ip, password }: Optional<CreateUser, 'password'>): Promise<UserEntity>; ensureTokenByUser(opts: Optional<CreateUser, 'password'>): Promise<{ user: UserEntity; token: TokenEntity; }>; create(createUser: CreateUser): Promise<{ user: UserEntity; token: TokenEntity; }>; saveUser(name: string, email: string, userPrefix?: string): Promise<{ changed: boolean; user: UserEntity; }>; createToken(userId: string, options?: CreateTokenOption): Promise<TokenEntity>; removeToken(userId: string, tokenKeyOrTokenValue: string): Promise<void>; findWebauthnCredential(userId: string, browserType: string | undefined | null): Promise<WebauthnCredentialEntity | null>; createWebauthnCredential(userId: string | undefined, options: CreateWebauthnCredentialOptions): Promise<WebauthnCredentialEntity>; removeWebauthnCredential(userId?: string, browserType?: string): Promise<void>; } export {};