@memberjunction/actions-apollo 2.111.0 → 2.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accounts.d.ts +5 -5
- package/dist/accounts.d.ts.map +1 -1
- package/dist/accounts.js +85 -83
- package/dist/accounts.js.map +1 -1
- package/dist/contacts.d.ts +5 -5
- package/dist/contacts.d.ts.map +1 -1
- package/dist/contacts.js +85 -76
- package/dist/contacts.js.map +1 -1
- package/dist/generic/apollo.types.d.ts +3 -3
- package/dist/generic/apollo.types.d.ts.map +1 -1
- package/package.json +4 -5
package/dist/accounts.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BaseAction } from
|
|
2
|
-
import { Metadata, UserInfo } from
|
|
3
|
-
import { AxiosResponse } from
|
|
4
|
-
import { ProcessSingleDomainParams, TechnologyMap } from
|
|
5
|
-
import { ActionResultSimple, RunActionParams } from
|
|
1
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
2
|
+
import { Metadata, UserInfo } from '@memberjunction/global';
|
|
3
|
+
import { AxiosResponse } from 'axios';
|
|
4
|
+
import { ProcessSingleDomainParams, TechnologyMap } from './generic/apollo.types';
|
|
5
|
+
import { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
6
6
|
/**
|
|
7
7
|
* Action that enriches account records using Apollo.io's organization and people data
|
|
8
8
|
*
|
package/dist/accounts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAmC,QAAQ,EAAW,QAAQ,EAAgB,MAAM,
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAmC,QAAQ,EAAW,QAAQ,EAAgB,MAAM,wBAAwB,CAAC;AACpH,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAML,yBAAyB,EAIzB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAe,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAchG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBACa,8BAA+B,SAAQ,UAAU;IAC5D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkE;IAEhG;;;;;;;;;;;OAWG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA4BvF;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAc7B;;;;;OAKG;IACH,OAAO,CAAC,4BAA4B;IA6DpC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAKxB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAc9B;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAetB;;;;;;;;OAQG;YACW,wBAAwB;IAuDtC;;;;;;;;OAQG;YACW,oBAAoB;IA6BlC;;;;;;;;;;OAUG;cACa,mBAAmB,CACjC,MAAM,EAAE,yBAAyB,EACjC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,QAAQ,GACpB,OAAO,CAAC,OAAO,CAAC;IAWnB;;;;;;;;;;OAUG;YACW,kBAAkB;IAmDhC;;;;;;;;;;OAUG;YACW,iCAAiC;IAoC/C;;;;;;;;;OASG;YACW,8BAA8B;IAsB5C;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAMxB;;;;;;;;;;;OAWG;cACa,8BAA8B,CAC5C,MAAM,EAAE,yBAAyB,EACjC,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,YAAY,EAAE,aAAa,EAAE,EAC7B,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,QAAQ,GACpB,OAAO,CAAC,OAAO,CAAC;IAqEnB;;;;;;;;;OASG;YACW,+BAA+B;IAgD7C;;;;;;;;;OASG;YACW,uBAAuB;IAuCrC;;;;;;;;;;;;OAYG;YACW,qBAAqB;IAyEnC;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;;;;;;;;;;;OAYG;YACW,sBAAsB;IA6CpC;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;;;;;;;;;;OAWG;YACW,kBAAkB;IA2EhC;;;;;;;;;;OAUG;YACW,gDAAgD;IA4E9D;;;;;;OAMG;IACH,SAAS,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAQlD;;;;;;OAMG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAOjD;;;;;;OAMG;IACH,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAOjD;;;;;;;;;;;OAWG;cACa,cAAc,CAC5B,MAAM,EAAE,KAAK,GAAG,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,GAAG,EACX,aAAa,GAAE,MAAU,GACxB,OAAO,CAAC,aAAa,CAAC;IAgCzB;;;;;;OAMG;YACW,OAAO;CAGtB;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,SAEjD"}
|
package/dist/accounts.js
CHANGED
|
@@ -36,7 +36,7 @@ exports.LoadApolloAccountsEnrichmentAction = exports.ApolloEnrichmentAccountsAct
|
|
|
36
36
|
const actions_1 = require("@memberjunction/actions");
|
|
37
37
|
const global_1 = require("@memberjunction/global");
|
|
38
38
|
const Config = __importStar(require("./config"));
|
|
39
|
-
const
|
|
39
|
+
const global_2 = require("@memberjunction/global");
|
|
40
40
|
const axios_1 = __importDefault(require("axios"));
|
|
41
41
|
/**
|
|
42
42
|
* Action that enriches account records using Apollo.io's organization and people data
|
|
@@ -118,11 +118,11 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
118
118
|
return await this.processAllAccountRecords(actionParams, params.ContextUser, 1);
|
|
119
119
|
}
|
|
120
120
|
catch (error) {
|
|
121
|
-
(0,
|
|
121
|
+
(0, global_2.LogError)('Unexpected error in ApolloAccountsEnrichmentAction', undefined, error);
|
|
122
122
|
return {
|
|
123
123
|
Success: false,
|
|
124
124
|
Message: `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
125
|
-
ResultCode:
|
|
125
|
+
ResultCode: 'FAILED',
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -137,8 +137,8 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
137
137
|
error: {
|
|
138
138
|
Success: false,
|
|
139
139
|
Message: 'Apollo.io API key not found in configuration',
|
|
140
|
-
ResultCode:
|
|
141
|
-
}
|
|
140
|
+
ResultCode: 'CONFIGURATION_ERROR',
|
|
141
|
+
},
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
return { success: true };
|
|
@@ -157,8 +157,8 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
157
157
|
error: {
|
|
158
158
|
Success: false,
|
|
159
159
|
Message: 'Missing required parameter: AccountEntityFieldMappings',
|
|
160
|
-
ResultCode:
|
|
161
|
-
}
|
|
160
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
161
|
+
},
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
let accountEntityFields;
|
|
@@ -174,8 +174,8 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
174
174
|
error: {
|
|
175
175
|
Success: false,
|
|
176
176
|
Message: 'Invalid AccountEntityFieldMappings parameter: must be valid JSON or object',
|
|
177
|
-
ResultCode:
|
|
178
|
-
}
|
|
177
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
178
|
+
},
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
181
|
// Extract optional parameters
|
|
@@ -190,8 +190,8 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
190
190
|
accountTechnologyEntityFields,
|
|
191
191
|
technologyCategoryEntityFields,
|
|
192
192
|
contactEntityFields,
|
|
193
|
-
contactEducationHistoryEntityFields
|
|
194
|
-
}
|
|
193
|
+
contactEducationHistoryEntityFields,
|
|
194
|
+
},
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
@@ -201,7 +201,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
201
201
|
* @returns The parameter if found, null otherwise
|
|
202
202
|
*/
|
|
203
203
|
getRequiredParam(params, paramName) {
|
|
204
|
-
const param = params.Params.find(p => p.Name === paramName);
|
|
204
|
+
const param = params.Params.find((p) => p.Name === paramName);
|
|
205
205
|
return param || null;
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
@@ -211,7 +211,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
211
211
|
* @returns Parsed object of type T or null if not provided/invalid
|
|
212
212
|
*/
|
|
213
213
|
parseOptionalJSONParam(params, paramName) {
|
|
214
|
-
const param = params.Params.find(p => p.Name === paramName);
|
|
214
|
+
const param = params.Params.find((p) => p.Name === paramName);
|
|
215
215
|
if (!param || !param.Value) {
|
|
216
216
|
return null;
|
|
217
217
|
}
|
|
@@ -219,7 +219,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
219
219
|
return this.parseJSONParam(param.Value) || null;
|
|
220
220
|
}
|
|
221
221
|
catch (error) {
|
|
222
|
-
(0,
|
|
222
|
+
(0, global_2.LogError)(`Error parsing ${paramName}`, undefined, error);
|
|
223
223
|
return null;
|
|
224
224
|
}
|
|
225
225
|
}
|
|
@@ -253,8 +253,8 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
253
253
|
* @returns Promise indicating overall success/failure of the batch
|
|
254
254
|
*/
|
|
255
255
|
async processAllAccountRecords(actionParams, contextUser, executionCount = 1) {
|
|
256
|
-
const md = new
|
|
257
|
-
const rv = new
|
|
256
|
+
const md = new global_2.Metadata();
|
|
257
|
+
const rv = new global_2.RunView();
|
|
258
258
|
// Initial query to get accounts to process
|
|
259
259
|
const runViewResult = await rv.RunView({
|
|
260
260
|
EntityName: actionParams.accountEntityFields.EntityName,
|
|
@@ -264,32 +264,32 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
264
264
|
return {
|
|
265
265
|
Success: false,
|
|
266
266
|
Message: runViewResult.ErrorMessage,
|
|
267
|
-
ResultCode:
|
|
267
|
+
ResultCode: 'FAILED',
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
270
|
const results = runViewResult.Results;
|
|
271
271
|
const resultLength = results.length;
|
|
272
272
|
if (resultLength === 0) {
|
|
273
|
-
(0,
|
|
273
|
+
(0, global_2.LogStatus)('+++ Completed domain enrichment, no records left to process.');
|
|
274
274
|
return {
|
|
275
275
|
Success: true,
|
|
276
|
-
Message:
|
|
277
|
-
ResultCode:
|
|
276
|
+
Message: 'ApolloAccountsEnrichment executed successfully.',
|
|
277
|
+
ResultCode: 'SUCCESS',
|
|
278
278
|
};
|
|
279
279
|
}
|
|
280
280
|
// Check execution limit to prevent infinite recursion
|
|
281
281
|
if (executionCount >= 5) {
|
|
282
|
-
(0,
|
|
282
|
+
(0, global_2.LogStatus)(`+++ Reached maximum execution limit (${executionCount}), stopping to prevent infinite recursion.`);
|
|
283
283
|
return {
|
|
284
284
|
Success: true,
|
|
285
285
|
Message: `ApolloAccountsEnrichment stopped after ${executionCount} executions to prevent infinite recursion. ${resultLength} records may remain unprocessed.`,
|
|
286
|
-
ResultCode:
|
|
286
|
+
ResultCode: 'SUCCESS',
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
// Process accounts in concurrent groups
|
|
290
290
|
await this.processAccountGroups(results, actionParams, md, contextUser);
|
|
291
291
|
// Check if there are more records to process by running the query again
|
|
292
|
-
(0,
|
|
292
|
+
(0, global_2.LogStatus)(`--- Checking for remaining records... (execution ${executionCount + 1}/5)`);
|
|
293
293
|
return await this.processAllAccountRecords(actionParams, contextUser, executionCount + 1);
|
|
294
294
|
}
|
|
295
295
|
/**
|
|
@@ -311,7 +311,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
311
311
|
AccountTechnologyEntity: actionParams.accountTechnologyEntityFields || null,
|
|
312
312
|
TechnologyCategoryEntity: actionParams.technologyCategoryEntityFields || null,
|
|
313
313
|
ContactEntity: actionParams.contactEntityFields || null,
|
|
314
|
-
ContactEducationHistoryEntity: actionParams.contactEducationHistoryEntityFields || null
|
|
314
|
+
ContactEducationHistoryEntity: actionParams.contactEducationHistoryEntityFields || null,
|
|
315
315
|
};
|
|
316
316
|
const task = this.ProcessSingleDomain(processParams, index, resultLength, md, contextUser);
|
|
317
317
|
tasks.push(task);
|
|
@@ -356,11 +356,11 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
356
356
|
const record = params.Record;
|
|
357
357
|
const orgQueryString = {
|
|
358
358
|
api_key: Config.ApolloAPIKey,
|
|
359
|
-
domain: record[params.AccountEntity.DomainField]
|
|
359
|
+
domain: record[params.AccountEntity.DomainField],
|
|
360
360
|
};
|
|
361
361
|
const headers = {
|
|
362
362
|
'Cache-Control': 'no-cache',
|
|
363
|
-
'Content-Type': 'application/json'
|
|
363
|
+
'Content-Type': 'application/json',
|
|
364
364
|
};
|
|
365
365
|
// Get the organization enrichment data
|
|
366
366
|
const orgResponse = await this.WrapApolloCall('get', 'organizations/enrich', null, { params: orgQueryString, headers: headers });
|
|
@@ -373,18 +373,20 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
373
373
|
bSuccess = await this.updateAccountWithOrganizationData(result.organization, params, record, md, currentUser);
|
|
374
374
|
if (params.AccountTechnologyEntity && bSuccess) {
|
|
375
375
|
const accountID = record[params.AccountEntity.AccountIDField];
|
|
376
|
-
bSuccess =
|
|
376
|
+
bSuccess =
|
|
377
|
+
bSuccess &&
|
|
378
|
+
(await this.CreateAccountTechnologyRecords(params, accountID, result.organization.current_technologies, md, currentUser));
|
|
377
379
|
}
|
|
378
380
|
}
|
|
379
381
|
else {
|
|
380
382
|
// No match found, but still update enriched timestamp
|
|
381
|
-
(0,
|
|
383
|
+
(0, global_2.LogStatus)(` > No matches found for this domain: ${params.Record[params.AccountEntity.DomainField]}`);
|
|
382
384
|
bSuccess = await this.updateAccountEnrichedTimestamp(params, record, md, currentUser);
|
|
383
385
|
}
|
|
384
386
|
return bSuccess;
|
|
385
387
|
}
|
|
386
388
|
catch (error) {
|
|
387
|
-
(0,
|
|
389
|
+
(0, global_2.LogError)('Error enriching organization', undefined, error);
|
|
388
390
|
return false;
|
|
389
391
|
}
|
|
390
392
|
}
|
|
@@ -401,7 +403,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
401
403
|
*/
|
|
402
404
|
async updateAccountWithOrganizationData(organization, params, record, md, currentUser) {
|
|
403
405
|
try {
|
|
404
|
-
const accountEntity = await md.GetEntityObject(params.AccountEntity.EntityName,
|
|
406
|
+
const accountEntity = await md.GetEntityObject(params.AccountEntity.EntityName, global_2.CompositeKey.FromID(record.ID), currentUser);
|
|
405
407
|
// Set organization data fields
|
|
406
408
|
this.setFieldIfExists(accountEntity, params.AccountEntity.AddressField, organization.street_address);
|
|
407
409
|
this.setFieldIfExists(accountEntity, params.AccountEntity.CityField, organization.city);
|
|
@@ -417,12 +419,12 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
417
419
|
this.setFieldIfExists(accountEntity, params.AccountEntity.EnrichedAtField, new Date());
|
|
418
420
|
const saveResult = await accountEntity.Save();
|
|
419
421
|
if (!saveResult) {
|
|
420
|
-
(0,
|
|
422
|
+
(0, global_2.LogError)('Error updating account record with enriched data', undefined, accountEntity.LatestResult);
|
|
421
423
|
}
|
|
422
424
|
return saveResult;
|
|
423
425
|
}
|
|
424
426
|
catch (error) {
|
|
425
|
-
(0,
|
|
427
|
+
(0, global_2.LogError)('Error updating account with organization data', undefined, error);
|
|
426
428
|
return false;
|
|
427
429
|
}
|
|
428
430
|
}
|
|
@@ -438,16 +440,16 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
438
440
|
*/
|
|
439
441
|
async updateAccountEnrichedTimestamp(params, record, md, currentUser) {
|
|
440
442
|
try {
|
|
441
|
-
const accountEntity = await md.GetEntityObject('Accounts',
|
|
443
|
+
const accountEntity = await md.GetEntityObject('Accounts', global_2.CompositeKey.FromID(record.ID), currentUser);
|
|
442
444
|
accountEntity.Set(params.AccountEntity.EnrichedAtField, new Date());
|
|
443
445
|
const saveResult = await accountEntity.Save();
|
|
444
446
|
if (!saveResult) {
|
|
445
|
-
(0,
|
|
447
|
+
(0, global_2.LogError)('Error updating account record with enriched timestamp', undefined, accountEntity.LatestResult);
|
|
446
448
|
}
|
|
447
449
|
return saveResult;
|
|
448
450
|
}
|
|
449
451
|
catch (error) {
|
|
450
|
-
(0,
|
|
452
|
+
(0, global_2.LogError)('Error updating account enriched timestamp', undefined, error);
|
|
451
453
|
return false;
|
|
452
454
|
}
|
|
453
455
|
}
|
|
@@ -484,13 +486,13 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
484
486
|
let bSuccess = true;
|
|
485
487
|
const ATEntity = params.AccountTechnologyEntity;
|
|
486
488
|
if (ATEntity.TechnologyIDField && ATEntity.TechnologyField && ATEntity.CategoryField) {
|
|
487
|
-
const rv = new
|
|
489
|
+
const rv = new global_2.RunView();
|
|
488
490
|
const runViewResult = await rv.RunView({
|
|
489
491
|
EntityName: ATEntity.EntityName,
|
|
490
|
-
ExtraFilter: `${ATEntity.AccountIDField} = ${accountID}
|
|
492
|
+
ExtraFilter: `${ATEntity.AccountIDField} = ${accountID}`,
|
|
491
493
|
}, currentUser);
|
|
492
494
|
if (!runViewResult.Success) {
|
|
493
|
-
(0,
|
|
495
|
+
(0, global_2.LogError)('Error querying for existing Account Technologies', undefined, runViewResult.ErrorMessage);
|
|
494
496
|
return false;
|
|
495
497
|
}
|
|
496
498
|
// Process each technology
|
|
@@ -504,7 +506,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
504
506
|
at.NewRecord();
|
|
505
507
|
at.Set(ATEntity.AccountIDField, accountID);
|
|
506
508
|
at.Set(ATEntity.TechnologyIDField, await this.getOrCreateTechnologyId(technology.name, categoryId, md, currentUser));
|
|
507
|
-
bSuccess = bSuccess && await at.Save();
|
|
509
|
+
bSuccess = bSuccess && (await at.Save());
|
|
508
510
|
}
|
|
509
511
|
else {
|
|
510
512
|
existingRow.matchFound = true;
|
|
@@ -513,11 +515,11 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
513
515
|
// Mark unmatched technologies as ended
|
|
514
516
|
for (const record of runViewResult.Results) {
|
|
515
517
|
if (!record.matchFound) {
|
|
516
|
-
const entity = await md.GetEntityObject(ATEntity.EntityName,
|
|
518
|
+
const entity = await md.GetEntityObject(ATEntity.EntityName, global_2.CompositeKey.FromID(record.ID), currentUser);
|
|
517
519
|
entity.Set(ATEntity.EndedUseAtField, new Date());
|
|
518
520
|
const saveResult = await entity.Save();
|
|
519
521
|
if (!saveResult) {
|
|
520
|
-
(0,
|
|
522
|
+
(0, global_2.LogError)('Error updating Account Technology record', undefined, entity.LatestResult);
|
|
521
523
|
}
|
|
522
524
|
bSuccess = bSuccess && saveResult;
|
|
523
525
|
}
|
|
@@ -526,7 +528,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
526
528
|
return bSuccess;
|
|
527
529
|
}
|
|
528
530
|
catch (error) {
|
|
529
|
-
(0,
|
|
531
|
+
(0, global_2.LogError)('Error creating account technology records', undefined, error);
|
|
530
532
|
return false;
|
|
531
533
|
}
|
|
532
534
|
}
|
|
@@ -546,13 +548,13 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
546
548
|
return 0;
|
|
547
549
|
}
|
|
548
550
|
try {
|
|
549
|
-
const rv = new
|
|
551
|
+
const rv = new global_2.RunView();
|
|
550
552
|
const runViewResult = await rv.RunView({
|
|
551
553
|
EntityName: TCEntity.EntityName,
|
|
552
|
-
ExtraFilter: `${TCEntity.NameField} = '${this.EscapeSingleQuotes(categoryName)}'
|
|
554
|
+
ExtraFilter: `${TCEntity.NameField} = '${this.EscapeSingleQuotes(categoryName)}'`,
|
|
553
555
|
}, currentUser);
|
|
554
556
|
if (!runViewResult.Success) {
|
|
555
|
-
(0,
|
|
557
|
+
(0, global_2.LogError)('Error querying for existing Technology Categories', undefined, runViewResult.ErrorMessage);
|
|
556
558
|
return 0;
|
|
557
559
|
}
|
|
558
560
|
if (runViewResult.Results.length > 0) {
|
|
@@ -564,13 +566,13 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
564
566
|
entity.Set(TCEntity.NameField, categoryName);
|
|
565
567
|
const saveResult = await entity.Save();
|
|
566
568
|
if (!saveResult) {
|
|
567
|
-
(0,
|
|
569
|
+
(0, global_2.LogError)('Error creating new Technology Category record', undefined, entity.LatestResult);
|
|
568
570
|
return 0;
|
|
569
571
|
}
|
|
570
572
|
return entity.Get(TCEntity.IDField);
|
|
571
573
|
}
|
|
572
574
|
catch (error) {
|
|
573
|
-
(0,
|
|
575
|
+
(0, global_2.LogError)('Error getting or creating technology category', undefined, error);
|
|
574
576
|
return 0;
|
|
575
577
|
}
|
|
576
578
|
}
|
|
@@ -586,13 +588,13 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
586
588
|
*/
|
|
587
589
|
async getOrCreateTechnologyId(name, categoryId, md, currentUser) {
|
|
588
590
|
try {
|
|
589
|
-
const rv = new
|
|
591
|
+
const rv = new global_2.RunView();
|
|
590
592
|
const runViewResult = await rv.RunView({
|
|
591
593
|
EntityName: 'Technologies',
|
|
592
|
-
ExtraFilter: `Name = '${this.EscapeSingleQuotes(name)}' AND CategoryID = ${categoryId}
|
|
594
|
+
ExtraFilter: `Name = '${this.EscapeSingleQuotes(name)}' AND CategoryID = ${categoryId}`,
|
|
593
595
|
}, currentUser);
|
|
594
596
|
if (!runViewResult.Success) {
|
|
595
|
-
(0,
|
|
597
|
+
(0, global_2.LogError)('Error querying for existing Technologies', undefined, runViewResult.ErrorMessage);
|
|
596
598
|
return 0;
|
|
597
599
|
}
|
|
598
600
|
if (runViewResult.Results.length > 0) {
|
|
@@ -605,13 +607,13 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
605
607
|
technologyEntity.Set('CategoryID', categoryId);
|
|
606
608
|
const saveResult = await technologyEntity.Save();
|
|
607
609
|
if (!saveResult) {
|
|
608
|
-
(0,
|
|
610
|
+
(0, global_2.LogError)('Error creating new Technology record', undefined, technologyEntity.LatestResult);
|
|
609
611
|
return 0;
|
|
610
612
|
}
|
|
611
613
|
return technologyEntity.Get('ID');
|
|
612
614
|
}
|
|
613
615
|
catch (error) {
|
|
614
|
-
(0,
|
|
616
|
+
(0, global_2.LogError)('Error getting or creating technology', undefined, error);
|
|
615
617
|
return 0;
|
|
616
618
|
}
|
|
617
619
|
}
|
|
@@ -637,21 +639,21 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
637
639
|
api_key: Config.ApolloAPIKey,
|
|
638
640
|
reveal_personal_emails: true,
|
|
639
641
|
q_organization_domains: domain,
|
|
640
|
-
page: 1
|
|
642
|
+
page: 1,
|
|
641
643
|
};
|
|
642
644
|
const headers = {
|
|
643
645
|
'Cache-Control': 'no-cache',
|
|
644
|
-
'Content-Type': 'application/json'
|
|
646
|
+
'Content-Type': 'application/json',
|
|
645
647
|
};
|
|
646
648
|
const response = await this.WrapApolloCall('post', 'mixed_people/search', APIparams, { headers: headers });
|
|
647
649
|
if (!response || response.status !== 200) {
|
|
648
|
-
(0,
|
|
650
|
+
(0, global_2.LogError)(`Error fetching data from Apollo.io: ${response?.statusText}`);
|
|
649
651
|
return false;
|
|
650
652
|
}
|
|
651
653
|
const data = response.data;
|
|
652
654
|
const allPeople = data.people;
|
|
653
655
|
// Fetch additional pages
|
|
654
|
-
for (let i = 1; i < data.pagination.total_pages && i <
|
|
656
|
+
for (let i = 1; i < data.pagination.total_pages && i < Config.MaxPeopleToEnrichPerOrg / 10; i++) {
|
|
655
657
|
APIparams.page = i + 1;
|
|
656
658
|
const nextResponse = await this.WrapApolloCall('post', 'mixed_people/search', APIparams, { headers: headers });
|
|
657
659
|
if (nextResponse.status !== 200) {
|
|
@@ -662,7 +664,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
662
664
|
allPeople.push(...nextResult.people);
|
|
663
665
|
}
|
|
664
666
|
if (allPeople.length === 0) {
|
|
665
|
-
(0,
|
|
667
|
+
(0, global_2.LogStatus)(`No people found for this domain: ${domain}`);
|
|
666
668
|
return true;
|
|
667
669
|
}
|
|
668
670
|
// Process all people
|
|
@@ -672,12 +674,12 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
672
674
|
if (this.shouldSkipPerson(person, domain)) {
|
|
673
675
|
continue;
|
|
674
676
|
}
|
|
675
|
-
bSuccess = bSuccess && await this.createAndEnrichContact(params, accountID, person, md, currentUser, i, allPeople.length);
|
|
677
|
+
bSuccess = bSuccess && (await this.createAndEnrichContact(params, accountID, person, md, currentUser, i, allPeople.length));
|
|
676
678
|
}
|
|
677
679
|
return bSuccess;
|
|
678
680
|
}
|
|
679
681
|
catch (error) {
|
|
680
|
-
(0,
|
|
682
|
+
(0, global_2.LogError)('Error creating and enriching people', undefined, error);
|
|
681
683
|
return false;
|
|
682
684
|
}
|
|
683
685
|
}
|
|
@@ -692,12 +694,12 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
692
694
|
shouldSkipPerson(person, domain) {
|
|
693
695
|
// Check for missing required data
|
|
694
696
|
if (!person.last_name || !person.email || person.email.split('@')[1] !== domain) {
|
|
695
|
-
(0,
|
|
697
|
+
(0, global_2.LogStatus)(`Skipping person: ${person.first_name} ${person.last_name} because email is missing or does not match domain`);
|
|
696
698
|
return true;
|
|
697
699
|
}
|
|
698
700
|
// Check for excluded titles
|
|
699
701
|
if (this.IsExcludedTitle(person.title)) {
|
|
700
|
-
(0,
|
|
702
|
+
(0, global_2.LogStatus)(`Skipping person: ${person.first_name} ${person.last_name} because title is excluded`);
|
|
701
703
|
return true;
|
|
702
704
|
}
|
|
703
705
|
return false;
|
|
@@ -721,7 +723,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
721
723
|
return false;
|
|
722
724
|
}
|
|
723
725
|
try {
|
|
724
|
-
(0,
|
|
726
|
+
(0, global_2.LogStatus)(`Enriching contact for person: ${person.first_name} ${person.last_name}, accountID: ${accountID} (${sequence} of ${total})`);
|
|
725
727
|
const contact = await this.getOrCreateContact(params, accountID, person, md, currentUser);
|
|
726
728
|
if (!contact) {
|
|
727
729
|
return false;
|
|
@@ -730,17 +732,17 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
730
732
|
this.updateContactFields(contact, person, CEntity);
|
|
731
733
|
const saveResult = await contact.Save();
|
|
732
734
|
if (!saveResult) {
|
|
733
|
-
(0,
|
|
735
|
+
(0, global_2.LogError)('Error updating contact record with enriched data', undefined, contact.LatestResult);
|
|
734
736
|
return false;
|
|
735
737
|
}
|
|
736
738
|
// Update employment and education history if configured
|
|
737
739
|
if (params.ContactEducationHistoryEntity) {
|
|
738
|
-
return await this.createUpdateContactEmploymentAndEducationHistory(params, contact.Get(
|
|
740
|
+
return await this.createUpdateContactEmploymentAndEducationHistory(params, contact.Get('ID'), person, md, currentUser);
|
|
739
741
|
}
|
|
740
742
|
return true;
|
|
741
743
|
}
|
|
742
744
|
catch (error) {
|
|
743
|
-
(0,
|
|
745
|
+
(0, global_2.LogError)('Error creating and enriching contact', undefined, error);
|
|
744
746
|
return false;
|
|
745
747
|
}
|
|
746
748
|
}
|
|
@@ -783,28 +785,28 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
783
785
|
return null;
|
|
784
786
|
}
|
|
785
787
|
try {
|
|
786
|
-
const rv = new
|
|
788
|
+
const rv = new global_2.RunView();
|
|
787
789
|
// Check if contact exists with different account
|
|
788
790
|
const conflictResult = await rv.RunView({
|
|
789
791
|
EntityName: CEntity.EntityName,
|
|
790
|
-
ExtraFilter: `${CEntity.EmailField} = '${this.EscapeSingleQuotes(person.email)}' AND ${CEntity.AccountIDField} <> ${accountID}
|
|
792
|
+
ExtraFilter: `${CEntity.EmailField} = '${this.EscapeSingleQuotes(person.email)}' AND ${CEntity.AccountIDField} <> ${accountID}`,
|
|
791
793
|
}, currentUser);
|
|
792
794
|
if (!conflictResult.Success) {
|
|
793
|
-
(0,
|
|
795
|
+
(0, global_2.LogError)('Error querying for existing Contacts', undefined, conflictResult.ErrorMessage);
|
|
794
796
|
return null;
|
|
795
797
|
}
|
|
796
798
|
if (conflictResult.Results.length > 0) {
|
|
797
799
|
const existing = conflictResult.Results[0];
|
|
798
|
-
(0,
|
|
800
|
+
(0, global_2.LogError)(`*** SKIPPING new contact record for ${person.first_name} ${person.last_name} because they are already associated with AccountID: ${existing.AccountID} - ContactID: ${existing.ID}`);
|
|
799
801
|
return null;
|
|
800
802
|
}
|
|
801
803
|
// Check if contact exists for this account
|
|
802
804
|
const existingResult = await rv.RunView({
|
|
803
805
|
EntityName: CEntity.EntityName,
|
|
804
|
-
ExtraFilter: `(${CEntity.EmailField} = '${this.EscapeSingleQuotes(person.email)}' OR (${CEntity.FirstNameField} = '${this.EscapeSingleQuotes(person.first_name)}' AND ${CEntity.LastNameField} = '${this.EscapeSingleQuotes(person.last_name)}')) AND ${CEntity.AccountIDField} = ${accountID}
|
|
806
|
+
ExtraFilter: `(${CEntity.EmailField} = '${this.EscapeSingleQuotes(person.email)}' OR (${CEntity.FirstNameField} = '${this.EscapeSingleQuotes(person.first_name)}' AND ${CEntity.LastNameField} = '${this.EscapeSingleQuotes(person.last_name)}')) AND ${CEntity.AccountIDField} = ${accountID}`,
|
|
805
807
|
}, currentUser);
|
|
806
808
|
if (!existingResult.Success) {
|
|
807
|
-
(0,
|
|
809
|
+
(0, global_2.LogError)('Error querying for existing Contacts', undefined, existingResult.ErrorMessage);
|
|
808
810
|
return null;
|
|
809
811
|
}
|
|
810
812
|
let contactEntity = null;
|
|
@@ -815,7 +817,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
815
817
|
}
|
|
816
818
|
else {
|
|
817
819
|
// Create new contact
|
|
818
|
-
(0,
|
|
820
|
+
(0, global_2.LogStatus)(` > Creating new contact record for ${person.first_name} ${person.last_name}`);
|
|
819
821
|
contactEntity = await md.GetEntityObject(CEntity.EntityName, currentUser);
|
|
820
822
|
contactEntity.NewRecord();
|
|
821
823
|
contactEntity.Set(CEntity.EmailField, person.email);
|
|
@@ -826,7 +828,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
826
828
|
return contactEntity;
|
|
827
829
|
}
|
|
828
830
|
catch (error) {
|
|
829
|
-
(0,
|
|
831
|
+
(0, global_2.LogError)('Error getting or creating contact', undefined, error);
|
|
830
832
|
return null;
|
|
831
833
|
}
|
|
832
834
|
}
|
|
@@ -848,21 +850,21 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
848
850
|
}
|
|
849
851
|
try {
|
|
850
852
|
let bSuccess = true;
|
|
851
|
-
const rv = new
|
|
853
|
+
const rv = new global_2.RunView();
|
|
852
854
|
for (const history of person.employment_history) {
|
|
853
855
|
if (history.degree && history.degree.length > 0) {
|
|
854
856
|
const EHRunViewResult = await rv.RunView({
|
|
855
857
|
EntityName: CEntity.EntityName,
|
|
856
|
-
ExtraFilter: `${CEntity.ContactIDField} = ${contactID} AND ${CEntity.InstitutionField} = '${this.EscapeSingleQuotes(history.organization_name)}' AND ${CEntity.DegreeField} = '${this.EscapeSingleQuotes(history.degree)}'
|
|
858
|
+
ExtraFilter: `${CEntity.ContactIDField} = ${contactID} AND ${CEntity.InstitutionField} = '${this.EscapeSingleQuotes(history.organization_name)}' AND ${CEntity.DegreeField} = '${this.EscapeSingleQuotes(history.degree)}'`,
|
|
857
859
|
}, currentUser);
|
|
858
860
|
if (!EHRunViewResult.Success) {
|
|
859
|
-
(0,
|
|
861
|
+
(0, global_2.LogError)('Error querying for existing Employment History', undefined, EHRunViewResult.ErrorMessage);
|
|
860
862
|
bSuccess = false;
|
|
861
863
|
continue;
|
|
862
864
|
}
|
|
863
865
|
let historyEntity = null;
|
|
864
866
|
if (EHRunViewResult.Results.length > 0) {
|
|
865
|
-
historyEntity = await md.GetEntityObject(CEntity.EntityName,
|
|
867
|
+
historyEntity = await md.GetEntityObject(CEntity.EntityName, global_2.CompositeKey.FromID(EHRunViewResult.Results[0].ID), currentUser);
|
|
866
868
|
}
|
|
867
869
|
else {
|
|
868
870
|
historyEntity = await md.GetEntityObject(CEntity.EntityName, currentUser);
|
|
@@ -882,7 +884,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
882
884
|
historyEntity.Set(CEntity.IsCurrentField, history.current);
|
|
883
885
|
const saveResult = await historyEntity.Save();
|
|
884
886
|
if (!saveResult) {
|
|
885
|
-
(0,
|
|
887
|
+
(0, global_2.LogError)('Error saving Employment History record', undefined, historyEntity.LatestResult);
|
|
886
888
|
bSuccess = false;
|
|
887
889
|
}
|
|
888
890
|
}
|
|
@@ -890,7 +892,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
890
892
|
return bSuccess;
|
|
891
893
|
}
|
|
892
894
|
catch (error) {
|
|
893
|
-
(0,
|
|
895
|
+
(0, global_2.LogError)('Error creating/updating contact employment and education history', undefined, error);
|
|
894
896
|
return false;
|
|
895
897
|
}
|
|
896
898
|
}
|
|
@@ -952,7 +954,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
952
954
|
let response = method === 'get' ? await axios_1.default.get(url, config) : await axios_1.default.post(url, data, config);
|
|
953
955
|
if (response.status === 429) {
|
|
954
956
|
if (retryAttempts > 0) {
|
|
955
|
-
(0,
|
|
957
|
+
(0, global_2.LogStatus)(' >>> Too many requests to Apollo.io API, waiting 1 minute and trying again...');
|
|
956
958
|
await this.Timeout(60000); // wait 1 minute
|
|
957
959
|
return await this.WrapApolloCall(method, endpoint, data, config, retryAttempts - 1);
|
|
958
960
|
}
|
|
@@ -966,7 +968,7 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
966
968
|
// axios could throw an exception for a 429 instead of a response, so we need to handle that here
|
|
967
969
|
if (apolloError && apolloError.response && apolloError.response.status === 429) {
|
|
968
970
|
if (retryAttempts > 0) {
|
|
969
|
-
(0,
|
|
971
|
+
(0, global_2.LogStatus)(' >>> Too many requests to Apollo.io API, waiting 1 minute and trying again...');
|
|
970
972
|
await this.Timeout(60000); // wait 1 minute
|
|
971
973
|
return await this.WrapApolloCall(method, endpoint, data, config, retryAttempts - 1);
|
|
972
974
|
}
|
|
@@ -987,12 +989,12 @@ let ApolloEnrichmentAccountsAction = class ApolloEnrichmentAccountsAction extend
|
|
|
987
989
|
* @returns Promise that resolves after the specified delay
|
|
988
990
|
*/
|
|
989
991
|
async Timeout(ms) {
|
|
990
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
992
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
991
993
|
}
|
|
992
994
|
};
|
|
993
995
|
exports.ApolloEnrichmentAccountsAction = ApolloEnrichmentAccountsAction;
|
|
994
996
|
exports.ApolloEnrichmentAccountsAction = ApolloEnrichmentAccountsAction = __decorate([
|
|
995
|
-
(0, global_1.RegisterClass)(actions_1.BaseAction,
|
|
997
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, 'ApolloEnrichmentAccountsAction')
|
|
996
998
|
], ApolloEnrichmentAccountsAction);
|
|
997
999
|
/**
|
|
998
1000
|
* Loader function to ensure the ApolloEnrichmentAccountsAction class is included in the bundle
|