@parcl-finance/product-sdk
Version:
TypeScript SDK for interacting with Parcl's product APIs
169 lines • 5.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Contest = void 0;
const constants_1 = require("./constants");
const httpClient_1 = require("./httpClient");
const utils_1 = require("./utils");
class Contest {
baseUrl;
headers;
client;
expressClient;
constructor(baseUrl, contest, accessToken, env) {
const headers = {};
if (accessToken !== undefined) {
headers["Authorization"] = "Bearer " + accessToken;
}
this.headers = headers;
this.baseUrl = baseUrl.concat(`/contest/${contest ?? Contest.defaultContest()}`);
this.client = new httpClient_1.HttpClient(this.baseUrl, this.headers);
this.expressClient = new httpClient_1.HttpClient((0, constants_1.getDefaultExpressApiUrl)(env), this.headers);
}
static defaultContest() {
return "royale";
}
/**
* @deprecated - please use getLeaderboardById instead
*/
async getLeaderboard(refresh) {
const { leaderboard, count, inTheMoneyCount } = await this.client.get({
path: "/leaderboard",
params: { refresh },
});
return { leaderboard: (0, utils_1.formatContestLeaderboard)(leaderboard), count, inTheMoneyCount };
}
/**
* @param contestId - the id of the contest
* @returns top 500 leaderboard for the contest
*/
async getLeaderboardById({ contestId }) {
const { leaderboard, count, inTheMoneyCount } = await this.expressClient.get({
path: `/contest/${contestId}/leaderboard`,
});
return { leaderboard, count, inTheMoneyCount };
}
async getAllContests(filters = {
live: false,
upcoming: false,
finished: false,
joined: false,
user: "",
}) {
const { contests } = await this.expressClient.get({
path: `/contest`,
params: filters,
});
return contests;
}
async getFilteredContests(params) {
const contests = await this.expressClient.get({
path: `/contest/filter`,
params: params,
});
return contests;
}
async getAllContestsIds() {
const { contestsIds } = await this.expressClient.get({
path: `/contest/ids`,
});
return contestsIds;
}
async getContestById({ contestId }) {
const { contest } = await this.expressClient.get({
path: `/contest/${contestId}`,
});
return contest;
}
/**
* @deprecated - please use getParticipantInfo instead
*/
async getLeaderboardWithUserInfo(user, refresh) {
const { info } = await this.client.get({
path: `/leaderboard/user/${user}`,
params: {
refresh,
},
});
return {
leaderboard: (0, utils_1.formatContestLeaderboard)(info.leaderboard),
userRow: (0, utils_1.formatContestLeaderboardPosition)(info.userRow),
surroundingCtx: {
aboveRow: info.surroundingCtx.aboveRow === null
? undefined
: (0, utils_1.formatContestLeaderboardPosition)(info.surroundingCtx.aboveRow),
belowRow: info.surroundingCtx.belowRow === null
? undefined
: (0, utils_1.formatContestLeaderboardPosition)(info.surroundingCtx.belowRow),
},
count: info.count,
inTheMoneyCount: info.inTheMoneyCount,
};
}
/**
* @param userAddress - the publicKey address of the user
* @param contestId - the id of the contest
* @returns - the user's position in the contest leaderboard
*/
async getParticipantInfo({ userAddress, contestId, }) {
const { participant } = await this.expressClient.get({
path: `/contest/${contestId}/leaderboard/${userAddress}`,
});
return participant;
}
/**
* @param contestId - the id of the contest
* @returns - the contest participants count
*/
async getParticipantCount({ contestId }) {
const { participantsCount } = await this.expressClient.get({
path: `/contest/${contestId}/participants-count`,
});
return participantsCount;
}
/**
* @deprecated - please use `getParticipantInfo` instead
*/
async isParticipating(user, refresh) {
const { isParticipating } = await this.client.get({
path: "/participate",
params: {
user,
refresh,
},
});
return isParticipating;
}
/**
* @deprecated - please use `enterContest` instead
*/
async participate(user, accessToken) {
const { isParticipating } = await this.client.post({
path: "/participate",
params: { user },
accessToken,
});
return isParticipating;
}
async enterContest({ userAddress, contestId, }) {
const { participant } = await this.expressClient.postWithAuth({
path: `/contest/${contestId}`,
body: { address: userAddress },
authority: userAddress,
});
return participant;
}
/**
* @deprecated
*/
async getPrizes(refresh) {
const { prizes } = await this.client.get({
path: "/prizes",
params: {
refresh,
},
});
return prizes;
}
}
exports.Contest = Contest;
//# sourceMappingURL=contest.js.map