n8n-bookstack-agent-tool
Version:
Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility
252 lines • 11.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceManager = exports.TagsResource = exports.AttachmentsResource = exports.RolesResource = exports.UsersResource = exports.ShelvesResource = exports.PagesResource = exports.ChaptersResource = exports.BooksResource = void 0;
var books_js_1 = require("./books.js");
Object.defineProperty(exports, "BooksResource", { enumerable: true, get: function () { return books_js_1.BooksResource; } });
var chapters_js_1 = require("./chapters.js");
Object.defineProperty(exports, "ChaptersResource", { enumerable: true, get: function () { return chapters_js_1.ChaptersResource; } });
var pages_js_1 = require("./pages.js");
Object.defineProperty(exports, "PagesResource", { enumerable: true, get: function () { return pages_js_1.PagesResource; } });
var shelves_js_1 = require("./shelves.js");
Object.defineProperty(exports, "ShelvesResource", { enumerable: true, get: function () { return shelves_js_1.ShelvesResource; } });
var users_js_1 = require("./users.js");
Object.defineProperty(exports, "UsersResource", { enumerable: true, get: function () { return users_js_1.UsersResource; } });
var roles_js_1 = require("./roles.js");
Object.defineProperty(exports, "RolesResource", { enumerable: true, get: function () { return roles_js_1.RolesResource; } });
var attachments_js_1 = require("./attachments.js");
Object.defineProperty(exports, "AttachmentsResource", { enumerable: true, get: function () { return attachments_js_1.AttachmentsResource; } });
var tags_js_1 = require("./tags.js");
Object.defineProperty(exports, "TagsResource", { enumerable: true, get: function () { return tags_js_1.TagsResource; } });
const books_js_2 = require("./books.js");
const chapters_js_2 = require("./chapters.js");
const pages_js_2 = require("./pages.js");
const shelves_js_2 = require("./shelves.js");
const users_js_2 = require("./users.js");
const roles_js_2 = require("./roles.js");
const attachments_js_2 = require("./attachments.js");
const tags_js_2 = require("./tags.js");
class ResourceManager {
constructor(config) {
this.config = config;
this.books = new books_js_2.BooksResource(config);
this.chapters = new chapters_js_2.ChaptersResource(config);
this.pages = new pages_js_2.PagesResource(config);
this.shelves = new shelves_js_2.ShelvesResource(config);
this.users = new users_js_2.UsersResource(config);
this.roles = new roles_js_2.RolesResource(config);
this.attachments = new attachments_js_2.AttachmentsResource(config);
this.tags = new tags_js_2.TagsResource(config);
}
getBooks() {
return this.books;
}
getChapters() {
return this.chapters;
}
getPages() {
return this.pages;
}
getShelves() {
return this.shelves;
}
getUsers() {
return this.users;
}
getRoles() {
return this.roles;
}
getAttachments() {
return this.attachments;
}
getTags() {
return this.tags;
}
async executeCommand(commandName, params) {
const [resource, operation] = this.parseCommandName(commandName);
switch (resource) {
case 'books':
return await this.executeBookCommand(operation, params);
case 'chapters':
return await this.executeChapterCommand(operation, params);
case 'pages':
return await this.executePageCommand(operation, params);
case 'shelves':
return await this.executeShelfCommand(operation, params);
case 'users':
return await this.executeUserCommand(operation, params);
case 'roles':
return await this.executeRoleCommand(operation, params);
case 'attachments':
return await this.executeAttachmentCommand(operation, params);
case 'tags':
return await this.executeTagCommand(operation, params);
default:
throw new Error(`Unknown resource: ${resource}`);
}
}
parseCommandName(commandName) {
const patterns = [
{ regex: /^exportBook(Html|Pdf|Markdown|Plaintext)$/, resource: 'books', operation: 'export' },
{ regex: /^(list|get|create|update|delete)Books?(.*)$/, resource: 'books' },
{ regex: /^(list|get|create|update|delete)Chapters?(.*)$/, resource: 'chapters' },
{ regex: /^(list|get|create|update|delete)Pages?(.*)$/, resource: 'pages' },
{ regex: /^(list|get|create|update|delete)Shelves?(.*)$/, resource: 'shelves' },
{ regex: /^(list|get|create|update|delete)Users?(.*)$/, resource: 'users' },
{ regex: /^(list|get|create|update|delete)Roles?(.*)$/, resource: 'roles' },
{ regex: /^(list|get|create|update|delete)Attachments?(.*)$/, resource: 'attachments' },
{ regex: /^(list|get|create|update|delete)Tags?(.*)$/, resource: 'tags' }
];
for (const pattern of patterns) {
const match = commandName.match(pattern.regex);
if (match) {
if (pattern.operation === 'export') {
const exportType = match[1].toLowerCase();
return [pattern.resource, `export${exportType}`];
}
else {
const operation = match[1].toLowerCase() + (match[2] || '');
return [pattern.resource, operation];
}
}
}
throw new Error(`Cannot parse command name: ${commandName}`);
}
async executeBookCommand(operation, params) {
switch (operation) {
case 'list':
return await this.books.listBooks(params);
case 'get':
return await this.books.getBook(params);
case 'create':
return await this.books.createBook(params);
case 'update':
return await this.books.updateBook(params);
case 'delete':
return await this.books.deleteBook(params);
case 'exporthtml':
return await this.books.exportBookHtml(params);
case 'exportpdf':
return await this.books.exportBookPdf(params);
case 'exportplaintext':
return await this.books.exportBookPlaintext(params);
case 'exportmarkdown':
return await this.books.exportBookMarkdown(params);
default:
throw new Error(`Unknown book operation: ${operation}`);
}
}
async executeChapterCommand(operation, params) {
switch (operation) {
case 'list':
return await this.chapters.listChapters(params);
case 'get':
return await this.chapters.getChapter(params);
case 'create':
return await this.chapters.createChapter(params);
case 'update':
return await this.chapters.updateChapter(params);
case 'delete':
return await this.chapters.deleteChapter(params);
default:
throw new Error(`Unknown chapter operation: ${operation}`);
}
}
async executePageCommand(operation, params) {
switch (operation) {
case 'list':
return await this.pages.listPages(params);
case 'get':
return await this.pages.getPage(params);
case 'create':
return await this.pages.createPage(params);
case 'update':
return await this.pages.updatePage(params);
case 'delete':
return await this.pages.deletePage(params);
default:
throw new Error(`Unknown page operation: ${operation}`);
}
}
async executeShelfCommand(operation, params) {
switch (operation) {
case 'list':
return await this.shelves.listShelves(params);
case 'get':
return await this.shelves.getShelf(params);
case 'create':
return await this.shelves.createShelf(params);
case 'update':
return await this.shelves.updateShelf(params);
case 'delete':
return await this.shelves.deleteShelf(params);
default:
throw new Error(`Unknown shelf operation: ${operation}`);
}
}
async executeUserCommand(operation, params) {
switch (operation) {
case 'list':
return await this.users.listUsers(params);
case 'get':
return await this.users.getUser(params);
case 'create':
return await this.users.createUser(params);
case 'update':
return await this.users.updateUser(params);
case 'delete':
return await this.users.deleteUser(params);
default:
throw new Error(`Unknown user operation: ${operation}`);
}
}
async executeRoleCommand(operation, params) {
switch (operation) {
case 'list':
return await this.roles.listRoles(params);
case 'get':
return await this.roles.getRole(params);
case 'create':
return await this.roles.createRole(params);
case 'update':
return await this.roles.updateRole(params);
case 'delete':
return await this.roles.deleteRole(params);
default:
throw new Error(`Unknown role operation: ${operation}`);
}
}
async executeAttachmentCommand(operation, params) {
switch (operation) {
case 'list':
return await this.attachments.listAttachments(params);
case 'get':
return await this.attachments.getAttachment(params);
case 'create':
return await this.attachments.createAttachment(params);
case 'update':
return await this.attachments.updateAttachment(params);
case 'delete':
return await this.attachments.deleteAttachment(params);
default:
throw new Error(`Unknown attachment operation: ${operation}`);
}
}
async executeTagCommand(operation, params) {
switch (operation) {
case 'list':
return await this.tags.listTags(params);
case 'get':
return await this.tags.getTag(params);
case 'create':
return await this.tags.createTag(params);
case 'update':
return await this.tags.updateTag(params);
case 'delete':
return await this.tags.deleteTag(params);
default:
throw new Error(`Unknown tag operation: ${operation}`);
}
}
}
exports.ResourceManager = ResourceManager;
//# sourceMappingURL=index.js.map