watchtower-node-sdk
Version:
A TypeScript Node.js SDK for the Watchtower API, providing API key management, connection string generation, and more
109 lines • 4.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetricsEndpoint = void 0;
const base_1 = require("../base");
const errors_1 = require("../../errors");
class MetricsEndpoint extends base_1.BaseEndpoint {
constructor(client) {
super(client, '/api/metrics');
}
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');
}
if (data.tenant_apikey === undefined) {
throw new errors_1.InvalidRequestError('tenant_apikey is required');
}
}
validateAppKeys(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');
}
}
/**
* Get metrics for a specific tenant
* @param data - The get metrics request parameters
* @returns Promise with the metrics response
* @throws {InvalidRequestError} If required fields are missing
* @throws {AuthenticationError} If API keys are invalid
* @throws {ServerError} If server encounters an error
*/
async getMetrics(data) {
this.validateRequiredKeys(data);
try {
return await this.get('', { 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;
}
}
/**
* Get metadata for a specific app
* @param data - The get app metadata request parameters
* @returns Promise with the app metadata response
* @throws {InvalidRequestError} If required fields are missing
* @throws {AuthenticationError} If API keys are invalid
* @throws {ServerError} If server encounters an error
*/
async getAppMetadata(data) {
this.validateAppKeys(data);
try {
return await this.get('/app', { 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;
}
}
/**
* Get metadata for a specific tenant
* @param data - The get tenant metadata request parameters
* @returns Promise with the tenant metadata response
* @throws {InvalidRequestError} If required fields are missing
* @throws {AuthenticationError} If API keys are invalid
* @throws {ServerError} If server encounters an error
*/
async getTenantMetadata(data) {
this.validateRequiredKeys(data);
try {
return await this.get('/tenant', { 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.MetricsEndpoint = MetricsEndpoint;
//# sourceMappingURL=handler.js.map