UNPKG

@questlabs/core

Version:
246 lines (245 loc) 12.8 kB
"use strict"; 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.Badge = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class Badge { constructor(questSdk) { this.questSdk = questSdk; } getAllBadgesForUser(options) { return __awaiter(this, void 0, void 0, function* () { try { const { userId, token } = this.questSdk.getUser(); (0, helperFunctions_1.validateParams)({ userId, token }); const url = `/badges`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getUserCreatedBadges(options) { return __awaiter(this, void 0, void 0, function* () { try { const { userId, token } = this.questSdk.getUser(); (0, helperFunctions_1.validateParams)({ userId, token }); const url = `/users/${userId}/created-badges`; return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams: options === null || options === void 0 ? void 0 : options._queryParams, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getAllBadgesForEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId } = {}, options) { try { const { userId } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId }); const url = `/entities/${defaultEntityId}/badges`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } addBadgeForEntity(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ name, imageIPFS, description, entityId, skills, userIds, endsAt, xp, airdropEnabled, typeData, type, totalCount, visibility, proofType, }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, name, imageIPFS, description, userId, token }); const url = `/entities/${defaultEntityId}/badges`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ name, imageIPFS, description, skills, userIds, endsAt, xp, airdropEnabled, typeData, type, totalCount, visibility, proofType }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getBadgeInfoForEntity(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId, badgeId, prefixBadgeIpfs }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, badgeId, userId, token }); const url = `/entities/${defaultEntityId}/badges/${badgeId}`; const queryParams = Object.assign(Object.assign({ userId }, (prefixBadgeIpfs && { prefixBadgeIpfs })), options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } updateBadgesForEntity(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ badgeId, entityId, name, imageIPFS, description, skills, userIds, endsAt, xp, typeData, type, }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, badgeId, userId, token }); const url = `/entities/${defaultEntityId}/badges/${badgeId}/update`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ name, imageIPFS, description, skills, userIds, endsAt, xp, typeData, type }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } claimBadgeForEntity(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ badgeId, addToDynamicNFT = false, entityId }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, badgeId, addToDynamicNFT, userId, token }); const url = `/entities/${defaultEntityId}/badges/${badgeId}/claim`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ addToDynamicNFT }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } addUsersToBadge(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ badgeId, userIds, entityId }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, badgeId, userIds, userId, token }); const url = `/entities/${defaultEntityId}/badges/${badgeId}/users`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ userIds }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getNumberOfBadgesEarned() { return __awaiter(this, arguments, void 0, function* ({ entityId, forUserId } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, userId, token }); if (!userId && !forUserId) { throw new Error("Please pass the userId or login"); } const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/badges-count`; return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, queryParams: options === null || options === void 0 ? void 0 : options._queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getUserEarnedBadgesForEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId, forUserId, limit, page } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, userId, token }); if (!userId && !forUserId) { throw new Error("Please pass the userId or login"); } const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/badges`; const queryParams = Object.assign(Object.assign(Object.assign({}, (page && { page })), (limit && { limit })), options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } } exports.Badge = Badge;