@absolutejs/engagement-apollo 0.0.1 → 0.0.2

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 (2) hide show
  1. package/dist/index.js +44 -13
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  // src/index.ts
3
3
  var APOLLO_BASE_URL = "https://api.apollo.io";
4
4
  var DEFAULT_ACTIVITY_LIMIT = 50;
5
+ var DEFAULT_SEARCH_LIMIT = 6;
6
+ var LOCKED_EMAIL = /email_not_unlocked/iu;
5
7
  var isRecord = (value) => typeof value === "object" && value !== null;
6
8
  var str = (value) => typeof value === "string" && value.length > 0 ? value : null;
7
9
  var num = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
@@ -34,22 +36,13 @@ var apolloSource = (options) => {
34
36
  const json = await res.json();
35
37
  return isRecord(json) ? json : null;
36
38
  };
37
- const enrichPerson = async (query) => {
38
- const json = await post("/v1/people/match", {
39
- domain: query.domain,
40
- email: query.email,
41
- linkedin_url: query.linkedinUrl,
42
- name: query.name,
43
- organization_name: query.company
44
- });
45
- const person = json && isRecord(json.person) ? json.person : null;
46
- if (!person)
47
- return null;
39
+ const normalizePerson = (person) => {
48
40
  const org = isRecord(person.organization) ? person.organization : null;
41
+ const email = str(person.email);
49
42
  return {
50
43
  company: org ? str(org.name) : null,
51
44
  companyDomain: org ? str(org.primary_domain) : null,
52
- email: str(person.email),
45
+ email: email && !LOCKED_EMAIL.test(email) ? email : null,
53
46
  firstName: str(person.first_name),
54
47
  lastName: str(person.last_name),
55
48
  linkedinUrl: str(person.linkedin_url),
@@ -64,6 +57,38 @@ var apolloSource = (options) => {
64
57
  title: str(person.title)
65
58
  };
66
59
  };
60
+ const matchById = async (id) => {
61
+ const json = await post("/v1/people/match", { id });
62
+ const person = json && isRecord(json.person) ? json.person : null;
63
+ return person ? normalizePerson(person) : null;
64
+ };
65
+ const enrichPerson = async (query) => {
66
+ const json = await post("/v1/people/match", {
67
+ domain: query.domain,
68
+ email: query.email,
69
+ linkedin_url: query.linkedinUrl,
70
+ name: query.name,
71
+ organization_name: query.company
72
+ });
73
+ const person = json && isRecord(json.person) ? json.person : null;
74
+ return person ? normalizePerson(person) : null;
75
+ };
76
+ const searchPeople = async (query) => {
77
+ const limit = query.limit ?? DEFAULT_SEARCH_LIMIT;
78
+ const search = await post("/v1/mixed_people/api_search", {
79
+ page: 1,
80
+ per_page: limit,
81
+ ...query.titles && query.titles.length > 0 ? { person_titles: query.titles } : {},
82
+ ...query.domain ? { q_organization_domains_list: [query.domain] } : {},
83
+ ...!query.domain && query.company ? { q_keywords: query.company } : {}
84
+ });
85
+ const previews = search && Array.isArray(search.people) ? search.people : [];
86
+ const ids = previews.map((person) => isRecord(person) ? str(person.id) : null).filter((id) => id !== null);
87
+ if (ids.length === 0)
88
+ return [];
89
+ const revealed = await Promise.all(ids.map((id) => matchById(id)));
90
+ return revealed.filter((person) => person !== null);
91
+ };
67
92
  const enrichCompany = async (query) => {
68
93
  if (!query.domain)
69
94
  return null;
@@ -116,7 +141,13 @@ var apolloSource = (options) => {
116
141
  const { since } = query;
117
142
  return since ? activities.filter((activity) => activity.occurredAt >= since) : activities;
118
143
  };
119
- return { enrichCompany, enrichPerson, id: "apollo", listActivities };
144
+ return {
145
+ enrichCompany,
146
+ enrichPerson,
147
+ id: "apollo",
148
+ listActivities,
149
+ searchPeople
150
+ };
120
151
  };
121
152
  export {
122
153
  apolloSource
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Alex Kahn",
3
3
  "description": "Apollo.io EngagementSource adapter for @absolutejs/engagement — person/company enrichment and outreach activity (emails sent/opened/replied) from the Apollo API.",
4
4
  "devDependencies": {
5
- "@absolutejs/engagement": "^0.0.1",
5
+ "@absolutejs/engagement": "^0.0.2",
6
6
  "@types/bun": "latest",
7
7
  "typescript": "5.8.3"
8
8
  },
@@ -39,5 +39,5 @@
39
39
  },
40
40
  "type": "module",
41
41
  "types": "./dist/index.d.ts",
42
- "version": "0.0.1"
42
+ "version": "0.0.2"
43
43
  }