@multiplayer-app/session-recorder-node
Version:
Multiplayer Fullstack Session Recorder for Node.js
117 lines • 4.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiService = void 0;
const config_1 = require("../config");
class ApiService {
constructor() {
this.config = {
exporterApiBaseUrl: config_1.MULTIPLAYER_BASE_API_URL,
};
}
/**
* Initialize the API service
* @param config - API service configuration
*/
init(config) {
this.config = { ...this.config, ...config };
}
/**
* Update the API service configuration
* @param config - Partial configuration to update
*/
updateConfigs(config) {
this.config = { ...this.config, ...config };
}
/**
* Start a new debug session
* @param requestBody - Session start request data
* @param signal - Optional AbortSignal for request cancellation
*/
async startSession(requestBody, signal) {
return this.makeRequest('/debug-sessions/start', 'POST', requestBody, signal);
}
/**
* Stop an active debug session
* @param sessionId - ID of the session to stop
* @param requestBody - Session stop request data
*/
async stopSession(sessionId, requestBody) {
return this.makeRequest(`/debug-sessions/${sessionId}/stop`, 'PATCH', requestBody);
}
/**
* Cancel an active session
* @param sessionId - ID of the session to cancel
*/
async cancelSession(sessionId) {
return this.makeRequest(`/debug-sessions/${sessionId}/cancel`, 'DELETE');
}
/**
* Start a new session
* @param requestBody - Session start request data
* @param signal - Optional AbortSignal for request cancellation
*/
async startContinuousSession(requestBody, signal) {
return this.makeRequest('/continuous-debug-sessions/start', 'POST', requestBody, signal);
}
/**
* Save a continuous session
* @param sessionId - ID of the session to save
* @param requestBody - Session save request data
* @param signal - Optional AbortSignal for request cancellation
*/
async saveContinuousSession(sessionId, requestBody, signal) {
return this.makeRequest(`/continuous-debug-sessions/${sessionId}/save`, 'POST', requestBody, signal);
}
/**
* Cancel an active debug session
* @param sessionId - ID of the session to cancel
*/
async stopContinuousSession(sessionId) {
return this.makeRequest(`/continuous-debug-sessions/${sessionId}/cancel`, 'DELETE');
}
/**
* Check debug session should be started remotely
*/
async checkRemoteSession(requestBody, signal) {
return this.makeRequest(`/remote-debug-session/check`, 'POST', requestBody, signal);
}
/**
* Make a request to the session API
* @param path - API endpoint path (relative to the base URL)
* @param method - HTTP method (GET, POST, PATCH, etc.)
* @param body - request payload
* @param signal - AbortSignal to set request's signal
*/
async makeRequest(path, method, body, signal) {
const url = `${this.config.exporterApiBaseUrl}/v0/radar${path}`;
const params = {
method,
body: body ? JSON.stringify(body) : null,
headers: {
'Content-Type': 'application/json',
...(this.config.apiKey && { 'X-Api-Key': this.config.apiKey }),
},
};
try {
const response = await fetch(url, {
...params,
credentials: 'include',
signal,
});
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
if (response.status === 204) {
return null;
}
return await response.json();
}
catch (error) {
if ((error === null || error === void 0 ? void 0 : error.name) === 'AbortError') {
throw new Error('Request aborted');
}
}
}
}
exports.ApiService = ApiService;
//# sourceMappingURL=api.service.js.map