chapybara 0.2.1 → 0.4.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/README.md CHANGED
@@ -28,6 +28,21 @@ const chapybara = new ChapybaraClient({
28
28
  });
29
29
  ```
30
30
 
31
+ ### Get Your IP Address
32
+
33
+ ```javascript
34
+ async function getUserIP() {
35
+ try {
36
+ const data = await chapybara.getUserIP();
37
+ console.log(data.ip);
38
+ } catch (error) {
39
+ console.error(`Error fetching user IP: ${error.message}`);
40
+ }
41
+ }
42
+
43
+ getUserIP();
44
+ ```
45
+
31
46
  ### Get Domain Intelligence
32
47
 
33
48
  ```javascript
@@ -76,6 +91,24 @@ async function getWebTechInfo() {
76
91
  getWebTechInfo();
77
92
  ```
78
93
 
94
+ ### Get Website Screenshot
95
+
96
+ ```javascript
97
+ import fs from "fs/promises";
98
+
99
+ async function getWebsiteScreenshot() {
100
+ try {
101
+ const imageBuffer = await chapybara.screenshot.get("apple.com");
102
+ await fs.writeFile("screenshot.png", imageBuffer);
103
+ console.log("Screenshot saved to screenshot.png");
104
+ } catch (error) {
105
+ console.error(`Error fetching screenshot: ${error.message}`);
106
+ }
107
+ }
108
+
109
+ getWebsiteScreenshot();
110
+ ```
111
+
79
112
  ### Get Account Information
80
113
 
81
114
  ```javascript
@@ -83,6 +116,7 @@ async function getAccountDetails() {
83
116
  try {
84
117
  const data = await chapybara.account.getInfo();
85
118
  console.log("Domain quota remaining:", data.quotas.domain.remaining);
119
+ console.log("Screenshot quota remaining:", data.quotas.screenshot.remaining);
86
120
  } catch (error) {
87
121
  console.error(`Error fetching account info: ${error.message}`);
88
122
  }
@@ -100,7 +134,7 @@ const chapybara = new ChapybaraClient({
100
134
  apiKey: "ck_your_api_key_here",
101
135
  baseUrl: "https://api.chapyapi.com/api/v1", // Optional: override base URL
102
136
  retries: 2, // Optional: number of retries on server errors (default: 2)
103
- timeout: 15000, // Optional: request timeout in ms (default: 20000)
137
+ timeout: 30000, // Optional: request timeout in ms (default: 30000)
104
138
  cacheOptions: {
105
139
  // Optional: LRU cache options
106
140
  max: 500, // Max number of items in cache
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { LRUCache } from "lru-cache";
2
+ import type { Buffer } from "node:buffer";
2
3
 
3
4
  declare module "chapybara" {
4
5
  interface ChapybaraClientOptions {
@@ -240,6 +241,7 @@ declare module "chapybara" {
240
241
  domain: { limit: number; used: number; remaining: number };
241
242
  ip: { limit: number; used: number; remaining: number };
242
243
  webtech: { limit: number; used: number; remaining: number };
244
+ screenshot: { limit: number; used: number; remaining: number };
243
245
  reset_date: string;
244
246
  };
245
247
  api_key: {
@@ -280,8 +282,14 @@ declare module "chapybara" {
280
282
  getScanner: (domain: string) => Promise<WebTechResponse>;
281
283
  };
282
284
 
285
+ screenshot: {
286
+ get: (domain: string) => Promise<Buffer>;
287
+ };
288
+
283
289
  account: {
284
290
  getInfo: () => Promise<AccountInfoResponse>;
285
291
  };
292
+
293
+ getUserIP: () => Promise<{ ip: string }>;
286
294
  }
287
295
  }
package/index.js CHANGED
@@ -3,9 +3,9 @@ import { APIError, AuthenticationError, BadRequestError, NotFoundError, RateLimi
3
3
 
4
4
  const DEFAULT_BASE_URL = "https://api.chapyapi.com/api/v1";
5
5
  const DEFAULT_RETRIES = 2;
6
- const DEFAULT_TIMEOUT = 20000;
6
+ const DEFAULT_TIMEOUT = 30000;
7
7
 
8
- const SDK_VERSION = "0.2.1";
8
+ const SDK_VERSION = "0.4.0";
9
9
 
10
10
  export class ChapybaraClient {
11
11
  constructor(options) {
@@ -34,14 +34,21 @@ export class ChapybaraClient {
34
34
  getScanner: (domain) => this._request(`/webtech/${domain}`),
35
35
  };
36
36
 
37
+ this.screenshot = {
38
+ get: (domain) => this._request(`/screenshot/${domain}`),
39
+ };
40
+
37
41
  this.account = {
38
42
  getInfo: () => this._request("/account"),
39
43
  };
44
+
45
+ this.getUserIP = () => this._request("/ip");
40
46
  }
41
47
 
42
48
  async _request(endpoint, attempt = 1) {
43
49
  const url = `${this.baseUrl}${endpoint}`;
44
50
  const cacheKey = endpoint;
51
+ const isScreenshotRequest = endpoint.startsWith("/screenshot");
45
52
 
46
53
  if (this.cache?.has(cacheKey)) {
47
54
  return this.cache.get(cacheKey);
@@ -72,7 +79,13 @@ export class ChapybaraClient {
72
79
  await this._handleError(response);
73
80
  }
74
81
 
75
- const data = await response.json();
82
+ let data;
83
+ if (isScreenshotRequest) {
84
+ const arrayBuffer = await response.arrayBuffer();
85
+ data = Buffer.from(arrayBuffer);
86
+ } else {
87
+ data = await response.json();
88
+ }
76
89
 
77
90
  if (this.cache) {
78
91
  this.cache.set(cacheKey, data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chapybara",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Official NodeJS SDK for the Chapybara Domain & IP Intelligence API.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -15,12 +15,13 @@
15
15
  "domain",
16
16
  "ip",
17
17
  "intelligence",
18
- "security"
18
+ "security",
19
+ "screenshot"
19
20
  ],
20
21
  "author": "Alpha System",
21
22
  "license": "MIT",
22
23
  "dependencies": {
23
- "lru-cache": "^11.2.1"
24
+ "lru-cache": "^11.2.2"
24
25
  },
25
26
  "engines": {
26
27
  "node": ">=18.0.0"