@hyperbrowser/sdk 0.3.0 → 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
@@ -0,0 +1,48 @@
1
+ # Hyperbrowser SDK
2
+
3
+ A TypeScript/JavaScript SDK for interacting with the Hyperbrowser API.
4
+
5
+ ## Installation
6
+
7
+ Hyperbrowser can be installed via npm by running:
8
+
9
+ ```bash
10
+ npm install @hyperbrowser/sdk
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { connect } from "puppeteer-core";
17
+ import Hyperbrowser from "hyperbrowser";
18
+ import dotenv from "dotenv";
19
+
20
+ dotenv.config();
21
+
22
+ const client = new Hyperbrowser({
23
+ apiKey: process.env.HYPERBROWSER_API_KEY,
24
+ });
25
+
26
+ (async () => {
27
+ const session = await client.createSession();
28
+
29
+ const browser = await connect({
30
+ browserWSEndpoint: session.wsEndpoint,
31
+ defaultViewport: null,
32
+ });
33
+
34
+ // Create a new page
35
+ const [page] = await browser.pages();
36
+
37
+ // Navigate to a website
38
+ console.log("Navigating to Hacker News...");
39
+ await page.goto("https://news.ycombinator.com/");
40
+ const pageTitle = await page.title();
41
+ console.log("Page title:", pageTitle);
42
+
43
+ await page.close();
44
+ await browser.close();
45
+ console.log("Session completed!");
46
+ await client.stopSession(session.id);
47
+ })().catch((error) => console.error(error.message));
48
+ ```
package/dist/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Response } from "node-fetch";
2
2
  import { HyperbrowserConfig } from "./types/config";
3
3
  import { BasicResponse, CreateSessionParams, SessionDetail, SessionListParams, SessionListResponse } from "./types/session";
4
+ import { ScrapeJobResponse, StartScrapeJobParams, StartScrapeJobResponse } from "./types/scrape";
4
5
  export declare class HyperbrowserError extends Error {
5
6
  statusCode?: number | undefined;
6
7
  response?: Response | undefined;
@@ -29,4 +30,6 @@ export declare class HyperbrowserClient {
29
30
  * List all sessions with optional filtering
30
31
  */
31
32
  listSessions(params?: SessionListParams): Promise<SessionListResponse>;
33
+ startScrapeJob(params: StartScrapeJobParams): Promise<StartScrapeJobResponse>;
34
+ getScrapeJob(id: string): Promise<ScrapeJobResponse>;
32
35
  }
package/dist/client.js CHANGED
@@ -137,5 +137,30 @@ class HyperbrowserClient {
137
137
  throw new HyperbrowserError("Failed to list sessions", undefined, undefined, error instanceof Error ? error : undefined);
138
138
  }
139
139
  }
140
+ async startScrapeJob(params) {
141
+ try {
142
+ return await this.request("/scrape", {
143
+ method: "POST",
144
+ body: JSON.stringify(params),
145
+ });
146
+ }
147
+ catch (error) {
148
+ if (error instanceof HyperbrowserError) {
149
+ throw error;
150
+ }
151
+ throw new HyperbrowserError("Failed to start scrape job", undefined, undefined, error instanceof Error ? error : undefined);
152
+ }
153
+ }
154
+ async getScrapeJob(id) {
155
+ try {
156
+ return await this.request(`/scrape/${id}`);
157
+ }
158
+ catch (error) {
159
+ if (error instanceof HyperbrowserError) {
160
+ throw error;
161
+ }
162
+ throw new HyperbrowserError(`Failed to get scrape job ${id}`, undefined, undefined, error instanceof Error ? error : undefined);
163
+ }
164
+ }
140
165
  }
141
166
  exports.HyperbrowserClient = HyperbrowserClient;
@@ -1,3 +1,4 @@
1
+ export type ScrapeJobStatus = "pending" | "running" | "completed" | "failed";
1
2
  export type Country = "AD" | "AE" | "AF" | "AL" | "AM" | "AO" | "AR" | "AT" | "AU" | "AW" | "AZ" | "BA" | "BD" | "BE" | "BG" | "BH" | "BJ" | "BO" | "BR" | "BS" | "BT" | "BY" | "BZ" | "CA" | "CF" | "CH" | "CI" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "EC" | "EE" | "EG" | "ES" | "ET" | "EU" | "FI" | "FJ" | "FR" | "GB" | "GE" | "GH" | "GM" | "GR" | "HK" | "HN" | "HR" | "HT" | "HU" | "ID" | "IE" | "IL" | "IN" | "IQ" | "IR" | "IS" | "IT" | "JM" | "JO" | "JP" | "KE" | "KH" | "KR" | "KW" | "KZ" | "LB" | "LI" | "LR" | "LT" | "LU" | "LV" | "MA" | "MC" | "MD" | "ME" | "MG" | "MK" | "ML" | "MM" | "MN" | "MR" | "MT" | "MU" | "MV" | "MX" | "MY" | "MZ" | "NG" | "NL" | "NO" | "NZ" | "OM" | "PA" | "PE" | "PH" | "PK" | "PL" | "PR" | "PT" | "PY" | "QA" | "RANDOM_COUNTRY" | "RO" | "RS" | "RU" | "SA" | "SC" | "SD" | "SE" | "SG" | "SI" | "SK" | "SN" | "SS" | "TD" | "TG" | "TH" | "TM" | "TN" | "TR" | "TT" | "TW" | "UA" | "UG" | "US" | "UY" | "UZ" | "VE" | "VG" | "VN" | "YE" | "ZA" | "ZM" | "ZW" | "ad" | "ae" | "af" | "al" | "am" | "ao" | "ar" | "at" | "au" | "aw" | "az" | "ba" | "bd" | "be" | "bg" | "bh" | "bj" | "bo" | "br" | "bs" | "bt" | "by" | "bz" | "ca" | "cf" | "ch" | "ci" | "cl" | "cm" | "cn" | "co" | "cr" | "cu" | "cy" | "cz" | "de" | "dj" | "dk" | "dm" | "ec" | "ee" | "eg" | "es" | "et" | "eu" | "fi" | "fj" | "fr" | "gb" | "ge" | "gh" | "gm" | "gr" | "hk" | "hn" | "hr" | "ht" | "hu" | "id" | "ie" | "il" | "in" | "iq" | "ir" | "is" | "it" | "jm" | "jo" | "jp" | "ke" | "kh" | "kr" | "kw" | "kz" | "lb" | "li" | "lr" | "lt" | "lu" | "lv" | "ma" | "mc" | "md" | "me" | "mg" | "mk" | "ml" | "mm" | "mn" | "mr" | "mt" | "mu" | "mv" | "mx" | "my" | "mz" | "ng" | "nl" | "no" | "nz" | "om" | "pa" | "pe" | "ph" | "pk" | "pl" | "pr" | "pt" | "py" | "qa" | "ro" | "rs" | "ru" | "sa" | "sc" | "sd" | "se" | "sg" | "si" | "sk" | "sn" | "ss" | "td" | "tg" | "th" | "tm" | "tn" | "tr" | "tt" | "tw" | "ua" | "ug" | "us" | "uy" | "uz" | "ve" | "vg" | "vn" | "ye" | "za" | "zm" | "zw";
2
3
  export type OperatingSystem = "windows" | "android" | "macos" | "linux" | "ios";
3
4
  export type Platform = "chrome" | "firefox" | "safari" | "edge";
@@ -0,0 +1,28 @@
1
+ import { ScrapeJobStatus } from "./constants";
2
+ export interface StartScrapeJobParams {
3
+ url: string;
4
+ }
5
+ export interface StartScrapeJobResponse {
6
+ jobId: string;
7
+ }
8
+ export interface ScrapeJobMetadata {
9
+ title: string;
10
+ description: string;
11
+ robots: string;
12
+ ogTitle: string;
13
+ ogDescription: string;
14
+ ogUrl: string;
15
+ ogImage: string;
16
+ ogLocaleAlternate: string[];
17
+ ogSiteName: string;
18
+ sourceURL: string;
19
+ }
20
+ export interface ScrapeJobData {
21
+ metadata: ScrapeJobMetadata;
22
+ markdown: string;
23
+ }
24
+ export interface ScrapeJobResponse {
25
+ status: ScrapeJobStatus;
26
+ data?: ScrapeJobData;
27
+ error?: string;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbrowser/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Node SDK for Hyperbrowser API",
5
5
  "author": "",
6
6
  "main": "dist/index.js",