watchtower-node-sdk
Version:
A TypeScript Node.js SDK for the Watchtower API, providing API key management, connection string generation, and more
80 lines • 3.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PDFEndpoint = void 0;
const base_1 = require("../base");
const errors_1 = require("../../errors");
class PDFEndpoint extends base_1.BaseEndpoint {
constructor(client) {
super(client, '/api/pdf');
}
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');
}
}
/**
* Generate a PDF export for a specific item
* @param data - The PDF export request parameters
* @returns Promise with the PDF export response
* @throws {InvalidRequestError} If required fields are missing or invalid
* @throws {AuthenticationError} If API keys are invalid
* @throws {ServerError} If server encounters an error
*/
async generatePDF(data) {
this.validateRequiredKeys(data);
if (!data.item_id) {
throw new errors_1.InvalidRequestError('item_id is required');
}
try {
return await this.post('/export', 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 status of a PDF export
* @param exportId - The ID of the export to check
* @param data - The request parameters containing API keys
* @returns Promise with the export status
* @throws {InvalidRequestError} If required fields are missing
* @throws {AuthenticationError} If API keys are invalid
* @throws {NotFoundError} If export is not found
* @throws {ServerError} If server encounters an error
*/
async getExportStatus(exportId, data) {
this.validateRequiredKeys(data);
try {
return await this.get(`/export/${exportId}/status`, { 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 === 404) {
throw new errors_1.NotFoundError(`Export with ID ${exportId} not found`);
}
if (error.response?.status === 500) {
throw new errors_1.ServerError('Internal server error');
}
throw error;
}
}
}
exports.PDFEndpoint = PDFEndpoint;
//# sourceMappingURL=handler.js.map