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

@doccop/server

v0.2.0

Published

Fastify HTTP server for doccop — templates, snippets, document rendering

Readme

@doccop/server

Fastify plugin exposing doccop's engine over /v1/* HTTP endpoints. Handles auth, idempotency, rate-limiting, multipart .docx uploads, and the full DocCopError → HTTP status mapping.

Status: 0.2.0-beta.0 — feature-frozen for the 0.2.0 line.

Install

npm install @doccop/server @doccop/core @fastify/multipart fastify

@doccop/server depends on @doccop/core exactly (no ^ — cross-package interface compatibility must agree).

Register the plugin

import fastify from "fastify";
import fastifyMultipart from "@fastify/multipart";
import { doccopRoutes } from "@doccop/server";

const app = fastify();
await app.register(fastifyMultipart);
await app.register(doccopRoutes, {
  config: {
    // Engine config (from @doccop/core)
    storage: myStorageAdapter,
    resolvers: [myPartyA, myPartyB, mySystem],
    requisitesResolver: mySnippetResolver,
    numbering: myNumberingService,
    naming: myNamingService,
    auth: myAuthAdapter,
    // Server stores (host-implemented — see Stores section)
    templates: myTemplateStore,
    templateVersions: myTemplateVersionStore,
    snippets: mySnippetStore,
    snippetVersions: mySnippetVersionStore,
    documents: myDocumentStore,
    idempotency: myIdempotencyStore,
    dataTypes: myDataTypeRegistry,
  },
});

await app.listen({ port: 3000 });

Mounts under /v1 by default. To customise the prefix, register inside an outer scope:

await app.register(async (scope) => {
  await scope.register(doccopRoutes, { config });
}, { prefix: "/api" });
// → POST /api/v1/documents, etc.

Routes

| Method | Path | Purpose | |---|---|---| | POST | /v1/templates | Upload a .docx, parse + normalise, create v1 | | GET | /v1/templates | List templates visible to the user | | GET | /v1/templates/:id | Template metadata | | GET | /v1/templates/:id/preview | HTML preview + anchor map | | POST | /v1/templates/:id/placeholders | Wrap inline / block placeholder (new version) | | DELETE | /v1/templates/:id/placeholders/:tag | Unwrap a placeholder | | POST | /v1/snippets | Upload a requisites snippet (admin-only) | | GET | /v1/snippets | List snippets | | DELETE | /v1/snippets/:id | Delete a snippet | | POST | /v1/documents | Render a document (idempotency-keyed, rate-limited) | | GET | /v1/documents | List own documents | | GET | /v1/documents/:id | Download generated .docx |

Every endpoint validates input via Zod before the engine sees bytes. Engine errors map deterministically onto HTTP status codes — see the error mapping table in INTEGRATION.md.

Stores you implement

Seven interfaces in @doccop/server (re-exported from this package):

  • TemplateStore, TemplateVersionStore
  • SnippetStore, SnippetVersionStore
  • DocumentStore
  • IdempotencyStore — atomic (key, userId) → documentId
  • DataTypeRegistry — placeholder tag → DataType

Reference impls:

  • In-memory, ~250 LoC: packages/server/test/helpers.ts in the doccop repository — passes the full test suite, perfect copy-paste starting point.
  • Postgres + Drizzle: install @doccop/storage-postgres and drop in the seven concrete classes.

Error handling

The default error envelope:

{ "error": { "code": "STRING_CODE", "message": "...", "details": {} } }

Map by code for i18n (the message is English-only).

To override the envelope, register your own error handler after doccopRoutes:

app.setErrorHandler((err, req, reply) => {
  if (err instanceof DocCopError) { /* your envelope */ }
  reply.status(500).send({ /* ... */ });
});

Rate limiting

Ships an in-memory limiter (InMemoryRateLimiter) — single-instance only. For multi-pod deployments, swap in a Redis-backed limiter at the host level.

Documentation

  • Integration guide — adapter implementations, deployment notes, migration patterns.
  • demo-app — Fastify server demo with in-memory stores you can npm run start immediately.

License

MIT — see LICENSE.