Dor Tools

@dor-tools/scaffold

Helpers for building a Dor Tool on @dor-tools/api: the loopback server that serves a Tool's page under a capability URL, the relay that answers the host's save request through that page, and the page's view of the host's theme. MIT-licensed, depending only on @dor-tools/api and Node built-ins. It is at 0.x, and its API may change before 1.0.

A complete Tool, which serves one page and prints its announcement for the host:

import { announceTool, reply, startToolServer } from '@dor-tools/scaffold/server';
import { HttpError } from '@dor-tools/scaffold/shared';

const tool = await startToolServer({
  csp: "default-src 'none'",
  unavailable: 'Page unavailable',
  route: async (req, res, prefix) => {
    if (req.url !== prefix) throw new HttpError(404);
    reply(res, 200, '<h1>Hello</h1>', 'text/html; charset=utf-8');
  },
});
process.stdout.write(announceTool({ ...tool, path: tool.prefix }, 'Hello'));

Every request needs the capability prefix, a loopback Host, and no foreign Origin, or it is answered 403 before route sees it. The package's rules are in Dormouse's docs/specs/dor-tools-scaffold.md.