n8n-bookstack-agent-tool
Version:
Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility
105 lines โข 4.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.testBookStackTool = testBookStackTool;
exports.demonstrateUsage = demonstrateUsage;
const index_js_1 = require("../index.js");
const error_handler_js_1 = require("../error/error-handler.js");
async function testBookStackTool() {
console.log('๐งช Testing BookStack n8n Tool...\n');
const config = {
baseUrl: 'https://demo.bookstackapp.com',
authType: 'bearer',
token: 'test-token-123',
timeout: 30000,
retryAttempts: 3,
retryDelay: 1000
};
try {
const tool = new index_js_1.BookStackN8nTool(config);
console.log('๐ Testing available commands...');
const commands = tool.getAvailableCommands();
console.log(`โ
Found ${commands.length} available commands`);
console.log('\n๐ Testing command metadata...');
const metadata = tool.getCommandMetadata();
console.log(`โ
Command metadata retrieved successfully`);
console.log('\n๐พ Testing cache functionality...');
const cacheStats = tool.getCacheStats();
console.log(`โ
Cache stats: ${JSON.stringify(cacheStats)}`);
console.log('\nโ Testing error handling...');
try {
await tool.execCommand('invalidCommand', {});
console.log('โ Should have thrown an error');
}
catch (error) {
if (error instanceof error_handler_js_1.BookStackError) {
console.log(`โ
Error handling works: ${error.type} - ${error.message}`);
}
else {
console.log(`โ
Error caught: ${error}`);
}
}
console.log('\n๐ Testing validation error...');
try {
await tool.execCommand('getBook', { id: 'invalid-id' });
console.log('โ Should have thrown a validation error');
}
catch (error) {
if (error instanceof error_handler_js_1.BookStackError && error.type === error_handler_js_1.BookStackErrorType.VALIDATION) {
console.log(`โ
Validation error handling works: ${error.message}`);
}
else {
console.log(`โ
Error caught: ${error}`);
}
}
console.log('\n๐ All tests completed successfully!');
}
catch (error) {
console.error('โ Test failed:', error);
throw error;
}
}
async function demonstrateUsage() {
console.log('\n๐ BookStack n8n Tool Usage Examples\n');
const config = {
baseUrl: 'https://your-bookstack.example.com',
authType: 'bearer',
token: 'your-api-token-here'
};
const tool = new index_js_1.BookStackN8nTool(config);
console.log('// Example 1: List books with pagination');
console.log('const books = await tool.execCommand("listBooks", {');
console.log(' count: 10,');
console.log(' offset: 0,');
console.log(' sort: "+name"');
console.log('});');
console.log('\n// Example 2: Create a new book');
console.log('const newBook = await tool.execCommand("createBook", {');
console.log(' name: "My Documentation",');
console.log(' description: "Comprehensive guide",');
console.log(' tags: [{ name: "category", value: "guide" }]');
console.log('});');
console.log('\n// Example 3: Get a specific page');
console.log('const page = await tool.execCommand("getPage", { id: 123 });');
console.log('\n// Example 4: Update a chapter');
console.log('const updatedChapter = await tool.execCommand("updateChapter", {');
console.log(' id: 456,');
console.log(' name: "Updated Chapter Title",');
console.log(' description: "New description"');
console.log('});');
console.log('\n// Example 5: Error handling');
console.log('try {');
console.log(' const result = await tool.execCommand("getBook", { id: 999 });');
console.log('} catch (error) {');
console.log(' if (error instanceof BookStackError) {');
console.log(' console.log("Error type:", error.type);');
console.log(' console.log("Status code:", error.statusCode);');
console.log(' console.log("Details:", error.details);');
console.log(' }');
console.log('}');
}
if (require.main === module) {
testBookStackTool()
.then(() => demonstrateUsage())
.catch(console.error);
}
//# sourceMappingURL=test-tool.js.map