0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-10 23:39:31 -05:00
verdaccio/packages/config/src/user.ts
Juan Picado 4b29d715b1
chore: move improvements from v5 to v6 (#3461)
* chore: migrate #3158 to v6

* chore: migrate #3151 to v6k

* chore: migrate #2787 to v6

* chore: migrate #2791 #2205 to v6

* chore: add changeset
2022-10-28 23:38:22 +02:00

53 lines
1.2 KiB
TypeScript

import { RemoteUser } from '@verdaccio/types';
import { ROLES } from './package-access';
/**
* All logged users will have by default the group $all and $authenticate
*/
export const defaultLoggedUserRoles = [
ROLES.$ALL,
ROLES.$AUTH,
ROLES.DEPRECATED_ALL,
ROLES.DEPRECATED_AUTH,
ROLES.ALL,
];
/**
*
*/
export const defaultNonLoggedUserRoles = [
ROLES.$ALL,
ROLES.$ANONYMOUS,
// groups without '$' are going to be deprecated eventually
ROLES.DEPRECATED_ALL,
ROLES.DEPRECATED_ANONYMOUS,
];
/**
* Create a RemoteUser object
* @return {Object} { name: xx, pluginGroups: [], real_groups: [] }
*/
export function createRemoteUser(name: string, pluginGroups: string[]): RemoteUser {
const isGroupValid: boolean = Array.isArray(pluginGroups);
const groups = Array.from(
new Set((isGroupValid ? pluginGroups : []).concat([...defaultLoggedUserRoles]))
);
return {
name,
groups,
real_groups: pluginGroups,
};
}
/**
* Builds an anonymous remote user in case none is logged in.
* @return {Object} { name: xx, groups: [], real_groups: [] }
*/
export function createAnonymousRemoteUser(): RemoteUser {
return {
name: undefined,
groups: [...defaultNonLoggedUserRoles],
real_groups: [],
};
}