import { SearchSchema } from "../search"; /** * E.g. * { * scopes: * { * scope: 'player', // no mutations except session allowed * contentId: 'x', // if omitted any content id accessible to the api client could be read * secure: 'true' // will not allow evaluate mode or any mode/role to be passed to models function that could return correct answers * } * } */ export interface Scopes { [key: string]: string; } /** * Get string value for a scope. */ export const getScopeVal = (scopes: Scopes, scopeKey: string) => (scopes ? scopes[scopeKey] : null); /** * Get boolean value for a scope. */ export const getScopeBooleanVal = (scopes: Scopes, scopeKey: string) => { const val = getScopeVal(scopes, scopeKey); return val ? JSON.parse(val) === true : null; }; /** * Get string value for a scope. Use dot ('.') notation for nested values. */ export const scopeExists = (scopes: Scopes, scopeKey: string): Boolean => { if (!scopeKey || !scopes) { return null; } // check on flat keys (including 'fake' scopes) const key = Object.keys(scopes).find((k) => k.indexOf(scopeKey) !== -1); if (key) { return true; } const val = getScopeVal(scopes, scopeKey); return !!val; }; /** Info available after a successful authentication; should be passed down the chain */ export interface AuthInfo { id?: string; // id of the token (optional) organizationId: string; issuedAt: number; // iat expiresAt: number; // exp admin: boolean; // whether the organization is an admin organization (shortcut so that organization doesn't need to be fetched too often) apiClientId: string; scopes?: Scopes; // scopes of the jwt (optional) searchSchemas(): Promise; // search schemas available to this client }