Skip to content

Commit

Permalink
Added Access levels
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Nov 6, 2023
1 parent 0b92f2c commit d816c66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/account.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Access } from 'auth.js';
import { request } from './request.js';
import type { KeyValue } from './utils.js';

Expand Down Expand Up @@ -185,15 +186,28 @@ export function getAccountRole(type: AccountType, short?: boolean): string {
* @param account the account to strip info from
* @returns a new object without the stripped info
*/
export function stripAccountInfo(account: Account): Account {
return {
export function stripAccountInfo(account: Account, access: Access): Account {
const info = {
id: account.id,
username: account.username,
oplvl: account.oplvl,
lastchange: account.lastchange,
created: account.created,
disabled: account.disabled,
};
if (access == Access.PUBLIC) {
return info;
}
Object.assign(info, {
email: account.email,
token: account.token,
session: account.session,
});
if (access == Access.PROTECTED || access == Access.PRIVATE) {
return info;
}

throw new Error('Invalid access level: ' + access);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ export let authToken: string;
export function auth(token: string): void {
authToken = token;
}

export enum Access {
PRIVATE = 0,
PROTECTED = 1,
PUBLIC = 2,
}

0 comments on commit d816c66

Please sign in to comment.