@expressive-analytics/deep-thought-service
Version:
Typescript conversion of Deep Thought Services (formerly providers)
37 lines (36 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DTBasicVerifier = void 0;
const deep_thought_js_1 = require("@expressive-analytics/deep-thought-js");
const DTSession_1 = require("./DTSession");
const DTRequestor_1 = require("./DTRequestor");
class DTBasicVerifier {
constructor(db) {
this._db = db;
if (db === undefined)
this._db = deep_thought_js_1.DTStorage.defaultStore();
}
requestor() {
return this.api;
}
verify(action, token) {
if (token === undefined || token == "")
throw new Error("Received empty consumer token.");
this.api = DTRequestor_1.DTRequestor.query(this._db.filter({
consumer_key: token.substring(10),
status: 1
}));
if (this.api.verifyProviderToken(token))
return true;
console.error(`Invalid request for consumer (${action})`);
return false;
}
userID() {
const session = DTSession_1.DTSession.shared();
return session["pvd_user_id"];
}
db() {
return this._db;
}
}
exports.DTBasicVerifier = DTBasicVerifier;