@absolutejs/engagement-apollo 0.0.14 → 0.0.15

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 +24 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -60,14 +60,17 @@ var apolloSource = (options) => {
60
60
  const res = await doFetch(`${baseUrl}${path}`, {
61
61
  body: JSON.stringify(body),
62
62
  headers,
63
- method: "POST"
63
+ method: "POST",
64
+ signal: AbortSignal.timeout(30000)
64
65
  });
65
66
  if (res.status === 429)
66
67
  throw new RateLimitError("apollo");
67
68
  if (!res.ok)
68
- return null;
69
- const json = await res.json();
70
- return isRecord(json) ? json : null;
69
+ throw new EngagementProviderError("apollo", res.status, path);
70
+ const json = await res.json().catch(() => null);
71
+ if (!isRecord(json))
72
+ throw new EngagementProviderError("apollo", 502, `invalid ${path} response`);
73
+ return json;
71
74
  };
72
75
  const normalizePerson = (person) => {
73
76
  const org = isRecord(person.organization) ? person.organization : null;
@@ -100,33 +103,42 @@ var apolloSource = (options) => {
100
103
  };
101
104
  };
102
105
  const matchById = async (id) => {
103
- const json = await post("/v1/people/match", { id });
104
- const person = json && isRecord(json.person) ? json.person : null;
106
+ const json = await post("/api/v1/people/match", { id });
107
+ if (json.person !== null && !isRecord(json.person))
108
+ throw new EngagementProviderError("apollo", 502, "invalid person enrichment response");
109
+ const person = isRecord(json.person) ? json.person : null;
105
110
  return person ? normalizePerson(person) : null;
106
111
  };
107
112
  const enrichPerson = async (query) => {
108
- const json = await post("/v1/people/match", {
113
+ const json = await post("/api/v1/people/match", {
109
114
  domain: query.domain,
110
115
  email: query.email,
111
116
  linkedin_url: query.linkedinUrl,
112
117
  name: query.name,
113
118
  organization_name: query.company
114
119
  });
115
- const person = json && isRecord(json.person) ? json.person : null;
120
+ if (json.person !== null && !isRecord(json.person))
121
+ throw new EngagementProviderError("apollo", 502, "invalid person enrichment response");
122
+ const person = isRecord(json.person) ? json.person : null;
116
123
  return person ? normalizePerson(person) : null;
117
124
  };
118
125
  const searchPeople = async (query) => {
119
126
  const limit = query.limit ?? DEFAULT_SEARCH_LIMIT;
120
- const search = await post("/v1/mixed_people/api_search", {
127
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100)
128
+ throw new RangeError("Apollo people limit must be an integer from 1 to 100");
129
+ const search = await post("/api/v1/mixed_people/api_search", {
121
130
  page: 1,
122
131
  per_page: limit,
123
132
  ...query.titles && query.titles.length > 0 ? { person_titles: query.titles } : {},
124
133
  ...query.domain ? { q_organization_domains_list: [query.domain] } : {},
125
134
  ...!query.domain && query.company ? { q_keywords: query.company } : {}
126
135
  });
127
- const searchRequests = search ? 1 : 0;
128
- const previews = search && Array.isArray(search.people) ? search.people : [];
129
- const ids = previews.map((person) => isRecord(person) ? str(person.id) : null).filter((id) => id !== null);
136
+ const searchRequests = 1;
137
+ if (!Array.isArray(search.people))
138
+ throw new EngagementProviderError("apollo", 502, "invalid people search response");
139
+ const ids = [
140
+ ...new Set(search.people.map((person) => isRecord(person) ? str(person.id) : null).filter((id) => id !== null))
141
+ ].slice(0, limit);
130
142
  if (ids.length === 0) {
131
143
  return { people: [], revealsAttempted: 0, searchRequests };
132
144
  }
package/package.json CHANGED
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "type": "module",
46
46
  "types": "./dist/index.d.ts",
47
- "version": "0.0.14",
47
+ "version": "0.0.15",
48
48
  "exports": {
49
49
  ".": {
50
50
  "types": "./dist/index.d.ts",