@hyperbrowser/sdk
Version:
Node SDK for Hyperbrowser API
123 lines (122 loc) • 3.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionsService = void 0;
const base_1 = require("./base");
const client_1 = require("../client");
class SessionsService extends base_1.BaseService {
/**
* Create a new browser session
* @param params Configuration parameters for the new session
*/
async create(params) {
try {
return await this.request("/session", {
method: "POST",
body: params ? JSON.stringify(params) : undefined,
});
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError("Failed to create session", undefined);
}
}
/**
* Get details of an existing session
* @param id The ID of the session to get
*/
async get(id) {
try {
return await this.request(`/session/${id}`);
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError(`Failed to get session ${id}`, undefined);
}
}
/**
* Stop a running session
* @param id The ID of the session to stop
*/
async stop(id) {
try {
return await this.request(`/session/${id}/stop`, {
method: "PUT",
});
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError(`Failed to stop session ${id}`, undefined);
}
}
/**
* List all sessions with optional filtering
* @param params Optional parameters to filter the sessions
*/
async list(params = {}) {
try {
return await this.request("/sessions", undefined, {
status: params.status,
page: params.page,
limit: params.limit,
});
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError("Failed to list sessions", undefined);
}
}
/**
* Get the recording of a session
* @param id The ID of the session to get the recording from
*/
async getRecording(id) {
try {
return await this.request(`/session/${id}/recording`);
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError(`Failed to get recording for session ${id}`, undefined);
}
}
/**
* Get the recording URL of a session
* @param id The ID of the session to get the recording URL from
*/
async getRecordingURL(id) {
try {
return await this.request(`/session/${id}/recording-url`);
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError(`Failed to get recording url for session ${id}`, undefined);
}
}
/**
* Get the downloads URL of a session
* @param id The ID of the session to get the downloads URL from
*/
async getDownloadsURL(id) {
try {
return await this.request(`/session/${id}/downloads-url`);
}
catch (error) {
if (error instanceof client_1.HyperbrowserError) {
throw error;
}
throw new client_1.HyperbrowserError(`Failed to get downloads url for session ${id}`, undefined);
}
}
}
exports.SessionsService = SessionsService;
;