@composable-os/pack-forms 0.0.0-stage → 0.1.0-beta.12

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/dist/index.js ADDED
@@ -0,0 +1,406 @@
1
+ // Forms (stage 29, step 3; ADR 0726): forms a business builds in the admin, with no developer (an
2
+ // enquiry, a sign-up, a survey, feedback after a class, a staff report), and the answers people send
3
+ // to them, kept as submissions in one inbox. Any product can turn it on (`packs` in its product.ts).
4
+ //
5
+ // Everything that is a rule is the host's, declared here as behaviours (ADR 0404):
6
+ // - a form is `publishable` (ADR 0446): staff and the assistant edit its working copy, and a
7
+ // person with the publish permission publishes it (ADR 0480). Its questions are a document field
8
+ // in the platform's question schema, checked on every write; who may answer, anonymity and the
9
+ // destination are published with them (ADR 0720);
10
+ // - a form takes answers through the host's one door, `intake` (ADR 0720): a submission is made
11
+ // only by `intake.submit`, which checks the form is open to the caller, the spam checks, the caps
12
+ // and the answers, and links or makes the submitter's Person (ADR 0721);
13
+ // - nobody outside the org reads a form's records or a submission: the public reads a form only
14
+ // through `intake.open`, as the door would take its answers (no public scope, ADR 0726), and a
15
+ // submission declares no customer or public read. Pack-role accounts (a coach, the door) reach
16
+ // none of it: the pack gives no role any reach;
17
+ // - opening and closing a form, its dates, its daily cap, its address and the hourly cap are a
18
+ // person's (`personApproves`); a
19
+ // submission's move into and out of spam is made only by `markSpam` and `notSpam`, which an AI
20
+ // may ask for and a person approves (ADR 0552).
21
+ // The tools in tools.ts compose the host's operations and add no rules of their own.
22
+ import { ANSWERS_MAX_BYTES, ANSWERS_SCHEMA, defineExtension, QUESTIONS_MAX_BYTES, QUESTIONS_SCHEMA, } from "@composable-os/sdk";
23
+ import { formsAutomations } from "./automations.js";
24
+ import { formsRoutineMail } from "./routine-mail.js";
25
+ import { enter, form, linkedForm, markSpam, move, notSpam, submit, submitLinked } from "./tools.js";
26
+ const INBOX_COLUMNS = ["title", "person", "certainty", "rating", "via", "owner", "createdAt"];
27
+ export default defineExtension({
28
+ id: "forms",
29
+ version: "0.1.0",
30
+ contractVersion: 1,
31
+ label: "Forms",
32
+ description: "Forms the business builds and publishes (enquiries, sign-ups, surveys, feedback, staff " +
33
+ "reports), and every answer in one inbox, linked to the person who sent it.",
34
+ permissions: {
35
+ // intake.open and intake.submit: the host's door for this pack's own forms (ADR 0720), from
36
+ // the `form`, `submit` and `enter` tools. notification.send: the low-rating notice.
37
+ // routine-mail: the receipt (ADR 0724: the host decides who it goes to and what it says),
38
+ // sent from the email-send connection a person binds to the receipt's automation.
39
+ operations: ["intake.open", "intake.submit", "notification.send"],
40
+ modules: ["ops", "routine-mail", "email-send"],
41
+ },
42
+ objects: {
43
+ form: {
44
+ label: "Form",
45
+ plural: "Forms",
46
+ icon: "clipboard-list",
47
+ titleField: "title",
48
+ description: "Questions the business asks, published as versions: an enquiry, a sign-up, a survey, " +
49
+ "feedback or a staff report. People answer the version last published.",
50
+ navigation: "main",
51
+ navigationOrder: 40,
52
+ fields: {
53
+ title: { type: "text", label: "Title", required: true },
54
+ slug: {
55
+ type: "slug",
56
+ label: "Address",
57
+ description: "How a link or a QR code names the form. Made from the title. Changed after " +
58
+ "publishing, the old address still finds the form.",
59
+ // Printed QR codes and shared links name it: a person's to change (an AI may ask).
60
+ personApproves: true,
61
+ },
62
+ kind: {
63
+ type: "select",
64
+ label: "Kind",
65
+ default: "enquiry",
66
+ options: [
67
+ { value: "enquiry", label: "Enquiry" },
68
+ { value: "signup", label: "Sign-up" },
69
+ { value: "survey", label: "Survey" },
70
+ { value: "feedback", label: "Feedback" },
71
+ { value: "staff", label: "Staff form" },
72
+ ],
73
+ description: "What the form is for. A staff form (an incident report) is answered by staff only: " +
74
+ "set who may answer to Staff.",
75
+ },
76
+ questions: {
77
+ type: "document",
78
+ label: "Questions",
79
+ schema: QUESTIONS_SCHEMA,
80
+ maxBytes: QUESTIONS_MAX_BYTES,
81
+ description: "What the form asks. No health questions, signatures or waivers: those are " +
82
+ "agreements.",
83
+ },
84
+ thanks: {
85
+ type: "longText",
86
+ label: "Thank-you words",
87
+ description: "Shown once the answers are sent.",
88
+ },
89
+ answeredBy: {
90
+ type: "select",
91
+ label: "Who may answer",
92
+ default: "public",
93
+ options: [
94
+ { value: "public", label: "Anyone" },
95
+ { value: "customers", label: "Signed-in customers" },
96
+ { value: "links", label: "By personal link" },
97
+ { value: "staff", label: "Staff only" },
98
+ ],
99
+ description: "Read from the version published: a change counts once it is published.",
100
+ },
101
+ anonymous: {
102
+ type: "boolean",
103
+ label: "Anonymous",
104
+ description: "Keeps no link to whoever answers: no person, no account, no receipt and no record " +
105
+ "made elsewhere. It cannot ask for an email that fills in a person.",
106
+ },
107
+ destination: {
108
+ type: "text",
109
+ label: "Also make",
110
+ description: "A record of another pack each answer also makes, named as <pack>.<object>. Only an " +
111
+ "installed pack whose record takes a form's answers can be named (none yet); never " +
112
+ "on an anonymous form.",
113
+ },
114
+ notify: {
115
+ type: "user",
116
+ label: "Who is told",
117
+ description: "Told of each answer. Left empty, the admins.",
118
+ },
119
+ receipt: {
120
+ type: "boolean",
121
+ label: "Send a receipt",
122
+ default: true,
123
+ description: "The sender gets a short email saying the answers arrived, with nothing they typed " +
124
+ "in it. Never on an anonymous form.",
125
+ },
126
+ lowRating: {
127
+ type: "number",
128
+ label: "Tell at a rating of",
129
+ min: 0,
130
+ max: 10,
131
+ step: 1,
132
+ description: "A first rating answer at or under this tells the answers' owner (or the admins). " +
133
+ "Left empty, no notice.",
134
+ },
135
+ // When a form takes answers, and how many a day, take effect at once (the door reads the
136
+ // working copy): a person's to change, as opening and closing it are (an AI may ask).
137
+ opensAt: { type: "datetime", label: "Open from", personApproves: true },
138
+ closesAt: { type: "datetime", label: "Open until", personApproves: true },
139
+ dailyCap: {
140
+ type: "number",
141
+ label: "Answers a day, at most",
142
+ min: 1,
143
+ step: 1,
144
+ description: "Left empty, no limit of its own.",
145
+ personApproves: true,
146
+ },
147
+ status: {
148
+ type: "select",
149
+ label: "Status",
150
+ track: "timeline",
151
+ // Opening and closing a form are a person's (an AI may ask): what the public may answer.
152
+ personApproves: true,
153
+ options: [
154
+ { value: "draft", label: "Draft" },
155
+ { value: "open", label: "Open" },
156
+ { value: "closed", label: "Closed" },
157
+ ],
158
+ },
159
+ },
160
+ states: {
161
+ field: "status",
162
+ initial: "draft",
163
+ moves: [
164
+ { from: "draft", to: "open", by: ["staff"] },
165
+ { from: "open", to: "closed", by: ["staff"] },
166
+ { from: "closed", to: "open", by: ["staff"] },
167
+ ],
168
+ },
169
+ publishable: {
170
+ content: ["title", "questions", "thanks", "answeredBy", "anonymous", "destination"],
171
+ slug: "slug",
172
+ },
173
+ intake: {
174
+ role: "form",
175
+ questions: "questions",
176
+ answeredBy: "answeredBy",
177
+ openIn: ["open"],
178
+ anonymous: "anonymous",
179
+ destination: "destination",
180
+ opensAt: "opensAt",
181
+ closesAt: "closesAt",
182
+ dailyCap: "dailyCap",
183
+ notify: "notify",
184
+ hourlyCap: "hourlyCap",
185
+ },
186
+ indexes: [["status"], ["kind"]],
187
+ },
188
+ submission: {
189
+ label: "Submission",
190
+ plural: "Submissions",
191
+ icon: "inbox",
192
+ titleField: "title",
193
+ titleDefault: { from: ["form"] },
194
+ description: "One set of answers to one version of a form, made only by the answers someone sends " +
195
+ "(or staff enter). Read by staff only, never by the person who sent it.",
196
+ navigation: "main",
197
+ navigationOrder: 41,
198
+ owner: "owner",
199
+ fields: {
200
+ title: {
201
+ type: "text",
202
+ label: "Title",
203
+ description: "Left empty, the form's title.",
204
+ },
205
+ form: { type: "relation", label: "Form", to: "forms.form", required: true },
206
+ version: {
207
+ type: "number",
208
+ label: "Version",
209
+ description: "The version of the form answered: its questions and words.",
210
+ },
211
+ person: {
212
+ type: "relation",
213
+ label: "Person",
214
+ to: "person",
215
+ description: "Who sent it. None on an anonymous form.",
216
+ },
217
+ certainty: {
218
+ type: "select",
219
+ label: "How sure",
220
+ options: [
221
+ { value: "account", label: "Signed in" },
222
+ { value: "link", label: "Personal link" },
223
+ { value: "staff", label: "Entered by staff" },
224
+ { value: "address", label: "Unconfirmed address", color: "amber" },
225
+ ],
226
+ description: "How the host knows whose it is. Unconfirmed address: someone typed this address; " +
227
+ "nothing on the person's record was changed by it.",
228
+ },
229
+ answers: {
230
+ type: "document",
231
+ label: "Answers",
232
+ schema: ANSWERS_SCHEMA,
233
+ maxBytes: ANSWERS_MAX_BYTES,
234
+ },
235
+ rating: {
236
+ type: "number",
237
+ label: "Rating",
238
+ description: "The first rating answered, for lists and dashboards.",
239
+ },
240
+ marketing: {
241
+ type: "boolean",
242
+ label: "Asked to hear from us",
243
+ description: "They ticked a “keep me updated” line. The words they saw are the version's.",
244
+ },
245
+ via: {
246
+ type: "select",
247
+ label: "Came in",
248
+ options: [
249
+ { value: "site", label: "Website" },
250
+ { value: "app", label: "App" },
251
+ { value: "page", label: "Form page" },
252
+ { value: "link", label: "Personal link" },
253
+ { value: "staff", label: "Staff" },
254
+ ],
255
+ },
256
+ // What a personal link was about (ADR 0723): a booking, for feedback after a class. Set
257
+ // by the host; a field, not a relation, as the record may be any installed pack's.
258
+ about: {
259
+ type: "text",
260
+ label: "About",
261
+ description: "The record the personal link was about (a booking's id), set by the host.",
262
+ },
263
+ aboutObject: {
264
+ type: "text",
265
+ label: "About (kind)",
266
+ description: "What kind of record that is (bookings.booking), set by the host.",
267
+ },
268
+ owner: { type: "user", label: "Owner" },
269
+ notes: { type: "longText", label: "Notes" },
270
+ status: {
271
+ type: "select",
272
+ label: "Status",
273
+ track: "timeline",
274
+ options: [
275
+ { value: "new", label: "New" },
276
+ { value: "inHand", label: "In hand" },
277
+ { value: "done", label: "Done" },
278
+ { value: "spam", label: "Spam", color: "gray" },
279
+ ],
280
+ },
281
+ },
282
+ states: {
283
+ field: "status",
284
+ initial: "new",
285
+ moves: [
286
+ { from: "new", to: "inHand", by: ["staff"] },
287
+ { from: ["new", "inHand"], to: "done", by: ["staff"] },
288
+ { from: "done", to: "inHand", by: ["staff"] },
289
+ // Spam is the host's (the door keeps a flood as spam) and a person's: markSpam and
290
+ // notSpam only, which an AI may ask for and a person approves (ADR 0552).
291
+ { from: ["new", "inHand", "done"], to: "spam", by: ["host"], tools: ["markSpam"] },
292
+ { from: "spam", to: "new", by: ["host"], tools: ["notSpam"] },
293
+ ],
294
+ },
295
+ intake: {
296
+ role: "submission",
297
+ form: "form",
298
+ version: "version",
299
+ answers: "answers",
300
+ person: "person",
301
+ certainty: "certainty",
302
+ spam: "spam",
303
+ via: "via",
304
+ rating: "rating",
305
+ marketing: "marketing",
306
+ about: "about",
307
+ aboutObject: "aboutObject",
308
+ },
309
+ // The door's caps count by form and time (ADR 0722); the inbox lists by state and time.
310
+ indexes: [
311
+ ["form", "createdAt"],
312
+ ["createdAt"],
313
+ ["status", "createdAt"],
314
+ ["person"],
315
+ ["about"],
316
+ ],
317
+ },
318
+ },
319
+ views: {
320
+ newAnswers: {
321
+ label: "New answers",
322
+ object: "forms.submission",
323
+ filter: { field: "status", op: "eq", value: "new" },
324
+ sort: { field: "createdAt", direction: "desc" },
325
+ columns: INBOX_COLUMNS,
326
+ },
327
+ inHand: {
328
+ label: "In hand",
329
+ object: "forms.submission",
330
+ filter: { field: "status", op: "eq", value: "inHand" },
331
+ sort: { field: "createdAt", direction: "desc" },
332
+ columns: INBOX_COLUMNS,
333
+ },
334
+ spam: {
335
+ label: "Spam",
336
+ object: "forms.submission",
337
+ filter: { field: "status", op: "eq", value: "spam" },
338
+ sort: { field: "createdAt", direction: "desc" },
339
+ columns: ["title", "person", "via", "createdAt"],
340
+ },
341
+ // "Keep me updated" (decision 10): who said yes, when, and to which version's words. Until
342
+ // Notifications keeps a consent register (stage 30), this list is where they are.
343
+ askedToHear: {
344
+ label: "Asked to hear from us",
345
+ object: "forms.submission",
346
+ filter: {
347
+ and: [
348
+ { field: "marketing", op: "eq", value: true },
349
+ { field: "status", op: "neq", value: "spam" },
350
+ ],
351
+ },
352
+ sort: { field: "createdAt", direction: "desc" },
353
+ columns: ["person", "form", "version", "createdAt"],
354
+ },
355
+ openForms: {
356
+ label: "Open forms",
357
+ object: "forms.form",
358
+ filter: { field: "status", op: "eq", value: "open" },
359
+ sort: { field: "title", direction: "asc" },
360
+ columns: ["title", "kind", "answeredBy", "publishState", "closesAt"],
361
+ },
362
+ },
363
+ // A person's answers on their page, and a form's on its own.
364
+ recordTabs: {
365
+ personAnswers: {
366
+ label: "Form answers",
367
+ on: "person",
368
+ view: {
369
+ type: "table",
370
+ object: "forms.submission",
371
+ relation: "person",
372
+ columns: ["title", "status", "certainty", "rating", "createdAt"],
373
+ sort: { field: "createdAt", direction: "desc" },
374
+ },
375
+ order: 60,
376
+ },
377
+ formAnswers: {
378
+ label: "Answers",
379
+ on: "forms.form",
380
+ view: {
381
+ type: "table",
382
+ object: "forms.submission",
383
+ relation: "form",
384
+ columns: INBOX_COLUMNS,
385
+ sort: { field: "createdAt", direction: "desc" },
386
+ },
387
+ order: 10,
388
+ },
389
+ },
390
+ settings: {
391
+ // The door's hourly cap across every form (ADR 0722): an abuse setting, a person's to change.
392
+ hourlyCap: {
393
+ type: "number",
394
+ label: "Answers an hour, at most",
395
+ description: "Across every form. Over it, new answers are turned away for the hour and the admins " +
396
+ "are told. Raise it for a busy day.",
397
+ default: 200,
398
+ min: 1,
399
+ max: 10_000,
400
+ personApproves: true,
401
+ },
402
+ },
403
+ automations: formsAutomations,
404
+ routineMail: formsRoutineMail,
405
+ tools: { form, submit, linkedForm, submitLinked, enter, move, markSpam, notSpam },
406
+ });
@@ -0,0 +1,23 @@
1
+ export declare const formsRoutineMail: {
2
+ receipt: {
3
+ label: string;
4
+ description: string;
5
+ about: string;
6
+ receipt: true;
7
+ slots: {
8
+ business: {
9
+ business: true;
10
+ };
11
+ form: {
12
+ field: string;
13
+ max: number;
14
+ };
15
+ };
16
+ messages: {
17
+ received: {
18
+ subject: string;
19
+ text: string;
20
+ };
21
+ };
22
+ };
23
+ };
@@ -0,0 +1,25 @@
1
+ export const formsRoutineMail = {
2
+ receipt: {
3
+ label: "Receipts",
4
+ description: "When someone sends answers to a form whose receipt is on, a short email to the address " +
5
+ "they gave (or signed in with) saying the answers arrived, naming the business and the " +
6
+ "form and nothing they typed. At most three a day to one address; never for an anonymous " +
7
+ "form, answers kept as spam, or answers staff entered.",
8
+ about: "submission",
9
+ receipt: true,
10
+ slots: {
11
+ business: { business: true },
12
+ form: { field: "form.title", max: 200 },
13
+ },
14
+ messages: {
15
+ received: {
16
+ subject: "{business}: we got your answers",
17
+ text: [
18
+ "Thank you: {business} got your answers to {form}.",
19
+ "",
20
+ "There is nothing more you need to do. If you did not send them, you can ignore this email.",
21
+ ].join("\n"),
22
+ },
23
+ },
24
+ },
25
+ };
@@ -0,0 +1,92 @@
1
+ import { z } from "@composable-os/sdk";
2
+ export declare const FORM = "forms.form";
3
+ export declare const SUBMISSION = "forms.submission";
4
+ export declare const form: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
5
+ slug: z.ZodOptional<z.ZodString>;
6
+ link: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strip>, z.ZodObject<{
8
+ id: z.ZodString;
9
+ version: z.ZodNumber;
10
+ title: z.ZodNullable<z.ZodString>;
11
+ questions: z.ZodObject<{
12
+ items: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
13
+ }, z.core.$strip>;
14
+ thanks: z.ZodNullable<z.ZodString>;
15
+ anonymous: z.ZodBoolean;
16
+ turnstile: z.ZodBoolean;
17
+ shown: z.ZodNullable<z.ZodString>;
18
+ }, z.core.$strip>>;
19
+ export declare const linkedForm: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
20
+ linkId: z.ZodString;
21
+ }, z.core.$strip>, z.ZodObject<{
22
+ id: z.ZodString;
23
+ version: z.ZodNumber;
24
+ title: z.ZodNullable<z.ZodString>;
25
+ questions: z.ZodObject<{
26
+ items: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
27
+ }, z.core.$strip>;
28
+ thanks: z.ZodNullable<z.ZodString>;
29
+ anonymous: z.ZodBoolean;
30
+ turnstile: z.ZodBoolean;
31
+ shown: z.ZodNullable<z.ZodString>;
32
+ }, z.core.$strip>>;
33
+ export declare const submit: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
34
+ id: z.ZodString;
35
+ version: z.ZodNumber;
36
+ answers: z.ZodRecord<z.ZodString, z.ZodUnknown>;
37
+ via: z.ZodOptional<z.ZodEnum<{
38
+ site: "site";
39
+ app: "app";
40
+ page: "page";
41
+ }>>;
42
+ turnstileToken: z.ZodOptional<z.ZodString>;
43
+ shown: z.ZodOptional<z.ZodString>;
44
+ honeypot: z.ZodOptional<z.ZodString>;
45
+ link: z.ZodOptional<z.ZodString>;
46
+ }, z.core.$strip>, z.ZodObject<{
47
+ received: z.ZodLiteral<true>;
48
+ }, z.core.$strip>>;
49
+ export declare const submitLinked: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
50
+ linkId: z.ZodString;
51
+ id: z.ZodString;
52
+ version: z.ZodNumber;
53
+ answers: z.ZodRecord<z.ZodString, z.ZodUnknown>;
54
+ honeypot: z.ZodOptional<z.ZodString>;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ received: z.ZodLiteral<true>;
57
+ }, z.core.$strip>>;
58
+ export declare const enter: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
59
+ formId: z.ZodString;
60
+ answers: z.ZodRecord<z.ZodString, z.ZodUnknown>;
61
+ }, z.core.$strip>, z.ZodObject<{
62
+ received: z.ZodLiteral<true>;
63
+ }, z.core.$strip>>;
64
+ export declare const move: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
65
+ submissionId: z.ZodString;
66
+ to: z.ZodEnum<{
67
+ new: "new";
68
+ inHand: "inHand";
69
+ done: "done";
70
+ }>;
71
+ from: z.ZodOptional<z.ZodEnum<{
72
+ new: "new";
73
+ inHand: "inHand";
74
+ done: "done";
75
+ spam: "spam";
76
+ }>>;
77
+ }, z.core.$strip>, z.ZodObject<{
78
+ id: z.ZodString;
79
+ status: z.ZodString;
80
+ }, z.core.$strip>>;
81
+ export declare const markSpam: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
82
+ submissionId: z.ZodString;
83
+ }, z.core.$strip>, z.ZodObject<{
84
+ id: z.ZodString;
85
+ status: z.ZodString;
86
+ }, z.core.$strip>>;
87
+ export declare const notSpam: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
88
+ submissionId: z.ZodString;
89
+ }, z.core.$strip>, z.ZodObject<{
90
+ id: z.ZodString;
91
+ status: z.ZodString;
92
+ }, z.core.$strip>>;