unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
42 lines • 1.61 kB
JavaScript
import { RoleName } from '../types/model.js';
import { NotFoundError } from '../error/index.js';
export class AccountService {
constructor(stores, { getLogger }, services) {
this.lastSeenSecrets = new Set();
this.logger = getLogger('service/account-service.ts');
this.store = stores.accountStore;
this.accessService = services.accessService;
}
async getAll() {
const accounts = await this.store.getAll();
const defaultRole = await this.accessService.getPredefinedRole(RoleName.VIEWER);
const userRoles = await this.accessService.getRootRoleForAllUsers();
const accountsWithRootRole = accounts.map((u) => {
const rootRole = userRoles.find((r) => r.userId === u.id);
const roleId = rootRole ? rootRole.roleId : defaultRole.id;
return { ...u, rootRole: roleId };
});
return accountsWithRootRole;
}
async getAccountByPersonalAccessToken(secret) {
const account = await this.store.getAccountByPersonalAccessToken(secret);
if (account === undefined) {
throw new NotFoundError();
}
return account;
}
async getAdminCount() {
return this.store.getAdminCount();
}
async updateLastSeen() {
if (this.lastSeenSecrets.size > 0) {
const toStore = [...this.lastSeenSecrets];
this.lastSeenSecrets = new Set();
await this.store.markSeenAt(toStore);
}
}
addPATSeen(secret) {
this.lastSeenSecrets.add(secret);
}
}
//# sourceMappingURL=account-service.js.map