diff --git a/src/account.ts b/src/account.ts index 1f6068d..82c8bc2 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,3 +1,4 @@ +import { Access } from 'auth.js'; import { request } from './request.js'; import type { KeyValue } from './utils.js'; @@ -185,8 +186,8 @@ 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, @@ -194,6 +195,19 @@ export function stripAccountInfo(account: Account): Account { 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); } /** diff --git a/src/auth.ts b/src/auth.ts index a224844..ac28deb 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -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, +}