UNPKG

@questlabs/core

Version:
216 lines (215 loc) 11.2 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.Event = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class Event { constructor(questSdk) { this.questSdk = questSdk; } createEvent({ source, eventName, entityId, description, metadata }, 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}/events`; const body = Object.assign(Object.assign(Object.assign({ source, eventName }, (description && { description })), { metadata }), 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; } }); } deleteEvent({ entityId, eventId, source }, 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, eventId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/events/${eventId}/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; } }); } updateEvent({ entityId, source, eventId, eventName, description, metadata }, 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, eventId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/events/${eventId}/update`; const body = Object.assign(Object.assign(Object.assign({ eventId, eventName, source }, (description && { description })), { metadata }), 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; } }); } getAllEventsByEntityId({ 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 }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/events`; const queryParams = Object.assign({}, 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; } }); } getEventDetails({ entityId, eventId }, 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, eventId }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/events/${eventId}`; const queryParams = Object.assign({}, 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; } }); } getAllEventsAndSourceByEntityId({ 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 }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/entities/${defaultEntityId}/eventsources`; const queryParams = Object.assign({}, 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; } }); } getEventSourceDetails({ entityId, eventId, source }, 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}/events/${eventId}/source`; const queryParams = Object.assign({ source }, 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; } }); } incrementEventCount({ entityId, eventName, source, properties, }, 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, eventName }); const url = `/entities/${defaultEntityId}/event/${eventName}/increment`; const body = Object.assign({ source, properties }, 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.Event = Event;