@mccaskie-labs/workbench-agreements 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,3 @@
1
+ export declare const SIGN_SCRIPT = "(function(){\nvar f=document.querySelector(\"form.wb-agreement-form[data-sign]\");if(!f)return;\nvar name=f.querySelector(\"input[name=name]\"),prev=f.querySelector(\".wb-agreement-typed-name\"),typed=f.querySelector(\".wb-agreement-typed\"),pad=f.querySelector(\".wb-agreement-pad\"),c=f.querySelector(\"canvas\"),out=f.querySelector(\"input[name=signature]\"),clr=f.querySelector(\".wb-agreement-clear\"),btn=f.querySelector(\".wb-agreement-sign\"),drawn=false;\nfunction upd(){if(prev&&name)prev.textContent=name.value;}\nif(name){name.addEventListener(\"input\",upd);upd();}\nfunction method(){var r=f.querySelector(\"input[name=method]:checked\");return r?r.value:(f.querySelector(\"input[name=method]\")||{}).value;}\nfunction show(){var m=method();if(typed)typed.hidden=m!==\"typed\";if(pad)pad.hidden=m!==\"drawn\";if(m===\"drawn\")size();}\nvar rs=f.querySelectorAll(\"input[name=method]\");for(var i=0;i<rs.length;i++)rs[i].addEventListener(\"change\",show);\nvar x=null,last=null;\nfunction size(){if(!c||c.width===c.clientWidth*2||!c.clientWidth)return;c.width=c.clientWidth*2;c.height=c.clientHeight*2;x=c.getContext(\"2d\");x.scale(2,2);x.lineWidth=2.5;x.lineCap=\"round\";x.lineJoin=\"round\";x.strokeStyle=\"#111\";drawn=false;}\nfunction pt(e){var b=c.getBoundingClientRect();return{x:e.clientX-b.left,y:e.clientY-b.top};}\nif(c){c.addEventListener(\"pointerdown\",function(e){size();last=pt(e);c.setPointerCapture(e.pointerId);e.preventDefault();});\nc.addEventListener(\"pointermove\",function(e){if(!last||!x)return;var p=pt(e);x.beginPath();x.moveTo(last.x,last.y);x.lineTo(p.x,p.y);x.stroke();last=p;drawn=true;e.preventDefault();});\nc.addEventListener(\"pointerup\",function(){last=null;});c.addEventListener(\"pointercancel\",function(){last=null;});}\nif(clr)clr.addEventListener(\"click\",function(){if(x){x.clearRect(0,0,c.width,c.height);}drawn=false;});\nf.addEventListener(\"submit\",function(){if(out)out.value=method()===\"drawn\"&&drawn&&c?c.toDataURL(\"image/png\"):\"\";if(btn)btn.disabled=true;});\nshow();\n})();";
2
+ /** The script's CSP hash, `'sha256-…'`, for the page's script-src. */
3
+ export declare function signScriptHash(): Promise<string>;
package/dist/script.js ADDED
@@ -0,0 +1,31 @@
1
+ // The signing page's script: the typed signature's live preview, drawing on
2
+ // the signature box (pointer events, so finger, pen and mouse), Clear, and
3
+ // showing only the chosen method. Without it the page still works for a typed
4
+ // signature; drawing needs it. It writes the drawing into the form's hidden
5
+ // `signature` field as a PNG data URL when the form is sent, and turns the
6
+ // Sign button off while sending. Plain ES5 with no helpers, so no bundler can
7
+ // add a reference the page doesn't define; its CSP hash is in script-src.
8
+ export const SIGN_SCRIPT = `(function(){
9
+ var f=document.querySelector("form.wb-agreement-form[data-sign]");if(!f)return;
10
+ var name=f.querySelector("input[name=name]"),prev=f.querySelector(".wb-agreement-typed-name"),typed=f.querySelector(".wb-agreement-typed"),pad=f.querySelector(".wb-agreement-pad"),c=f.querySelector("canvas"),out=f.querySelector("input[name=signature]"),clr=f.querySelector(".wb-agreement-clear"),btn=f.querySelector(".wb-agreement-sign"),drawn=false;
11
+ function upd(){if(prev&&name)prev.textContent=name.value;}
12
+ if(name){name.addEventListener("input",upd);upd();}
13
+ function method(){var r=f.querySelector("input[name=method]:checked");return r?r.value:(f.querySelector("input[name=method]")||{}).value;}
14
+ function show(){var m=method();if(typed)typed.hidden=m!=="typed";if(pad)pad.hidden=m!=="drawn";if(m==="drawn")size();}
15
+ var rs=f.querySelectorAll("input[name=method]");for(var i=0;i<rs.length;i++)rs[i].addEventListener("change",show);
16
+ var x=null,last=null;
17
+ function size(){if(!c||c.width===c.clientWidth*2||!c.clientWidth)return;c.width=c.clientWidth*2;c.height=c.clientHeight*2;x=c.getContext("2d");x.scale(2,2);x.lineWidth=2.5;x.lineCap="round";x.lineJoin="round";x.strokeStyle="#111";drawn=false;}
18
+ function pt(e){var b=c.getBoundingClientRect();return{x:e.clientX-b.left,y:e.clientY-b.top};}
19
+ if(c){c.addEventListener("pointerdown",function(e){size();last=pt(e);c.setPointerCapture(e.pointerId);e.preventDefault();});
20
+ c.addEventListener("pointermove",function(e){if(!last||!x)return;var p=pt(e);x.beginPath();x.moveTo(last.x,last.y);x.lineTo(p.x,p.y);x.stroke();last=p;drawn=true;e.preventDefault();});
21
+ c.addEventListener("pointerup",function(){last=null;});c.addEventListener("pointercancel",function(){last=null;});}
22
+ if(clr)clr.addEventListener("click",function(){if(x){x.clearRect(0,0,c.width,c.height);}drawn=false;});
23
+ f.addEventListener("submit",function(){if(out)out.value=method()==="drawn"&&drawn&&c?c.toDataURL("image/png"):"";if(btn)btn.disabled=true;});
24
+ show();
25
+ })();`;
26
+ let hash;
27
+ /** The script's CSP hash, `'sha256-…'`, for the page's script-src. */
28
+ export function signScriptHash() {
29
+ hash ??= crypto.subtle.digest("SHA-256", new TextEncoder().encode(SIGN_SCRIPT)).then((d) => `'sha256-${btoa(String.fromCharCode(...new Uint8Array(d)))}'`);
30
+ return hash;
31
+ }
@@ -0,0 +1,7 @@
1
+ export declare function newToken(): string;
2
+ export declare const isToken: (s: string) => boolean;
3
+ /** Six digits, evenly spread (no modulo bias). */
4
+ export declare function newCode(): string;
5
+ export declare function sha256Hex(data: Uint8Array | string): Promise<string>;
6
+ /** A code's stored form: tied to its signer, so one signer's hash can't be tried for another. */
7
+ export declare const codeHash: (signerId: string, code: string) => Promise<string>;
@@ -0,0 +1,26 @@
1
+ // Signing tokens, email codes and hashes. A token is 32 random bytes in
2
+ // base64url (43 characters): holding it is what lets a signer open their
3
+ // page, so it is never logged. A code is 6 digits, kept only as a hash with
4
+ // the signer's id, for 10 minutes and 5 tries.
5
+ const B64URL = /^[A-Za-z0-9_-]{43}$/;
6
+ const b64url = (bytes) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
7
+ export function newToken() {
8
+ return b64url(crypto.getRandomValues(new Uint8Array(32)));
9
+ }
10
+ export const isToken = (s) => B64URL.test(s);
11
+ /** Six digits, evenly spread (no modulo bias). */
12
+ export function newCode() {
13
+ const a = new Uint32Array(1);
14
+ for (;;) {
15
+ crypto.getRandomValues(a);
16
+ if (a[0] < 4_294_000_000)
17
+ return String(a[0] % 1_000_000).padStart(6, "0");
18
+ }
19
+ }
20
+ export async function sha256Hex(data) {
21
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
22
+ const d = await crypto.subtle.digest("SHA-256", bytes);
23
+ return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, "0")).join("");
24
+ }
25
+ /** A code's stored form: tied to its signer, so one signer's hash can't be tried for another. */
26
+ export const codeHash = (signerId, code) => sha256Hex(`wb-agreement-code|${signerId}|${code}`);
@@ -0,0 +1,9 @@
1
+ export interface DrawnSignature {
2
+ png: Uint8Array;
3
+ width: number;
4
+ height: number;
5
+ }
6
+ /** The PNG, or a reason it isn't one we accept. */
7
+ export declare function readDrawnSignature(dataUrl: string): DrawnSignature | {
8
+ problem: string;
9
+ };
@@ -0,0 +1,35 @@
1
+ // A drawn signature arrives as a PNG data URL from the page's script. It is
2
+ // checked here before anything is stored: a real PNG, of a sensible size,
3
+ // that isn't empty.
4
+ const MAX_SIGNATURE_BYTES = 150_000;
5
+ /** The PNG, or a reason it isn't one we accept. */
6
+ export function readDrawnSignature(dataUrl) {
7
+ const m = /^data:image\/png;base64,([A-Za-z0-9+/]+={0,2})$/.exec(dataUrl);
8
+ if (!m)
9
+ return { problem: "not a PNG data URL" };
10
+ if ((m[1].length * 3) / 4 > MAX_SIGNATURE_BYTES)
11
+ return { problem: "too big" };
12
+ let bin;
13
+ try {
14
+ bin = atob(m[1]);
15
+ }
16
+ catch {
17
+ return { problem: "not base64" };
18
+ }
19
+ const png = Uint8Array.from(bin, (c) => c.charCodeAt(0));
20
+ const sig = [137, 80, 78, 71, 13, 10, 26, 10];
21
+ if (png.length < 33 || sig.some((b, i) => png[i] !== b))
22
+ return { problem: "not a PNG" };
23
+ // The first chunk must be IHDR: width and height, big-endian, at bytes 16 and 20.
24
+ if (String.fromCharCode(...png.slice(12, 16)) !== "IHDR")
25
+ return { problem: "not a PNG" };
26
+ const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
27
+ const width = view.getUint32(16);
28
+ const height = view.getUint32(20);
29
+ if (width < 100 || height < 40 || width > 2400 || height > 1200)
30
+ return { problem: "an odd size" };
31
+ // An empty canvas compresses to a few hundred bytes; a real signature is more.
32
+ if (png.length < 600)
33
+ return { problem: "empty" };
34
+ return { png, width, height };
35
+ }
@@ -0,0 +1,33 @@
1
+ /** One CSS custom property the rules read, with its default. */
2
+ export interface StyleVariable {
3
+ /** `--wb-<tool>-<what>`. */
4
+ name: string;
5
+ value: string;
6
+ about: string;
7
+ }
8
+ /** A rule for a class in another state, or for an element inside it. */
9
+ export interface StyleState {
10
+ selector: string;
11
+ about: string;
12
+ css: string;
13
+ }
14
+ /** One class the tool puts on an element, with its default rule. */
15
+ export interface StyleClass {
16
+ name: string;
17
+ element: string;
18
+ about: string;
19
+ css: string;
20
+ states?: readonly StyleState[];
21
+ }
22
+ /** Every class and variable the tool draws with. */
23
+ export interface ToolStyles {
24
+ format: 1;
25
+ tool: string;
26
+ package: string;
27
+ title: string;
28
+ prefix: string;
29
+ variables: readonly StyleVariable[];
30
+ classes: readonly StyleClass[];
31
+ }
32
+ /** The style hooks of the signing page, its code check, and its done and ended pages. */
33
+ export declare const AGREEMENT_STYLES: ToolStyles;
package/dist/styles.js ADDED
@@ -0,0 +1,68 @@
1
+ // The look the signing page starts with (docs/capabilities-manifest.md §10).
2
+ // Every element the page draws carries one of these classes, and every class
3
+ // has a default rule here, so the page looks finished out of the box and a
4
+ // project restyles it from its own project.css by the same names.
5
+ // `npx workbench-ui styles` writes these into the project's
6
+ // public/styles/workbench.css. The names are public: renaming one is a
7
+ // breaking change. Signers are mostly on a phone, so it starts light, with
8
+ // 48 px buttons.
9
+ const v = (name) => `var(--wb-agreement-${name})`;
10
+ const button = `display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:100%;min-height:48px;padding:0 1.25rem;border-radius:${v("radius")};font:inherit;font-weight:600;text-decoration:none;cursor:pointer`;
11
+ const focus = { selector: ":focus-visible", about: "Has focus", css: `outline:none;box-shadow:0 0 0 3px ${v("focus")}` };
12
+ const field = `box-sizing:border-box;width:100%;min-height:48px;padding:.5rem .75rem;border:1px solid ${v("line")};border-radius:${v("radius")};background:${v("surface")};color:${v("text")};font:inherit`;
13
+ /** The style hooks of the signing page, its code check, and its done and ended pages. */
14
+ export const AGREEMENT_STYLES = {
15
+ format: 1,
16
+ tool: "agreements",
17
+ package: "@mccaskie-labs/workbench-agreements",
18
+ title: "Agreement signing page",
19
+ prefix: "wb-agreement-",
20
+ variables: [
21
+ { name: "--wb-agreement-text", value: "#1d1d22", about: "Text" },
22
+ { name: "--wb-agreement-muted", value: "#5f5f6b", about: "Quieter text: who it's from, hints, the deadline" },
23
+ { name: "--wb-agreement-surface", value: "#ffffff", about: "Background of the page and the fields" },
24
+ { name: "--wb-agreement-line", value: "#d6d6de", about: "Borders of the fields and the signature box" },
25
+ { name: "--wb-agreement-accent", value: "#1b66d6", about: "The Sign button and links" },
26
+ { name: "--wb-agreement-on-accent", value: "#ffffff", about: "Text on the Sign button" },
27
+ { name: "--wb-agreement-danger", value: "#b42318", about: "Problems and the Decline button" },
28
+ { name: "--wb-agreement-danger-soft", value: "#fef3f2", about: "Background of the problem box" },
29
+ { name: "--wb-agreement-focus", value: "rgba(27,102,214,.35)", about: "The ring round whatever has focus" },
30
+ { name: "--wb-agreement-radius", value: "10px", about: "Corner rounding of fields, buttons and the signature box" },
31
+ { name: "--wb-agreement-width", value: "36rem", about: "Widest the page grows" },
32
+ { name: "--wb-agreement-signature-font", value: '"Segoe Script","Brush Script MT","Snell Roundhand",cursive', about: "The typed signature's handwriting font" },
33
+ ],
34
+ classes: [
35
+ { name: "wb-agreement", element: "main", about: "The whole page", css: `box-sizing:border-box;max-width:${v("width")};margin:0 auto;padding:1rem 1rem 2rem;color:${v("text")};background:${v("surface")};font:16px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif` },
36
+ { name: "wb-agreement-title", element: "h1", about: "The agreement's title, or the page's heading", css: "margin:0 0 .25rem;font-size:1.5rem;line-height:1.25;font-weight:700" },
37
+ { name: "wb-agreement-meta", element: "p", about: "A detail under the title: who it's from, who it's for, the deadline, who else signs", css: `margin:0 0 .25rem;color:${v("muted")}` },
38
+ { name: "wb-agreement-read", element: "a", about: "The button that opens the agreement's PDF", css: `${button};margin:1.25rem 0 .25rem;border:1px solid ${v("accent")};color:${v("accent")};background:transparent`, states: [focus] },
39
+ { name: "wb-agreement-hint", element: "p", about: "A short hint under a button or field", css: `margin:.25rem 0 0;color:${v("muted")};font-size:.9rem` },
40
+ { name: "wb-agreement-problems", element: "div", about: "The box listing what to fix", css: `margin:1rem 0;padding:.75rem 1rem;border:1px solid ${v("danger")};border-radius:${v("radius")};background:${v("danger-soft")};color:${v("danger")}` },
41
+ { name: "wb-agreement-problems-title", element: "p", about: "The problem box's heading", css: "margin:0 0 .25rem;font-weight:700" },
42
+ { name: "wb-agreement-problem-list", element: "ul", about: "The problems", css: "margin:0;padding-left:1.25rem" },
43
+ { name: "wb-agreement-problem", element: "li", about: "One problem", css: "margin:0" },
44
+ { name: "wb-agreement-form", element: "form", about: "The signing form, and the code form", css: "display:flex;flex-direction:column;gap:1rem;margin:1.25rem 0 0" },
45
+ { name: "wb-agreement-check", element: "label", about: "A tick box with its words", css: "display:flex;gap:.6rem;align-items:flex-start;cursor:pointer" },
46
+ { name: "wb-agreement-check-input", element: "input", about: "The tick box", css: "flex:none;width:1.25rem;height:1.25rem;margin:.15rem 0 0", states: [focus] },
47
+ { name: "wb-agreement-field", element: "div", about: "A label, its field and its hint", css: "display:flex;flex-direction:column;gap:.25rem" },
48
+ { name: "wb-agreement-label", element: "label", about: "A field's label", css: "font-weight:600" },
49
+ { name: "wb-agreement-input", element: "input", about: "A text field: the full name, the code", css: field, states: [focus] },
50
+ { name: "wb-agreement-methods", element: "fieldset", about: "The choice of typed or drawn", css: "display:flex;flex-direction:column;gap:.5rem;margin:0;padding:0;border:0" },
51
+ { name: "wb-agreement-methods-legend", element: "legend", about: "The choice's question", css: "margin:0 0 .25rem;padding:0;font-weight:600" },
52
+ { name: "wb-agreement-method", element: "label", about: "One way to sign", css: "display:flex;gap:.6rem;align-items:center;cursor:pointer" },
53
+ { name: "wb-agreement-method-input", element: "input", about: "The radio button for one way to sign", css: "flex:none;width:1.25rem;height:1.25rem;margin:0", states: [focus] },
54
+ { name: "wb-agreement-typed", element: "div", about: "The typed signature's preview", css: `display:flex;flex-direction:column;gap:.25rem`, states: [{ selector: "[hidden]", about: "When drawing is chosen", css: "display:none" }] },
55
+ { name: "wb-agreement-typed-name", element: "p", about: "The typed name in handwriting", css: `margin:0;min-height:3.5rem;padding:.5rem .75rem;border-bottom:2px solid ${v("line")};font:2rem/1.3 ${v("signature-font")};overflow-wrap:anywhere` },
56
+ { name: "wb-agreement-pad", element: "div", about: "The signature box and its Clear button", css: "display:flex;flex-direction:column;gap:.5rem", states: [{ selector: "[hidden]", about: "When typing is chosen", css: "display:none" }] },
57
+ { name: "wb-agreement-canvas", element: "canvas", about: "The box a signature is drawn in", css: `display:block;width:100%;height:10rem;border:1px dashed ${v("line")};border-radius:${v("radius")};background:${v("surface")};touch-action:none;cursor:crosshair` },
58
+ { name: "wb-agreement-clear", element: "button", about: "Clears the drawn signature", css: `align-self:flex-end;min-height:40px;padding:0 1rem;border:1px solid ${v("line")};border-radius:${v("radius")};background:transparent;color:${v("text")};font:inherit;cursor:pointer`, states: [focus] },
59
+ { name: "wb-agreement-data", element: "input", about: "A hidden field the form sends (which action, the drawn signature)", css: "display:none" },
60
+ { name: "wb-agreement-sign", element: "button", about: "The Sign button, and the code form's buttons", css: `${button};border:0;color:${v("on-accent")};background:${v("accent")}`, states: [focus, { selector: ":disabled", about: "While the form is sending", css: "opacity:.6;cursor:wait" }] },
61
+ { name: "wb-agreement-decline", element: "details", about: "The fold with the way to decline", css: "margin:1.5rem 0 0" },
62
+ { name: "wb-agreement-decline-summary", element: "summary", about: "Opens the fold", css: `color:${v("muted")};cursor:pointer` },
63
+ { name: "wb-agreement-textarea", element: "textarea", about: "Why they decline", css: `${field};min-height:6rem;resize:vertical`, states: [focus] },
64
+ { name: "wb-agreement-decline-button", element: "button", about: "The Decline button", css: `${button};border:1px solid ${v("danger")};color:${v("danger")};background:transparent`, states: [focus] },
65
+ { name: "wb-agreement-text", element: "p", about: "A paragraph on the done, declined, ended and code pages", css: "margin:.5rem 0 0" },
66
+ { name: "wb-agreement-download", element: "a", about: "Downloads the signed copy", css: `${button};margin:1.25rem 0 0;border:0;color:${v("on-accent")};background:${v("accent")}`, states: [focus] },
67
+ ],
68
+ };
@@ -0,0 +1,73 @@
1
+ import type { AgreementLanguage } from "./config.ts";
2
+ /** The project's strings: `t("ui.wbagreement.sign", {})`. Undefined for a word it lacks. */
3
+ export type AgreementStrings = (key: string, params?: Readonly<Record<string, string | number>>, language?: AgreementLanguage) => string | undefined;
4
+ declare const EN: {
5
+ readonly "page.from": "From {business}";
6
+ readonly "page.for": "For {name}";
7
+ readonly "page.read": "Read the agreement";
8
+ readonly "page.read_hint": "Opens the PDF ({pages}). Read it all before you sign.";
9
+ readonly "page.pages_one": "1 page";
10
+ readonly "page.pages_many": "{count} pages";
11
+ readonly "page.others": "Also signing: {names}";
12
+ readonly "page.expires": "Sign by {date}";
13
+ readonly "consent.read": "I have read the agreement.";
14
+ readonly "consent.esign": "I agree to sign electronically, to receive the agreement and the signed copy by email, and that my electronic signature is as binding as signing by hand.";
15
+ readonly "name.label": "Your full name";
16
+ readonly "name.hint": "As it appears on your ID.";
17
+ readonly "method.label": "How would you like to sign?";
18
+ readonly "method.typed": "Type my name";
19
+ readonly "method.drawn": "Draw my signature";
20
+ readonly "typed.preview": "Your signature will look like this:";
21
+ readonly "drawn.hint": "Draw your signature in the box with your finger or mouse.";
22
+ readonly "drawn.clear": "Clear";
23
+ readonly sign: "Sign agreement";
24
+ readonly sign_hint: "By tapping Sign agreement you sign it as {name}.";
25
+ readonly "decline.open": "I don't want to sign";
26
+ readonly "decline.reason": "Tell {business} why (optional)";
27
+ readonly decline: "Decline to sign";
28
+ readonly "problem.title": "Please fix this first";
29
+ readonly "problem.consent_read": "Tick the box to say you have read the agreement.";
30
+ readonly "problem.consent_esign": "Tick the box to agree to sign electronically.";
31
+ readonly "problem.name": "Type your full name (2 to 120 characters).";
32
+ readonly "problem.method": "Choose how to sign.";
33
+ readonly "problem.drawn": "Draw your signature in the box.";
34
+ readonly "problem.code": "That code isn't right. Check the latest email and try again.";
35
+ readonly "problem.code_expired": "That code has expired. Send a new one.";
36
+ readonly "problem.code_locked": "Too many tries. Send a new code.";
37
+ readonly "problem.code_wait": "A code was sent less than a minute ago. Check your email.";
38
+ readonly "code.title": "Check it's you";
39
+ readonly "code.text": "We'll email a 6-digit code to {email}. Type it here to open the agreement.";
40
+ readonly "code.send": "Email me a code";
41
+ readonly "code.sent": "We emailed a code to {email}. It works for 10 minutes.";
42
+ readonly "code.label": "The 6-digit code";
43
+ readonly "code.check": "Continue";
44
+ readonly "done.title": "Signed. Thank you";
45
+ readonly "done.text": "You signed this agreement on {date}. We've emailed the signed copy to everyone.";
46
+ readonly "done.waiting": "You signed this agreement on {date}. Once everyone has signed, we'll email you the signed copy.";
47
+ readonly "done.download": "Download the signed copy";
48
+ readonly "declined.title": "You declined to sign";
49
+ readonly "declined.text": "We've told {business}. If that was a mistake, ask them to send it again.";
50
+ readonly "ended.title": "This agreement is closed";
51
+ readonly "ended.voided": "{business} has withdrawn this agreement. Ask them if you were expecting to sign it.";
52
+ readonly "ended.expired": "The time to sign this agreement has passed. Ask {business} to send it again.";
53
+ readonly "ended.declined": "Someone has declined to sign, so this agreement is closed. Ask {business} if you have questions.";
54
+ readonly "not_found.title": "We can't find this agreement";
55
+ readonly "not_found.text": "Check the link you were sent, or ask whoever sent it for a new one.";
56
+ readonly "email.invite.subject": "Please sign: {title}";
57
+ readonly "email.invite.text": "Hi {name},\n\n{business} has sent you an agreement to sign online: {title}.\n\nRead and sign it here by {date}:\n{url}\n\nIf you weren't expecting this, you can ignore this email.";
58
+ readonly "email.reminder.subject": "Reminder: please sign {title}";
59
+ readonly "email.reminder.text": "Hi {name},\n\nA reminder that {business} is waiting for you to sign {title}.\n\nRead and sign it here by {date}:\n{url}";
60
+ readonly "email.code.subject": "Your code to sign {title}";
61
+ readonly "email.code.text": "Your code is {code}. It works for 10 minutes.\n\nIf you didn't ask for a code, someone may have your signing link. Don't share this code with anyone.";
62
+ readonly "email.signed.subject": "Signed: {title}";
63
+ readonly "email.signed.text": "Hi,\n\nEveryone has signed {title}. The signed copy is attached, with a signing certificate on its last page.\n\nAgreement {id}\nSigned copy SHA-256: {sha256}\n\nKeep this email for your records.";
64
+ readonly "email.declined.subject": "Declined: {title}";
65
+ readonly "email.declined.text": "{name} declined to sign {title}.{reason}\n\nThe agreement is now closed.";
66
+ readonly "share.text": "Hi {name}, please read and sign {title} here: {url}";
67
+ };
68
+ export type AgreementWordKey = keyof typeof EN;
69
+ export declare const AGREEMENT_WORD_KEYS: AgreementWordKey[];
70
+ export declare const AGREEMENT_WORDS: Readonly<Record<AgreementLanguage, Readonly<Record<string, string>>>>;
71
+ /** One word: the project's, else this package's in the language, else the English. */
72
+ export declare function agreementWord(t: AgreementStrings | undefined, language: AgreementLanguage, key: AgreementWordKey, params?: Readonly<Record<string, string | number>>): string;
73
+ export {};
package/dist/words.js ADDED
@@ -0,0 +1,162 @@
1
+ // The signing page's and the emails' words, keyed as the project's strings
2
+ // catalogue keys them (`ui.wbagreement.*`), in English, Tagalog and Taglish. A
3
+ // project copies them into its catalogue (or keeps its own) and passes its `t`
4
+ // to createAgreements; a word the catalogue lacks falls back to the words
5
+ // here, so a page never fails in front of a signer. The Tagalog and Taglish
6
+ // are starter words: have a fluent reader check them before a client sees
7
+ // them.
8
+ const EN = {
9
+ "page.from": "From {business}",
10
+ "page.for": "For {name}",
11
+ "page.read": "Read the agreement",
12
+ "page.read_hint": "Opens the PDF ({pages}). Read it all before you sign.",
13
+ "page.pages_one": "1 page",
14
+ "page.pages_many": "{count} pages",
15
+ "page.others": "Also signing: {names}",
16
+ "page.expires": "Sign by {date}",
17
+ "consent.read": "I have read the agreement.",
18
+ "consent.esign": "I agree to sign electronically, to receive the agreement and the signed copy by email, and that my electronic signature is as binding as signing by hand.",
19
+ "name.label": "Your full name",
20
+ "name.hint": "As it appears on your ID.",
21
+ "method.label": "How would you like to sign?",
22
+ "method.typed": "Type my name",
23
+ "method.drawn": "Draw my signature",
24
+ "typed.preview": "Your signature will look like this:",
25
+ "drawn.hint": "Draw your signature in the box with your finger or mouse.",
26
+ "drawn.clear": "Clear",
27
+ "sign": "Sign agreement",
28
+ "sign_hint": "By tapping Sign agreement you sign it as {name}.",
29
+ "decline.open": "I don't want to sign",
30
+ "decline.reason": "Tell {business} why (optional)",
31
+ "decline": "Decline to sign",
32
+ "problem.title": "Please fix this first",
33
+ "problem.consent_read": "Tick the box to say you have read the agreement.",
34
+ "problem.consent_esign": "Tick the box to agree to sign electronically.",
35
+ "problem.name": "Type your full name (2 to 120 characters).",
36
+ "problem.method": "Choose how to sign.",
37
+ "problem.drawn": "Draw your signature in the box.",
38
+ "problem.code": "That code isn't right. Check the latest email and try again.",
39
+ "problem.code_expired": "That code has expired. Send a new one.",
40
+ "problem.code_locked": "Too many tries. Send a new code.",
41
+ "problem.code_wait": "A code was sent less than a minute ago. Check your email.",
42
+ "code.title": "Check it's you",
43
+ "code.text": "We'll email a 6-digit code to {email}. Type it here to open the agreement.",
44
+ "code.send": "Email me a code",
45
+ "code.sent": "We emailed a code to {email}. It works for 10 minutes.",
46
+ "code.label": "The 6-digit code",
47
+ "code.check": "Continue",
48
+ "done.title": "Signed. Thank you",
49
+ "done.text": "You signed this agreement on {date}. We've emailed the signed copy to everyone.",
50
+ "done.waiting": "You signed this agreement on {date}. Once everyone has signed, we'll email you the signed copy.",
51
+ "done.download": "Download the signed copy",
52
+ "declined.title": "You declined to sign",
53
+ "declined.text": "We've told {business}. If that was a mistake, ask them to send it again.",
54
+ "ended.title": "This agreement is closed",
55
+ "ended.voided": "{business} has withdrawn this agreement. Ask them if you were expecting to sign it.",
56
+ "ended.expired": "The time to sign this agreement has passed. Ask {business} to send it again.",
57
+ "ended.declined": "Someone has declined to sign, so this agreement is closed. Ask {business} if you have questions.",
58
+ "not_found.title": "We can't find this agreement",
59
+ "not_found.text": "Check the link you were sent, or ask whoever sent it for a new one.",
60
+ "email.invite.subject": "Please sign: {title}",
61
+ "email.invite.text": "Hi {name},\n\n{business} has sent you an agreement to sign online: {title}.\n\nRead and sign it here by {date}:\n{url}\n\nIf you weren't expecting this, you can ignore this email.",
62
+ "email.reminder.subject": "Reminder: please sign {title}",
63
+ "email.reminder.text": "Hi {name},\n\nA reminder that {business} is waiting for you to sign {title}.\n\nRead and sign it here by {date}:\n{url}",
64
+ "email.code.subject": "Your code to sign {title}",
65
+ "email.code.text": "Your code is {code}. It works for 10 minutes.\n\nIf you didn't ask for a code, someone may have your signing link. Don't share this code with anyone.",
66
+ "email.signed.subject": "Signed: {title}",
67
+ "email.signed.text": "Hi,\n\nEveryone has signed {title}. The signed copy is attached, with a signing certificate on its last page.\n\nAgreement {id}\nSigned copy SHA-256: {sha256}\n\nKeep this email for your records.",
68
+ "email.declined.subject": "Declined: {title}",
69
+ "email.declined.text": "{name} declined to sign {title}.{reason}\n\nThe agreement is now closed.",
70
+ "share.text": "Hi {name}, please read and sign {title} here: {url}",
71
+ };
72
+ export const AGREEMENT_WORD_KEYS = Object.keys(EN);
73
+ const prefix = (o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [`ui.wbagreement.${k}`, v]));
74
+ const TL = {
75
+ "page.from": "Mula kay {business}",
76
+ "page.for": "Para kay {name}",
77
+ "page.read": "Basahin ang kasunduan",
78
+ "page.read_hint": "Bubuksan ang PDF ({pages}). Basahin ito nang buo bago pumirma.",
79
+ "page.pages_one": "1 pahina",
80
+ "page.pages_many": "{count} pahina",
81
+ "page.others": "Pipirma rin: {names}",
82
+ "page.expires": "Pumirma bago ang {date}",
83
+ "consent.read": "Nabasa ko na ang kasunduan.",
84
+ "consent.esign": "Pumapayag akong pumirma nang electronic, tumanggap ng kasunduan at ng pirmadong kopya sa email, at na kasing-bisa ng pirma sa papel ang aking electronic na pirma.",
85
+ "name.label": "Buong pangalan mo",
86
+ "name.hint": "Gaya ng nasa ID mo.",
87
+ "method.label": "Paano mo gustong pumirma?",
88
+ "method.typed": "I-type ang pangalan ko",
89
+ "method.drawn": "Iguhit ang pirma ko",
90
+ "typed.preview": "Ganito ang magiging itsura ng pirma mo:",
91
+ "drawn.hint": "Iguhit ang pirma mo sa kahon gamit ang daliri o mouse.",
92
+ "drawn.clear": "Burahin",
93
+ "sign": "Pirmahan ang kasunduan",
94
+ "sign_hint": "Sa pag-tap ng Pirmahan, pumipirma ka bilang {name}.",
95
+ "decline.open": "Ayokong pumirma",
96
+ "decline.reason": "Sabihin kay {business} kung bakit (hindi kailangan)",
97
+ "decline": "Tanggihan",
98
+ "problem.title": "Pakiayos muna ito",
99
+ "problem.consent_read": "Lagyan ng tsek para sabihing nabasa mo ang kasunduan.",
100
+ "problem.consent_esign": "Lagyan ng tsek para pumayag na pumirma nang electronic.",
101
+ "problem.name": "I-type ang buong pangalan mo (2 hanggang 120 titik).",
102
+ "problem.method": "Piliin kung paano pipirma.",
103
+ "problem.drawn": "Iguhit ang pirma mo sa kahon.",
104
+ "problem.code": "Mali ang code. Tingnan ang pinakabagong email at subukan ulit.",
105
+ "problem.code_expired": "Expired na ang code. Magpadala ng bago.",
106
+ "problem.code_locked": "Sobra na ang subok. Magpadala ng bagong code.",
107
+ "problem.code_wait": "May code na naipadala wala pang isang minuto. Tingnan ang email mo.",
108
+ "code.title": "Tiyakin nating ikaw ito",
109
+ "code.text": "Magpapadala kami ng 6-digit na code sa {email}. I-type ito rito para mabuksan ang kasunduan.",
110
+ "code.send": "I-email ang code",
111
+ "code.sent": "Nag-email kami ng code sa {email}. Gagana ito nang 10 minuto.",
112
+ "code.label": "Ang 6-digit na code",
113
+ "code.check": "Magpatuloy",
114
+ "done.title": "Napirmahan na. Salamat",
115
+ "done.text": "Pinirmahan mo ang kasunduang ito noong {date}. Na-email na namin ang pirmadong kopya sa lahat.",
116
+ "done.waiting": "Pinirmahan mo ang kasunduang ito noong {date}. Kapag nakapirma na ang lahat, ie-email namin sa iyo ang pirmadong kopya.",
117
+ "done.download": "I-download ang pirmadong kopya",
118
+ "declined.title": "Tinanggihan mong pumirma",
119
+ "declined.text": "Sinabihan na namin si {business}. Kung nagkamali ka, pakiusapan silang ipadala ulit.",
120
+ "ended.title": "Sarado na ang kasunduang ito",
121
+ "ended.voided": "Binawi na ni {business} ang kasunduang ito. Tanungin sila kung inaasahan mong pumirma.",
122
+ "ended.expired": "Lumipas na ang oras para pumirma. Pakiusapan si {business} na ipadala ulit.",
123
+ "ended.declined": "May tumangging pumirma, kaya sarado na ang kasunduan. Tanungin si {business} kung may tanong ka.",
124
+ "not_found.title": "Hindi namin makita ang kasunduang ito",
125
+ "not_found.text": "Pakitingnan ang link na pinadala sa inyo, o humingi ng bago sa nagpadala.",
126
+ "share.text": "Hi {name}, pakibasa at pakipirmahan ang {title} dito: {url}",
127
+ };
128
+ const TAGLISH = {
129
+ "page.read": "Basahin po ang agreement",
130
+ "page.read_hint": "Mag-o-open po ang PDF ({pages}). Pakibasa po lahat bago mag-sign.",
131
+ "page.expires": "Pa-sign po bago mag-{date}",
132
+ "consent.read": "Nabasa ko na po ang agreement.",
133
+ "consent.esign": "Okay lang po sa akin mag-sign electronically, matanggap ang agreement at signed copy sa email, at kasing-bisa ng sign sa papel ang electronic signature ko.",
134
+ "name.label": "Full name mo po",
135
+ "method.label": "Paano mo po gustong mag-sign?",
136
+ "method.typed": "I-type ang name ko",
137
+ "method.drawn": "I-draw ang signature ko",
138
+ "drawn.hint": "I-draw po ang signature mo sa box gamit ang daliri o mouse.",
139
+ "sign": "I-sign ang agreement",
140
+ "sign_hint": "Pag-tap mo po ng I-sign, nagsa-sign ka bilang {name}.",
141
+ "decline.open": "Ayoko pong mag-sign",
142
+ "decline": "I-decline",
143
+ "done.title": "Signed na po. Salamat!",
144
+ "done.text": "Na-sign mo po ito noong {date}. Na-email na namin ang signed copy sa lahat.",
145
+ "done.waiting": "Na-sign mo po ito noong {date}. Pag naka-sign na lahat, i-email namin sa inyo ang signed copy.",
146
+ "done.download": "I-download ang signed copy",
147
+ "share.text": "Hi {name}, pa-read and pa-sign po ng {title} dito: {url}",
148
+ };
149
+ export const AGREEMENT_WORDS = Object.freeze({
150
+ en: prefix(EN),
151
+ tl: prefix(TL),
152
+ taglish: prefix({ ...TL, ...TAGLISH }),
153
+ });
154
+ const fill = (s, params) => s.replace(/\{(\w+)\}/g, (m, k) => (params && k in params ? String(params[k]) : m));
155
+ /** One word: the project's, else this package's in the language, else the English. */
156
+ export function agreementWord(t, language, key, params) {
157
+ const full = `ui.wbagreement.${key}`;
158
+ const own = t?.(full, params, language);
159
+ if (own !== undefined)
160
+ return own;
161
+ return fill(AGREEMENT_WORDS[language][full] ?? AGREEMENT_WORDS.en[full], params);
162
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-agreements",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
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
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/mccaskie-labs/workbench.git",
10
+ "directory": "packages/agreements"
11
+ },
12
+ "engines": {
13
+ "node": ">=24"
14
+ },
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./styles": {
22
+ "types": "./dist/styles.d.ts",
23
+ "default": "./dist/styles.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "bin": {
28
+ "workbench-agreements": "./dist/cli.js"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "CHANGELOG.md"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "typecheck": "tsc -p tsconfig.check.json && tsc -p test/tsconfig.json",
40
+ "test": "vitest run",
41
+ "test:store": "vitest run --config vitest.db.config.ts",
42
+ "build": "node scripts/build.mjs",
43
+ "prepack": "node scripts/build.mjs"
44
+ },
45
+ "dependencies": {
46
+ "pdf-lib": "1.17.1"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "24.19.2",
50
+ "postgres": "4.1.0",
51
+ "vitest": "^5.1.0"
52
+ }
53
+ }