watchtower-node-sdk
Version:
A TypeScript Node.js SDK for the Watchtower API, providing API key management, connection string generation, and more
72 lines • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppEndpoint = void 0;
const base_1 = require("../base");
const errors_1 = require("../../errors");
class AppEndpoint extends base_1.BaseEndpoint {
constructor(client) {
super(client, '/api/app');
}
validateRequiredKeys(data) {
if (!data.organization_apikey) {
throw new errors_1.InvalidRequestError('organization_apikey is required');
}
if (!data.app_apikey) {
throw new errors_1.InvalidRequestError('app_apikey is required');
}
}
/**
* Update the status of an app
* @param data - The request parameters
* @returns Promise with the app status overview
* @throws {InvalidRequestError} If required fields are missing or invalid
* @throws {AuthenticationError} If API keys are invalid
* @throws {ServerError} If server encounters an error
*/
async updateStatus(data) {
this.validateRequiredKeys(data);
try {
return await this.post('/status', data);
}
catch (error) {
if (error.response?.status === 400) {
throw new errors_1.InvalidRequestError(error.response.data?.message || 'Invalid request');
}
if (error.response?.status === 401) {
throw new errors_1.AuthenticationError('Invalid API keys');
}
if (error.response?.status === 500) {
throw new errors_1.ServerError('Internal server error');
}
throw error;
}
}
/**
* Get the latest status of an app
* @param data - The request parameters
* @returns Promise with the app status overview
* @throws {InvalidRequestError} If required fields are missing or invalid
* @throws {AuthenticationError} If API keys are invalid
* @throws {ServerError} If server encounters an error
*/
async getLatestStatus(data) {
this.validateRequiredKeys(data);
try {
return await this.get('/status/latest', { params: data });
}
catch (error) {
if (error.response?.status === 400) {
throw new errors_1.InvalidRequestError(error.response.data?.message || 'Invalid request');
}
if (error.response?.status === 401) {
throw new errors_1.AuthenticationError('Invalid API keys');
}
if (error.response?.status === 500) {
throw new errors_1.ServerError('Internal server error');
}
throw error;
}
}
}
exports.AppEndpoint = AppEndpoint;
//# sourceMappingURL=handler.js.map