@eagleeye-solutions/integration-events-common
Version:
Eagle Eye CDP connector common functionality
188 lines • 8.32 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPointsAttributesFromWalletAccountTransactionEntity = getPointsAttributesFromWalletAccountTransactionEntity;
exports.getBehavioralActionAttributesFromWalletAccountTransactionEntity = getBehavioralActionAttributesFromWalletAccountTransactionEntity;
exports.getCouponAttributesFromWalletAccountTransactionEntity = getCouponAttributesFromWalletAccountTransactionEntity;
exports.getCouponAttributesWithValueFromWalletAccountTransactionEntity = getCouponAttributesWithValueFromWalletAccountTransactionEntity;
exports.getStandardSubscriptionAttributesFromWalletAccountTransactionEntity = getStandardSubscriptionAttributesFromWalletAccountTransactionEntity;
exports.getContinuityAttributesFromWalletAccountTransactionEntity = getContinuityAttributesFromWalletAccountTransactionEntity;
exports.getQuestAttributesFromWalletAccountTransactionEntity = getQuestAttributesFromWalletAccountTransactionEntity;
exports.getStampCardAttributesFromWalletAccountTransactionEntity = getStampCardAttributesFromWalletAccountTransactionEntity;
const date_fns_1 = require("date-fns");
function getPointsAttributesFromWalletAccountTransactionEntity(walletAccountTransactionEntity) {
const account = walletAccountTransactionEntity.objectValue.account;
const balances = account.balances;
if (balances !== null &&
balances !== undefined &&
'current' in balances &&
balances.current !== undefined) {
return {
pointsBalance: balances.current,
};
}
else {
throw new Error('Points balance not available in walletAccountTransactionEntity');
}
}
function getBehavioralActionAttributesFromWalletAccountTransactionEntity(walletAccountTransactionEntity) {
const objectValue = walletAccountTransactionEntity.objectValue;
const redeemedValue = objectValue.value;
if (walletAccountTransactionEntity.operationType === 'CREATE' &&
objectValue.account.type === 'BEHAVIOURAL_ACTION' &&
objectValue.event === 'REDEEM') {
return {
points: redeemedValue,
accountId: objectValue.account.accountId,
campaignId: objectValue.account.campaignId,
};
}
else {
throw new Error('Points balance not available in walletAccountTransactionEntity');
}
}
function getCouponAttributesFromWalletAccountTransactionEntity(walletAccountTransactionEntity) {
const account = walletAccountTransactionEntity.objectValue.account;
return {
accountId: account.accountId,
campaignId: account.campaignId,
type: account.type,
clientType: account.clientType,
state: account.state,
status: account.status,
dateStart: (0, date_fns_1.parseISO)(account.dates.start),
dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null,
relationships: account.relationships,
};
}
function getCouponAttributesWithValueFromWalletAccountTransactionEntity(entity) {
return {
...getCouponAttributesFromWalletAccountTransactionEntity(entity),
value: entity.objectValue.value,
};
}
function getStandardSubscriptionAttributesFromWalletAccountTransactionEntity(entity) {
const account = entity.objectValue.account;
return {
accountId: account.accountId,
campaignId: account.campaignId,
type: account.type,
clientType: account.clientType ?? null,
state: account.state,
status: account.status,
dateStart: (0, date_fns_1.parseISO)(account.dates.start),
dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null,
};
}
function getContinuityAttributesFromWalletAccountTransactionEntity(entity) {
const account = entity.objectValue.account;
return {
accountId: account.accountId,
campaignId: account.campaignId,
type: account.type,
clientType: account.clientType ?? null,
state: account.state,
status: account.status,
dateStart: (0, date_fns_1.parseISO)(account.dates.start),
dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null,
balances: {
totalSpend: account.balances.totalSpend,
currentSpend: account.balances.currentSpend,
transactionCount: account.balances.transactionCount,
currentTransactions: account.balances.currentTransactions,
totalUnits: account.balances.totalUnits,
currentUnits: account.balances.currentUnits,
},
};
}
function getQuestAttributesFromWalletAccountTransactionEntity(entity) {
const account = entity.objectValue.account;
return {
accountId: account.accountId,
campaignId: account.campaignId,
type: account.type,
clientType: account.clientType ?? null,
state: account.state,
status: account.status,
dateStart: (0, date_fns_1.parseISO)(account.dates.start),
dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null,
balances: {
objectivesMet: account.balances.objectivesMet,
},
relationships: account.relationships,
};
}
function getStampCardAttributesFromWalletAccountTransactionEntity(entity) {
const account = entity.objectValue.account;
return {
accountId: account.accountId,
campaignId: account.campaignId,
type: account.type,
clientType: account.clientType ?? null,
state: account.state,
status: account.status,
dateStart: (0, date_fns_1.parseISO)(account.dates.start),
dateEnd: account.dates.end ? (0, date_fns_1.parseISO)(account.dates.end) : null,
balances: {
available: account.balances.available,
refundable: account.balances.refundable,
},
};
}
exports.default = {
CreatePoints: {
getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity,
getAwardedPointsAttributes: getBehavioralActionAttributesFromWalletAccountTransactionEntity,
},
CreateEcoupon: {
getCouponAttributes: getCouponAttributesFromWalletAccountTransactionEntity,
},
CreateStandardSubscription: {
getStandardSubscriptionAttributes: getStandardSubscriptionAttributesFromWalletAccountTransactionEntity,
},
CreateContinuity: {
getContinuityAttributes: getContinuityAttributesFromWalletAccountTransactionEntity,
},
CreateQuest: {
getQuestAttributes: getQuestAttributesFromWalletAccountTransactionEntity,
},
CreateStampCard: {
getStampCardAttributes: getStampCardAttributesFromWalletAccountTransactionEntity,
},
UpdateStandardSubscription: {
getStandardSubscriptionAttributes: getStandardSubscriptionAttributesFromWalletAccountTransactionEntity,
},
UpdateCreditPoints: {
getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity,
},
UpdateRefundDebitPoints: {
getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity,
},
UpdateEarnPoints: {
getPointsAttributes: getPointsAttributesFromWalletAccountTransactionEntity,
},
UpdateRedeemEcoupon: {
getCouponAttributes: getCouponAttributesWithValueFromWalletAccountTransactionEntity,
},
UpdateUnredeemEcoupon: {
getCouponAttributes: getCouponAttributesWithValueFromWalletAccountTransactionEntity,
},
UpdateCreditContinuity: {
getContinuityAttributes: getContinuityAttributesFromWalletAccountTransactionEntity,
},
UpdateRedeemContinuity: {
getContinuityAttributes: getContinuityAttributesFromWalletAccountTransactionEntity,
},
UpdateQuest: {
getQuestAttributes: getQuestAttributesFromWalletAccountTransactionEntity,
},
UpdateRedeemQuest: {
getQuestAttributes: getQuestAttributesFromWalletAccountTransactionEntity,
},
UpdateCreditStampCard: {
getStampCardAttributes: getStampCardAttributesFromWalletAccountTransactionEntity,
},
UpdateRedeemStampCard: {
getStampCardAttributes: getStampCardAttributesFromWalletAccountTransactionEntity,
},
};
//# sourceMappingURL=wallet-account-transaction-entity.js.map