@memberjunction/actions-apollo 6.2.0-edge.3 → 6.2.0-edge.4

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.
Files changed (44) hide show
  1. package/README.md +88 -53
  2. package/dist/__tests__/apollo-enrichment.test.js +339 -233
  3. package/dist/__tests__/apollo-enrichment.test.js.map +1 -1
  4. package/dist/__tests__/apollo-lists.test.js +29 -1
  5. package/dist/__tests__/apollo-lists.test.js.map +1 -1
  6. package/dist/__tests__/apollo-people-client.test.d.ts +2 -0
  7. package/dist/__tests__/apollo-people-client.test.d.ts.map +1 -0
  8. package/dist/__tests__/apollo-people-client.test.js +153 -0
  9. package/dist/__tests__/apollo-people-client.test.js.map +1 -0
  10. package/dist/accounts.d.ts +80 -291
  11. package/dist/accounts.d.ts.map +1 -1
  12. package/dist/accounts.js +391 -782
  13. package/dist/accounts.js.map +1 -1
  14. package/dist/contacts.d.ts +140 -207
  15. package/dist/contacts.d.ts.map +1 -1
  16. package/dist/contacts.js +372 -724
  17. package/dist/contacts.js.map +1 -1
  18. package/dist/generic/apollo-lists.types.d.ts +18 -3
  19. package/dist/generic/apollo-lists.types.d.ts.map +1 -1
  20. package/dist/http/ApolloHttp.d.ts +42 -0
  21. package/dist/http/ApolloHttp.d.ts.map +1 -0
  22. package/dist/http/ApolloHttp.js +117 -0
  23. package/dist/http/ApolloHttp.js.map +1 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +5 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/lists/ApolloRESTClient.d.ts +2 -0
  29. package/dist/lists/ApolloRESTClient.d.ts.map +1 -1
  30. package/dist/lists/ApolloRESTClient.js +33 -52
  31. package/dist/lists/ApolloRESTClient.js.map +1 -1
  32. package/dist/lists/ApolloSearchActions.d.ts +6 -1
  33. package/dist/lists/ApolloSearchActions.d.ts.map +1 -1
  34. package/dist/lists/ApolloSearchActions.js +19 -4
  35. package/dist/lists/ApolloSearchActions.js.map +1 -1
  36. package/dist/people/ApolloPeopleClient.d.ts +114 -0
  37. package/dist/people/ApolloPeopleClient.d.ts.map +1 -0
  38. package/dist/people/ApolloPeopleClient.js +168 -0
  39. package/dist/people/ApolloPeopleClient.js.map +1 -0
  40. package/dist/people/apollo-people.types.d.ts +55 -0
  41. package/dist/people/apollo-people.types.d.ts.map +1 -0
  42. package/dist/people/apollo-people.types.js +8 -0
  43. package/dist/people/apollo-people.types.js.map +1 -0
  44. package/package.json +8 -8
package/README.md CHANGED
@@ -28,14 +28,17 @@ flowchart TB
28
28
  subgraph Apollo["@memberjunction/actions-apollo"]
29
29
  AccAction["ApolloEnrichmentAccountsAction"]
30
30
  ConAction["ApolloEnrichmentContactsAction"]
31
- Config["Configuration\n(API key, batch sizes)"]
31
+ PeopleClient["ApolloPeopleClient\n(bulk_match, organizations/enrich)"]
32
+ RESTClient["ApolloRESTClient\n(lists, api_search)"]
33
+ Http["ApolloHttp\n(header auth, typed errors)"]
34
+ Config["Configuration\n(batch sizes, endpoints)"]
32
35
  Types["Apollo Type Definitions"]
33
36
  end
34
37
 
35
38
  subgraph ApolloAPI["Apollo.io REST API"]
36
39
  OrgEnrich["/organizations/enrich"]
37
40
  BulkMatch["/people/bulk_match"]
38
- PeopleSearch["/mixed_people/search"]
41
+ PeopleSearch["/mixed_people/api_search"]
39
42
  end
40
43
 
41
44
  subgraph MJCore["MemberJunction Core"]
@@ -50,10 +53,14 @@ flowchart TB
50
53
  ConAction --> Config
51
54
  AccAction --> Types
52
55
  ConAction --> Types
53
- AccAction -->|HTTP via axios| OrgEnrich
54
- AccAction -->|HTTP via axios| PeopleSearch
55
- ConAction -->|HTTP via axios| BulkMatch
56
- ConAction -->|HTTP via axios| PeopleSearch
56
+ AccAction --> PeopleClient
57
+ AccAction --> RESTClient
58
+ ConAction --> PeopleClient
59
+ PeopleClient --> Http
60
+ RESTClient --> Http
61
+ Http --> OrgEnrich
62
+ Http --> BulkMatch
63
+ Http --> PeopleSearch
57
64
  AccAction -->|read/write entities| MJCore
58
65
  ConAction -->|read/write entities| MJCore
59
66
 
@@ -70,8 +77,9 @@ flowchart LR
70
77
  Start["Load accounts\nmatching filter"] --> OrgAPI["Call /organizations/enrich\nper domain"]
71
78
  OrgAPI --> UpdateAcct["Update account\nfields"]
72
79
  OrgAPI --> TechRec["Create/update\ntechnology records"]
73
- OrgAPI --> PeopleAPI["Call /mixed_people/search\nfor domain contacts"]
74
- PeopleAPI --> CreateContact["Create/update\ncontact records"]
80
+ OrgAPI --> PeopleAPI["Call /mixed_people/api_search\nfor the ids at the domain (free)"]
81
+ PeopleAPI --> Match["Call /people/bulk_match\nby id, 10 at a time (1 credit per match)"]
82
+ Match --> CreateContact["Create/update\ncontact records"]
75
83
  CreateContact --> History["Create education\nhistory records"]
76
84
  UpdateAcct --> Next["Next account"]
77
85
  TechRec --> Next
@@ -82,6 +90,7 @@ flowchart LR
82
90
  style UpdateAcct fill:#2d8659,stroke:#1a5c3a,color:#fff
83
91
  style TechRec fill:#2d8659,stroke:#1a5c3a,color:#fff
84
92
  style PeopleAPI fill:#b8762f,stroke:#8a5722,color:#fff
93
+ style Match fill:#b8762f,stroke:#8a5722,color:#fff
85
94
  style CreateContact fill:#2d8659,stroke:#1a5c3a,color:#fff
86
95
  style History fill:#2d8659,stroke:#1a5c3a,color:#fff
87
96
  style Next fill:#64748b,stroke:#475569,color:#fff
@@ -91,9 +100,9 @@ flowchart LR
91
100
 
92
101
  ```mermaid
93
102
  flowchart LR
94
- Start["Page contacts\nmatching filter"] --> Batch["Batch into groups\nof 10"]
103
+ Start["Keyset-page contacts\nmatching filter"] --> Batch["Batch into groups\nof 10"]
95
104
  Batch --> BulkAPI["Call /people/bulk_match\nper batch"]
96
- BulkAPI --> Update["Update contact\nfields from matches"]
105
+ BulkAPI --> Update["Update matched fields;\nstamp EnrichedAt on every row sent"]
97
106
  Update --> EmpHist["Upsert employment\nhistory"]
98
107
  Update --> EduHist["Upsert education\nhistory"]
99
108
  EmpHist --> NextBatch["Next batch"]
@@ -117,7 +126,7 @@ npm install @memberjunction/actions-apollo
117
126
  ## Prerequisites
118
127
 
119
128
  1. An active Apollo.io account with API access
120
- 2. Apollo.io API key set as the environment variable `APOLLO_API_KEY`
129
+ 2. An Apollo.io API key, either as the environment variable `APOLLO_API_KEY` or on a company's **MJ: Company Integrations** row for the `Apollo` Integration (passed as the `CompanyID` param; see [Credentials](#credentials))
121
130
  3. MemberJunction framework properly configured with server-side action engine
122
131
  4. Target entities configured for storing enriched data (accounts, contacts, technologies, etc.)
123
132
 
@@ -135,10 +144,11 @@ The package defines the following defaults in `config.ts`:
135
144
 
136
145
  | Constant | Default | Description |
137
146
  |---|---|---|
138
- | `ApolloAPIEndpoint` | `https://api.apollo.io/v1` | Apollo.io API base URL |
147
+ | `ApolloRESTEndpoint` | `https://api.apollo.io/api/v1` | Apollo.io API base URL used by every client in this package |
148
+ | `ApolloAPIEndpoint` | `https://api.apollo.io/v1` | Legacy enrichment base URL; kept for consumers, no longer called |
139
149
  | `EmailSourceName` | `Apollo.io` | Source label applied to enriched emails |
140
150
  | `GroupSize` | `10` | Records per API batch request (Apollo max is 10) |
141
- | `ConcurrentGroups` | `1` | Number of concurrent API request groups |
151
+ | `ConcurrentGroups` | `1` | Kept for consumers; groups are sent one at a time |
142
152
  | `MaxPeopleToEnrichPerOrg` | `500` | Maximum contacts to enrich per organization |
143
153
  | `ApolloAPIKey` | `process.env.APOLLO_API_KEY` | Read from environment at startup |
144
154
 
@@ -157,6 +167,7 @@ The `ApolloEnrichmentAccountsAction` enriches account/organization records by lo
157
167
  | `TechnologyCategoryEntityFieldMappings` | No | JSON string | Maps technology category fields |
158
168
  | `ContactEntityFieldMappings` | No | JSON string | Maps contact entity fields for discovered contacts |
159
169
  | `ContactEducationHistoryEntityFieldMappings` | No | JSON string | Maps education history fields |
170
+ | `CompanyID` | No | string | Resolve the key from this company's `Apollo` credential; falls back to `APOLLO_API_KEY` |
160
171
 
161
172
  #### AccountEntityFields Structure
162
173
 
@@ -258,26 +269,39 @@ The `ApolloEnrichmentContactsAction` enriches existing contact records by matchi
258
269
  | `FacebookField` | No | string | Field for Facebook profile URLs |
259
270
  | `EmploymentHistoryFieldMappings` | No | JSON string | Employment history entity field mappings |
260
271
  | `EducationHistoryFieldMappings` | No | JSON string | Education history entity field mappings |
272
+ | `CompanyID` | No | string | Resolve the key from this company's `Apollo` credential; falls back to `APOLLO_API_KEY` |
273
+
274
+ Every record the action sends to Apollo is stamped with `EnrichedAtField`, whether or not Apollo matched it, so a `Filter` on that stamp (as in the example) never re-sends, and never pays for, the same miss. Records nothing identifies (no email, and not a first and last name with a domain or account name) are stamped without a lookup.
261
275
 
262
276
  #### EmploymentHistoryFieldMappings Structure
263
277
 
278
+ Keys are matched case-insensitively. Only the columns named here are ever written.
279
+
264
280
  ```typescript
265
281
  {
266
- EmploymentHistoryEntityName: string; // Employment history entity
267
- EmploymentHistoryContactIDFieldName: string; // Foreign key to contact
268
- EmploymentHistoryOrganizationFieldName: string; // Organization name field
269
- EmploymentHistoryTitleFieldName: string; // Job title field
282
+ EntityName: string; // Employment history entity
283
+ ContactIDFieldName: string; // Foreign key to contact (the contact entity must have a single-column key)
284
+ OrganizationFieldName: string; // Organization name field
285
+ TitleFieldName: string; // Job title field
286
+ StartDateFieldName?: string; // Optional: start date
287
+ EndDateFieldName?: string; // Optional: end date
288
+ IsCurrentFieldName?: string; // Optional: current-position flag
270
289
  }
271
290
  ```
272
291
 
273
292
  #### EducationHistoryFieldMappings Structure
274
293
 
294
+ Education is written whenever this mapping is present, independently of the employment mapping. Apollo returns education as `employment_history` entries that carry a degree or an education `kind`; the client files those under education and everything else (a trustee seat at a university, say) under employment.
295
+
275
296
  ```typescript
276
297
  {
277
- EducationHistoryEntityName: string; // Education history entity
278
- EducationHistoryContactIDFieldName: string; // Foreign key to contact
279
- EducationHistoryInstitutionFieldName: string; // Institution name field
280
- EducationHistoryDegreeFieldName: string; // Degree field
298
+ EntityName: string; // Education history entity
299
+ ContactIDFieldName: string; // Foreign key to contact
300
+ InstitutionFieldName: string; // Institution name field
301
+ DegreeFieldName: string; // Degree field
302
+ GradeLevelFieldName?: string; // Optional: grade level
303
+ StartDateFieldName?: string; // Optional: start date
304
+ EndDateFieldName?: string; // Optional: end date
281
305
  }
282
306
  ```
283
307
 
@@ -303,19 +327,22 @@ const result = await engine.RunAction({
303
327
  {
304
328
  Name: 'EmploymentHistoryFieldMappings',
305
329
  Value: JSON.stringify({
306
- EmploymentHistoryEntityName: 'Contact Employment Histories',
307
- EmploymentHistoryContactIDFieldName: 'ContactID',
308
- EmploymentHistoryOrganizationFieldName: 'Organization',
309
- EmploymentHistoryTitleFieldName: 'Title'
330
+ EntityName: 'Contact Employment Histories',
331
+ ContactIDFieldName: 'ContactID',
332
+ OrganizationFieldName: 'Organization',
333
+ TitleFieldName: 'Title',
334
+ StartDateFieldName: 'StartedAt',
335
+ EndDateFieldName: 'EndedAt',
336
+ IsCurrentFieldName: 'IsCurrent'
310
337
  })
311
338
  },
312
339
  {
313
340
  Name: 'EducationHistoryFieldMappings',
314
341
  Value: JSON.stringify({
315
- EducationHistoryEntityName: 'Contact Education Histories',
316
- EducationHistoryContactIDFieldName: 'ContactID',
317
- EducationHistoryInstitutionFieldName: 'Institution',
318
- EducationHistoryDegreeFieldName: 'Degree'
342
+ EntityName: 'Contact Education Histories',
343
+ ContactIDFieldName: 'ContactID',
344
+ InstitutionFieldName: 'Institution',
345
+ DegreeFieldName: 'Degree'
319
346
  })
320
347
  }
321
348
  ],
@@ -327,7 +354,7 @@ const result = await engine.RunAction({
327
354
 
328
355
  Seven actions cover the other half of Apollo: which records are on which list, and moving them between lists. They are the outbound-campaign surface — build a list, drain it through a sequence of stages, and see what is where.
329
356
 
330
- These talk to a **different Apollo base path** from enrichment: `api.apollo.io/api/v1` rather than `api.apollo.io/v1`. The paths are not interchangeable; the same path under the wrong prefix returns 404. Both are declared side by side in `src/config.ts`.
357
+ Every client in this package now talks to `api.apollo.io/api/v1` (`ApolloRESTEndpoint`), which serves enrichment, search and lists alike; the older `api.apollo.io/v1` constant remains exported but unused. All HTTP goes through `src/http/ApolloHttp.ts`: `X-Api-Key` header auth, JSON handling, and typed errors (`ApolloAuthError` for 401/403, `ApolloRateLimitError` with the window for 429, `ApolloRequestError` otherwise).
331
358
 
332
359
  | Action | Purpose | Key required |
333
360
  |---|---|---|
@@ -335,7 +362,7 @@ These talk to a **different Apollo base path** from enrichment: `api.apollo.io/a
335
362
  | `ApolloCreateListAction` | Create a list, idempotently. A same-named label is returned as-is with `AlreadyExisted: true` | MASTER |
336
363
  | `ApolloGetListAccountsAction` | One page of a list's accounts, with each one's current label names | MASTER |
337
364
  | `ApolloGetListContactsAction` | One page of a list's contacts, same shape | MASTER |
338
- | `ApolloSearchPeopleAction` | Search Apollo's people database by organization, title and seniority. At least one filter is required | scoped is fine |
365
+ | `ApolloSearchPeopleAction` | Search Apollo's people database by organization, title, seniority, location and keywords. At least one filter is required. Outputs `Count` (this page) and `TotalEntries` (all pages). Since 2026 the results are obfuscated (`lastNameObfuscated`, no LinkedIn URL, no email); details need a paid `bulk_match` by id | scoped is fine |
339
366
  | `ApolloMoveListAccountsAction` | Move accounts between lists, preserving every other membership | MASTER |
340
367
  | `ApolloMoveListContactsAction` | The same for contacts | MASTER |
341
368
 
@@ -414,20 +441,20 @@ Registered as `"ApolloEnrichmentAccountsAction"` via `@RegisterClass(BaseAction)
414
441
  - For each account, calls `/organizations/enrich` with the domain
415
442
  - Updates account fields with enriched organization data
416
443
  - Optionally creates/updates technology stack records with historical tracking (marks ended technologies)
417
- - Optionally discovers and creates contact records via `/mixed_people/search`
418
- - Processes recursively up to 5 times to handle remaining records
419
- - Supports concurrent domain processing (configurable via `ConcurrentGroups`)
444
+ - Optionally discovers contacts: `/mixed_people/api_search` for the ids at the domain (free), then `/people/bulk_match` by id (one credit per match, up to `MaxPeopleToEnrichPerOrg`), creating or updating a contact for each in-domain email
445
+ - Looks contacts up by their real primary keys, quoted per column type, so UUID and integer keys both work
446
+ - Processes recursively up to 5 times to handle remaining records; every save runs even after an earlier one fails
420
447
 
421
448
  #### `ApolloEnrichmentContactsAction`
422
449
 
423
450
  Registered as `"ApolloEnrichmentContactsAction"` via `@RegisterClass(BaseAction)`. Extends `BaseAction`.
424
451
 
425
452
  **Processing behavior:**
426
- - Pages through contact records matching the configured filter (500 per page)
427
- - Batches contacts into groups of 10 for Apollo's `/people/bulk_match` endpoint
428
- - Updates matching contacts with enriched social profiles and company data
429
- - Optionally creates/updates employment and education history records
430
- - Supports secondary enrichment via `/mixed_people/search` for organization-level lookups
453
+ - Pages through contact records matching the configured filter (500 per page) by keyset on a single-column key, so a filter that drains as rows are stamped cannot skip rows; a composite-key entity re-reads the first page excluding rows stamped this run
454
+ - Batches contacts into groups of 10 for Apollo's `/people/bulk_match` endpoint through `ApolloPeopleClient`
455
+ - Updates matching contacts with enriched social profiles and company data, and stamps every row sent
456
+ - Optionally creates/updates employment and education history records, each from its own mapping, writing only the columns the mapping names and storing values as Apollo sent them
457
+ - Returns `RATE_LIMIT_EXCEEDED` at once on an hourly or daily Apollo limit (the client retries a per-minute limit once, after at most 60 seconds)
431
458
 
432
459
  ### Exported Types
433
460
 
@@ -450,19 +477,27 @@ All types are exported from `src/generic/apollo.types.ts`:
450
477
  | `OrganizationEnrichmentOrganization` | Detailed organization data from Apollo |
451
478
  | `OrganizationEnrichmentOrganizationAccount` | Account data within organization response |
452
479
  | `TechnologyMap` | Technology record with name, category, and UID |
453
- | `SearchPeopleResponse` | Response from `/mixed_people/search` |
454
- | `SearchPeopleResponsePerson` | Individual person data from search response |
480
+ | `SearchPeopleResponse` | Legacy: the deprecated `/mixed_people/search` response (Apollo answers 422 now) |
481
+ | `SearchPeopleResponsePerson` | Legacy: individual person data from that response |
455
482
  | `EmploymentHistory` | Employment/education history entry |
456
483
 
484
+ ### `ApolloPeopleClient`
485
+
486
+ `src/people/ApolloPeopleClient.ts`. The table-agnostic enrichment client both actions use, and the one the BizApps Common person-enrichment engine wraps. It returns normalized data and writes nothing.
487
+
488
+ - `BulkMatch(inputs, { RevealPersonalEmails?, IncludeRaw? })`: up to `MaxBatchSize` (10) people per call; each input needs an Apollo id, an email, a LinkedIn URL, or a first and last name with an organization. Results come back in input order with the caller's `Key`; a miss is `Matched: false`. `CreditsConsumed` is Apollo's count (one per match, misses free). The education split described above lives here.
489
+ - `EnrichOrganization(domain)`: `organizations/enrich`, null on a miss.
490
+ - `ForCompany(companyID, contextUser)`: resolves the key through the credentials path (company credential, then `APOLLO_API_KEY`).
491
+ - A per-minute 429 waits at most 60 seconds and retries once; an hourly or daily 429 throws `ApolloRateLimitError` immediately. The client never sleeps longer than a minute.
492
+
457
493
  ## Rate Limiting and Error Handling
458
494
 
459
- Both action classes include a `WrapApolloCall` method that provides:
495
+ All HTTP goes through `src/http/ApolloHttp.ts`, which maps failures onto typed errors:
460
496
 
461
- - **Automatic retry** on HTTP 429 (Too Many Requests) responses
462
- - **Per-minute backoff**: 60-second wait on standard rate limit responses
463
- - **Hourly backoff**: 60-minute wait when Apollo's hourly rate limit is detected (contact action only)
464
- - **Exception handling**: Catches both Axios response errors and thrown exceptions for 429 status codes
465
- - **Comprehensive logging** via MemberJunction's `LogError` and `LogStatus` utilities
497
+ - `ApolloRateLimitError` (429) carries `Window` (`minute`, `hour`, `day`, `unknown`) and `RetryAfterSeconds`. The people client retries a per-minute limit once after at most 60 seconds; the actions return `RATE_LIMIT_EXCEEDED` immediately on any other window, so a scheduled job never holds its lock through an hour-long sleep.
498
+ - `ApolloAuthError` (401, 403) becomes `CONFIGURATION_ERROR`; a 403 on a master-key operation says so.
499
+ - `ApolloRequestError` for anything else, with the status and the body Apollo sent.
500
+ - Everything is logged via MemberJunction's `LogError` and `LogStatus` utilities.
466
501
 
467
502
  ### Title Filtering
468
503
 
@@ -476,9 +511,9 @@ Both actions automatically exclude contacts with the following job titles to mai
476
511
 
477
512
  | Endpoint | HTTP Method | Used By | Purpose |
478
513
  |---|---|---|---|
479
- | `/organizations/enrich` | GET | Accounts action | Organization data by domain |
480
- | `/people/bulk_match` | POST | Contacts action | Bulk contact matching (up to 10 per request) |
481
- | `/mixed_people/search` | POST | Both actions | People search by organization domain |
514
+ | `/organizations/enrich` | GET | Accounts action | Organization data by domain (header auth) |
515
+ | `/people/bulk_match` | POST | Both actions | Bulk people matching, up to 10 per request, one credit per match |
516
+ | `/mixed_people/api_search` | POST | Accounts action, Search People action | Prospecting search: ids, first names, titles and employers only (obfuscated). `/mixed_people/search` is deprecated and answers 422 |
482
517
 
483
518
  ## Dependencies
484
519
 
@@ -494,10 +529,10 @@ Both actions automatically exclude contacts with the following job titles to mai
494
529
  ## Limitations
495
530
 
496
531
  - Maximum 10 records per bulk API request (Apollo.io API limitation)
497
- - Rate limits apply based on your Apollo.io subscription tier (handled automatically with retries)
532
+ - Rate limits apply based on your Apollo.io subscription tier; a per-minute limit is retried once, an hourly or daily limit ends the run with `RATE_LIMIT_EXCEEDED`
498
533
  - Personal emails may not be revealed in GDPR-compliant regions
499
- - Account enrichment processes domains sequentially within each concurrent group
500
- - Contact enrichment paginates with a maximum of 500 contacts per organization
534
+ - Account enrichment processes domains one at a time and discovers at most `MaxPeopleToEnrichPerOrg` (500) people per organization, each matched person costing one credit
535
+ - Contact enrichment on a composite-key entity pages by re-reading the first page of rows not yet stamped this run; a row whose save fails is skipped for the rest of the run
501
536
  - Account enrichment recurses up to 5 times to prevent infinite loops
502
537
  - Excluded job titles (member, student member, student, volunteer) are automatically skipped
503
538