leadmeteor 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.
- package/dist/client.d.ts +4 -0
- package/dist/client.js +48 -13
- package/dist/index.d.ts +6 -6
- package/dist/index.js +19 -13
- package/dist/resources/emails.js +1 -1
- package/dist/types/emails.d.ts +30 -16
- package/package.json +15 -2
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export type ClientOptions = {
|
|
2
2
|
apiKey: string;
|
|
3
3
|
baseUrl?: string;
|
|
4
|
+
maxRetries?: number;
|
|
4
5
|
};
|
|
5
6
|
export declare class Client {
|
|
6
7
|
private readonly apiKey;
|
|
7
8
|
private readonly baseUrl;
|
|
9
|
+
private readonly maxRetries;
|
|
8
10
|
constructor(options: ClientOptions);
|
|
9
11
|
request<T>(method: string, path: string, params?: Record<string, string>): Promise<T>;
|
|
12
|
+
private getRetryDelay;
|
|
13
|
+
private sleep;
|
|
10
14
|
}
|
package/dist/client.js
CHANGED
|
@@ -5,32 +5,67 @@ const error_1 = require("./error");
|
|
|
5
5
|
class Client {
|
|
6
6
|
apiKey;
|
|
7
7
|
baseUrl;
|
|
8
|
+
maxRetries;
|
|
8
9
|
constructor(options) {
|
|
9
10
|
if (!options.apiKey) {
|
|
10
11
|
throw new error_1.LeadmeteorError("API key is required", 0);
|
|
11
12
|
}
|
|
12
13
|
this.apiKey = options.apiKey;
|
|
13
14
|
this.baseUrl = (options.baseUrl ?? "https://api.leadmeteor.com").replace(/\/+$/, "");
|
|
15
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
14
16
|
}
|
|
15
17
|
async request(method, path, params) {
|
|
16
18
|
let url = `${this.baseUrl}${path}`;
|
|
17
|
-
|
|
19
|
+
const isGet = method.toUpperCase() === "GET";
|
|
20
|
+
if (params && isGet) {
|
|
18
21
|
const query = new URLSearchParams(params).toString();
|
|
19
22
|
url += `?${query}`;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
let lastError;
|
|
25
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
26
|
+
if (attempt > 0) {
|
|
27
|
+
await this.sleep(this.getRetryDelay(attempt));
|
|
28
|
+
}
|
|
29
|
+
let response;
|
|
30
|
+
try {
|
|
31
|
+
response = await fetch(url, {
|
|
32
|
+
method,
|
|
33
|
+
headers: {
|
|
34
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
},
|
|
37
|
+
...(params && !isGet ? { body: JSON.stringify(params) } : {}),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
lastError = error;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (response.status >= 500) {
|
|
45
|
+
const body = await response.json().catch(() => null);
|
|
46
|
+
const message = body?.error?.message ?? `Request failed with status ${response.status}`;
|
|
47
|
+
lastError = new error_1.LeadmeteorError(message, response.status);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const body = await response.json().catch(() => null);
|
|
52
|
+
const message = body?.error?.message ?? `Request failed with status ${response.status}`;
|
|
53
|
+
throw new error_1.LeadmeteorError(message, response.status);
|
|
54
|
+
}
|
|
55
|
+
return (await response.json());
|
|
32
56
|
}
|
|
33
|
-
|
|
57
|
+
if (lastError instanceof error_1.LeadmeteorError) {
|
|
58
|
+
throw lastError;
|
|
59
|
+
}
|
|
60
|
+
throw new error_1.LeadmeteorError(lastError instanceof Error ? lastError.message : "Request failed after retries", 0);
|
|
61
|
+
}
|
|
62
|
+
getRetryDelay(attempt) {
|
|
63
|
+
const baseDelay = Math.min(0.5 * Math.pow(2, attempt - 1), 5);
|
|
64
|
+
const jitter = 0.5 * (1 + Math.random());
|
|
65
|
+
return Math.max(0.5, baseDelay * jitter) * 1000;
|
|
66
|
+
}
|
|
67
|
+
sleep(ms) {
|
|
68
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34
69
|
}
|
|
35
70
|
}
|
|
36
71
|
exports.Client = Client;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { People } from "./resources/people";
|
|
|
3
3
|
import { Companies } from "./resources/companies";
|
|
4
4
|
import * as _EmailsModule from "./types/emails";
|
|
5
5
|
import * as _DomainsModule from "./types/domains";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(apiKey: string, options?: Omit<ClientOptions, "apiKey">);
|
|
6
|
+
interface Leadmeteor {
|
|
7
|
+
emails: Leadmeteor.Emails;
|
|
8
|
+
people: People;
|
|
9
|
+
companies: Companies;
|
|
10
|
+
domains: Leadmeteor.Domains;
|
|
12
11
|
}
|
|
12
|
+
declare function Leadmeteor(this: Leadmeteor | void, apiKey: string, options?: Omit<ClientOptions, "apiKey">): Leadmeteor;
|
|
13
13
|
declare namespace Leadmeteor {
|
|
14
14
|
export import Emails = _EmailsModule.Emails;
|
|
15
15
|
interface Emails {
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LeadmeteorError =
|
|
3
|
+
exports.LeadmeteorError = void 0;
|
|
4
|
+
exports.Leadmeteor = Leadmeteor;
|
|
4
5
|
const client_1 = require("./client");
|
|
5
6
|
const emails_1 = require("./resources/emails");
|
|
6
7
|
const people_1 = require("./resources/people");
|
|
7
8
|
const companies_1 = require("./resources/companies");
|
|
8
9
|
const domains_1 = require("./resources/domains");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
companies;
|
|
13
|
-
domains;
|
|
14
|
-
constructor(apiKey, options) {
|
|
15
|
-
const client = new client_1.Client({ apiKey, ...options });
|
|
16
|
-
this.emails = new emails_1.EmailsResource(client);
|
|
17
|
-
this.people = new people_1.People(client);
|
|
18
|
-
this.companies = new companies_1.Companies(client);
|
|
19
|
-
this.domains = new domains_1.DomainsResource(client);
|
|
10
|
+
function Leadmeteor(apiKey, options) {
|
|
11
|
+
if (!(this instanceof Leadmeteor)) {
|
|
12
|
+
return new Leadmeteor(apiKey, options);
|
|
20
13
|
}
|
|
14
|
+
const client = new client_1.Client({ apiKey, ...options });
|
|
15
|
+
this.emails = new emails_1.EmailsResource(client);
|
|
16
|
+
this.people = new people_1.People(client);
|
|
17
|
+
this.companies = new companies_1.Companies(client);
|
|
18
|
+
this.domains = new domains_1.DomainsResource(client);
|
|
19
|
+
return this;
|
|
21
20
|
}
|
|
22
|
-
exports.Leadmeteor = Leadmeteor;
|
|
23
21
|
(function (Leadmeteor) {
|
|
24
22
|
})(Leadmeteor || (exports.Leadmeteor = Leadmeteor = {}));
|
|
25
23
|
exports.default = Leadmeteor;
|
|
26
24
|
var error_1 = require("./error");
|
|
27
25
|
Object.defineProperty(exports, "LeadmeteorError", { enumerable: true, get: function () { return error_1.LeadmeteorError; } });
|
|
26
|
+
// Support both CJS patterns:
|
|
27
|
+
// const Leadmeteor = require('leadmeteor'); new Leadmeteor('sk_test_...');
|
|
28
|
+
// const leadmeteor = require('leadmeteor')('sk_test_...');
|
|
29
|
+
module.exports = Leadmeteor;
|
|
30
|
+
module.exports.default = Leadmeteor;
|
|
31
|
+
module.exports.Leadmeteor = Leadmeteor;
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
33
|
+
module.exports.LeadmeteorError = require("./error").LeadmeteorError;
|
package/dist/resources/emails.js
CHANGED
package/dist/types/emails.d.ts
CHANGED
|
@@ -3,8 +3,36 @@ export declare namespace Emails {
|
|
|
3
3
|
email: string;
|
|
4
4
|
};
|
|
5
5
|
type EmailVerification = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
email: string;
|
|
7
|
+
status: string;
|
|
8
|
+
checks: {
|
|
9
|
+
format: {
|
|
10
|
+
status: string;
|
|
11
|
+
passed: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
};
|
|
14
|
+
dns: {
|
|
15
|
+
status: string;
|
|
16
|
+
passed: boolean;
|
|
17
|
+
reason?: string;
|
|
18
|
+
};
|
|
19
|
+
mx: {
|
|
20
|
+
status: string;
|
|
21
|
+
passed: boolean;
|
|
22
|
+
reason?: string;
|
|
23
|
+
};
|
|
24
|
+
smtp: {
|
|
25
|
+
status: string;
|
|
26
|
+
passed: boolean;
|
|
27
|
+
reason?: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
is_disposable: boolean;
|
|
31
|
+
is_free_provider: boolean;
|
|
32
|
+
is_role_based: boolean;
|
|
33
|
+
id: string;
|
|
34
|
+
object: string;
|
|
35
|
+
created_at: number;
|
|
8
36
|
};
|
|
9
37
|
type LookupParams = EmailVerificationParams | {
|
|
10
38
|
name: string;
|
|
@@ -16,18 +44,4 @@ export declare namespace Emails {
|
|
|
16
44
|
domain: string;
|
|
17
45
|
email?: string;
|
|
18
46
|
};
|
|
19
|
-
type CheckStatus = Status;
|
|
20
|
-
type Status = "valid" | "skipped" | "invalid" | "unknown" | "risky";
|
|
21
|
-
type CheckResult = {
|
|
22
|
-
status: Status;
|
|
23
|
-
passed: boolean;
|
|
24
|
-
reason?: string;
|
|
25
|
-
};
|
|
26
|
-
type Checks = {
|
|
27
|
-
format: CheckResult;
|
|
28
|
-
disposable: CheckResult;
|
|
29
|
-
dns: CheckResult;
|
|
30
|
-
mx: CheckResult;
|
|
31
|
-
smtp: CheckResult;
|
|
32
|
-
};
|
|
33
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leadmeteor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Official Leadmeteor SDK for Node.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,9 +12,22 @@
|
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
|
-
"keywords": [
|
|
15
|
+
"keywords": [
|
|
16
|
+
"leadmeteor",
|
|
17
|
+
"lead",
|
|
18
|
+
"leads",
|
|
19
|
+
"email",
|
|
20
|
+
"emails",
|
|
21
|
+
"email verification",
|
|
22
|
+
"email checker",
|
|
23
|
+
"email verifier",
|
|
24
|
+
"js",
|
|
25
|
+
"node",
|
|
26
|
+
"sdk"
|
|
27
|
+
],
|
|
16
28
|
"license": "MIT",
|
|
17
29
|
"devDependencies": {
|
|
30
|
+
"@types/node": "^25.5.0",
|
|
18
31
|
"typescript": "^5.9.3"
|
|
19
32
|
}
|
|
20
33
|
}
|