@x12i/reportix-composer-api-client
v0.6.0
Published
Typed fetch client for the Reportix Composer HTTP API.
Downloads
250
Maintainers
Readme
@x12i/reportix-composer-api-client
Typed fetch client for the Reportix Composer HTTP API (@x12i/reportix-composer-api).
Install
npm install @x12i/reportix-composer-api-clientUsage
import { ReportixComposerClient, ReportixComposerApiError } from "@x12i/reportix-composer-api-client";
const client = new ReportixComposerClient({
baseUrl: "http://localhost:6460",
apiKey: process.env.REPORTIX_COMPOSER_API_KEY // optional; required if the server sets REPORTIX_COMPOSER_API_KEY
});
const templates = await client.listTemplates();
const htmlResult = await client.compose({
markdown: "# Hello",
templateId: "clean-report",
output: { format: "html" }
});
if (htmlResult.format === "html") {
console.log(htmlResult.data.title, htmlResult.data.html.slice(0, 80));
}
const pdfResult = await client.compose({
markdown: "# Hello",
templateId: "clean-report",
metadata: { title: "Hello", author: "Taylor Reynolds" },
output: { format: "pdf" }
});
await client.createTemplateFromHtml({
id: "my-report",
name: "My Report",
layoutHtml: "<!doctype html><html><head></head><body><!--CONTENT--></body></html>",
stylesCss: "body { font-family: sans-serif; }"
});
const copy = await client.duplicateTemplate("clean-report", { id: "my-copy", name: "My Copy" });
const preview = await client.previewTemplate(copy.manifest.id, {
sample: { markdown: "# Hello" },
format: "html",
anatomy: true
});
try {
await client.getTemplate("missing");
} catch (err) {
if (err instanceof ReportixComposerApiError) {
console.error(err.status, err.code, err.message, err.requestId);
}
}Methods
| Method | API |
| --- | --- |
| listTemplates() | GET /templates |
| getTemplate(id) | GET /templates/:id |
| createTemplateFromHtml(input) | POST /templates/from-html |
| createTemplateFromImage(input) | POST /templates/from-image (multipart) |
| updateTemplate(id, patch) | PATCH /templates/:id |
| duplicateTemplate(sourceId, input) | POST /templates/:id/duplicate |
| previewTemplate(id, request) | POST /templates/:id/preview |
| deleteTemplate(id) | DELETE /templates/:id |
| compose({ templateId, markdown, metadata?, documentType?, output }) | POST /compose |
Asset upload/list/delete (/assets*) are not wrapped yet — call the HTTP API directly (multipart for upload).
Default baseUrl is http://localhost:6460 (org port-map zone default for this repo).
