@mccaskie-labs/workbench-agreements 0.3.0 → 0.3.2

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,225 @@
1
+ import { type Context, type Form } from "@mccaskie-labs/workbench-forms";
2
+ import type { AgreementLanguage, AgreementsConfig, SigningMethod } from "./config.ts";
3
+ import { type AgreementStrings } from "./words.ts";
4
+ /** A form an open document may ask: the generated form and its validation context (bounds from boundsFor, choices, country). */
5
+ export interface DocumentForm {
6
+ form: Form;
7
+ context: Context;
8
+ }
9
+ /** How long a signature lasts: one event (a booking), or a number of months. */
10
+ export type Validity = "event" | {
11
+ months: number;
12
+ };
13
+ export type ForChild = "never" | "allowed" | "always";
14
+ export interface SaveDocumentRequest {
15
+ /** The app's own account (the business). */
16
+ account: string;
17
+ /** Its public link's last part: lower-case letters, digits and dashes, 3 to 60 (`tour-waiver`). Saving the same slug again makes a new version. */
18
+ slug: string;
19
+ title: string;
20
+ business: string;
21
+ /** The wording as a PDF, made with workbench-pdf. Its SHA-256 is what each person signs. */
22
+ document: Uint8Array;
23
+ /** The form whose questions it asks (a key of `documentForms`). */
24
+ form?: string;
25
+ /** Whether a parent or guardian may sign for a child. Default never. */
26
+ forChild?: ForChild;
27
+ validity: Validity;
28
+ /** The business's own addresses that get each signed copy (up to five). */
29
+ copyTo?: readonly string[];
30
+ language?: AgreementLanguage;
31
+ }
32
+ export interface OpenDocument {
33
+ id: string;
34
+ account: string;
35
+ slug: string;
36
+ version: number;
37
+ title: string;
38
+ business: string;
39
+ language: AgreementLanguage;
40
+ documentSha256: string;
41
+ pages: number;
42
+ form: string | null;
43
+ forChild: ForChild;
44
+ validity: Validity;
45
+ copyTo: string[];
46
+ createdAt: string;
47
+ retiredAt: string | null;
48
+ /** The public link: put it on the website or in a QR code. */
49
+ url: string;
50
+ /** From list(): how many have signed this version. */
51
+ signed?: number;
52
+ }
53
+ export interface RequestSignaturesRequest {
54
+ slug: string;
55
+ /** The app's own row the signatures are for (a booking). A document that lasts one event is valid for this subject only. */
56
+ subject: {
57
+ type: string;
58
+ id: string;
59
+ };
60
+ /** One link per person, 1 to 50. */
61
+ places: number;
62
+ /** A document that lasts one event: when that event is over (its signatures and their sensitive answers then lapse). */
63
+ validUntil?: Date;
64
+ /** When the links stop working. Default validUntil, else config.expires_after_days from now. */
65
+ expiresAt?: Date;
66
+ /** Email all the links to the person who booked, to pass on. */
67
+ email?: {
68
+ to: string;
69
+ name: string;
70
+ };
71
+ }
72
+ export interface SignatureFile {
73
+ field: string;
74
+ name: string;
75
+ kind: string;
76
+ size: number;
77
+ sha256: string;
78
+ }
79
+ export interface DocumentSignature {
80
+ id: string;
81
+ slug: string;
82
+ version: number;
83
+ title: string;
84
+ subject: {
85
+ type: string;
86
+ id: string;
87
+ } | null;
88
+ name: string;
89
+ email: string;
90
+ forChild: boolean;
91
+ childName: string | null;
92
+ relationship: "parent" | "guardian" | null;
93
+ /** The ordinary answers. */
94
+ answers: Record<string, unknown>;
95
+ /** The sensitive answers: show them only on the owner's and staff's own pages. Null once deleted (sensitiveDeletedAt). */
96
+ sensitive: Record<string, unknown> | null;
97
+ files: SignatureFile[];
98
+ signedAt: string;
99
+ validUntil: string | null;
100
+ method: SigningMethod;
101
+ typedName: string;
102
+ signedSha256: string | null;
103
+ sensitiveDeletedAt: string | null;
104
+ }
105
+ export interface Documents {
106
+ /** Saves a document, or a new version of one (the old version keeps its signatures). Throws conflict when another account has the slug. */
107
+ save(req: SaveDocumentRequest): Promise<OpenDocument>;
108
+ /** A slug's current version. */
109
+ get(slug: string): Promise<OpenDocument | null>;
110
+ list(account: string, limit?: number): Promise<OpenDocument[]>;
111
+ /** Stops a document being signed from its public link (request links already sent still work). */
112
+ retire(account: string, slug: string): Promise<boolean>;
113
+ /** The public link, for the website or a QR code. */
114
+ link(slug: string): string;
115
+ /** A message with the public link to paste into Messenger or WhatsApp. Never SMS. */
116
+ share(slug: string): Promise<{
117
+ url: string;
118
+ text: string;
119
+ whatsapp: string;
120
+ } | null>;
121
+ /** One link per place on a booking, each signed once. With `email`, they go to the booker in one email. */
122
+ request(req: RequestSignaturesRequest): Promise<{
123
+ links: string[];
124
+ }>;
125
+ /** The person's signature that is valid now, for themselves or for a child; for a document that lasts one event, on that subject. Null: check-in should wait. */
126
+ valid(slug: string, person: {
127
+ email: string;
128
+ child?: string;
129
+ }, subject?: {
130
+ type: string;
131
+ id: string;
132
+ }): Promise<{
133
+ id: string;
134
+ version: number;
135
+ signedAt: string;
136
+ validUntil: string | null;
137
+ } | null>;
138
+ /** The account's signatures, newest first, sensitive answers included: for the owner's own pages only. */
139
+ signatures(account: string, opts?: {
140
+ slug?: string;
141
+ limit?: number;
142
+ }): Promise<DocumentSignature[]>;
143
+ /** One signature with its audit trail. */
144
+ signature(id: string): Promise<(DocumentSignature & {
145
+ account: string;
146
+ events: {
147
+ kind: string;
148
+ at: string;
149
+ ip: string | null;
150
+ userAgent: string | null;
151
+ }[];
152
+ }) | null>;
153
+ /** The signed copy, or an uploaded file, for the owner's own pages. */
154
+ file(id: string, which: "signed" | {
155
+ field: string;
156
+ }): Promise<{
157
+ bytes: Uint8Array;
158
+ contentType: string;
159
+ name: string;
160
+ } | null>;
161
+ }
162
+ /** What createAgreements shares with the open documents. */
163
+ export interface DocumentsKit {
164
+ config: AgreementsConfig;
165
+ base: string;
166
+ t?: AgreementStrings;
167
+ forms: Readonly<Record<string, DocumentForm>>;
168
+ replyTo?: string;
169
+ locale: string;
170
+ now: () => Date;
171
+ call<T>(fn: string, args: Record<string, unknown>, what: string): Promise<T>;
172
+ load(key: string): Promise<Uint8Array>;
173
+ store(key: string, bytes: Uint8Array, contentType: string): Promise<void>;
174
+ remove(keys: string[]): Promise<void>;
175
+ mailer: {
176
+ send(mail: {
177
+ to: string | string[];
178
+ subject: string;
179
+ text: string;
180
+ template: string;
181
+ replyTo?: string;
182
+ attachments?: {
183
+ filename: string;
184
+ mimeType: string;
185
+ bytes: Uint8Array;
186
+ }[];
187
+ idempotencyKey?: string;
188
+ }): Promise<unknown>;
189
+ };
190
+ dateLabel(iso: string): string;
191
+ device(request: Request): {
192
+ ip: string | null;
193
+ ua: string | null;
194
+ };
195
+ html(status: number, body: string, script: boolean, head: boolean): Promise<Response>;
196
+ redirect(to: string): Response;
197
+ bare(status: number, extra?: Record<string, string>): Response;
198
+ pdf(bytes: Uint8Array, name: string, head: boolean): Response;
199
+ common(language: AgreementLanguage): {
200
+ language: AgreementLanguage;
201
+ t?: AgreementStrings;
202
+ styles?: readonly string[];
203
+ };
204
+ slug(s: string): string;
205
+ }
206
+ /** Names the signing page uses itself: a form an open document asks can't have a field by one of these. */
207
+ export declare const RESERVED_FIELDS: readonly string[];
208
+ /** Adds whole calendar months in UTC, keeping the day where the month has it (31 January + 1 month is 28 or 29 February). */
209
+ export declare function addMonths(d: Date, months: number): Date;
210
+ export declare function openDocuments(kit: DocumentsKit): {
211
+ api: Documents;
212
+ handle(request: Request, ctx: {
213
+ waitUntil(p: Promise<unknown>): void;
214
+ }): Promise<Response | null>;
215
+ tick(): Promise<{
216
+ finished: number;
217
+ copies: number;
218
+ renewed: number;
219
+ failed: number;
220
+ }>;
221
+ cleanup(): Promise<{
222
+ deleted: number;
223
+ scrubbed: number;
224
+ }>;
225
+ };