@eagleeye-solutions/integration-events-common
Version:
Eagle Eye CDP connector common functionality
48 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateAuthenticationHash = generateAuthenticationHash;
exports.getEesCalledUniqueIdHeader = getEesCalledUniqueIdHeader;
exports.getAirUrl = getAirUrl;
const crypto_1 = require("crypto");
function generateAuthenticationHash(clientSecret, requestUrl, requestBody) {
const url = new URL(requestUrl);
const preHashedString = `${url.pathname}${url.search}` + (requestBody ?? '') + clientSecret;
return (0, crypto_1.createHash)('sha256').update(preHashedString).digest('hex');
}
function getEesCalledUniqueIdHeader(res) {
const header = 'x-ees-called-unique-id';
return res.headers ? res.headers.get(header) || null : null;
}
function getAirUrl(connectorConfig, type, logger, substitutions) {
const pathMap = {
'services/trigger': {
path: 'services/trigger',
domain: 'wallet',
},
'wallet/walletId/transaction/transactionId': {
path: 'wallet/walletId/transaction/transactionId',
domain: 'wallet',
},
'wallet/walletId/accounts': {
path: 'wallet/walletId/accounts',
domain: 'wallet',
},
};
const details = pathMap[type];
if (substitutions) {
Object.keys(substitutions).forEach(sub => {
details.path = details.path.replace(sub, substitutions[sub]);
});
}
if (details) {
const baseUrl = new URL(connectorConfig.domains[details.domain]);
const url = new URL(details.path, baseUrl);
return url;
}
else {
const error = new Error(`Unrecognised type: ${type}`);
logger.error(error);
throw error;
}
}
//# sourceMappingURL=utils.js.map