chapybara 0.2.0 → 0.3.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 +20 -1
- package/index.d.ts +6 -0
- package/index.js +15 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -76,6 +76,24 @@ async function getWebTechInfo() {
|
|
|
76
76
|
getWebTechInfo();
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
### Get Website Screenshot
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
import fs from "fs/promises";
|
|
83
|
+
|
|
84
|
+
async function getWebsiteScreenshot() {
|
|
85
|
+
try {
|
|
86
|
+
const imageBuffer = await chapybara.screenshot.get("apple.com");
|
|
87
|
+
await fs.writeFile("screenshot.png", imageBuffer);
|
|
88
|
+
console.log("Screenshot saved to screenshot.png");
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`Error fetching screenshot: ${error.message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getWebsiteScreenshot();
|
|
95
|
+
```
|
|
96
|
+
|
|
79
97
|
### Get Account Information
|
|
80
98
|
|
|
81
99
|
```javascript
|
|
@@ -83,6 +101,7 @@ async function getAccountDetails() {
|
|
|
83
101
|
try {
|
|
84
102
|
const data = await chapybara.account.getInfo();
|
|
85
103
|
console.log("Domain quota remaining:", data.quotas.domain.remaining);
|
|
104
|
+
console.log("Screenshot quota remaining:", data.quotas.screenshot.remaining);
|
|
86
105
|
} catch (error) {
|
|
87
106
|
console.error(`Error fetching account info: ${error.message}`);
|
|
88
107
|
}
|
|
@@ -100,7 +119,7 @@ const chapybara = new ChapybaraClient({
|
|
|
100
119
|
apiKey: "ck_your_api_key_here",
|
|
101
120
|
baseUrl: "https://api.chapyapi.com/api/v1", // Optional: override base URL
|
|
102
121
|
retries: 2, // Optional: number of retries on server errors (default: 2)
|
|
103
|
-
timeout:
|
|
122
|
+
timeout: 30000, // Optional: request timeout in ms (default: 30000)
|
|
104
123
|
cacheOptions: {
|
|
105
124
|
// Optional: LRU cache options
|
|
106
125
|
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,6 +282,10 @@ 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
|
};
|
package/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { LRUCache } from "lru-cache";
|
|
2
2
|
import { APIError, AuthenticationError, BadRequestError, NotFoundError, RateLimitError, ServerError } from "./lib/errors.js";
|
|
3
|
-
import { version as SDK_VERSION } from "./package.json" assert { type: "json" };
|
|
4
3
|
|
|
5
4
|
const DEFAULT_BASE_URL = "https://api.chapyapi.com/api/v1";
|
|
6
5
|
const DEFAULT_RETRIES = 2;
|
|
7
|
-
const DEFAULT_TIMEOUT =
|
|
6
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
7
|
+
|
|
8
|
+
const SDK_VERSION = "0.3.0";
|
|
8
9
|
|
|
9
10
|
export class ChapybaraClient {
|
|
10
11
|
constructor(options) {
|
|
@@ -33,6 +34,10 @@ export class ChapybaraClient {
|
|
|
33
34
|
getScanner: (domain) => this._request(`/webtech/${domain}`),
|
|
34
35
|
};
|
|
35
36
|
|
|
37
|
+
this.screenshot = {
|
|
38
|
+
get: (domain) => this._request(`/screenshot/${domain}`),
|
|
39
|
+
};
|
|
40
|
+
|
|
36
41
|
this.account = {
|
|
37
42
|
getInfo: () => this._request("/account"),
|
|
38
43
|
};
|
|
@@ -41,6 +46,7 @@ export class ChapybaraClient {
|
|
|
41
46
|
async _request(endpoint, attempt = 1) {
|
|
42
47
|
const url = `${this.baseUrl}${endpoint}`;
|
|
43
48
|
const cacheKey = endpoint;
|
|
49
|
+
const isScreenshotRequest = endpoint.startsWith("/screenshot");
|
|
44
50
|
|
|
45
51
|
if (this.cache?.has(cacheKey)) {
|
|
46
52
|
return this.cache.get(cacheKey);
|
|
@@ -71,7 +77,13 @@ export class ChapybaraClient {
|
|
|
71
77
|
await this._handleError(response);
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
let data;
|
|
81
|
+
if (isScreenshotRequest) {
|
|
82
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
83
|
+
data = Buffer.from(arrayBuffer);
|
|
84
|
+
} else {
|
|
85
|
+
data = await response.json();
|
|
86
|
+
}
|
|
75
87
|
|
|
76
88
|
if (this.cache) {
|
|
77
89
|
this.cache.set(cacheKey, data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chapybara",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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,7 +15,8 @@
|
|
|
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",
|