UNPKG

@questlabs/core

Version:
413 lines (412 loc) 23.1 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.DynamicNft = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class DynamicNft { constructor(questSdk) { this.questSdk = questSdk; } mintDynamicNFT({ type, forUserId, entityId }, 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)({ entityId: defaultEntityId, type, forUserId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/mint`; const queryParams = Object.assign({ type, userId, forUserId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body: options === null || options === void 0 ? void 0 : options._body, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } addRunningXP({ xp, forUserId, entityId, title, isAccumulateXP, metadata }, options) { return __awaiter(this, void 0, void 0, function* () { try { const user = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); const userId = forUserId || user.userId; (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, xp }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token: user.token }); } const url = `/entities/${defaultEntityId}/add-xp`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign(Object.assign(Object.assign({ xp, forUserId: userId }, (title && { title })), options === null || options === void 0 ? void 0 : options._body), { isAccumulateXP, metadata }); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getMyDynamicNFTs(options) { return __awaiter(this, void 0, void 0, function* () { try { const { userId, token } = this.questSdk.getUser(); (0, helperFunctions_1.validateParams)({ userId, token }); const url = `/mynfts`; 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, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getMyDynamicNFTDetailsForEntity({ entityId } = {}, 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)({ entityId: defaultEntityId, userId, token }); const url = `/entities/${entityId}/mynfts`; 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, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getXpForUser({ entityId, userId } = {}, options) { return __awaiter(this, void 0, void 0, function* () { try { const user = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); const defaultUserId = userId || user.userId; (0, helperFunctions_1.validateParams)({ userId: defaultUserId, token: user.token, entityId: defaultEntityId }); const url = `/entities/${defaultEntityId}/users/${defaultUserId}/xp`; 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; } }); } getXpForUsers({ userIds, entityId }, 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)({ userId, token, entityId: defaultEntityId, userIds }); const url = `/entities/${defaultEntityId}/users/xp`; 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: options === null || options === void 0 ? void 0 : options._queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getXpForEntity({ entityId } = {}, 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)({ userId, token, entityId: defaultEntityId }); const url = `/entities/${defaultEntityId}/xp`; 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; } }); } getXpForEntities({ entityIds }, options) { return __awaiter(this, void 0, void 0, function* () { try { const { userId, token } = this.questSdk.getUser(); (0, helperFunctions_1.validateParams)({ userId, token, entityIds }); const url = `/entities/xp`; const body = Object.assign({ entityIds }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, queryParams: options === null || options === void 0 ? void 0 : options._queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } recalculateUsersDynamicNFT({ entityId, userId } = {}, options) { return __awaiter(this, void 0, void 0, function* () { try { const user = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); const defaultUserId = userId || user.userId; (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, userId: defaultUserId, token: user.token }); const url = `/hidden/entities/${defaultEntityId}/recalculate-mynft`; const queryParams = Object.assign({ userId: defaultUserId }, 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; } }); } getAllThemesForEntity({ entityId } = {}, 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)({ entityId: defaultEntityId, userId, token }); const url = `/entities/${defaultEntityId}/themes`; 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, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } addNewThemeForEntity({ membershipTier, title, price, entityId, backgroundImageIPFS, horizontalLogoImageIPFS, squareLogoImageIPFS, backgroundColor, accentColor1, accentColor2, metadataIPFS, }, 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)({ entityId: defaultEntityId, membershipTier, title, price }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/themes`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ membershipTier, title, price }, (backgroundImageIPFS && { backgroundImageIPFS })), (horizontalLogoImageIPFS && { horizontalLogoImageIPFS })), (squareLogoImageIPFS && { squareLogoImageIPFS })), (backgroundColor && { backgroundColor })), (accentColor1 && { accentColor1 })), (accentColor2 && { accentColor2 })), (metadataIPFS && { metadataIPFS })), options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getThemeDetailsForEntity({ entityId, themeId }, 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)({ entityId: defaultEntityId, themeId, userId, token }); const url = `/entities/${defaultEntityId}/themes/${themeId}`; 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; } }); } updateThemeForEntity({ themeId, entityId, membershipTier, title, price, backgroundImageIPFS, horizontalLogoImageIPFS, squareLogoImageIPFS, backgroundColor, accentColor1, accentColor2, metadataIPFS, }, 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)({ entityId: defaultEntityId, themeId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/themes/${themeId}/update`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (membershipTier && { membershipTier })), (price && { price })), (title && { title })), (backgroundImageIPFS && { backgroundImageIPFS })), (horizontalLogoImageIPFS && { horizontalLogoImageIPFS })), (squareLogoImageIPFS && { squareLogoImageIPFS })), (backgroundColor && { backgroundColor })), (accentColor1 && { accentColor1 })), (accentColor2 && { accentColor2 })), (metadataIPFS && { metadataIPFS })), options === null || options === void 0 ? void 0 : options._body); if (Object.keys(body).length === 0) { throw new Error("Invalid request. Atleast one field is required to update."); } return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } deleteThemeForEntity({ entityId, themeId }, 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)({ entityId: defaultEntityId, themeId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/themes/${themeId}/delete`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body: options === null || options === void 0 ? void 0 : options._body, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } setDefaultThemeForEntity({ entityId, themeId }, 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)({ entityId: defaultEntityId, themeId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/themes/default`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ themeId }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, body, queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getUserXpLeaderboardRank({ entityId, forUserId, threshold } = {}, 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)({ entityId: defaultEntityId, userId, token }); const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/xp-leaderboard-rank`; const queryParams = Object.assign(Object.assign({ userId: forUserId || userId }, (threshold && { threshold })), 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; } }); } getUserXpHistory({ entityId, forUserId, limit, page } = {}, 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)({ entityId: defaultEntityId, userId, token }); const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/xp-history`; const queryParams = Object.assign(Object.assign(Object.assign({}, (limit && { limit })), (page && { page })), 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; } }); } getUserXpLeaderboard({ entityId, limit, page } = {}, 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)({ entityId: defaultEntityId, userId, token }); const url = `/entities/${defaultEntityId}/xp-leaderboard`; const queryParams = Object.assign(Object.assign(Object.assign({}, (limit && { limit })), (page && { page })), 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.DynamicNft = DynamicNft;