scrapebadger 0.1.7 → 0.1.8

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