@hyperbrowser/sdk 0.8.0 → 0.10.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 +2 -0
- package/dist/client.js +6 -3
- package/dist/services/base.d.ts +2 -1
- package/dist/services/base.js +3 -1
- package/dist/services/profiles.d.ts +19 -0
- package/dist/services/profiles.js +56 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/profile.d.ts +9 -0
- package/dist/types/profile.js +2 -0
- package/dist/types/session.d.ts +6 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { HyperbrowserConfig } from "./types/config";
|
|
|
2
2
|
import { SessionsService } from "./services/sessions";
|
|
3
3
|
import { ScrapeService } from "./services/scrape";
|
|
4
4
|
import { CrawlService } from "./services/crawl";
|
|
5
|
+
import { ProfilesService } from "./services/profiles";
|
|
5
6
|
export declare class HyperbrowserError extends Error {
|
|
6
7
|
statusCode?: number | undefined;
|
|
7
8
|
constructor(message: string, statusCode?: number | undefined);
|
|
@@ -10,5 +11,6 @@ export declare class HyperbrowserClient {
|
|
|
10
11
|
readonly sessions: SessionsService;
|
|
11
12
|
readonly scrape: ScrapeService;
|
|
12
13
|
readonly crawl: CrawlService;
|
|
14
|
+
readonly profiles: ProfilesService;
|
|
13
15
|
constructor(config: HyperbrowserConfig);
|
|
14
16
|
}
|
package/dist/client.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.HyperbrowserClient = exports.HyperbrowserError = void 0;
|
|
|
4
4
|
const sessions_1 = require("./services/sessions");
|
|
5
5
|
const scrape_1 = require("./services/scrape");
|
|
6
6
|
const crawl_1 = require("./services/crawl");
|
|
7
|
+
const profiles_1 = require("./services/profiles");
|
|
7
8
|
class HyperbrowserError extends Error {
|
|
8
9
|
constructor(message, statusCode) {
|
|
9
10
|
super(`[Hyperbrowser]: ${message}`);
|
|
@@ -16,12 +17,14 @@ class HyperbrowserClient {
|
|
|
16
17
|
constructor(config) {
|
|
17
18
|
const apiKey = config.apiKey;
|
|
18
19
|
const baseUrl = config.baseUrl || "https://app.hyperbrowser.ai";
|
|
20
|
+
const timeout = config.timeout || 30000;
|
|
19
21
|
if (!apiKey) {
|
|
20
22
|
throw new HyperbrowserError("API key is required");
|
|
21
23
|
}
|
|
22
|
-
this.sessions = new sessions_1.SessionsService(apiKey, baseUrl);
|
|
23
|
-
this.scrape = new scrape_1.ScrapeService(apiKey, baseUrl);
|
|
24
|
-
this.crawl = new crawl_1.CrawlService(apiKey, baseUrl);
|
|
24
|
+
this.sessions = new sessions_1.SessionsService(apiKey, baseUrl, timeout);
|
|
25
|
+
this.scrape = new scrape_1.ScrapeService(apiKey, baseUrl, timeout);
|
|
26
|
+
this.crawl = new crawl_1.CrawlService(apiKey, baseUrl, timeout);
|
|
27
|
+
this.profiles = new profiles_1.ProfilesService(apiKey, baseUrl, timeout);
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
exports.HyperbrowserClient = HyperbrowserClient;
|
package/dist/services/base.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { RequestInit } from "node-fetch";
|
|
|
2
2
|
export declare class BaseService {
|
|
3
3
|
protected readonly apiKey: string;
|
|
4
4
|
protected readonly baseUrl: string;
|
|
5
|
-
|
|
5
|
+
protected readonly timeout: number;
|
|
6
|
+
constructor(apiKey: string, baseUrl: string, timeout?: number);
|
|
6
7
|
protected request<T>(path: string, init?: RequestInit, params?: Record<string, string | number | undefined>): Promise<T>;
|
|
7
8
|
}
|
package/dist/services/base.js
CHANGED
|
@@ -7,9 +7,10 @@ exports.BaseService = void 0;
|
|
|
7
7
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
8
|
const client_1 = require("../client");
|
|
9
9
|
class BaseService {
|
|
10
|
-
constructor(apiKey, baseUrl) {
|
|
10
|
+
constructor(apiKey, baseUrl, timeout = 30000) {
|
|
11
11
|
this.apiKey = apiKey;
|
|
12
12
|
this.baseUrl = baseUrl;
|
|
13
|
+
this.timeout = timeout;
|
|
13
14
|
}
|
|
14
15
|
async request(path, init, params) {
|
|
15
16
|
try {
|
|
@@ -23,6 +24,7 @@ class BaseService {
|
|
|
23
24
|
}
|
|
24
25
|
const response = await (0, node_fetch_1.default)(url.toString(), {
|
|
25
26
|
...init,
|
|
27
|
+
timeout: this.timeout,
|
|
26
28
|
headers: {
|
|
27
29
|
"x-api-key": this.apiKey,
|
|
28
30
|
"Content-Type": "application/json",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseService } from "./base";
|
|
2
|
+
import { ProfileResponse, CreateProfileResponse } from "../types/profile";
|
|
3
|
+
import { BasicResponse } from "../types";
|
|
4
|
+
export declare class ProfilesService extends BaseService {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new profile
|
|
7
|
+
*/
|
|
8
|
+
create(): Promise<CreateProfileResponse>;
|
|
9
|
+
/**
|
|
10
|
+
* Get details of an existing profile
|
|
11
|
+
* @param id The ID of the profile to get
|
|
12
|
+
*/
|
|
13
|
+
get(id: string): Promise<ProfileResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Delete an existing profile
|
|
16
|
+
* @param id The ID of the profile to delete
|
|
17
|
+
*/
|
|
18
|
+
delete(id: string): Promise<BasicResponse>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfilesService = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
const client_1 = require("../client");
|
|
6
|
+
class ProfilesService extends base_1.BaseService {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new profile
|
|
9
|
+
*/
|
|
10
|
+
async create() {
|
|
11
|
+
try {
|
|
12
|
+
return await this.request("/profile", {
|
|
13
|
+
method: "POST",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
throw new client_1.HyperbrowserError("Failed to create profile", undefined);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get details of an existing profile
|
|
25
|
+
* @param id The ID of the profile to get
|
|
26
|
+
*/
|
|
27
|
+
async get(id) {
|
|
28
|
+
try {
|
|
29
|
+
return await this.request(`/profile/${id}`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
throw new client_1.HyperbrowserError(`Failed to get profile ${id}`, undefined);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Delete an existing profile
|
|
40
|
+
* @param id The ID of the profile to delete
|
|
41
|
+
*/
|
|
42
|
+
async delete(id) {
|
|
43
|
+
try {
|
|
44
|
+
return await this.request(`/profile/${id}`, {
|
|
45
|
+
method: "DELETE",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof client_1.HyperbrowserError) {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
throw new client_1.HyperbrowserError(`Failed to delete profile ${id}`, undefined);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ProfilesService = ProfilesService;
|
package/dist/types/config.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { HyperbrowserConfig } from "./config";
|
|
|
2
2
|
export { StartCrawlJobParams, StartCrawlJobResponse, CrawledPage, CrawlJobResponse, GetCrawlJobParams, } from "./crawl";
|
|
3
3
|
export { StartScrapeJobParams, StartScrapeJobResponse, ScrapeJobData, ScrapeJobResponse, } from "./scrape";
|
|
4
4
|
export { BasicResponse, SessionStatus, Session, SessionDetail, SessionListParams, SessionListResponse, ScreenConfig, CreateSessionParams, } from "./session";
|
|
5
|
+
export { ProfileResponse, CreateProfileResponse } from "./profile";
|
|
5
6
|
export { ScrapeJobStatus, CrawlJobStatus, Country, ISO639_1, OperatingSystem, Platform, } from "./constants";
|
package/dist/types/session.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface Session {
|
|
|
12
12
|
createdAt: string;
|
|
13
13
|
updatedAt: string;
|
|
14
14
|
sessionUrl: string;
|
|
15
|
+
token: string;
|
|
15
16
|
}
|
|
16
17
|
export interface SessionDetail extends Session {
|
|
17
18
|
wsEndpoint?: string;
|
|
@@ -30,6 +31,10 @@ export interface ScreenConfig {
|
|
|
30
31
|
width: number;
|
|
31
32
|
height: number;
|
|
32
33
|
}
|
|
34
|
+
export interface CreateSessionProfile {
|
|
35
|
+
id?: string;
|
|
36
|
+
persistChanges?: boolean;
|
|
37
|
+
}
|
|
33
38
|
export interface CreateSessionParams {
|
|
34
39
|
useStealth?: boolean;
|
|
35
40
|
useProxy?: boolean;
|
|
@@ -47,6 +52,7 @@ export interface CreateSessionParams {
|
|
|
47
52
|
trackers?: boolean;
|
|
48
53
|
annoyances?: boolean;
|
|
49
54
|
enableWebRecording?: boolean;
|
|
55
|
+
profile?: CreateSessionProfile;
|
|
50
56
|
}
|
|
51
57
|
export interface SessionRecording {
|
|
52
58
|
type: number;
|