UNPKG

@questlabs/core

Version:
229 lines (228 loc) 12.5 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.Plgos = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class Plgos { constructor(questSdk) { this.questSdk = questSdk; } fetchCampaigns(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId, title, limit, page, campaignId, platform, hasFlow, type }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId }); const url = `/v2/entities/${defaultEntityId}/campaigns`; const queryParams = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (title && { title })), (limit && { limit })), (page && { page })), (campaignId && { campaignId })), (platform && { platform })), (hasFlow && { hasFlow })), (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; } }); } createCampaign(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId }); const url = `/v2/entities/${defaultEntityId}/campaigns`; const body = Object.assign({}, 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; } }); } updateCampaign(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ campaignId, entityId }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, campaignId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}`; const body = Object.assign({}, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.PATCH, 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; } }); } createParentCampaign(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId }); const url = `/v2/entities/${defaultEntityId}/campaigns/parent`; const body = Object.assign({}, 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; } }); } updateParentCampaign(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ campaignId, entityId }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, campaignId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}/parent`; const body = Object.assign({}, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.PATCH, 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; } }); } deleteCampaign(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId, campaignId, variation }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, campaignId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}`; const queryParams = Object.assign(Object.assign({}, (variation && { variation })), options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.DELETE, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } fetchCampaignDetails(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ campaignId, entityId, variation, platform, isQuestApp }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, campaignId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}`; const queryParams = Object.assign(Object.assign(Object.assign(Object.assign({}, (variation && { variation })), (platform && { platform })), (isQuestApp && { isQuestApp })), 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; } }); } fetchParentCampaignDetails(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ campaignId, entityId, variation, platform }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, campaignId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}/parent`; const queryParams = Object.assign(Object.assign(Object.assign({}, (variation && { variation })), (platform && { platform })), 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; } }); } submitCampaignResponses(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId, actions, campaignId, campaignVariationId, autoClaim, editSubmissionCriteria }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, actions, campaignId, campaignVariationId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}/verify`; const body = Object.assign(Object.assign(Object.assign({ actions, campaignId, campaignVariationId }, (autoClaim && { autoClaim })), (editSubmissionCriteria && { editSubmissionCriteria })), 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; } }); } claimCampaignRewards(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ campaignId, campaignVariationId, entityId, referralCode }, options) { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, campaignId, campaignVariationId }); const url = `/v2/entities/${defaultEntityId}/campaigns/${campaignId}/claim`; const body = Object.assign(Object.assign({ campaignVariationId }, (referralCode && { referralCode })), 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.Plgos = Plgos;