({ inputs, params }, context)
| 147 | deprecated: false, |
| 148 | }, |
| 149 | async execute({ inputs, params }, context) { |
| 150 | const { ipAddress, apiKey } = inputs; |
| 151 | const { maxAgeInDays, verbose } = params; |
| 152 | |
| 153 | if (!ipAddress) { |
| 154 | throw new ValidationError('IP Address is required', { |
| 155 | fieldErrors: { ipAddress: ['IP Address is required'] }, |
| 156 | }); |
| 157 | } |
| 158 | if (!apiKey) { |
| 159 | throw new ConfigurationError('AbuseIPDB API Key is required', { |
| 160 | configKey: 'apiKey', |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | const endpoint = 'https://api.abuseipdb.com/api/v2/check'; |
| 165 | const queryParams = new URLSearchParams({ |
| 166 | ipAddress, |
| 167 | maxAgeInDays: String(maxAgeInDays), |
| 168 | }); |
| 169 | if (verbose) { |
| 170 | queryParams.append('verbose', 'true'); |
| 171 | } |
| 172 | |
| 173 | const url = `${endpoint}?${queryParams.toString()}`; |
| 174 | |
| 175 | context.logger.info(`[AbuseIPDB] Checking IP: ${ipAddress}`); |
| 176 | |
| 177 | const response = await context.http.fetch(url, { |
| 178 | method: 'GET', |
| 179 | headers: { |
| 180 | Key: apiKey, |
| 181 | Accept: 'application/json', |
| 182 | }, |
| 183 | }); |
| 184 | |
| 185 | if (response.status === 404) { |
| 186 | context.logger.warn(`[AbuseIPDB] IP not found: ${ipAddress}`); |
| 187 | return { |
| 188 | ipAddress, |
| 189 | results: [], |
| 190 | abuseConfidenceScore: 0, |
| 191 | full_report: { error: 'Not Found' }, |
| 192 | }; |
| 193 | } |
| 194 | |
| 195 | if (!response.ok) { |
| 196 | const text = await response.text(); |
| 197 | throw fromHttpResponse(response, text); |
| 198 | } |
| 199 | |
| 200 | const data = (await response.json()) as Record<string, unknown>; |
| 201 | const info = (data.data || {}) as Record<string, unknown>; |
| 202 | |
| 203 | const abuseConfidenceScore = info.abuseConfidenceScore as number; |
| 204 | |
| 205 | context.logger.info(`[AbuseIPDB] Score for ${ipAddress}: ${abuseConfidenceScore}`); |
| 206 |
nothing calls this directly
no test coverage detected