@mccaskie-labs/workbench-agreements 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mccaskie-labs/workbench-agreements
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - `pdf-lib` is loaded only when a PDF is read or made, so importing the package keeps Workers test runs under the runtime's message size limit ("Message is too large").
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  - First version: `createAgreements` (create, invite, share for Messenger and WhatsApp, get, list, void, file, verify, the signing route, tick, cleanup), `agreementsMigration`, the signed copy with its signing certificate (`buildSignedCopy`), the signing pages with `wb-agreement-*` classes and `AGREEMENT_STYLES`, words in English, Tagalog and Taglish, and `npx workbench-agreements init|generate [--check]|migration`.
package/README.md CHANGED
@@ -37,3 +37,7 @@ ctx.waitUntil(agreements.cleanup());
37
37
  | `AGREEMENT_WORDS` | The words in English, Tagalog and Taglish (`ui.wbagreement.*`) |
38
38
 
39
39
  Commands: `npx workbench-agreements init`, `generate [--check]`, `migration`.
40
+
41
+ ## Size and Workers tests
42
+
43
+ PDF work uses `pdf-lib` (about 1 MB), which the package loads only when a PDF is read or made: on `create`, on signing, and in `pdfPages` or `buildSignedCopy`. Importing the package doesn't load it, so a Workers test run (`@cloudflare/vitest-plugin`), which sends each test file's modules to the runtime, doesn't fail with "Message is too large". If a test file of yours imports `pdf-lib` itself, for example to make a sample PDF, load it with `await import("pdf-lib")` inside the test, not at the top of the file.
@@ -1,4 +1,4 @@
1
- import { type PDFFont } from "pdf-lib";
1
+ import type { PDFFont } from "pdf-lib";
2
2
  import type { IdentityCheck, SigningMethod } from "./config.ts";
3
3
  export interface CertificateSigner {
4
4
  name: string;
@@ -9,12 +9,17 @@
9
9
  // The standard PDF fonts only draw Western European letters (WinAnsi), which
10
10
  // covers English and Filipino names (ñ, é); anything else is shown by its
11
11
  // plain letter, or "?", and the exact text stays in the database.
12
- import { PDFDocument, rgb, StandardFonts } from "pdf-lib";
12
+ // pdf-lib is loaded only when a PDF is read or made, never at import: a Worker
13
+ // that imports the package (or a Workers test run that loads it in every test
14
+ // file) then doesn't carry it until an agreement is created or signed.
15
+ let pdfLib;
16
+ const loadPdfLib = () => (pdfLib ??= import("pdf-lib"));
13
17
  import { AgreementsError } from "./errors.js";
14
18
  /** The page count, refusing a file pdf-lib can't open or one that is encrypted (a signed copy couldn't be made from it). */
15
19
  export async function pdfPages(bytes) {
16
20
  if (bytes.length < 8 || String.fromCharCode(...bytes.slice(0, 5)) !== "%PDF-")
17
21
  throw new AgreementsError("invalid_request", "document must be a PDF");
22
+ const { PDFDocument } = await loadPdfLib();
18
23
  try {
19
24
  const doc = await PDFDocument.load(bytes, { updateMetadata: false });
20
25
  const n = doc.getPageCount();
@@ -28,9 +33,11 @@ export async function pdfPages(bytes) {
28
33
  }
29
34
  const A4 = { width: 595.28, height: 841.89 };
30
35
  const MARGIN = 50;
31
- const INK = rgb(0.11, 0.11, 0.13);
32
- const MUTED = rgb(0.37, 0.37, 0.42);
33
- const RULE = rgb(0.84, 0.84, 0.87);
36
+ // pdf-lib's rgb() makes exactly this shape; written out so no import is needed here.
37
+ const colour = (red, green, blue) => ({ type: "RGB", red, green, blue });
38
+ const INK = colour(0.11, 0.11, 0.13);
39
+ const MUTED = colour(0.37, 0.37, 0.42);
40
+ const RULE = colour(0.84, 0.84, 0.87);
34
41
  /** Text a standard font can draw: each character it can't becomes its plain letter, or "?". */
35
42
  export function winAnsi(font, s) {
36
43
  const set = new Set(font.getCharacterSet());
@@ -84,6 +91,7 @@ const METHOD = { typed: "Typed their name", drawn: "Drew their signature" };
84
91
  const IDENTITY = { link: "Opened the private signing link sent to them", email_code: "Opened the private signing link and entered a one-time code emailed to them" };
85
92
  /** The signed copy's bytes. */
86
93
  export async function buildSignedCopy(c) {
94
+ const { PDFDocument, StandardFonts } = await loadPdfLib();
87
95
  let doc;
88
96
  try {
89
97
  doc = await PDFDocument.load(c.document, { updateMetadata: false });
package/dist/cli.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-agreements",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Agreements and e-signing for Workbench apps: send a branded PDF agreement, let each person sign it online with a typed or drawn signature, keep a timestamped audit trail, and email the signed copy, with a signing certificate, to everyone. Runs in the app's own Worker, database and R2 bucket.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",