@hyperbrowser/sdk 0.19.0 → 0.21.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/dist/client.d.ts CHANGED
@@ -4,6 +4,7 @@ import { ScrapeService } from "./services/scrape";
4
4
  import { CrawlService } from "./services/crawl";
5
5
  import { ProfilesService } from "./services/profiles";
6
6
  import { ExtensionService } from "./services/extensions";
7
+ import { ExtractService } from "./services/extract";
7
8
  export declare class HyperbrowserError extends Error {
8
9
  statusCode?: number | undefined;
9
10
  constructor(message: string, statusCode?: number | undefined);
@@ -12,6 +13,7 @@ export declare class HyperbrowserClient {
12
13
  readonly sessions: SessionsService;
13
14
  readonly scrape: ScrapeService;
14
15
  readonly crawl: CrawlService;
16
+ readonly extract: ExtractService;
15
17
  readonly profiles: ProfilesService;
16
18
  readonly extensions: ExtensionService;
17
19
  constructor(config: HyperbrowserConfig);
package/dist/client.js CHANGED
@@ -6,6 +6,7 @@ const scrape_1 = require("./services/scrape");
6
6
  const crawl_1 = require("./services/crawl");
7
7
  const profiles_1 = require("./services/profiles");
8
8
  const extensions_1 = require("./services/extensions");
9
+ const extract_1 = require("./services/extract");
9
10
  class HyperbrowserError extends Error {
10
11
  constructor(message, statusCode) {
11
12
  super(`[Hyperbrowser]: ${message}`);
@@ -25,6 +26,7 @@ class HyperbrowserClient {
25
26
  this.sessions = new sessions_1.SessionsService(apiKey, baseUrl, timeout);
26
27
  this.scrape = new scrape_1.ScrapeService(apiKey, baseUrl, timeout);
27
28
  this.crawl = new crawl_1.CrawlService(apiKey, baseUrl, timeout);
29
+ this.extract = new extract_1.ExtractService(apiKey, baseUrl, timeout);
28
30
  this.profiles = new profiles_1.ProfilesService(apiKey, baseUrl, timeout);
29
31
  this.extensions = new extensions_1.ExtensionService(apiKey, baseUrl, timeout);
30
32
  }
@@ -0,0 +1,20 @@
1
+ import { BaseService } from "./base";
2
+ import { ExtractJobResponse, StartExtractJobResponse } from "../types/extract";
3
+ import { StartExtractJobParams } from "../types/extract";
4
+ export declare class ExtractService extends BaseService {
5
+ /**
6
+ * Start a new extract job
7
+ * @param params The parameters for the extract job
8
+ */
9
+ start(params: StartExtractJobParams): Promise<StartExtractJobResponse>;
10
+ /**
11
+ * Get the status of an extract job
12
+ * @param id The ID of the extract job to get
13
+ */
14
+ get(id: string): Promise<ExtractJobResponse>;
15
+ /**
16
+ * Start an extract job and wait for it to complete
17
+ * @param params The parameters for the extract job
18
+ */
19
+ startAndWait(params: StartExtractJobParams): Promise<ExtractJobResponse>;
20
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtractService = void 0;
4
+ const zod_to_json_schema_1 = require("zod-to-json-schema");
5
+ const base_1 = require("./base");
6
+ const utils_1 = require("../utils");
7
+ const client_1 = require("../client");
8
+ const isZodSchema = (schema) => {
9
+ return (schema &&
10
+ typeof schema === "object" &&
11
+ "_def" in schema &&
12
+ "parse" in schema &&
13
+ typeof schema.parse === "function");
14
+ };
15
+ class ExtractService extends base_1.BaseService {
16
+ /**
17
+ * Start a new extract job
18
+ * @param params The parameters for the extract job
19
+ */
20
+ async start(params) {
21
+ try {
22
+ if (!params.schema && !params.prompt) {
23
+ throw new client_1.HyperbrowserError("Either schema or prompt must be provided");
24
+ }
25
+ if (params.schema) {
26
+ if (isZodSchema(params.schema)) {
27
+ params.schema = (0, zod_to_json_schema_1.zodToJsonSchema)(params.schema);
28
+ }
29
+ }
30
+ return await this.request("/extract", {
31
+ method: "POST",
32
+ body: JSON.stringify(params),
33
+ });
34
+ }
35
+ catch (error) {
36
+ if (error instanceof client_1.HyperbrowserError) {
37
+ throw error;
38
+ }
39
+ throw new client_1.HyperbrowserError("Failed to start extract job", undefined);
40
+ }
41
+ }
42
+ /**
43
+ * Get the status of an extract job
44
+ * @param id The ID of the extract job to get
45
+ */
46
+ async get(id) {
47
+ try {
48
+ return await this.request(`/extract/${id}`);
49
+ }
50
+ catch (error) {
51
+ if (error instanceof client_1.HyperbrowserError) {
52
+ throw error;
53
+ }
54
+ throw new client_1.HyperbrowserError(`Failed to get extract job ${id}`, undefined);
55
+ }
56
+ }
57
+ /**
58
+ * Start an extract job and wait for it to complete
59
+ * @param params The parameters for the extract job
60
+ */
61
+ async startAndWait(params) {
62
+ const job = await this.start(params);
63
+ const jobId = job.jobId;
64
+ if (!jobId) {
65
+ throw new client_1.HyperbrowserError("Failed to start extract job, could not get job ID");
66
+ }
67
+ let jobResponse;
68
+ while (true) {
69
+ jobResponse = await this.get(jobId);
70
+ if (jobResponse.status === "completed" || jobResponse.status === "failed") {
71
+ break;
72
+ }
73
+ await (0, utils_1.sleep)(2000);
74
+ }
75
+ return jobResponse;
76
+ }
77
+ }
78
+ exports.ExtractService = ExtractService;
@@ -1,5 +1,6 @@
1
1
  export type ScrapeFormat = "markdown" | "html" | "links" | "screenshot";
2
2
  export type ScrapeJobStatus = "pending" | "running" | "completed" | "failed";
3
+ export type ExtractJobStatus = "pending" | "running" | "completed" | "failed";
3
4
  export type CrawlJobStatus = "pending" | "running" | "completed" | "failed";
4
5
  export type CrawlPageStatus = "completed" | "failed";
5
6
  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";
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ import { ExtractJobStatus } from "./constants";
3
+ import { CreateSessionParams } from "./session";
4
+ export interface StartExtractJobParams {
5
+ urls: string[];
6
+ prompt?: string;
7
+ schema?: z.ZodSchema | object;
8
+ sessionOptions?: CreateSessionParams;
9
+ }
10
+ export interface StartExtractJobResponse {
11
+ jobId: string;
12
+ }
13
+ export interface ExtractJobResponse {
14
+ jobId: string;
15
+ status: ExtractJobStatus;
16
+ data?: object;
17
+ error?: string;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -55,6 +55,7 @@ export interface CreateSessionParams {
55
55
  enableWebRecording?: boolean;
56
56
  profile?: CreateSessionProfile;
57
57
  extensionIds?: Array<string>;
58
+ staticIpId?: string;
58
59
  }
59
60
  export interface SessionRecording {
60
61
  type: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbrowser/sdk",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Node SDK for Hyperbrowser API",
5
5
  "author": "",
6
6
  "main": "dist/index.js",
@@ -31,7 +31,9 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "form-data": "^4.0.1",
34
- "node-fetch": "2.7.0"
34
+ "node-fetch": "2.7.0",
35
+ "zod": "^3.24.1",
36
+ "zod-to-json-schema": "^3.24.1"
35
37
  },
36
38
  "devDependencies": {
37
39
  "@types/node": "^22.9.1",
@@ -60,8 +62,12 @@
60
62
  },
61
63
  "typesVersions": {
62
64
  "*": {
63
- "types": ["./dist/types/index.d.ts"],
64
- "tools": ["./dist/tools/index.d.ts"]
65
+ "types": [
66
+ "./dist/types/index.d.ts"
67
+ ],
68
+ "tools": [
69
+ "./dist/tools/index.d.ts"
70
+ ]
65
71
  }
66
72
  }
67
73
  }