UNPKG

@expressive-analytics/deep-thought-service

Version:

Typescript conversion of Deep Thought Services (formerly providers)

42 lines (35 loc) 957 B
import {DTStorage,DTStore} from '@expressive-analytics/deep-thought-js' import {DTSession} from './DTSession' import {DTVerifier} from './DTVerifier' import {DTRequestor} from './DTRequestor' export class DTBasicVerifier implements DTVerifier{ protected _db:DTStore protected api?:DTRequestor constructor(db?:DTStore){ this._db = db if(db===undefined) this._db = (DTStorage.defaultStore() as DTStore) } requestor(){ return this.api; } verify(action,token?:string){ if(token===undefined||token=="") throw new Error("Received empty consumer token."); this.api = DTRequestor.query(this._db.filter({ consumer_key: token.substring(10), status: 1 })) as DTRequestor if(this.api.verifyProviderToken(token)) return true; console.error(`Invalid request for consumer (${action})`) return false; } userID(){ const session = DTSession.shared(); return session["pvd_user_id"]; } db(){ return this._db } }