scrapebadger 0.1.7 → 0.1.9
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/dist/{index-qYk-iloT.d.cts → index-9Mu-b1MB.d.cts} +11 -5
- package/dist/{index-qYk-iloT.d.ts → index-9Mu-b1MB.d.ts} +11 -5
- package/dist/index.d.cts +161 -3
- package/dist/index.d.ts +161 -3
- package/dist/index.js +131 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -23
- package/dist/index.mjs.map +1 -1
- package/dist/twitter/index.d.cts +1 -1
- package/dist/twitter/index.d.ts +1 -1
- package/dist/twitter/index.js +28 -22
- package/dist/twitter/index.js.map +1 -1
- package/dist/twitter/index.mjs +28 -22
- package/dist/twitter/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1059,6 +1059,28 @@ var CommunitiesClient = class {
|
|
|
1059
1059
|
constructor(client) {
|
|
1060
1060
|
this.client = client;
|
|
1061
1061
|
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Parse a community member from the API response.
|
|
1064
|
+
* Handles both flat format (user_id, username, role at top level)
|
|
1065
|
+
* and nested format (user object with id, username).
|
|
1066
|
+
*/
|
|
1067
|
+
parseCommunityMember(item) {
|
|
1068
|
+
if ("user" in item && item.user) {
|
|
1069
|
+
return item;
|
|
1070
|
+
}
|
|
1071
|
+
return {
|
|
1072
|
+
user: {
|
|
1073
|
+
id: item.user_id ?? "",
|
|
1074
|
+
username: item.username ?? "",
|
|
1075
|
+
name: item.name ?? "",
|
|
1076
|
+
profile_image_url: item.profile_image_url,
|
|
1077
|
+
verified: item.verified ?? false,
|
|
1078
|
+
is_blue_verified: item.is_blue_verified
|
|
1079
|
+
},
|
|
1080
|
+
role: item.role,
|
|
1081
|
+
joined_at: item.joined_at
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1062
1084
|
/**
|
|
1063
1085
|
* Get details for a specific community.
|
|
1064
1086
|
*
|
|
@@ -1147,17 +1169,9 @@ var CommunitiesClient = class {
|
|
|
1147
1169
|
const response = await this.client.request(`/v1/twitter/communities/${communityId}/members`, {
|
|
1148
1170
|
params: { count: options.count ?? 20, cursor: options.cursor }
|
|
1149
1171
|
});
|
|
1150
|
-
const data = (response.data ?? []).map(
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
}
|
|
1154
|
-
const userItem = item;
|
|
1155
|
-
return {
|
|
1156
|
-
user: item,
|
|
1157
|
-
role: userItem.role,
|
|
1158
|
-
joined_at: userItem.joined_at
|
|
1159
|
-
};
|
|
1160
|
-
});
|
|
1172
|
+
const data = (response.data ?? []).map(
|
|
1173
|
+
(item) => this.parseCommunityMember(item)
|
|
1174
|
+
);
|
|
1161
1175
|
return createPaginatedResponse(data, response.next_cursor);
|
|
1162
1176
|
}
|
|
1163
1177
|
/**
|
|
@@ -1171,17 +1185,9 @@ var CommunitiesClient = class {
|
|
|
1171
1185
|
const response = await this.client.request(`/v1/twitter/communities/${communityId}/moderators`, {
|
|
1172
1186
|
params: { count: options.count ?? 20, cursor: options.cursor }
|
|
1173
1187
|
});
|
|
1174
|
-
const data = (response.data ?? []).map(
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1178
|
-
const userItem = item;
|
|
1179
|
-
return {
|
|
1180
|
-
user: item,
|
|
1181
|
-
role: "moderator",
|
|
1182
|
-
joined_at: userItem.joined_at
|
|
1183
|
-
};
|
|
1184
|
-
});
|
|
1188
|
+
const data = (response.data ?? []).map(
|
|
1189
|
+
(item) => this.parseCommunityMember(item)
|
|
1190
|
+
);
|
|
1185
1191
|
return createPaginatedResponse(data, response.next_cursor);
|
|
1186
1192
|
}
|
|
1187
1193
|
/**
|
|
@@ -1427,11 +1433,112 @@ var TwitterClient = class {
|
|
|
1427
1433
|
}
|
|
1428
1434
|
};
|
|
1429
1435
|
|
|
1436
|
+
// src/web/client.ts
|
|
1437
|
+
var WebClient = class {
|
|
1438
|
+
client;
|
|
1439
|
+
constructor(client) {
|
|
1440
|
+
this.client = client;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Scrape a web page.
|
|
1444
|
+
*/
|
|
1445
|
+
async scrape(url, options = {}) {
|
|
1446
|
+
const body = { url };
|
|
1447
|
+
if (options.renderJs) body.render_js = true;
|
|
1448
|
+
if (options.outputFormat && options.outputFormat !== "html")
|
|
1449
|
+
body.output_format = options.outputFormat;
|
|
1450
|
+
if (options.proxyCountry) body.proxy_country = options.proxyCountry;
|
|
1451
|
+
if (options.proxyType) body.proxy_type = options.proxyType;
|
|
1452
|
+
if (options.sessionId) body.session_id = options.sessionId;
|
|
1453
|
+
if (options.engine) body.engine = options.engine;
|
|
1454
|
+
if (options.maxCost !== void 0) body.max_cost = options.maxCost;
|
|
1455
|
+
if (options.headers) body.headers = options.headers;
|
|
1456
|
+
if (options.waitFor) body.wait_for = options.waitFor;
|
|
1457
|
+
if (options.timeout !== void 0) body.timeout = options.timeout;
|
|
1458
|
+
if (options.jsScenario) body.js_scenario = options.jsScenario;
|
|
1459
|
+
return this.client.request("/v1/web/scrape", {
|
|
1460
|
+
method: "POST",
|
|
1461
|
+
body
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Take a screenshot of a web page.
|
|
1466
|
+
*/
|
|
1467
|
+
async screenshot(url, options = {}) {
|
|
1468
|
+
const body = { url };
|
|
1469
|
+
if (options.fullPage) body.full_page = true;
|
|
1470
|
+
if (options.viewportWidth && options.viewportWidth !== 1280)
|
|
1471
|
+
body.viewport_width = options.viewportWidth;
|
|
1472
|
+
if (options.viewportHeight && options.viewportHeight !== 720)
|
|
1473
|
+
body.viewport_height = options.viewportHeight;
|
|
1474
|
+
if (options.imageFormat && options.imageFormat !== "png")
|
|
1475
|
+
body.image_format = options.imageFormat;
|
|
1476
|
+
if (options.waitFor) body.wait_for = options.waitFor;
|
|
1477
|
+
if (options.timeout !== void 0) body.timeout = options.timeout;
|
|
1478
|
+
return this.client.request("/v1/web/screenshot", {
|
|
1479
|
+
method: "POST",
|
|
1480
|
+
body
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Extract structured data from a web page.
|
|
1485
|
+
*/
|
|
1486
|
+
async extract(url, options = {}) {
|
|
1487
|
+
const body = { url };
|
|
1488
|
+
if (options.schema) body.extraction_schema = options.schema;
|
|
1489
|
+
if (options.renderJs) body.render_js = true;
|
|
1490
|
+
if (options.waitFor) body.wait_for = options.waitFor;
|
|
1491
|
+
if (options.timeout !== void 0) body.timeout = options.timeout;
|
|
1492
|
+
return this.client.request("/v1/web/extract", {
|
|
1493
|
+
method: "POST",
|
|
1494
|
+
body
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Scrape multiple URLs in a batch.
|
|
1499
|
+
*/
|
|
1500
|
+
async batch(urls, options = {}) {
|
|
1501
|
+
const body = { urls };
|
|
1502
|
+
if (options.renderJs) body.render_js = true;
|
|
1503
|
+
if (options.outputFormat && options.outputFormat !== "html")
|
|
1504
|
+
body.output_format = options.outputFormat;
|
|
1505
|
+
if (options.maxConcurrency && options.maxConcurrency !== 5)
|
|
1506
|
+
body.max_concurrency = options.maxConcurrency;
|
|
1507
|
+
if (options.engine) body.engine = options.engine;
|
|
1508
|
+
if (options.timeout !== void 0) body.timeout = options.timeout;
|
|
1509
|
+
return this.client.request("/v1/web/batch", {
|
|
1510
|
+
method: "POST",
|
|
1511
|
+
body
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Create a new scraping session for a domain.
|
|
1516
|
+
*/
|
|
1517
|
+
async createSession(domain, persist = true) {
|
|
1518
|
+
return this.client.request("/v1/web/sessions", {
|
|
1519
|
+
method: "POST",
|
|
1520
|
+
body: {
|
|
1521
|
+
domain,
|
|
1522
|
+
new_session: true,
|
|
1523
|
+
persist_session: persist
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Scrape using an existing session.
|
|
1529
|
+
*/
|
|
1530
|
+
async reuseSession(url, sessionId, options = {}) {
|
|
1531
|
+
return this.scrape(url, { ...options, sessionId });
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1430
1535
|
// src/client.ts
|
|
1431
1536
|
var ScrapeBadger = class {
|
|
1432
1537
|
baseClient;
|
|
1433
1538
|
/** Twitter API client */
|
|
1434
1539
|
twitter;
|
|
1540
|
+
/** Web scraping API client */
|
|
1541
|
+
web;
|
|
1435
1542
|
/**
|
|
1436
1543
|
* Create a new ScrapeBadger client.
|
|
1437
1544
|
*
|
|
@@ -1467,9 +1574,10 @@ var ScrapeBadger = class {
|
|
|
1467
1574
|
const resolvedConfig = resolveConfig({ ...config, apiKey });
|
|
1468
1575
|
this.baseClient = new BaseClient(resolvedConfig);
|
|
1469
1576
|
this.twitter = new TwitterClient(this.baseClient);
|
|
1577
|
+
this.web = new WebClient(this.baseClient);
|
|
1470
1578
|
}
|
|
1471
1579
|
};
|
|
1472
1580
|
|
|
1473
|
-
export { AccountRestrictedError, AuthenticationError, CommunitiesClient, GeoClient, InsufficientCreditsError, ListsClient, NotFoundError, RateLimitError, ScrapeBadger, ScrapeBadgerError, ServerError, TimeoutError, TrendsClient, TweetsClient, TwitterClient, UsersClient, ValidationError, collectAll };
|
|
1581
|
+
export { AccountRestrictedError, AuthenticationError, CommunitiesClient, GeoClient, InsufficientCreditsError, ListsClient, NotFoundError, RateLimitError, ScrapeBadger, ScrapeBadgerError, ServerError, TimeoutError, TrendsClient, TweetsClient, TwitterClient, UsersClient, ValidationError, WebClient, collectAll };
|
|
1474
1582
|
//# sourceMappingURL=index.mjs.map
|
|
1475
1583
|
//# sourceMappingURL=index.mjs.map
|