@hyperbrowser/sdk 0.1.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/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/client.d.ts +31 -0
- package/dist/client.js +94 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -0
- package/dist/types/config.d.ts +4 -0
- package/dist/types/config.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +17 -0
- package/dist/types/session.d.ts +24 -0
- package/dist/types/session.js +2 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 hyperbrowserai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Response } from "node-fetch";
|
|
2
|
+
import { HyperbrowserConfig } from "./types/config";
|
|
3
|
+
import { SessionDetail, SessionListParams, SessionListResponse } from "./types/session";
|
|
4
|
+
export declare class HyperbrowserError extends Error {
|
|
5
|
+
statusCode?: number | undefined;
|
|
6
|
+
response?: Response | undefined;
|
|
7
|
+
constructor(message: string, statusCode?: number | undefined, response?: Response | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare class HyperbrowserClient {
|
|
10
|
+
private readonly apiKey;
|
|
11
|
+
private readonly baseUrl;
|
|
12
|
+
constructor(config: HyperbrowserConfig);
|
|
13
|
+
private request;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new browser session
|
|
16
|
+
*/
|
|
17
|
+
createSession(): Promise<SessionDetail>;
|
|
18
|
+
/**
|
|
19
|
+
* Get details of an existing session
|
|
20
|
+
*/
|
|
21
|
+
getSession(id: string): Promise<SessionDetail>;
|
|
22
|
+
/**
|
|
23
|
+
* Stop a running session
|
|
24
|
+
* @returns true if the session was successfully stopped
|
|
25
|
+
*/
|
|
26
|
+
stopSession(id: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* List all sessions with optional filtering
|
|
29
|
+
*/
|
|
30
|
+
listSessions(params?: SessionListParams): Promise<SessionListResponse>;
|
|
31
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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.HyperbrowserClient = exports.HyperbrowserError = void 0;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
class HyperbrowserError extends Error {
|
|
9
|
+
constructor(message, statusCode, response) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
this.response = response;
|
|
13
|
+
this.name = "HyperbrowserError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.HyperbrowserError = HyperbrowserError;
|
|
17
|
+
class HyperbrowserClient {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.apiKey = config.apiKey;
|
|
20
|
+
this.baseUrl = config.baseUrl || "https://app.hyperbrowser.ai";
|
|
21
|
+
if (!this.apiKey) {
|
|
22
|
+
throw new Error("API key is required");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async request(path, init, params) {
|
|
26
|
+
const url = new URL(`${this.baseUrl}/api${path}`);
|
|
27
|
+
if (params) {
|
|
28
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
29
|
+
if (value !== undefined) {
|
|
30
|
+
url.searchParams.append(key, value.toString());
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const response = await (0, node_fetch_1.default)(url.toString(), {
|
|
35
|
+
...init,
|
|
36
|
+
headers: {
|
|
37
|
+
"x-api-key": this.apiKey,
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
...init?.headers,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new HyperbrowserError(`HTTP error! status: ${response.status}`, response.status, response);
|
|
44
|
+
}
|
|
45
|
+
// Handle empty responses (like for stop session)
|
|
46
|
+
if (response.headers.get("content-length") === "0") {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return (await response.json());
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new HyperbrowserError("Failed to parse JSON response", response.status, response);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a new browser session
|
|
58
|
+
*/
|
|
59
|
+
async createSession() {
|
|
60
|
+
return this.request("/session", { method: "POST" });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get details of an existing session
|
|
64
|
+
*/
|
|
65
|
+
async getSession(id) {
|
|
66
|
+
return this.request(`/session/${id}`);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Stop a running session
|
|
70
|
+
* @returns true if the session was successfully stopped
|
|
71
|
+
*/
|
|
72
|
+
async stopSession(id) {
|
|
73
|
+
try {
|
|
74
|
+
await this.request(`/session/${id}/stop`, { method: "PUT" });
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof HyperbrowserError && error.statusCode && error.statusCode > 300) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List all sessions with optional filtering
|
|
86
|
+
*/
|
|
87
|
+
async listSessions(params = {}) {
|
|
88
|
+
return this.request("/sessions", undefined, {
|
|
89
|
+
status: params.status,
|
|
90
|
+
page: params.page,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.HyperbrowserClient = HyperbrowserClient;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.HyperbrowserError = exports.default = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_1.HyperbrowserClient; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
var client_2 = require("./client");
|
|
22
|
+
Object.defineProperty(exports, "HyperbrowserError", { enumerable: true, get: function () { return client_2.HyperbrowserError; } });
|
|
23
|
+
module.exports = require("./client").HyperbrowserClient;
|
|
24
|
+
module.exports.default = module.exports;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from ".";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("."), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type SessionStatus = "active" | "closed" | "error";
|
|
2
|
+
export interface Session {
|
|
3
|
+
id: string;
|
|
4
|
+
teamId: string;
|
|
5
|
+
status: SessionStatus;
|
|
6
|
+
startTime?: number;
|
|
7
|
+
endTime?: number;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
sessionUrl: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SessionDetail extends Session {
|
|
13
|
+
wsEndpoint?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SessionListParams {
|
|
16
|
+
status?: SessionStatus;
|
|
17
|
+
page?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SessionListResponse {
|
|
20
|
+
sessions: Session[];
|
|
21
|
+
totalCount: number;
|
|
22
|
+
page: number;
|
|
23
|
+
perPage: number;
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hyperbrowser/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Javascript SDK for Hyperbrowser API",
|
|
5
|
+
"author": "",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "commonjs",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"lint": "eslint src/**/*.ts",
|
|
13
|
+
"prepare": "yarn build",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"format": "prettier --write 'src/**/*.ts'"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"hyperbrowser",
|
|
24
|
+
"browser",
|
|
25
|
+
"automation"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"node-fetch": "^2.6.7"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.9.1",
|
|
32
|
+
"@types/node-fetch": "^2.6.4",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
34
|
+
"@typescript-eslint/parser": "^8.15.0",
|
|
35
|
+
"eslint": "^9.15.0",
|
|
36
|
+
"eslint-config-prettier": "^9.1.0",
|
|
37
|
+
"prettier": "^3.3.3",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^5.6.3"
|
|
40
|
+
}
|
|
41
|
+
}
|