@apiverve/spfvalidator 1.1.14 → 1.2.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 (5) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +327 -299
  3. package/index.d.ts +57 -41
  4. package/index.js +209 -209
  5. package/package.json +6 -7
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 APIVerve, and EvlarSoft LLC
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 APIVerve and EvlarSoft LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,237 +1,137 @@
1
- # SPF Validator API
2
-
3
- SPF Validator checks the Sender Policy Framework (SPF) DNS record for a domain to verify if it’s valid and optionally whether a given IP address is authorized to send emails for that domain.
4
-
5
- ![Build Status](https://img.shields.io/badge/build-passing-green)
6
- ![Code Climate](https://img.shields.io/badge/maintainability-B-purple)
7
- ![Prod Ready](https://img.shields.io/badge/production-ready-blue)
8
- [![npm version](https://img.shields.io/npm/v/@apiverve/spfvalidator.svg)](https://www.npmjs.com/package/@apiverve/spfvalidator)
9
-
10
- This is a Javascript Wrapper for the [SPF Validator API](https://spfvalidator.apiverve.com?utm_source=npm&utm_medium=readme)
11
-
12
- ---
13
-
14
- ## Installation
15
-
16
- Using npm:
17
- ```shell
18
- npm install @apiverve/spfvalidator
19
- ```
20
-
21
- Using yarn:
22
- ```shell
23
- yarn add @apiverve/spfvalidator
24
- ```
25
-
26
- ---
27
-
28
- ## Configuration
29
-
30
- Before using the SPF Validator API client, you have to setup your account and obtain your API Key.
31
- You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=readme)
32
-
33
- ---
34
-
35
- ## Quick Start
36
-
37
- [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=readme)
38
-
39
- The SPF Validator API documentation is found here: [https://docs.apiverve.com/ref/spfvalidator](https://docs.apiverve.com/ref/spfvalidator?utm_source=npm&utm_medium=readme).
40
- You can find parameters, example responses, and status codes documented here.
41
-
42
- ### Setup
43
-
44
- ```javascript
45
- const spfvalidatorAPI = require('@apiverve/spfvalidator');
46
- const api = new spfvalidatorAPI({
47
- api_key: '[YOUR_API_KEY]'
48
- });
49
- ```
50
-
51
- ---
52
-
53
- ## Usage
54
-
55
- ---
56
-
57
- ### Perform Request
58
-
59
- Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
60
-
61
- ```javascript
1
+ # SPF Validator API
2
+
3
+ SPF Validator checks the Sender Policy Framework (SPF) DNS record for a domain to verify if it’s valid and optionally whether a given IP address is authorized to send emails for that domain.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@apiverve/spfvalidator.svg)](https://www.npmjs.com/package/@apiverve/spfvalidator)
6
+
7
+ This is a JavaScript wrapper for the [SPF Validator API](https://apiverve.com/marketplace/spfvalidator?utm_source=npm&utm_medium=referral&utm_content=readme)
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ Using npm:
14
+ ```shell
15
+ npm install @apiverve/spfvalidator
16
+ ```
17
+
18
+ Using yarn:
19
+ ```shell
20
+ yarn add @apiverve/spfvalidator
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Configuration
26
+
27
+ Before using the SPF Validator API client, you have to setup your account and obtain your API Key.
28
+ You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=referral&utm_content=readme)
29
+
30
+ ---
31
+
32
+ ## Quick Start
33
+
34
+ [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=referral&utm_content=readme)
35
+
36
+ The SPF Validator API documentation is found here: [https://docs.apiverve.com/ref/spfvalidator](https://docs.apiverve.com/ref/spfvalidator?utm_source=npm&utm_medium=referral&utm_content=readme).
37
+ You can find parameters, example responses, and status codes documented here.
38
+
39
+ ### Setup
40
+
41
+ ```javascript
42
+ const spfvalidatorAPI = require('@apiverve/spfvalidator');
43
+ const api = new spfvalidatorAPI({
44
+ api_key: '[YOUR_API_KEY]'
45
+ });
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Usage
51
+
52
+ ---
53
+
54
+ ### Perform Request
55
+
56
+ Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
57
+
58
+ ```javascript
62
59
  var query = {
63
60
  domain: "myspace.com"
64
- };
65
-
66
- api.execute(query, function (error, data) {
67
- if (error) {
68
- return console.error(error);
69
- } else {
70
- console.log(data);
71
- }
72
- });
73
- ```
74
-
75
- ---
76
-
77
- ### Using Promises
78
-
79
- You can also use promises to make requests. The API returns a promise that you can use to handle the response.
80
-
81
- ```javascript
61
+ };
62
+
63
+ api.execute(query, function (error, data) {
64
+ if (error) {
65
+ return console.error(error);
66
+ } else {
67
+ console.log(data);
68
+ }
69
+ });
70
+ ```
71
+
72
+ ---
73
+
74
+ ### Using Promises
75
+
76
+ You can also use promises to make requests. The API returns a promise that you can use to handle the response.
77
+
78
+ ```javascript
82
79
  var query = {
83
80
  domain: "myspace.com"
84
- };
85
-
86
- api.execute(query)
87
- .then(data => {
88
- console.log(data);
89
- })
90
- .catch(error => {
91
- console.error(error);
92
- });
93
- ```
94
-
95
- ---
96
-
97
- ### Using Async/Await
98
-
99
- You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
100
-
101
- ```javascript
102
- async function makeRequest() {
81
+ };
82
+
83
+ api.execute(query)
84
+ .then(data => {
85
+ console.log(data);
86
+ })
87
+ .catch(error => {
88
+ console.error(error);
89
+ });
90
+ ```
91
+
92
+ ---
93
+
94
+ ### Using Async/Await
95
+
96
+ You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
97
+
98
+ ```javascript
99
+ async function makeRequest() {
103
100
  var query = {
104
101
  domain: "myspace.com"
105
- };
106
-
107
- try {
108
- const data = await api.execute(query);
109
- console.log(data);
110
- } catch (error) {
111
- console.error(error);
112
- }
113
- }
114
- ```
115
-
116
- ---
117
-
118
- ## Example Response
119
-
120
- ```json
102
+ };
103
+
104
+ try {
105
+ const data = await api.execute(query);
106
+ console.log(data);
107
+ } catch (error) {
108
+ console.error(error);
109
+ }
110
+ }
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Example Response
116
+
117
+ ```json
121
118
  {
122
119
  "status": "ok",
123
120
  "error": null,
124
121
  "data": {
125
- "authorized_ips": {
126
- "ipv4": [
127
- "63.208.226.34",
128
- "204.16.32.0/22",
129
- "67.134.143.0/24",
130
- "216.205.243.0/24",
131
- "34.85.156.5/32",
132
- "35.245.108.108/32",
133
- "34.86.129.193/32",
134
- "34.86.134.94/32",
135
- "34.85.222.234/32",
136
- "34.86.176.234/32",
137
- "34.86.125.212/32",
138
- "34.85.224.60/32",
139
- "34.86.160.49/32",
140
- "35.245.64.166/32",
141
- "35.188.226.11/32",
142
- "34.86.208.228/32",
143
- "34.85.216.144/32",
144
- "35.221.22.153/32",
145
- "34.86.137.108/32",
146
- "34.86.51.35/32",
147
- "34.150.221.40/32",
148
- "34.85.216.70/32",
149
- "34.86.37.191/32",
150
- "34.85.214.215/32",
151
- "35.236.234.82/32",
152
- "34.86.161.241/32",
153
- "216.32.181.16",
154
- "216.178.32.0/20",
155
- "168.235.224.0/24",
156
- "195.130.217.0/24",
157
- "91.220.42.0/24",
158
- "146.101.78.0/24",
159
- "207.82.80.0/24",
160
- "213.167.81.0/25",
161
- "193.7.207.0/25",
162
- "213.167.75.0/25",
163
- "185.58.85.0/24",
164
- "185.58.86.0/24",
165
- "193.7.206.0/25",
166
- "147.28.36.0/24",
167
- "207.211.31.0/25",
168
- "205.139.110.0/24",
169
- "216.205.24.0/24",
170
- "170.10.129.0/24",
171
- "63.128.21.0/24",
172
- "170.10.133.0/24",
173
- "185.58.84.93/32",
174
- "207.211.41.113/32",
175
- "207.211.30.64/26",
176
- "207.211.30.128/25",
177
- "216.145.221.0/24",
178
- "170.10.128.0/24",
179
- "170.10.132.56/29",
180
- "170.10.132.64/29",
181
- "41.74.192.0/22",
182
- "41.74.200.0/23",
183
- "41.74.196.0/22",
184
- "41.74.204.0/23",
185
- "41.74.206.0/24",
186
- "51.163.158.0/24",
187
- "194.104.109.0/24",
188
- "194.104.111.0/24",
189
- "194.104.110.21/32",
190
- "194.104.110.240/28",
191
- "62.140.10.21/32",
192
- "62.140.7.0/24",
193
- "194.104.108.240/29",
194
- "194.104.108.21/32",
195
- "103.13.69.0/24",
196
- "124.47.150.0/24",
197
- "124.47.189.0/24",
198
- "103.96.23.0/24",
199
- "103.96.21.0/24",
200
- "180.189.28.0/24",
201
- "216.145.217.0/24",
202
- "103.96.22.96/28",
203
- "103.96.22.22/32",
204
- "103.96.20.22/32",
205
- "103.96.20.96/28",
206
- "170.10.145.0/24",
207
- "170.10.147.0/24",
208
- "170.10.144.126/32",
209
- "170.10.146.126/32",
210
- "170.10.144.240/29",
211
- "170.10.146.240/29",
212
- "216.145.216.0/24"
213
- ]
214
- },
215
- "dns_lookups_num": 8,
216
- "domains_extracted": [
217
- "myspace.com",
218
- "_netblocks.mimecast.com",
219
- "eu._netblocks.mimecast.com",
220
- "us._netblocks.mimecast.com",
221
- "za._netblocks.mimecast.com",
222
- "de._netblocks.mimecast.com",
223
- "au._netblocks.mimecast.com",
224
- "ca._netblocks.mimecast.com"
225
- ],
226
- "elapsed_ms": 1118,
227
- "has_issues": false,
228
- "has_spf_record": true,
229
122
  "host": "myspace.com",
230
- "ip_pass": false,
231
- "macros_found": false,
123
+ "has_spf_record": true,
124
+ "dns_lookups_num": 9,
232
125
  "spf_record": "v=spf1 mx ip4:63.208.226.34 ip4:204.16.32.0/22 ip4:67.134.143.0/24 ip4:216.205.243.0/24 ip4:34.85.156.5/32 ip4:35.245.108.108/32 ip4:34.86.129.193/32 ip4:34.86.134.94/32 ip4:34.85.222.234/32 ip4:34.86.176.234/32 ip4:34.86.125.212/32 ip4:34.85.224.60/32 ip4:34.86.160.49/32 ip4:35.245.64.166/32 ip4:35.188.226.11/32 ip4:34.86.208.228/32 ip4:34.85.216.144/32 ip4:35.221.22.153/32 ip4:34.86.137.108/32 ip4:34.86.51.35/32 ip4:34.150.221.40/32 ip4:34.85.216.70/32 ip4:34.86.37.191/32 ip4:34.85.214.215/32 ip4:35.236.234.82/32 ip4:34.86.161.241/32 ip4:216.32.181.16 ip4:216.178.32.0/20 ip4:168.235.224.0/24 include:_netblocks.mimecast.com -all",
233
126
  "spf_records_list": [
234
127
  {
128
+ "origin": "myspace.com",
129
+ "record": "v=spf1 mx ip4:63.208.226.34 ip4:204.16.32.0/22 ip4:67.134.143.0/24 ip4:216.205.243.0/24 ip4:34.85.156.5/32 ip4:35.245.108.108/32 ip4:34.86.129.193/32 ip4:34.86.134.94/32 ip4:34.85.222.234/32 ip4:34.86.176.234/32 ip4:34.86.125.212/32 ip4:34.85.224.60/32 ip4:34.86.160.49/32 ip4:35.245.64.166/32 ip4:35.188.226.11/32 ip4:34.86.208.228/32 ip4:34.85.216.144/32 ip4:35.221.22.153/32 ip4:34.86.137.108/32 ip4:34.86.51.35/32 ip4:34.150.221.40/32 ip4:34.85.216.70/32 ip4:34.86.37.191/32 ip4:34.85.214.215/32 ip4:35.236.234.82/32 ip4:34.86.161.241/32 ip4:216.32.181.16 ip4:216.178.32.0/20 ip4:168.235.224.0/24 include:_netblocks.mimecast.com -all",
130
+ "chars_num": 637,
131
+ "use_macro": false,
132
+ "domains": [
133
+ "_netblocks.mimecast.com"
134
+ ],
235
135
  "authorized_ips": {
236
136
  "ipv4": [
237
137
  "63.208.226.34",
@@ -264,30 +164,28 @@ async function makeRequest() {
264
164
  "216.178.32.0/20",
265
165
  "168.235.224.0/24"
266
166
  ]
267
- },
268
- "chars_num": 637,
269
- "domains": [
270
- "_netblocks.mimecast.com"
271
- ],
272
- "origin": "myspace.com",
273
- "record": "v=spf1 mx ip4:63.208.226.34 ip4:204.16.32.0/22 ip4:67.134.143.0/24 ip4:216.205.243.0/24 ip4:34.85.156.5/32 ip4:35.245.108.108/32 ip4:34.86.129.193/32 ip4:34.86.134.94/32 ip4:34.85.222.234/32 ip4:34.86.176.234/32 ip4:34.86.125.212/32 ip4:34.85.224.60/32 ip4:34.86.160.49/32 ip4:35.245.64.166/32 ip4:35.188.226.11/32 ip4:34.86.208.228/32 ip4:34.85.216.144/32 ip4:35.221.22.153/32 ip4:34.86.137.108/32 ip4:34.86.51.35/32 ip4:34.150.221.40/32 ip4:34.85.216.70/32 ip4:34.86.37.191/32 ip4:34.85.214.215/32 ip4:35.236.234.82/32 ip4:34.86.161.241/32 ip4:216.32.181.16 ip4:216.178.32.0/20 ip4:168.235.224.0/24 include:_netblocks.mimecast.com -all",
274
- "use_macro": false
167
+ }
275
168
  },
276
169
  {
277
- "chars_num": 221,
170
+ "origin": "_netblocks.mimecast.com",
171
+ "record": "v=spf1 include:eu._netblocks.mimecast.com include:us._netblocks.mimecast.com include:za._netblocks.mimecast.com include:de._netblocks.mimecast.com include:au._netblocks.mimecast.com include:ca._netblocks.mimecast.com include:usb._netblocks.mimecast.com ~all",
172
+ "chars_num": 257,
173
+ "use_macro": false,
278
174
  "domains": [
279
175
  "eu._netblocks.mimecast.com",
280
176
  "us._netblocks.mimecast.com",
281
177
  "za._netblocks.mimecast.com",
282
178
  "de._netblocks.mimecast.com",
283
179
  "au._netblocks.mimecast.com",
284
- "ca._netblocks.mimecast.com"
285
- ],
286
- "origin": "_netblocks.mimecast.com",
287
- "record": "v=spf1 include:eu._netblocks.mimecast.com include:us._netblocks.mimecast.com include:za._netblocks.mimecast.com include:de._netblocks.mimecast.com include:au._netblocks.mimecast.com include:ca._netblocks.mimecast.com ~all",
288
- "use_macro": false
180
+ "ca._netblocks.mimecast.com",
181
+ "usb._netblocks.mimecast.com"
182
+ ]
289
183
  },
290
184
  {
185
+ "origin": "eu._netblocks.mimecast.com",
186
+ "record": "v=spf1 ip4:195.130.217.0/24 ip4:91.220.42.0/24 ip4:146.101.78.0/24 ip4:207.82.80.0/24 ip4:213.167.81.0/25 ip4:193.7.207.0/25 ip4:213.167.75.0/25 ip4:185.58.85.0/24 ip4:185.58.86.0/24 ip4:193.7.206.0/25 ip4:147.28.36.0/24 ~all",
187
+ "chars_num": 225,
188
+ "use_macro": false,
291
189
  "authorized_ips": {
292
190
  "ipv4": [
293
191
  "195.130.217.0/24",
@@ -302,13 +200,13 @@ async function makeRequest() {
302
200
  "193.7.206.0/25",
303
201
  "147.28.36.0/24"
304
202
  ]
305
- },
306
- "chars_num": 225,
307
- "origin": "eu._netblocks.mimecast.com",
308
- "record": "v=spf1 ip4:195.130.217.0/24 ip4:91.220.42.0/24 ip4:146.101.78.0/24 ip4:207.82.80.0/24 ip4:213.167.81.0/25 ip4:193.7.207.0/25 ip4:213.167.75.0/25 ip4:185.58.85.0/24 ip4:185.58.86.0/24 ip4:193.7.206.0/25 ip4:147.28.36.0/24 ~all",
309
- "use_macro": false
203
+ }
310
204
  },
311
205
  {
206
+ "origin": "us._netblocks.mimecast.com",
207
+ "record": "v=spf1 ip4:207.211.31.0/25 ip4:205.139.110.0/24 ip4:216.205.24.0/24 ip4:170.10.129.0/24 ip4:63.128.21.0/24 ip4:170.10.133.0/24 ip4:185.58.84.93/32 ip4:207.211.41.113/32 ip4:207.211.30.64/26 ip4:207.211.30.128/25 ip4:216.145.221.0/24 ip4:170.10.128.0/24 ip4:170.10.132.56/29 ip4:170.10.132.64/29 ~all",
208
+ "chars_num": 299,
209
+ "use_macro": false,
312
210
  "authorized_ips": {
313
211
  "ipv4": [
314
212
  "207.211.31.0/25",
@@ -326,13 +224,13 @@ async function makeRequest() {
326
224
  "170.10.132.56/29",
327
225
  "170.10.132.64/29"
328
226
  ]
329
- },
330
- "chars_num": 299,
331
- "origin": "us._netblocks.mimecast.com",
332
- "record": "v=spf1 ip4:207.211.31.0/25 ip4:205.139.110.0/24 ip4:216.205.24.0/24 ip4:170.10.129.0/24 ip4:63.128.21.0/24 ip4:170.10.133.0/24 ip4:185.58.84.93/32 ip4:207.211.41.113/32 ip4:207.211.30.64/26 ip4:207.211.30.128/25 ip4:216.145.221.0/24 ip4:170.10.128.0/24 ip4:170.10.132.56/29 ip4:170.10.132.64/29 ~all",
333
- "use_macro": false
227
+ }
334
228
  },
335
229
  {
230
+ "origin": "za._netblocks.mimecast.com",
231
+ "record": "v=spf1 ip4:41.74.192.0/22 ip4:41.74.200.0/23 ip4:41.74.196.0/22 ip4:41.74.204.0/23 ip4:41.74.206.0/24 ~all",
232
+ "chars_num": 106,
233
+ "use_macro": false,
336
234
  "authorized_ips": {
337
235
  "ipv4": [
338
236
  "41.74.192.0/22",
@@ -341,13 +239,13 @@ async function makeRequest() {
341
239
  "41.74.204.0/23",
342
240
  "41.74.206.0/24"
343
241
  ]
344
- },
345
- "chars_num": 106,
346
- "origin": "za._netblocks.mimecast.com",
347
- "record": "v=spf1 ip4:41.74.192.0/22 ip4:41.74.200.0/23 ip4:41.74.196.0/22 ip4:41.74.204.0/23 ip4:41.74.206.0/24 ~all",
348
- "use_macro": false
242
+ }
349
243
  },
350
244
  {
245
+ "origin": "de._netblocks.mimecast.com",
246
+ "record": "v=spf1 ip4:51.163.158.0/24 ip4:194.104.109.0/24 ip4:194.104.111.0/24 ip4:194.104.110.21/32 ip4:194.104.110.240/28 ip4:62.140.10.21/32 ip4:62.140.7.0/24 ip4:194.104.108.240/29 ip4:194.104.108.21/32 ip4:51.163.159.0/24 ~all",
247
+ "chars_num": 221,
248
+ "use_macro": false,
351
249
  "authorized_ips": {
352
250
  "ipv4": [
353
251
  "51.163.158.0/24",
@@ -358,15 +256,16 @@ async function makeRequest() {
358
256
  "62.140.10.21/32",
359
257
  "62.140.7.0/24",
360
258
  "194.104.108.240/29",
361
- "194.104.108.21/32"
259
+ "194.104.108.21/32",
260
+ "51.163.159.0/24"
362
261
  ]
363
- },
364
- "chars_num": 201,
365
- "origin": "de._netblocks.mimecast.com",
366
- "record": "v=spf1 ip4:51.163.158.0/24 ip4:194.104.109.0/24 ip4:194.104.111.0/24 ip4:194.104.110.21/32 ip4:194.104.110.240/28 ip4:62.140.10.21/32 ip4:62.140.7.0/24 ip4:194.104.108.240/29 ip4:194.104.108.21/32 ~all",
367
- "use_macro": false
262
+ }
368
263
  },
369
264
  {
265
+ "origin": "au._netblocks.mimecast.com",
266
+ "record": "v=spf1 ip4:103.13.69.0/24 ip4:124.47.150.0/24 ip4:124.47.189.0/24 ip4:103.96.23.0/24 ip4:103.96.21.0/24 ip4:180.189.28.0/24 ip4:216.145.217.0/24 ip4:103.96.22.96/28 ip4:103.96.22.22/32 ip4:103.96.20.22/32 ip4:103.96.20.96/28 ~all",
267
+ "chars_num": 229,
268
+ "use_macro": false,
370
269
  "authorized_ips": {
371
270
  "ipv4": [
372
271
  "103.13.69.0/24",
@@ -381,13 +280,13 @@ async function makeRequest() {
381
280
  "103.96.20.22/32",
382
281
  "103.96.20.96/28"
383
282
  ]
384
- },
385
- "chars_num": 229,
386
- "origin": "au._netblocks.mimecast.com",
387
- "record": "v=spf1 ip4:103.13.69.0/24 ip4:124.47.150.0/24 ip4:124.47.189.0/24 ip4:103.96.23.0/24 ip4:103.96.21.0/24 ip4:180.189.28.0/24 ip4:216.145.217.0/24 ip4:103.96.22.96/28 ip4:103.96.22.22/32 ip4:103.96.20.22/32 ip4:103.96.20.96/28 ~all",
388
- "use_macro": false
283
+ }
389
284
  },
390
285
  {
286
+ "origin": "ca._netblocks.mimecast.com",
287
+ "record": "v=spf1 ip4:170.10.145.0/24 ip4:170.10.147.0/24 ip4:170.10.144.126/32 ip4:170.10.146.126/32 ip4:170.10.144.240/29 ip4:170.10.146.240/29 ip4:216.145.216.0/24 ~all",
288
+ "chars_num": 160,
289
+ "use_macro": false,
391
290
  "authorized_ips": {
392
291
  "ipv4": [
393
292
  "170.10.145.0/24",
@@ -398,45 +297,174 @@ async function makeRequest() {
398
297
  "170.10.146.240/29",
399
298
  "216.145.216.0/24"
400
299
  ]
401
- },
402
- "chars_num": 160,
403
- "origin": "ca._netblocks.mimecast.com",
404
- "record": "v=spf1 ip4:170.10.145.0/24 ip4:170.10.147.0/24 ip4:170.10.144.126/32 ip4:170.10.146.126/32 ip4:170.10.144.240/29 ip4:170.10.146.240/29 ip4:216.145.216.0/24 ~all",
405
- "use_macro": false
300
+ }
301
+ },
302
+ {
303
+ "origin": "usb._netblocks.mimecast.com",
304
+ "record": "v=spf1 ip4:170.10.151.0/24 ip4:170.10.153.0/24 ip4:170.10.150.240/29 ip4:170.10.152.240/29 ip4:170.10.156.0/24 ip4:170.10.157.0/24 ~all",
305
+ "chars_num": 135,
306
+ "use_macro": false,
307
+ "authorized_ips": {
308
+ "ipv4": [
309
+ "170.10.151.0/24",
310
+ "170.10.153.0/24",
311
+ "170.10.150.240/29",
312
+ "170.10.152.240/29",
313
+ "170.10.156.0/24",
314
+ "170.10.157.0/24"
315
+ ]
316
+ }
406
317
  }
407
318
  ],
408
- "spf_valid": true
319
+ "domains_extracted": [
320
+ "myspace.com",
321
+ "_netblocks.mimecast.com",
322
+ "eu._netblocks.mimecast.com",
323
+ "us._netblocks.mimecast.com",
324
+ "za._netblocks.mimecast.com",
325
+ "de._netblocks.mimecast.com",
326
+ "au._netblocks.mimecast.com",
327
+ "ca._netblocks.mimecast.com",
328
+ "usb._netblocks.mimecast.com"
329
+ ],
330
+ "authorized_ips": {
331
+ "ipv4": [
332
+ "63.208.226.34",
333
+ "204.16.32.0/22",
334
+ "67.134.143.0/24",
335
+ "216.205.243.0/24",
336
+ "34.85.156.5/32",
337
+ "35.245.108.108/32",
338
+ "34.86.129.193/32",
339
+ "34.86.134.94/32",
340
+ "34.85.222.234/32",
341
+ "34.86.176.234/32",
342
+ "34.86.125.212/32",
343
+ "34.85.224.60/32",
344
+ "34.86.160.49/32",
345
+ "35.245.64.166/32",
346
+ "35.188.226.11/32",
347
+ "34.86.208.228/32",
348
+ "34.85.216.144/32",
349
+ "35.221.22.153/32",
350
+ "34.86.137.108/32",
351
+ "34.86.51.35/32",
352
+ "34.150.221.40/32",
353
+ "34.85.216.70/32",
354
+ "34.86.37.191/32",
355
+ "34.85.214.215/32",
356
+ "35.236.234.82/32",
357
+ "34.86.161.241/32",
358
+ "216.32.181.16",
359
+ "216.178.32.0/20",
360
+ "168.235.224.0/24",
361
+ "195.130.217.0/24",
362
+ "91.220.42.0/24",
363
+ "146.101.78.0/24",
364
+ "207.82.80.0/24",
365
+ "213.167.81.0/25",
366
+ "193.7.207.0/25",
367
+ "213.167.75.0/25",
368
+ "185.58.85.0/24",
369
+ "185.58.86.0/24",
370
+ "193.7.206.0/25",
371
+ "147.28.36.0/24",
372
+ "207.211.31.0/25",
373
+ "205.139.110.0/24",
374
+ "216.205.24.0/24",
375
+ "170.10.129.0/24",
376
+ "63.128.21.0/24",
377
+ "170.10.133.0/24",
378
+ "185.58.84.93/32",
379
+ "207.211.41.113/32",
380
+ "207.211.30.64/26",
381
+ "207.211.30.128/25",
382
+ "216.145.221.0/24",
383
+ "170.10.128.0/24",
384
+ "170.10.132.56/29",
385
+ "170.10.132.64/29",
386
+ "41.74.192.0/22",
387
+ "41.74.200.0/23",
388
+ "41.74.196.0/22",
389
+ "41.74.204.0/23",
390
+ "41.74.206.0/24",
391
+ "51.163.158.0/24",
392
+ "194.104.109.0/24",
393
+ "194.104.111.0/24",
394
+ "194.104.110.21/32",
395
+ "194.104.110.240/28",
396
+ "62.140.10.21/32",
397
+ "62.140.7.0/24",
398
+ "194.104.108.240/29",
399
+ "194.104.108.21/32",
400
+ "51.163.159.0/24",
401
+ "103.13.69.0/24",
402
+ "124.47.150.0/24",
403
+ "124.47.189.0/24",
404
+ "103.96.23.0/24",
405
+ "103.96.21.0/24",
406
+ "180.189.28.0/24",
407
+ "216.145.217.0/24",
408
+ "103.96.22.96/28",
409
+ "103.96.22.22/32",
410
+ "103.96.20.22/32",
411
+ "103.96.20.96/28",
412
+ "170.10.145.0/24",
413
+ "170.10.147.0/24",
414
+ "170.10.144.126/32",
415
+ "170.10.146.126/32",
416
+ "170.10.144.240/29",
417
+ "170.10.146.240/29",
418
+ "216.145.216.0/24",
419
+ "170.10.151.0/24",
420
+ "170.10.153.0/24",
421
+ "170.10.150.240/29",
422
+ "170.10.152.240/29",
423
+ "170.10.156.0/24",
424
+ "170.10.157.0/24"
425
+ ],
426
+ "ipv6": []
427
+ },
428
+ "issues_found": [],
429
+ "spf_valid": true,
430
+ "has_issues": false,
431
+ "macros_found": false,
432
+ "ip_pass": false,
433
+ "elapsed_ms": 431,
434
+ "all_qualifier": "fail",
435
+ "risk_score": 5,
436
+ "risk_level": "low"
409
437
  }
410
- }
411
- ```
412
-
413
- ---
414
-
415
- ## Customer Support
416
-
417
- Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=readme).
418
-
419
- ---
420
-
421
- ## Updates
422
-
423
- Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
424
-
425
- ---
426
-
427
- ## Legal
428
-
429
- All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=readme), [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=readme), and [Refund Policy](https://apiverve.com/refund?utm_source=npm&utm_medium=readme).
430
-
431
- ---
432
-
433
- ## License
434
- Licensed under the The MIT License (MIT)
435
-
436
- Copyright (©) 2026 APIVerve, and EvlarSoft LLC
437
-
438
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
439
-
440
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
441
-
442
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
438
+ }
439
+ ```
440
+
441
+ ---
442
+
443
+ ## Customer Support
444
+
445
+ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=referral&utm_content=readme).
446
+
447
+ ---
448
+
449
+ ## Updates
450
+
451
+ Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
452
+
453
+ ---
454
+
455
+ ## Legal
456
+
457
+ All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=referral&utm_content=readme) and [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=referral&utm_content=readme).
458
+
459
+ ---
460
+
461
+ ## License
462
+ Licensed under the MIT License (MIT)
463
+
464
+ Copyright (©) 2026 APIVerve, and EvlarSoft LLC
465
+
466
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
467
+
468
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
469
+
470
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/index.d.ts CHANGED
@@ -1,50 +1,66 @@
1
- declare module '@apiverve/spfvalidator' {
2
- export interface spfvalidatorOptions {
3
- api_key: string;
4
- secure?: boolean;
5
- }
6
-
7
- export interface spfvalidatorResponse {
8
- status: string;
9
- error: string | null;
10
- data: SPFValidatorData;
11
- code?: number;
12
- }
13
-
1
+ declare module '@apiverve/spfvalidator' {
2
+ export interface spfvalidatorOptions {
3
+ api_key: string;
4
+ secure?: boolean;
5
+ }
6
+
7
+ /**
8
+ * Describes fields the current plan does not unlock. Locked fields arrive as null
9
+ * in `data`; `locked_fields` names them, using dot paths for nested fields.
10
+ * Absent when the plan unlocks everything.
11
+ */
12
+ export interface PremiumInfo {
13
+ message: string;
14
+ upgrade_url: string;
15
+ locked_fields: string[];
16
+ }
17
+
18
+ export interface spfvalidatorResponse {
19
+ status: string;
20
+ error: string | null;
21
+ data: SPFValidatorData;
22
+ code?: number;
23
+ premium?: PremiumInfo;
24
+ }
25
+
14
26
 
15
27
  interface SPFValidatorData {
16
- authorizedIPS: AuthorizedIPS;
17
- dnsLookupsNum: number;
18
- domainsExtracted: string[];
19
- elapsedMS: number;
20
- hasIssues: boolean;
21
- hasSPFRecord: boolean;
22
- host: string;
23
- ipPass: boolean;
24
- macrosFound: boolean;
25
- spfRecord: string;
28
+ host: null | string;
29
+ hasSPFRecord: boolean | null;
30
+ dnsLookupsNum: number | null;
31
+ spfRecord: null | string;
26
32
  spfRecordsList: SPFRecordsList[];
27
- spfValid: boolean;
28
- }
29
-
30
- interface AuthorizedIPS {
31
- ipv4: string[];
33
+ domainsExtracted: (null | string)[];
34
+ authorizedIPS: { [key: string]: (null | string)[] };
35
+ issuesFound: any[];
36
+ spfValid: boolean | null;
37
+ hasIssues: boolean | null;
38
+ macrosFound: boolean | null;
39
+ ipPass: boolean | null;
40
+ elapsedMS: number | null;
41
+ allQualifier: null | string;
42
+ riskScore: number | null;
43
+ riskLevel: null | string;
32
44
  }
33
45
 
34
46
  interface SPFRecordsList {
47
+ origin: null | string;
48
+ record: null | string;
49
+ charsNum: number | null;
50
+ useMacro: boolean | null;
51
+ domains?: (null | string)[];
35
52
  authorizedIPS?: AuthorizedIPS;
36
- charsNum: number;
37
- domains?: string[];
38
- origin: string;
39
- record: string;
40
- useMacro: boolean;
41
53
  }
54
+
55
+ interface AuthorizedIPS {
56
+ ipv4: (null | string)[];
57
+ }
58
+
59
+ export default class spfvalidatorWrapper {
60
+ constructor(options: spfvalidatorOptions);
42
61
 
43
- export default class spfvalidatorWrapper {
44
- constructor(options: spfvalidatorOptions);
45
-
46
- execute(callback: (error: any, data: spfvalidatorResponse | null) => void): Promise<spfvalidatorResponse>;
47
- execute(query: Record<string, any>, callback: (error: any, data: spfvalidatorResponse | null) => void): Promise<spfvalidatorResponse>;
48
- execute(query?: Record<string, any>): Promise<spfvalidatorResponse>;
49
- }
50
- }
62
+ execute(callback: (error: any, data: spfvalidatorResponse | null) => void): Promise<spfvalidatorResponse>;
63
+ execute(query: Record<string, any>, callback: (error: any, data: spfvalidatorResponse | null) => void): Promise<spfvalidatorResponse>;
64
+ execute(query?: Record<string, any>): Promise<spfvalidatorResponse>;
65
+ }
66
+ }
package/index.js CHANGED
@@ -1,209 +1,209 @@
1
- const axios = require('axios');
2
-
3
- class spfvalidatorWrapper {
4
-
5
- constructor(options) {
6
- if (!options || typeof options !== 'object') {
7
- throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/spfvalidator');
8
- }
9
-
10
- const { api_key, secure = true } = options;
11
-
12
- if (!api_key || typeof api_key !== 'string') {
13
- throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
14
- }
15
-
16
- // Validate API key format (GUID, prefixed keys like apv_xxx, or alphanumeric)
17
- const apiKeyPattern = /^[a-zA-Z0-9_-]+$/;
18
- if (!apiKeyPattern.test(api_key)) {
19
- throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens and underscores. Get your API key at: https://apiverve.com');
20
- }
21
-
22
- if (typeof secure !== 'boolean') {
23
- throw new Error('Secure parameter must be a boolean value.');
24
- }
25
-
26
- this.APIKey = api_key;
27
- this.IsSecure = secure;
28
-
29
- // secure is deprecated, all requests must be made over HTTPS
30
- this.baseURL = 'https://api.apiverve.com/v1/spfvalidator';
31
-
32
- // Validation rules for parameters (generated from schema)
33
- this.validationRules = {"domain":{"type":"string","required":true}};
34
- }
35
-
36
- /**
37
- * Validate query parameters against schema rules
38
- * @param {Object} query - The query parameters to validate
39
- * @throws {Error} - If validation fails
40
- */
41
- validateParams(query) {
42
- const errors = [];
43
-
44
- for (const [paramName, rules] of Object.entries(this.validationRules)) {
45
- const value = query[paramName];
46
-
47
- // Check required
48
- if (rules.required && (value === undefined || value === null || value === '')) {
49
- errors.push(`Required parameter [${paramName}] is missing.`);
50
- continue;
51
- }
52
-
53
- // Skip validation if value is not provided and not required
54
- if (value === undefined || value === null) {
55
- continue;
56
- }
57
-
58
- // Type validation
59
- if (rules.type === 'integer' || rules.type === 'number') {
60
- const numValue = Number(value);
61
- if (isNaN(numValue)) {
62
- errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
63
- continue;
64
- }
65
-
66
- if (rules.type === 'integer' && !Number.isInteger(numValue)) {
67
- errors.push(`Parameter [${paramName}] must be an integer.`);
68
- continue;
69
- }
70
-
71
- // Min/max validation for numbers
72
- if (rules.min !== undefined && numValue < rules.min) {
73
- errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
74
- }
75
- if (rules.max !== undefined && numValue > rules.max) {
76
- errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
77
- }
78
- } else if (rules.type === 'string') {
79
- if (typeof value !== 'string') {
80
- errors.push(`Parameter [${paramName}] must be a string.`);
81
- continue;
82
- }
83
-
84
- // Length validation for strings
85
- if (rules.minLength !== undefined && value.length < rules.minLength) {
86
- errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
87
- }
88
- if (rules.maxLength !== undefined && value.length > rules.maxLength) {
89
- errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
90
- }
91
-
92
- // Format validation
93
- if (rules.format) {
94
- const formatPatterns = {
95
- 'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
96
- 'url': /^https?:\/\/.+/i,
97
- 'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
98
- 'date': /^\d{4}-\d{2}-\d{2}$/,
99
- 'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
100
- };
101
-
102
- if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
103
- errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
104
- }
105
- }
106
- } else if (rules.type === 'boolean') {
107
- if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
108
- errors.push(`Parameter [${paramName}] must be a boolean.`);
109
- }
110
- } else if (rules.type === 'array') {
111
- if (!Array.isArray(value)) {
112
- errors.push(`Parameter [${paramName}] must be an array.`);
113
- }
114
- }
115
-
116
- // Enum validation
117
- if (rules.enum && Array.isArray(rules.enum)) {
118
- if (!rules.enum.includes(value)) {
119
- errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
120
- }
121
- }
122
- }
123
-
124
- if (errors.length > 0) {
125
- throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/spfvalidator`);
126
- }
127
- }
128
-
129
- async execute(query, callback) {
130
- // Handle different argument patterns
131
- if(arguments.length === 0) {
132
- // execute() - no args
133
- query = {};
134
- callback = null;
135
- } else if(arguments.length === 1) {
136
- if (typeof query === 'function') {
137
- // execute(callback)
138
- callback = query;
139
- query = {};
140
- } else {
141
- // execute(query)
142
- callback = null;
143
- }
144
- } else {
145
- // execute(query, callback)
146
- if (!query || typeof query !== 'object') {
147
- throw new Error('Query parameters must be provided as an object.');
148
- }
149
- }
150
-
151
- // Validate parameters against schema rules
152
- this.validateParams(query);
153
-
154
- const method = 'GET';
155
- const url = method === 'POST' ? this.baseURL : this.constructURL(query);
156
-
157
- try {
158
- const response = await axios({
159
- method,
160
- url,
161
- headers: {
162
- 'Content-Type': 'application/json',
163
- 'x-api-key': this.APIKey,
164
- 'auth-mode': 'npm-package'
165
- },
166
- data: method === 'POST' ? query : undefined
167
- });
168
-
169
- const data = response.data;
170
- if (callback) callback(null, data);
171
- return data;
172
- } catch (error) {
173
- let apiError;
174
-
175
- if (error.response && error.response.data) {
176
- apiError = error.response.data;
177
- } else if (error.message) {
178
- apiError = { error: error.message, status: 'error' };
179
- } else {
180
- apiError = { error: 'An unknown error occurred', status: 'error' };
181
- }
182
-
183
- if (callback) {
184
- callback(apiError, null);
185
- return; // Don't throw if callback is provided
186
- }
187
-
188
- throw apiError;
189
- }
190
- }
191
-
192
- constructURL(query) {
193
- let url = this.baseURL;
194
-
195
- if(query && typeof query === 'object')
196
- {
197
- if (Object.keys(query).length > 0) {
198
- const queryString = Object.keys(query)
199
- .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
200
- .join('&');
201
- url += `?${queryString}`;
202
- }
203
- }
204
- return url;
205
- }
206
-
207
- }
208
-
209
- module.exports = spfvalidatorWrapper;
1
+ const axios = require('axios');
2
+
3
+ class spfvalidatorWrapper {
4
+
5
+ constructor(options) {
6
+ if (!options || typeof options !== 'object') {
7
+ throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/spfvalidator');
8
+ }
9
+
10
+ const { api_key, secure = true } = options;
11
+
12
+ if (!api_key || typeof api_key !== 'string') {
13
+ throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
14
+ }
15
+
16
+ // Validate API key format (GUID, prefixed keys like apv_xxx, or alphanumeric)
17
+ const apiKeyPattern = /^[a-zA-Z0-9_-]+$/;
18
+ if (!apiKeyPattern.test(api_key)) {
19
+ throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens and underscores. Get your API key at: https://apiverve.com');
20
+ }
21
+
22
+ if (typeof secure !== 'boolean') {
23
+ throw new Error('Secure parameter must be a boolean value.');
24
+ }
25
+
26
+ this.APIKey = api_key;
27
+ this.IsSecure = secure;
28
+
29
+ // secure is deprecated, all requests must be made over HTTPS
30
+ this.baseURL = 'https://api.apiverve.com/v1/spfvalidator';
31
+
32
+ // Validation rules for parameters (generated from schema)
33
+ this.validationRules = {"domain":{"type":"string","required":true,"format":"domain"}};
34
+ }
35
+
36
+ /**
37
+ * Validate query parameters against schema rules
38
+ * @param {Object} query - The query parameters to validate
39
+ * @throws {Error} - If validation fails
40
+ */
41
+ validateParams(query) {
42
+ const errors = [];
43
+
44
+ for (const [paramName, rules] of Object.entries(this.validationRules)) {
45
+ const value = query[paramName];
46
+
47
+ // Check required
48
+ if (rules.required && (value === undefined || value === null || value === '')) {
49
+ errors.push(`Required parameter [${paramName}] is missing.`);
50
+ continue;
51
+ }
52
+
53
+ // Skip validation if value is not provided and not required
54
+ if (value === undefined || value === null) {
55
+ continue;
56
+ }
57
+
58
+ // Type validation
59
+ if (rules.type === 'integer' || rules.type === 'number') {
60
+ const numValue = Number(value);
61
+ if (isNaN(numValue)) {
62
+ errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
63
+ continue;
64
+ }
65
+
66
+ if (rules.type === 'integer' && !Number.isInteger(numValue)) {
67
+ errors.push(`Parameter [${paramName}] must be an integer.`);
68
+ continue;
69
+ }
70
+
71
+ // Min/max validation for numbers
72
+ if (rules.min !== undefined && numValue < rules.min) {
73
+ errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
74
+ }
75
+ if (rules.max !== undefined && numValue > rules.max) {
76
+ errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
77
+ }
78
+ } else if (rules.type === 'string') {
79
+ if (typeof value !== 'string') {
80
+ errors.push(`Parameter [${paramName}] must be a string.`);
81
+ continue;
82
+ }
83
+
84
+ // Length validation for strings
85
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
86
+ errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
87
+ }
88
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
89
+ errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
90
+ }
91
+
92
+ // Format validation
93
+ if (rules.format) {
94
+ const formatPatterns = {
95
+ 'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
96
+ 'url': /^https?:\/\/.+/i,
97
+ 'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
98
+ 'date': /^\d{4}-\d{2}-\d{2}$/,
99
+ 'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
100
+ };
101
+
102
+ if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
103
+ errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
104
+ }
105
+ }
106
+ } else if (rules.type === 'boolean') {
107
+ if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
108
+ errors.push(`Parameter [${paramName}] must be a boolean.`);
109
+ }
110
+ } else if (rules.type === 'array') {
111
+ if (!Array.isArray(value)) {
112
+ errors.push(`Parameter [${paramName}] must be an array.`);
113
+ }
114
+ }
115
+
116
+ // Enum validation
117
+ if (rules.enum && Array.isArray(rules.enum)) {
118
+ if (!rules.enum.includes(value)) {
119
+ errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
120
+ }
121
+ }
122
+ }
123
+
124
+ if (errors.length > 0) {
125
+ throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/spfvalidator`);
126
+ }
127
+ }
128
+
129
+ async execute(query, callback) {
130
+ // Handle different argument patterns
131
+ if(arguments.length === 0) {
132
+ // execute() - no args
133
+ query = {};
134
+ callback = null;
135
+ } else if(arguments.length === 1) {
136
+ if (typeof query === 'function') {
137
+ // execute(callback)
138
+ callback = query;
139
+ query = {};
140
+ } else {
141
+ // execute(query)
142
+ callback = null;
143
+ }
144
+ } else {
145
+ // execute(query, callback)
146
+ if (!query || typeof query !== 'object') {
147
+ throw new Error('Query parameters must be provided as an object.');
148
+ }
149
+ }
150
+
151
+ // Validate parameters against schema rules
152
+ this.validateParams(query);
153
+
154
+ const method = 'GET';
155
+ const url = method === 'POST' ? this.baseURL : this.constructURL(query);
156
+
157
+ try {
158
+ const response = await axios({
159
+ method,
160
+ url,
161
+ headers: {
162
+ 'Content-Type': 'application/json',
163
+ 'x-api-key': this.APIKey,
164
+ 'auth-mode': 'npm-package'
165
+ },
166
+ data: method === 'POST' ? query : undefined
167
+ });
168
+
169
+ const data = response.data;
170
+ if (callback) callback(null, data);
171
+ return data;
172
+ } catch (error) {
173
+ let apiError;
174
+
175
+ if (error.response && error.response.data) {
176
+ apiError = error.response.data;
177
+ } else if (error.message) {
178
+ apiError = { error: error.message, status: 'error' };
179
+ } else {
180
+ apiError = { error: 'An unknown error occurred', status: 'error' };
181
+ }
182
+
183
+ if (callback) {
184
+ callback(apiError, null);
185
+ return; // Don't throw if callback is provided
186
+ }
187
+
188
+ throw apiError;
189
+ }
190
+ }
191
+
192
+ constructURL(query) {
193
+ let url = this.baseURL;
194
+
195
+ if(query && typeof query === 'object')
196
+ {
197
+ if (Object.keys(query).length > 0) {
198
+ const queryString = Object.keys(query)
199
+ .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
200
+ .join('&');
201
+ url += `?${queryString}`;
202
+ }
203
+ }
204
+ return url;
205
+ }
206
+
207
+ }
208
+
209
+ module.exports = spfvalidatorWrapper;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@apiverve/spfvalidator",
3
- "version": "1.1.14",
3
+ "version": "1.2.2",
4
4
  "description": "SPF Validator checks the Sender Policy Framework (SPF) DNS record for a domain to verify if it’s valid and optionally whether a given IP address is authorized to send emails for that domain.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "sideEffects": false,
8
8
  "engines": {
9
- "node": ">=14.0.0"
9
+ "node": ">=18.0.0"
10
10
  },
11
11
  "files": [
12
12
  "index.js",
@@ -23,7 +23,7 @@
23
23
  "directory": "npm"
24
24
  },
25
25
  "keywords": [
26
- ""
26
+ "spf", "spf check", "spf validator", "spf test", "email authentication"
27
27
  ],
28
28
  "author": {
29
29
  "name": "APIVerve",
@@ -34,15 +34,14 @@
34
34
  "bugs": {
35
35
  "url": "https://github.com/apiverve/spfvalidator-api/issues"
36
36
  },
37
- "homepage": "https://spfvalidator.apiverve.com?utm_source=npm&utm_medium=homepage",
37
+ "homepage": "https://apiverve.com/marketplace/spfvalidator?utm_source=npm&utm_medium=referral&utm_content=homepage",
38
38
  "devDependencies": {
39
39
  "mocha": "^11.0.1",
40
40
  "chai": "^5.1.2",
41
41
  "dotenv": "^16.4.7"
42
42
  },
43
43
  "dependencies": {
44
- "node-fetch": "^3.3.2",
45
- "promise": "^8.3.0",
46
- "axios": "1.13.2"
44
+ "axios": "1.13.2",
45
+ "form-data": "^4.0.1"
47
46
  }
48
47
  }