@hyperbrowser/sdk 0.82.0 → 0.82.2

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.
@@ -0,0 +1,26 @@
1
+ import { BatchFetchJobResponse, BatchFetchJobStatusResponse, GetBatchFetchJobParams, StartBatchFetchJobParams, StartBatchFetchJobResponse } from "../../types/web/batch-fetch";
2
+ import { BaseService } from "../base";
3
+ export declare class BatchFetchService extends BaseService {
4
+ /**
5
+ * Start a new batch fetch job
6
+ * @param params The parameters for the batch fetch job
7
+ */
8
+ start(params: StartBatchFetchJobParams): Promise<StartBatchFetchJobResponse>;
9
+ /**
10
+ * Get the status of a batch fetch job
11
+ * @param id The ID of the batch fetch job to get
12
+ */
13
+ getStatus(id: string): Promise<BatchFetchJobStatusResponse>;
14
+ /**
15
+ * Get the details of a batch fetch job
16
+ * @param id The ID of the batch fetch job to get
17
+ * @param params Optional parameters to filter the batch fetch job
18
+ */
19
+ get(id: string, params?: GetBatchFetchJobParams): Promise<BatchFetchJobResponse>;
20
+ /**
21
+ * Start a batch fetch job and wait for it to complete
22
+ * @param params The parameters for the batch fetch job
23
+ * @param returnAllPages Whether to return all pages in the batch fetch job response
24
+ */
25
+ startAndWait(params: StartBatchFetchJobParams, returnAllPages?: boolean): Promise<BatchFetchJobResponse>;
26
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BatchFetchService = void 0;
7
+ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
8
+ const zod_1 = require("zod");
9
+ const base_1 = require("../base");
10
+ const utils_1 = require("../../utils");
11
+ const client_1 = require("../../client");
12
+ const constants_1 = require("../../types/constants");
13
+ const utils_2 = require("../../utils");
14
+ class BatchFetchService extends base_1.BaseService {
15
+ /**
16
+ * Start a new batch fetch job
17
+ * @param params The parameters for the batch fetch job
18
+ */
19
+ async start(params) {
20
+ try {
21
+ if (params.outputs?.formats) {
22
+ for (const output of params.outputs.formats) {
23
+ if (typeof output === "object" && "type" in output && output.type === "json") {
24
+ const jsonOutput = output;
25
+ if (jsonOutput.schema) {
26
+ if ((0, utils_2.isZodSchema)(jsonOutput.schema)) {
27
+ try {
28
+ output.schema = (0, zod_1.toJSONSchema)(jsonOutput.schema);
29
+ }
30
+ catch {
31
+ output.schema = (0, zod_to_json_schema_1.default)(jsonOutput.schema);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return await this.request("/web/batch-fetch", {
39
+ method: "POST",
40
+ body: JSON.stringify(params),
41
+ });
42
+ }
43
+ catch (error) {
44
+ if (error instanceof client_1.HyperbrowserError) {
45
+ throw error;
46
+ }
47
+ throw new client_1.HyperbrowserError("Failed to start batch fetch job", undefined);
48
+ }
49
+ }
50
+ /**
51
+ * Get the status of a batch fetch job
52
+ * @param id The ID of the batch fetch job to get
53
+ */
54
+ async getStatus(id) {
55
+ try {
56
+ return await this.request(`/web/batch-fetch/${id}/status`);
57
+ }
58
+ catch (error) {
59
+ if (error instanceof client_1.HyperbrowserError) {
60
+ throw error;
61
+ }
62
+ throw new client_1.HyperbrowserError(`Failed to get batch fetch job ${id} status`, undefined);
63
+ }
64
+ }
65
+ /**
66
+ * Get the details of a batch fetch job
67
+ * @param id The ID of the batch fetch job to get
68
+ * @param params Optional parameters to filter the batch fetch job
69
+ */
70
+ async get(id, params) {
71
+ try {
72
+ return await this.request(`/web/batch-fetch/${id}`, undefined, {
73
+ page: params?.page,
74
+ batchSize: params?.batchSize,
75
+ });
76
+ }
77
+ catch (error) {
78
+ if (error instanceof client_1.HyperbrowserError) {
79
+ throw error;
80
+ }
81
+ throw new client_1.HyperbrowserError(`Failed to get batch fetch job ${id}`, undefined);
82
+ }
83
+ }
84
+ /**
85
+ * Start a batch fetch job and wait for it to complete
86
+ * @param params The parameters for the batch fetch job
87
+ * @param returnAllPages Whether to return all pages in the batch fetch job response
88
+ */
89
+ async startAndWait(params, returnAllPages = true) {
90
+ const job = await this.start(params);
91
+ const jobId = job.jobId;
92
+ if (!jobId) {
93
+ throw new client_1.HyperbrowserError("Failed to start batch fetch job, could not get job ID");
94
+ }
95
+ let failures = 0;
96
+ let jobStatus = "pending";
97
+ while (true) {
98
+ try {
99
+ const { status } = await this.getStatus(jobId);
100
+ if (status === "completed" || status === "failed") {
101
+ jobStatus = status;
102
+ break;
103
+ }
104
+ failures = 0;
105
+ }
106
+ catch (error) {
107
+ failures++;
108
+ if (failures >= constants_1.POLLING_ATTEMPTS) {
109
+ throw new client_1.HyperbrowserError(`Failed to poll batch fetch job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
110
+ }
111
+ }
112
+ await (0, utils_1.sleep)(2000);
113
+ }
114
+ failures = 0;
115
+ if (!returnAllPages) {
116
+ while (true) {
117
+ try {
118
+ return await this.get(jobId);
119
+ }
120
+ catch (error) {
121
+ failures++;
122
+ if (failures >= constants_1.POLLING_ATTEMPTS) {
123
+ throw new client_1.HyperbrowserError(`Failed to get batch fetch job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
124
+ }
125
+ }
126
+ await (0, utils_1.sleep)(500);
127
+ }
128
+ }
129
+ failures = 0;
130
+ const jobResponse = {
131
+ jobId,
132
+ status: jobStatus,
133
+ data: [],
134
+ currentPageBatch: 0,
135
+ totalPageBatches: 0,
136
+ totalPages: 0,
137
+ batchSize: 100,
138
+ };
139
+ let firstCheck = true;
140
+ while (firstCheck || jobResponse.currentPageBatch < jobResponse.totalPageBatches) {
141
+ try {
142
+ const tmpJobResponse = await this.get(jobId, {
143
+ page: jobResponse.currentPageBatch + 1,
144
+ batchSize: 100,
145
+ });
146
+ if (tmpJobResponse.data) {
147
+ jobResponse.data?.push(...tmpJobResponse.data);
148
+ }
149
+ if (tmpJobResponse.error) {
150
+ jobResponse.error = tmpJobResponse.error;
151
+ }
152
+ jobResponse.currentPageBatch = tmpJobResponse.currentPageBatch;
153
+ jobResponse.totalPages = tmpJobResponse.totalPages;
154
+ jobResponse.totalPageBatches = tmpJobResponse.totalPageBatches;
155
+ jobResponse.batchSize = tmpJobResponse.batchSize;
156
+ failures = 0;
157
+ firstCheck = false;
158
+ }
159
+ catch (error) {
160
+ failures++;
161
+ if (failures >= constants_1.POLLING_ATTEMPTS) {
162
+ throw new client_1.HyperbrowserError(`Failed to get batch page ${jobResponse.currentPageBatch + 1} for job ${jobId} after ${constants_1.POLLING_ATTEMPTS} attempts: ${error}`);
163
+ }
164
+ }
165
+ await (0, utils_1.sleep)(500);
166
+ }
167
+ return jobResponse;
168
+ }
169
+ }
170
+ exports.BatchFetchService = BatchFetchService;
@@ -1,7 +1,10 @@
1
1
  import { BaseService } from "../base";
2
2
  import { FetchParams, FetchResponse } from "../../types/web/fetch";
3
3
  import { WebSearchParams, WebSearchResponse } from "../../types/web/search";
4
+ import { BatchFetchService } from "./batch-fetch";
4
5
  export declare class WebService extends BaseService {
6
+ readonly batchFetch: BatchFetchService;
7
+ constructor(apiKey: string, baseUrl: string, timeout: number);
5
8
  /**
6
9
  * Fetch a URL and extract content
7
10
  * @param params The parameters for the fetch request
@@ -9,14 +9,18 @@ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
9
9
  const base_1 = require("../base");
10
10
  const client_1 = require("../../client");
11
11
  const utils_1 = require("../../utils");
12
+ const batch_fetch_1 = require("./batch-fetch");
12
13
  class WebService extends base_1.BaseService {
14
+ constructor(apiKey, baseUrl, timeout) {
15
+ super(apiKey, baseUrl, timeout);
16
+ this.batchFetch = new batch_fetch_1.BatchFetchService(apiKey, baseUrl, timeout);
17
+ }
13
18
  /**
14
19
  * Fetch a URL and extract content
15
20
  * @param params The parameters for the fetch request
16
21
  */
17
22
  async fetch(params) {
18
23
  try {
19
- // Handle JSON schema serialization if needed (similar to Python SDK)
20
24
  if (params.outputs?.formats) {
21
25
  for (const output of params.outputs.formats) {
22
26
  if (typeof output === "object" && "type" in output && output.type === "json") {
@@ -14,5 +14,6 @@ export { ExtractJobStatus, BrowserUseTaskStatus, BrowserUseLlm, ClaudeComputerUs
14
14
  export { TeamCreditInfo } from "./team";
15
15
  export { ComputerAction, Coordinate, ClickActionParams, DragActionParams, PressKeysActionParams, MoveMouseActionParams, ScreenshotActionParams, ScrollActionParams, TypeTextActionParams, ComputerActionParams, ComputerActionResponse, ComputerActionMouseButton, ComputerActionResponseData, HoldKeyActionParams, MouseDownActionParams, MouseUpActionParams, GetClipboardTextActionParams, PutSelectionTextActionParams, ComputerActionResponseDataClipboardText, } from "./computer-action";
16
16
  export { FetchParams, FetchResponse, FetchResponseData, FetchStatus } from "./web/fetch";
17
+ export { StartBatchFetchJobParams, GetBatchFetchJobParams, StartBatchFetchJobResponse, BatchFetchJobStatusResponse, BatchFetchJobResponse, BatchFetchJobStatus, } from "./web/batch-fetch";
17
18
  export { WebSearchParams, WebSearchResponse, WebSearchResponseData, WebSearchResultItem, WebSearchFilters, WebSearchLocation, WebSearchFiletype, WebSearchStatus, } from "./web/search";
18
19
  export { FetchStealthMode, FetchSanitizeMode, FetchWaitUntil, FetchScreenshotFormat, PageStatus, FetchOutputScreenshotOptions, FetchStorageStateOptions, FetchBrowserLocationOptions, PageData, FetchOutputMarkdown, FetchOutputHtml, FetchOutputLinks, FetchOutputScreenshot, FetchOutputJsonOptions, FetchOutputJson, FetchOutputFormat, FetchOutputOptions, FetchBrowserOptions, FetchNavigationOptions, FetchCacheOptions, } from "./web/common";
@@ -143,6 +143,9 @@ export interface GetSessionDownloadsUrlResponse {
143
143
  }
144
144
  export interface UploadFileResponse {
145
145
  message: string;
146
+ filePath?: string;
147
+ fileName?: string;
148
+ originalName?: string;
146
149
  }
147
150
  export interface UploadFileOptions {
148
151
  fileInput: string | fs.ReadStream | Buffer;
@@ -0,0 +1,30 @@
1
+ import { FetchBrowserOptions, FetchCacheOptions, FetchNavigationOptions, FetchOutputOptions, FetchStealthMode, PageData } from "./common";
2
+ export type BatchFetchJobStatus = "pending" | "running" | "completed" | "failed";
3
+ export interface StartBatchFetchJobParams {
4
+ urls: string[];
5
+ stealth?: FetchStealthMode;
6
+ outputs?: FetchOutputOptions;
7
+ browser?: FetchBrowserOptions;
8
+ navigation?: FetchNavigationOptions;
9
+ cache?: FetchCacheOptions;
10
+ }
11
+ export interface GetBatchFetchJobParams {
12
+ page?: number;
13
+ batchSize?: number;
14
+ }
15
+ export interface StartBatchFetchJobResponse {
16
+ jobId: string;
17
+ }
18
+ export interface BatchFetchJobStatusResponse {
19
+ status: BatchFetchJobStatus;
20
+ }
21
+ export interface BatchFetchJobResponse {
22
+ jobId: string;
23
+ status: BatchFetchJobStatus;
24
+ error?: string;
25
+ data?: PageData[];
26
+ totalPages: number;
27
+ totalPageBatches: number;
28
+ currentPageBatch: number;
29
+ batchSize: number;
30
+ }
@@ -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.82.0",
3
+ "version": "0.82.2",
4
4
  "description": "Node SDK for Hyperbrowser API",
5
5
  "author": "",
6
6
  "main": "dist/index.js",