Compare commits

..
4 Commits
Author SHA1 Message Date
Denise_Datinguinoo 06649044ba changes in the flag unset (we consider both 0 and 1) 2026-08-26 17:33:56 +02:00
ptorric f21a572f45 some fixes 2026-08-26 16:27:15 +02:00
Denise_Datinguinoo 57c28b2806 minor change 2026-08-26 12:36:31 +02:00
Denise_Datinguinoo 58fdd9c581 minor change 2026-08-26 12:01:56 +02:00
3 changed files with 24 additions and 10 deletions

No files matched your search

+3 -3
View File
@@ -1,8 +1,8 @@
{
"token_type": "bearer",
"refresh_token": "dfdb8172-1072-4a95-8122-6f4be5dbcbaf",
"access_token": "CPDM2euDNBInQlNQMl8kQEwrAhoACAcCAhICEgkEHgEBAQEBAQEbAQIBLh4BIAEgGI-0ogEgopooKMKUazIUAyadDK38t_Nd7afu92XPlJWNIAo6a0JTUDJfJEBMKwNcAAeOAgTLAhP1AgaYAwejAwaBBQaJBggTGRobH4oBiwGQAbsB3gH6AfsB_AGVApYCtgLHAv8DgASEBIUEowSkBKUEpwSoBN0E4QbiBuMGlZoFrO8F3_cFgvkFg_kF_PUIQhSC4VGhsI_4_JW1pwepVd_QSHEyGEoDbmExUgBaAGAAaKKaKHAAeAA",
"hub_id": 2660879,
"refresh_token": "na1-c9d6-ac6a-4cf7-900e-fbf129e4d304",
"access_token": "CJO3xvSDNBInQlNQMl8kQEwrAhoACAcCAhICEgkEHgEBAQEBAQEbAQIBLh4BIAEgGLSDjwQgopooKMKUazIU7Voj7R3fYKocVet-YlLBF5eMWBg6aUJTUDJfJEBMKwNbAAeOAgTLAhP1AgaYAwejAwaBBQaJBggTGRobH4oBiwGQAbsB3gH6AfsB_AGVApYCtgLHAv8DgASEBIUEowSlBKcEqATdBOEG4gbjBpWaBazvBd_3BYL5BYP5Bfz1CEIUJXR4UFjJB7TIP67bXBkIRps5j5pKA25hMVIAWgBgAGiimihwAHgA",
"hub_id": 8634804,
"scopes": [
"crm.lists.read",
"crm.objects.deals.read",
+3
View File
@@ -26,6 +26,9 @@ async function getLeads(lastRunDate, currentDate, unsent, test) {
const result = await response.json();
console.log(JSON.stringify(result,null,2));
if (!Array.isArray(result?.data)) {
console.log('API response empty or invalid: ', result?.message || 'No data array found');
return [];
+18 -7
View File
@@ -51,7 +51,7 @@ let fields = {
return targetCountry.toUpperCase();
},*/
corso_keystone: (lead) => lead.programList?.join('; ') ?? '',
leadsource: () => 'keystone'
leadsource: () => 'Keystone'
};
function mapFields(lead) {
@@ -134,7 +134,10 @@ async function runConnector() {
//isDryRun = true;
// here we consider the last time we ran the connector
let lastRunDate = ''; // we will use this to simplify the management of the leads
let currentDate = new Date().toISOString(); // we consider only the date of the current datestamp
let date = new Date();
date.setDate(date.getDate() + 1);
let tomorrowDate = date.toISOString(); // we consider only the date of the current datestamp
let currentDate = new Date().toISOString();
if (fs.existsSync(FILE_PATH)) {
const file = fs.readFileSync(FILE_PATH, 'utf8');
lastRunDate = JSON.parse(file).lastRun;
@@ -148,16 +151,24 @@ async function runConnector() {
}
try {
console.log('Retrieving data from Keystone...', lastRunDate, currentDate, isDryRun );
console.log('Retrieving data from Keystone...', lastRunDate, tomorrowDate, isDryRun );
// getLeads(lastRunDate, currentDate, unsent, test)
const unsetValue = 0;
const firstUnsetValue = 1;
const secondUnsetValue = 0;
const testValue = isDryRun ? 1 : 0;
const leads = await getLeads(lastRunDate, currentDate, unsetValue, testValue);
const newLeads = await getLeads(lastRunDate, tomorrowDate, firstUnsetValue, testValue);
const oldLeads = await getLeads(lastRunDate, tomorrowDate, secondUnsetValue, testValue);
if (!leads.length) {
const allLeads = [...newLeads, ...oldLeads].filter(
(elem, index, self) => index === self.findIndex((el) => el.id === elem.id)
); // questo evita duplicati basati sull'id
//console.log(allLeads);
if (!allLeads.length) {
console.log('No data retrieved.');
return;
}
console.log('New leads:', allLeads.length);
// here we save the last time we ran the connector
if (!isDryRun) {
@@ -176,7 +187,7 @@ async function runConnector() {
console.log('Connection successful!');
// leadsArray accepts either a single lead object or multiple leads(array)
const leadsArray = Array.isArray(leads) ? leads : [leads];
const leadsArray = Array.isArray(allLeads) ? allLeads : [allLeads];
let allPayloads = (aggregateLeadsByEmail(leadsArray)).map(lead => mapFields(lead));
/*let nationalityOptions = '';