UNPKG

n8n-bookstack-agent-tool

Version:

Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility

105 lines โ€ข 4.46 kB
"use strict"; 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