n8n-bookstack-agent-tool
Version:
Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility
58 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PagesResource = void 0;
const client_js_1 = require("../auth/client.js");
const zod_1 = require("zod");
const BasePageSchema = zod_1.z.object({
id: zod_1.z.number().optional(),
name: zod_1.z.string().min(1, 'Page name is required'),
html: zod_1.z.string().optional(),
markdown: zod_1.z.string().optional(),
book_id: zod_1.z.number().optional(),
chapter_id: zod_1.z.number().optional(),
tags: zod_1.z.array(zod_1.z.object({
name: zod_1.z.string(),
value: zod_1.z.string()
})).optional()
});
const PageSchema = BasePageSchema.refine(data => data.book_id || data.chapter_id, {
message: 'Either book_id or chapter_id must be provided',
path: ['book_id']
});
const ListPagesParamsSchema = zod_1.z.object({
count: zod_1.z.number().min(1).max(500).optional(),
offset: zod_1.z.number().min(0).optional(),
sort: zod_1.z.string().optional()
});
const PageIdParamsSchema = zod_1.z.object({
id: zod_1.z.number().min(1, 'Page ID is required')
});
class PagesResource {
constructor(config) {
this.client = new client_js_1.BookStackClient(config);
}
async listPages(params = {}) {
const validatedParams = ListPagesParamsSchema.parse(params);
return await this.client.get('/api/pages', validatedParams);
}
async getPage(params) {
const validatedParams = PageIdParamsSchema.parse(params);
return await this.client.get('/api/pages/{id}', validatedParams);
}
async createPage(params) {
const validatedParams = PageSchema.parse(params);
return await this.client.post('/api/pages', validatedParams);
}
async updatePage(params) {
const { id, ...pageData } = params;
const validatedId = PageIdParamsSchema.parse({ id });
const validatedData = BasePageSchema.partial().parse(pageData);
return await this.client.put('/api/pages/{id}', { ...validatedId, ...validatedData });
}
async deletePage(params) {
const validatedParams = PageIdParamsSchema.parse(params);
return await this.client.delete('/api/pages/{id}', validatedParams);
}
}
exports.PagesResource = PagesResource;
//# sourceMappingURL=pages.js.map