@questlabs/core
Version:
This is the quest SDK
71 lines (70 loc) • 3.14 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Twitter = void 0;
const constants_1 = require("../../utils/constants");
const helperFunctions_1 = require("../../utils/helperFunctions");
class Twitter {
constructor(questSdk) {
this.questSdk = questSdk;
}
connect({ redirectUri, twitterRedirectCode, entityId, type }, options) {
return __awaiter(this, void 0, void 0, function* () {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ redirectUri, twitterRedirectCode, entityId: defaultEntityId, userId, token });
const url = "/twitter/login";
const body = {
code: twitterRedirectCode,
redirectUri,
entityId: defaultEntityId,
userId,
type,
};
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
body,
headers: options === null || options === void 0 ? void 0 : options._body,
queryParams: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
throw error;
}
});
}
disconnect(entityId, userId, token) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!entityId || entityId == "") {
throw new Error("Invalid entityId");
}
if (!userId || userId == "") {
throw new Error("Invalid userId");
}
if (!token || token == "") {
throw new Error("Invalid token");
}
// const headers = { ...this.config.headers, entityId, userId, token };
// const body = { entityId, userId };
// const response = await axios.post(`${this.baseUrl}/twitter/logout`, body, { headers });
// return response.data;
}
catch (error) {
throw new Error(error.message);
}
});
}
}
exports.Twitter = Twitter;
exports.default = Twitter;