@absolutejs/engagement-apollo 0.0.15 → 0.0.16
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/index.d.ts +6 -0
- package/dist/index.js +21 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EngagementProviderError } from "@absolutejs/engagement";
|
|
1
2
|
import type { EngagementSource } from "@absolutejs/engagement";
|
|
2
3
|
export type ApolloOptions = {
|
|
3
4
|
apiKey: string;
|
|
@@ -6,4 +7,9 @@ export type ApolloOptions = {
|
|
|
6
7
|
/** Inject a fetch (tests, instrumentation). Defaults to global fetch. */
|
|
7
8
|
fetchImpl?: typeof fetch;
|
|
8
9
|
};
|
|
10
|
+
/** Safe provider classification; response bodies and billing context stay private. */
|
|
11
|
+
export declare class ApolloProviderError extends EngagementProviderError {
|
|
12
|
+
readonly code: string | null;
|
|
13
|
+
constructor(status: number, operation: string, code: string | null);
|
|
14
|
+
}
|
|
9
15
|
export declare const apolloSource: (options: ApolloOptions) => EngagementSource;
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,18 @@ var APOLLO_BASE_URL = "https://api.apollo.io";
|
|
|
8
8
|
var DEFAULT_ACTIVITY_LIMIT = 50;
|
|
9
9
|
var DEFAULT_SEARCH_LIMIT = 6;
|
|
10
10
|
var LOCKED_EMAIL = /email_not_unlocked/iu;
|
|
11
|
+
|
|
12
|
+
class ApolloProviderError extends EngagementProviderError {
|
|
13
|
+
code;
|
|
14
|
+
constructor(status, operation, code) {
|
|
15
|
+
super("apollo", status, operation);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.name = "ApolloProviderError";
|
|
18
|
+
if (code === "BILLING.LIMIT.CREDITS_EXHAUSTED") {
|
|
19
|
+
this.message = "Apollo lead credits are exhausted. An administrator must replenish the connected Apollo account; application credits do not fund Apollo.";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
24
|
var str = (value) => typeof value === "string" && value.length > 0 ? value : null;
|
|
13
25
|
var num = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
@@ -49,6 +61,12 @@ var reference = (value) => isRecord(value) ? {
|
|
|
49
61
|
employeeCount: count(value.estimated_num_employees),
|
|
50
62
|
industries: strings(value.industries)
|
|
51
63
|
} : null;
|
|
64
|
+
var providerFailure = async (res, operation) => {
|
|
65
|
+
const value = await res.json().catch(() => null);
|
|
66
|
+
const details = isRecord(value) && isRecord(value.error_details) ? value.error_details : null;
|
|
67
|
+
const code = details && typeof details.code === "string" && /^[A-Z0-9_.]{1,120}$/u.test(details.code) ? details.code : null;
|
|
68
|
+
return new ApolloProviderError(res.status, operation, code);
|
|
69
|
+
};
|
|
52
70
|
var apolloSource = (options) => {
|
|
53
71
|
const baseUrl = options.baseUrl ?? APOLLO_BASE_URL;
|
|
54
72
|
const doFetch = options.fetchImpl ?? fetch;
|
|
@@ -66,7 +84,7 @@ var apolloSource = (options) => {
|
|
|
66
84
|
if (res.status === 429)
|
|
67
85
|
throw new RateLimitError("apollo");
|
|
68
86
|
if (!res.ok)
|
|
69
|
-
throw
|
|
87
|
+
throw await providerFailure(res, path);
|
|
70
88
|
const json = await res.json().catch(() => null);
|
|
71
89
|
if (!isRecord(json))
|
|
72
90
|
throw new EngagementProviderError("apollo", 502, `invalid ${path} response`);
|
|
@@ -215,7 +233,7 @@ var apolloSource = (options) => {
|
|
|
215
233
|
if (res.status === 404 && !body)
|
|
216
234
|
return null;
|
|
217
235
|
if (!res.ok)
|
|
218
|
-
throw
|
|
236
|
+
throw await providerFailure(res, body ? "company search" : "company enrichment");
|
|
219
237
|
const value = await res.json();
|
|
220
238
|
if (!isRecord(value))
|
|
221
239
|
throw new EngagementProviderError("apollo", 502, "invalid company response");
|
|
@@ -301,5 +319,6 @@ var apolloSource = (options) => {
|
|
|
301
319
|
};
|
|
302
320
|
};
|
|
303
321
|
export {
|
|
322
|
+
ApolloProviderError,
|
|
304
323
|
apolloSource
|
|
305
324
|
};
|