chapybara 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Anderson L Polo A
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
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # Chapybara NodeJS SDK
2
+
3
+ The official NodeJS SDK for the Chapybara Domain & IP Intelligence API.
4
+
5
+ ## Features
6
+
7
+ - **Fluent, Promise-based API**: Modern and easy to use with `async/await`.
8
+ - **Automatic Retries**: Automatically retries failed requests on server errors (5xx) with exponential backoff.
9
+ - **Configurable Caching**: Built-in LRU caching to reduce latency and save on API quotas.
10
+ - **TypeScript Support**: Ships with detailed type definitions for a superior developer experience.
11
+ - **Custom Error Handling**: Throws specific error types for robust error management.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install chapybara
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ First, import and instantiate the client with your API key.
22
+
23
+ ```javascript
24
+ import { ChapybaraClient } from "chapybara";
25
+
26
+ const chapybara = new ChapybaraClient({
27
+ apiKey: "ck_your_api_key_here",
28
+ });
29
+ ```
30
+
31
+ ### Get Domain Intelligence
32
+
33
+ ```javascript
34
+ async function getDomainInfo() {
35
+ try {
36
+ const data = await chapybara.domain.getIntelligence("google.com");
37
+ console.log(data.domain_identity);
38
+ console.log(data.security_analysis);
39
+ } catch (error) {
40
+ console.error(`Error fetching domain data: ${error.message}`);
41
+ }
42
+ }
43
+
44
+ getDomainInfo();
45
+ ```
46
+
47
+ ### Get IP Intelligence
48
+
49
+ ```javascript
50
+ async function getIpInfo() {
51
+ try {
52
+ const data = await chapybara.ip.getIntelligence("8.8.8.8");
53
+ console.log(data.location.country.name);
54
+ console.log(data.network.organization);
55
+ } catch (error) {
56
+ console.error(`Error fetching IP data: ${error.message}`);
57
+ }
58
+ }
59
+
60
+ getIpInfo();
61
+ ```
62
+
63
+ ### Get Web Tech Data
64
+
65
+ ```javascript
66
+ async function getWebTechInfo() {
67
+ try {
68
+ const data = await chapybara.webtech.getScanner("github.com");
69
+ console.log(data.title);
70
+ console.log(data.technologies);
71
+ } catch (error) {
72
+ console.error(`Error fetching web tech data: ${error.message}`);
73
+ }
74
+ }
75
+
76
+ getWebTechInfo();
77
+ ```
78
+
79
+ ### Get Account Information
80
+
81
+ ```javascript
82
+ async function getAccountDetails() {
83
+ try {
84
+ const data = await chapybara.account.getInfo();
85
+ console.log("Domain quota remaining:", data.quotas.domain.remaining);
86
+ } catch (error) {
87
+ console.error(`Error fetching account info: ${error.message}`);
88
+ }
89
+ }
90
+
91
+ getAccountDetails();
92
+ ```
93
+
94
+ ## Configuration
95
+
96
+ You can pass a configuration object to the `ChapybaraClient` constructor:
97
+
98
+ ```javascript
99
+ const chapybara = new ChapybaraClient({
100
+ apiKey: "ck_your_api_key_here",
101
+ baseUrl: "https://api.chapyapi.com/api/v1", // Optional: override base URL
102
+ retries: 2, // Optional: number of retries on server errors (default: 2)
103
+ timeout: 15000, // Optional: request timeout in ms (default: 20000)
104
+ cacheOptions: {
105
+ // Optional: LRU cache options
106
+ max: 500, // Max number of items in cache
107
+ ttl: 1000 * 60 * 5, // Cache TTL in ms (5 minutes)
108
+ },
109
+ });
110
+ ```
111
+
112
+ ## Error Handling
113
+
114
+ The SDK throws custom errors for different API responses, allowing you to handle them gracefully. All errors extend `ChapybaraError`.
115
+
116
+ - `AuthenticationError`: Invalid or missing API key (401, 403).
117
+ - `RateLimitError`: Rate limit exceeded (429).
118
+ - `NotFoundError`: Resource not found (404).
119
+ - `BadRequestError`: Invalid input (400, 402).
120
+ - `ServerError`: An error occurred on the Chapybara servers (5xx).
121
+ - `APIError`: A generic API error.
122
+
123
+ ```javascript
124
+ import { RateLimitError, AuthenticationError } from "chapybara";
125
+
126
+ async function handleErrors() {
127
+ try {
128
+ await chapybara.domain.getIntelligence("invalid-domain");
129
+ } catch (error) {
130
+ if (error instanceof RateLimitError) {
131
+ console.log("Rate limit hit. Please wait before trying again.");
132
+ } else if (error instanceof AuthenticationError) {
133
+ console.log("Authentication failed. Please check your API key.");
134
+ } else {
135
+ console.log(`An API error occurred: ${error.message}`);
136
+ console.log(`Request ID: ${error.requestId}`);
137
+ }
138
+ }
139
+ }
140
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,100 @@
1
+ import type { LRUCache } from "lru-cache";
2
+
3
+ declare module "chapybara" {
4
+ interface ChapybaraClientOptions {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ retries?: number;
8
+ timeout?: number;
9
+ cacheOptions?: LRUCache.Options<string, any, unknown>;
10
+ }
11
+
12
+ // API Response Types
13
+ interface DomainIntelligenceResponse {
14
+ domain_identity: any;
15
+ classification: any;
16
+ dns_records: any;
17
+ dns_analysis: any;
18
+ tls_certificate: any;
19
+ network_details: any;
20
+ security_analysis: any;
21
+ metadata: any;
22
+ }
23
+
24
+ interface IPIntelligenceResponse {
25
+ ip: string;
26
+ hostnames: string[];
27
+ location: any;
28
+ network: any;
29
+ time_zone: string | null;
30
+ security: any;
31
+ ads: any;
32
+ metadata: any;
33
+ }
34
+
35
+ interface WebTechResponse {
36
+ domain: string;
37
+ final_url: string;
38
+ status_code: number;
39
+ title: string | null;
40
+ meta: any;
41
+ headers: Record<string, string | string[]>;
42
+ security_headers: Record<string, string | string[]>;
43
+ cookies: string[];
44
+ links: any;
45
+ structure: any;
46
+ technologies: string[];
47
+ redirect_chain: any[];
48
+ metadata: any;
49
+ }
50
+
51
+ interface AccountInfoResponse {
52
+ quotas: {
53
+ domain: { limit: number; used: number; remaining: number };
54
+ ip: { limit: number; used: number; remaining: number };
55
+ webtech: { limit: number; used: number; remaining: number };
56
+ reset_date: string;
57
+ };
58
+ api_key: {
59
+ name: string;
60
+ requests_made: number;
61
+ allowed_endpoints: string[];
62
+ };
63
+ metadata: any;
64
+ }
65
+
66
+ // Error Types
67
+ export class ChapybaraError extends Error {}
68
+ export class APIError extends ChapybaraError {
69
+ status: number;
70
+ code?: string;
71
+ requestId?: string;
72
+ }
73
+ export class AuthenticationError extends APIError {}
74
+ export class RateLimitError extends APIError {}
75
+ export class NotFoundError extends APIError {}
76
+ export class ServerError extends APIError {}
77
+ export class BadRequestError extends APIError {}
78
+
79
+ export class ChapybaraClient {
80
+ constructor(options: ChapybaraClientOptions);
81
+
82
+ domain: {
83
+ getIntelligence: (
84
+ domain: string,
85
+ ) => Promise<DomainIntelligenceResponse>;
86
+ };
87
+
88
+ ip: {
89
+ getIntelligence: (ip: string) => Promise<IPIntelligenceResponse>;
90
+ };
91
+
92
+ webtech: {
93
+ getScanner: (domain: string) => Promise<WebTechResponse>;
94
+ };
95
+
96
+ account: {
97
+ getInfo: () => Promise<AccountInfoResponse>;
98
+ };
99
+ }
100
+ }
package/index.js ADDED
@@ -0,0 +1,116 @@
1
+ import fetch from "node-fetch";
2
+ import { LRUCache } from "lru-cache";
3
+ import { APIError, AuthenticationError, BadRequestError, NotFoundError, RateLimitError, ServerError } from "./lib/errors.js";
4
+
5
+ const DEFAULT_BASE_URL = "https://chapyapi.com/api/v1";
6
+ const DEFAULT_RETRIES = 2;
7
+ const DEFAULT_TIMEOUT = 20000;
8
+
9
+ export class ChapybaraClient {
10
+ constructor(options) {
11
+ if (!options || !options.apiKey) {
12
+ throw new Error("API key is required.");
13
+ }
14
+
15
+ this.apiKey = options.apiKey;
16
+ this.baseUrl = options.baseUrl || DEFAULT_BASE_URL;
17
+ this.retries = options.retries ?? DEFAULT_RETRIES;
18
+ this.timeout = options.timeout || DEFAULT_TIMEOUT;
19
+
20
+ if (options.cacheOptions) {
21
+ this.cache = new LRUCache(options.cacheOptions);
22
+ }
23
+
24
+ this.domain = {
25
+ getIntelligence: (domain) => this._request(`/domain/${domain}`),
26
+ };
27
+
28
+ this.ip = {
29
+ getIntelligence: (ip) => this._request(`/ip/${ip}`),
30
+ };
31
+
32
+ this.webtech = {
33
+ getScanner: (domain) => this._request(`/webtech/${domain}`),
34
+ };
35
+
36
+ this.account = {
37
+ getInfo: () => this._request("/account"),
38
+ };
39
+ }
40
+
41
+ async _request(endpoint, attempt = 1) {
42
+ const url = `${this.baseUrl}${endpoint}`;
43
+ const cacheKey = endpoint;
44
+
45
+ if (this.cache?.has(cacheKey)) {
46
+ return this.cache.get(cacheKey);
47
+ }
48
+
49
+ const controller = new AbortController();
50
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
51
+
52
+ try {
53
+ const response = await fetch(url, {
54
+ method: "GET",
55
+ headers: {
56
+ "X-API-Key": this.apiKey,
57
+ "Content-Type": "application/json",
58
+ "User-Agent": "Chapybara-NodeJS-SDK/1.0.0",
59
+ },
60
+ signal: controller.signal,
61
+ });
62
+
63
+ clearTimeout(timeoutId);
64
+
65
+ if (!response.ok) {
66
+ if (response.status >= 500 && attempt <= this.retries) {
67
+ const delay = 2 ** attempt * 100;
68
+ await new Promise((resolve) => setTimeout(resolve, delay));
69
+ return this._request(endpoint, attempt + 1);
70
+ }
71
+ await this._handleError(response);
72
+ }
73
+
74
+ const data = await response.json();
75
+
76
+ if (this.cache) {
77
+ this.cache.set(cacheKey, data);
78
+ }
79
+
80
+ return data;
81
+ } catch (error) {
82
+ clearTimeout(timeoutId);
83
+ if (error.name === "AbortError") {
84
+ throw new Error("Request timed out");
85
+ }
86
+ throw error;
87
+ }
88
+ }
89
+
90
+ async _handleError(response) {
91
+ let errorData;
92
+ try {
93
+ errorData = await response.json();
94
+ } catch (e) {
95
+ errorData = { error: `HTTP ${response.status} Error` };
96
+ }
97
+
98
+ switch (response.status) {
99
+ case 401:
100
+ case 403:
101
+ throw new AuthenticationError(response.status, errorData);
102
+ case 404:
103
+ throw new NotFoundError(response.status, errorData);
104
+ case 429:
105
+ throw new RateLimitError(response.status, errorData);
106
+ case 400:
107
+ case 402:
108
+ throw new BadRequestError(response.status, errorData);
109
+ default:
110
+ if (response.status >= 500) {
111
+ throw new ServerError(response.status, errorData);
112
+ }
113
+ throw new APIError(response.status, errorData);
114
+ }
115
+ }
116
+ }
package/lib/errors.js ADDED
@@ -0,0 +1,51 @@
1
+ export class ChapybaraError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "ChapybaraError";
5
+ }
6
+ }
7
+
8
+ export class APIError extends ChapybaraError {
9
+ constructor(status, error) {
10
+ super(error?.error || `Request failed with status code ${status}`);
11
+ this.name = "APIError";
12
+ this.status = status;
13
+ this.code = error?.code;
14
+ this.requestId = error?.requestId;
15
+ }
16
+ }
17
+
18
+ export class AuthenticationError extends APIError {
19
+ constructor(status, error) {
20
+ super(status, error);
21
+ this.name = "AuthenticationError";
22
+ }
23
+ }
24
+
25
+ export class RateLimitError extends APIError {
26
+ constructor(status, error) {
27
+ super(status, error);
28
+ this.name = "RateLimitError";
29
+ }
30
+ }
31
+
32
+ export class NotFoundError extends APIError {
33
+ constructor(status, error) {
34
+ super(status, error);
35
+ this.name = "NotFoundError";
36
+ }
37
+ }
38
+
39
+ export class ServerError extends APIError {
40
+ constructor(status, error) {
41
+ super(status, error);
42
+ this.name = "ServerError";
43
+ }
44
+ }
45
+
46
+ export class BadRequestError extends APIError {
47
+ constructor(status, error) {
48
+ super(status, error);
49
+ this.name = "BadRequestError";
50
+ }
51
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "chapybara",
3
+ "version": "0.1.0",
4
+ "description": "Official NodeJS SDK for the Chapybara Domain & IP Intelligence API.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "keywords": [
12
+ "chapybara",
13
+ "api",
14
+ "sdk",
15
+ "domain",
16
+ "ip",
17
+ "intelligence",
18
+ "security"
19
+ ],
20
+ "author": "Alpha System",
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "lru-cache": "^11.2.0",
24
+ "node-fetch": "^3.3.2"
25
+ },
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ }
29
+ }