@absolutejs/engagement-apollo 0.0.10 → 0.0.12

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 +19 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,6 +11,20 @@ var LOCKED_EMAIL = /email_not_unlocked/iu;
11
11
  var isRecord = (value) => typeof value === "object" && value !== null;
12
12
  var str = (value) => typeof value === "string" && value.length > 0 ? value : null;
13
13
  var num = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
14
+ var companyDomain = (org) => {
15
+ const primary = str(org.primary_domain);
16
+ if (primary)
17
+ return primary;
18
+ const website = str(org.website_url);
19
+ if (!website)
20
+ return null;
21
+ try {
22
+ const url = new URL(website);
23
+ return (url.protocol === "https:" || url.protocol === "http:") && !url.username && !url.password ? url.hostname.toLowerCase().replace(/^www\./u, "") || null : null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ };
14
28
  var joinLocation = (parts) => {
15
29
  const present = parts.filter((part) => part !== null);
16
30
  return present.length > 0 ? present.join(", ") : null;
@@ -119,7 +133,10 @@ var apolloSource = (options) => {
119
133
  const enrichCompany = async (query) => {
120
134
  if (!query.domain)
121
135
  return null;
122
- const json = await get(`/v1/organizations/enrich?domain=${encodeURIComponent(query.domain)}`);
136
+ const params = new URLSearchParams({ domain: query.domain });
137
+ if (query.name?.trim())
138
+ params.set("name", query.name.trim());
139
+ const json = await get(`/v1/organizations/enrich?${params.toString()}`);
123
140
  const org = json && isRecord(json.organization) ? json.organization : null;
124
141
  if (!org)
125
142
  return null;
@@ -136,7 +153,7 @@ var apolloSource = (options) => {
136
153
  observedAt: new Date().toISOString()
137
154
  } : null,
138
155
  description: str(org.short_description),
139
- domain: str(org.primary_domain),
156
+ domain: companyDomain(org),
140
157
  employeeCount: num(org.estimated_num_employees),
141
158
  foundedYear: num(org.founded_year),
142
159
  industry: str(org.industry),
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.10",
47
+ "version": "0.0.12",
48
48
  "exports": {
49
49
  ".": {
50
50
  "types": "./dist/index.d.ts",