@pubby/sdk
Version:
Pubby Development Kit
53 lines (50 loc) • 2.1 kB
JavaScript
import { __awaiter, __generator } from 'tslib';
import { OAuthClient, ClientCredentialsGrant } from './oauth.js';
var BotStrategy = /** @class */ (function () {
function BotStrategy(options) {
this.options = options;
}
BotStrategy.prototype.init = function (pubby) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
this.oauth = new OAuthClient({
tokenUrl: pubby.config.current.baseURL + "/oauth/token",
clientId: this.options.clientId,
clientSecret: this.options.secret,
});
return [4 /*yield*/, this.oauth.requestTokenAndSave(ClientCredentialsGrant(["user"]))];
case 1:
_b.sent();
_a = this;
return [4 /*yield*/, pubby.api.user.getProfile()];
case 2:
_a.user = _b.sent();
if (!pubby.has("ws")) return [3 /*break*/, 4];
return [4 /*yield*/, pubby.ws.connect()];
case 3:
_b.sent();
_b.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
BotStrategy.prototype.getToken = function () {
return this.oauth.getToken().then(function (token) { return token.accessToken; });
};
BotStrategy.prototype.getTicket = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.getToken()];
});
});
};
BotStrategy.prototype.isAuthenticated = function () {
return this.oauth.isAuthenticated();
};
return BotStrategy;
}());
export { BotStrategy };