@questlabs/core
Version:
This is the quest SDK
204 lines (203 loc) • 11.2 kB
JavaScript
"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.DappMetric = void 0;
const constants_1 = require("../../utils/constants");
const helperFunctions_1 = require("../../utils/helperFunctions");
class DappMetric {
constructor(questSdk) {
this.questSdk = questSdk;
}
createDappMetrics({ metric, thresholdTime, name, description, type, entityId, platform, eventName }, 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, metric });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/metrics`;
const body = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ metric }, (thresholdTime && { thresholdTime })), (name && { name })), (description && { description })), (type && { type })), (platform && { platform })), (eventName && { eventName })), 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,
body,
headers: options === null || options === void 0 ? void 0 : options._headers,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
deleteDappMetrics({ entityId, metric }, 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, metric });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/metrics/${metric}/delete`;
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
body: options === null || options === void 0 ? void 0 : options._body,
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;
}
});
}
editDappMetrics({ entityId, metric, name, description, type, thresholdTime, platform, eventName }, 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, metric });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/metrics/${metric}/update`;
const body = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ metric,
thresholdTime }, (name && { name })), (description && { description })), (type && { type })), (platform && { platform })), (eventName && { eventName })), 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: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
getAllDappMetrics({ 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)({ entityId: defaultEntityId });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/metrics`;
const queryParams = Object.assign(Object.assign({}, (type && { type })), 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;
}
});
}
getDappMetricForUser({ entityId, metric, forUserId }, 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, metric });
const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/metrics/${metric}`;
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;
}
});
}
incrementDappMetricForUser({ entityId, metric, count, forUserId }, 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, metric, count });
const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/metrics/${metric}`;
const body = Object.assign({ count }, 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: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
getAllDappMetricsForUser({ entityId, forUserId } = {}, 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}/metrics`;
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;
}
});
}
incrementMultipleMetricsForUser({ entityId, metrics, forUserId }, 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, metrics });
const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/metrics`;
const body = Object.assign({ metrics }, 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: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
}
exports.DappMetric = DappMetric;