npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@haneinfo/document-templates

v0.2.9

Published

Structured instance document templates with PDF and Word generation.

Readme

@haneinfo/document-templates

Structured PDF and Word downloads for readable StateMachine instances, implemented under approved decision 202610-d4f6. See package.json for the current package version.

Install the plugin with definition-registry, form and state-machine. The package name is plural; the manifest id is document-template, matching the definition permission namespace required by the RBAC permission catalog. No Prisma fragment, migration, new capability or plugin API version is needed.

{ "plugin": "@haneinfo/document-templates", "instanceId": "default", "enabled": true,
  "required": true, "configRef": "documentTemplates" }
runtime: {
  documentTemplates: {
    pdfFontPath: "/private/fonts/NotoSansTC-Regular.otf",
    docxFontName: "Noto Sans TC",
    images: { logo: "/private/images/logo.png" },
    maxPages: 50, maxTableRows: 500, maxOutputBytes: 10485760,
    generationTimeoutMs: 30000, maxConcurrentGenerations: 2,
  },
}

The strict config rejects unknown properties. pdfFontPath is mandatory and checked at startup; the font must be a readable OpenType/TrueType file (maximum 32 MiB) with the required CJK glyphs. Images are registered static PNG/JPEG files, maximum 2 MiB and 4096 pixels in each dimension, maximum 50 keys. Files are loaded at startup: restarting applies changes. Templates cannot supply paths, URLs or image data. Supply suitably licensed fonts/images and retain their license notices. No font ships in the production package. The renamed, SIL OFL 1.1 test subset lives only in src/__tests__/fixtures, with the full license and source/version/SHA-256 metadata.

See the complete loan receipt and approval proof definitions. They reference the equipment-loan App's Form and StateMachine; register logo before adopting the proof.

| HTTP (InteractiveAuthGuard) | Behavior | | --- | --- | | GET /state-machine-instances/:id/documents/templates | { items: [{ code, name, version }] } for available latest published templates | | POST /state-machine-instances/:id/documents | Strict { templateCode, format: "pdf" \| "docx" }; streamed attachment download |

Both routes check the shared state-machine read rule before template availability: submitter, effective instance:read, or matching personal/role readership. Unreadable and missing instances return the same INSTANCE_NOT_FOUND/404. The POST ignores no extra fields. Downloads carry attachment disposition with sanitized ASCII fallback and RFC 5987 UTF-8 filename, nosniff, no-store, correct content type and length. The filename combines template code and application number (instance id when no number exists). Successful generation records DOCUMENT history with actor, template code/version and format, without changing state/revision or sending notifications.

Register registry.register(...documentTemplatesMcpTools.commands({ scopeNamespace })) in the App's existing registry. Exactly two read tools use <namespace>:instance:read and require a user binding: list_document_templates({ instanceId }) and preview_document_text({ instanceId, templateCode }). Names and the resolved preview document are wrapped in $userContent. Previews do not render files or add history. There is no MCP file generation or publication tool. The generic registry tools automatically support DocumentTemplate drafts/patches/validation; people publish via the existing /definitions/publish HTTP route.

Definition permissions are document-template:definition:read, :write, :publish, declared in the manifest and discovered by RbacPermissionCatalog. Instance readers do not need definition permissions.

PDF uses pdfmake; Word uses docx. Both consume one resolved block tree. Cancellable worker threads bound CPU work, output bytes and concurrent generations. No temporary files are created. Rendering finishes into bounded memory before response headers, then HTTP streams the result, so limit errors return structured responses without partially sent documents. Word page limits use the canonical PDF layout preflight; Word clients may paginate differently when substituting fonts or editing content.

| Error | HTTP | | --- | --- | | INSTANCE_NOT_FOUND | 404 | | TEMPLATE_NOT_AVAILABLE | 409 | | TEMPLATE_INVALID | 409 (runtime compatibility), 400 (invalid text/render input) | | SUBJECT_UNAVAILABLE | 500 | | DOCUMENT_TOO_LARGE | 413 (rows, text, pages or bytes) | | DOCUMENT_BUSY | 429 | | DOCUMENT_TIMEOUT | 504 | | DOCUMENT_ABORTED | 400 (usually the client has already disconnected) | | DOCUMENT_FAILED | 500 | | INVALID_INPUT | 400; invalid MCP input returns { ok: false, error } | | FORBIDDEN | 403; MCP credential has no acting user |

Read agent-guide.md before designing a template. Build with pnpm build, then run the package tests. Tests require compiled worker output and run with one Vitest worker to avoid competing cold renderer startup on Windows. All runtime dependencies are pure JavaScript.

Development and maintenance scripts

  • Watch compilation during local development: pnpm --filter @haneinfo/document-templates dev (runs tsc -p tsconfig.build.json --watch).
  • Regenerate the template JSON Schema (schemas/document-template.spec.json) after modifying src/schema.ts: build first (pnpm --filter @haneinfo/document-templates build), then run node scripts/schema.mjs inside packages/document-templates.
  • Reproduce the test-only subset font (src/__tests__/fixtures/HaneinfoFixture.otf, SIL OFL 1.1) with Python and fonttools 4.60.1: python src/__tests__/fixtures/subset-font.py <source-font.otf> inside packages/document-templates.

Localized Form labels (approved decision 202610-a8d3)

Form field, column and option labels given as zh-TW/en maps are rendered in zh-TW (documents carry no request locale). Template labels and titles are unchanged. Requires plugin API 1.26.0.