@composable-os/cli 0.1.0-beta.11 → 0.1.0-beta.14
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/{accounts-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
- package/dist/app-OSPZHKOI.js +43 -0
- package/dist/app-upload-LH4PXKI4.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-6DZIP47W.js} +207 -25
- package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
- package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
- package/dist/{chunk-MBIKVRAC.js → chunk-5YDYQM6V.js} +830 -47
- package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
- package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
- package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
- package/dist/chunk-KMFMD52Z.js +13276 -0
- package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
- package/dist/{chunk-PDD2ETVF.js → chunk-O37YUZ52.js} +172 -16
- package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
- package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
- package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
- package/dist/cli.js +5 -5
- package/dist/{client-repo-SE4EKG6W.js → client-repo-MPCPTXLF.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
- package/dist/gateway-DPPEQZT4.js +25 -0
- package/dist/grants-6JY4XZO7.js +27 -0
- package/dist/invoke-MRONRZ5Q.js +33 -0
- package/dist/moves-UAUCMWL5.js +36 -0
- package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0730_practitioners.sql +79 -0
- package/dist/platform/migrations/0750_routine_mail.sql +98 -0
- package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
- package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
- package/dist/platform/migrations/0811_staff_time.sql +109 -0
- package/dist/platform/migrations/0812_staff_offers.sql +112 -0
- package/dist/platform/migrations/0813_pay_periods.sql +241 -0
- package/dist/platform/migrations/0814_staff_feed.sql +47 -0
- package/dist/platform/migrations/0815_checklists.sql +237 -0
- package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
- package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
- package/dist/platform/migrations/0850_agreements.sql +271 -0
- package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
- package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
- package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
- package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
- package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
- package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
- package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
- package/dist/platform/migrations/0910_routine_messages.sql +99 -0
- package/dist/platform/migrations/0911_texts.sql +60 -0
- package/dist/platform/migrations/0913_contact_consent.sql +93 -0
- package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
- package/dist/platform/migrations/0930_stock_movements.sql +95 -0
- package/dist/platform/migrations/0931_stock_low.sql +25 -0
- package/dist/platform/migrations/0932_order_delivery.sql +78 -0
- package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
- package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
- package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
- package/dist/platform/migrations/0953_discount_uses.sql +183 -0
- package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
- package/dist/platform/migrations/0970_published_text.sql +59 -0
- package/dist/platform/migrations/0971_publish_acks.sql +68 -0
- package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
- package/dist/platform/migrations/1010_intake_links.sql +148 -0
- package/dist/platform/migrations/1030_invoices.sql +747 -0
- package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
- package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
- package/dist/platform/migrations/1090_staff_hours.sql +43 -0
- package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
- package/dist/platform/migrations/1092_client_guard.sql +26 -0
- package/dist/platform/migrations/1095_thing_time.sql +70 -0
- package/dist/platform/migrations/1130_devices.sql +162 -0
- package/dist/platform/migrations/1135_person_codes.sql +88 -0
- package/dist/platform/migrations/1150_finance_periods.sql +316 -0
- package/dist/platform/migrations/1151_payouts.sql +202 -0
- package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
- package/dist/platform/migrations/1170_journeys.sql +318 -0
- package/dist/platform/migrations/1171_person_birthday.sql +52 -0
- package/dist/platform/migrations/1175_person_signals.sql +29 -0
- package/dist/platform/migrations/1190_restricted_values.sql +25 -0
- package/dist/platform/migrations/1230_note_levels.sql +113 -0
- package/dist/platform/migrations/1231_person_carers.sql +33 -0
- package/dist/platform/migrations/1232_note_kinds.sql +122 -0
- package/dist/platform/migrations/1270_time_entries.sql +145 -0
- package/dist/platform/migrations/1271_leave.sql +249 -0
- package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
- package/dist/platform/migrations/1330_accounting.sql +260 -0
- package/dist/platform/migrations/1350_customer_feed.sql +24 -0
- package/dist/platform/migrations/1390_locations.sql +77 -0
- package/dist/platform/migrations/1410_outside_copy.sql +213 -0
- package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
- package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
- package/dist/platform/sdk/acknowledge.ts +100 -0
- package/dist/platform/sdk/agreements.ts +185 -0
- package/dist/platform/sdk/allowance.ts +98 -8
- package/dist/platform/sdk/automation-check.ts +120 -9
- package/dist/platform/sdk/automation.ts +78 -10
- package/dist/platform/sdk/behaviour.ts +26 -6
- package/dist/platform/sdk/calendar-entry.ts +258 -0
- package/dist/platform/sdk/capacity.ts +1 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +489 -27
- package/dist/platform/sdk/discount.ts +408 -0
- package/dist/platform/sdk/document.ts +4 -2
- package/dist/platform/sdk/field-types.ts +5 -0
- package/dist/platform/sdk/formula/compile.ts +10 -0
- package/dist/platform/sdk/index.ts +17 -0
- package/dist/platform/sdk/intake.ts +380 -0
- package/dist/platform/sdk/journey-signals.ts +215 -0
- package/dist/platform/sdk/manifest.ts +1236 -65
- package/dist/platform/sdk/mine.ts +161 -0
- package/dist/platform/sdk/occupies.ts +192 -0
- package/dist/platform/sdk/questions.ts +681 -0
- package/dist/platform/sdk/recurring.ts +90 -9
- package/dist/platform/sdk/restricted-fields.ts +129 -0
- package/dist/platform/sdk/rich-text.ts +112 -0
- package/dist/platform/sdk/routine-mail.ts +1272 -0
- package/dist/platform/sdk/runtime.ts +25 -12
- package/dist/platform/sdk/screens.ts +91 -0
- package/dist/platform/sdk/sellable.ts +344 -0
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +68 -26
- package/dist/platform/sdk/stock.ts +332 -0
- package/dist/platform/sdk/team.ts +83 -0
- package/dist/platform/sdk/testing.ts +70 -6
- package/dist/platform/sdk/worked-on.ts +134 -0
- package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
- package/dist/run-7ID64RA6.js +65 -0
- package/dist/run-FH7OGGTV.js +131 -0
- package/dist/run-OYZIAP6M.js +3363 -0
- package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
- package/package.json +2 -2
- package/dist/chunk-2TWV3SVB.js +0 -349
- package/dist/chunk-2XC5JLBO.js +0 -1931
- package/dist/chunk-324WJXNP.js +0 -320
- package/dist/chunk-6ELZRNUU.js +0 -116
- package/dist/chunk-6WGFA2IV.js +0 -643
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-7OGCMQXG.js +0 -284
- package/dist/chunk-FJIZGS5Q.js +0 -698
- package/dist/chunk-UB4I2QKR.js +0 -31575
- package/dist/chunk-WHKJGF36.js +0 -2418
- package/dist/chunk-YNUZRTPH.js +0 -182
- package/dist/chunk-ZZFWMVJO.js +0 -704
- package/dist/grants-LOW6TSWD.js +0 -32
- package/dist/invoke-6KVT6WJI.js +0 -41
- package/dist/moves-E2HKYCTK.js +0 -41
- package/dist/plan-on-sale-TJPFCNL7.js +0 -26
- package/dist/src-CRO35DYY.js +0 -46
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// The `intake` behaviour (stage 29 step 2, ADR 0720): the one reviewed way the public may create
|
|
2
|
+
// a record. An object of a shipped pack opts in, and the host's one door, `intake.submit`, writes
|
|
3
|
+
// it. Its declaration, its manifest schema and its contract checks live here; the host's side (the
|
|
4
|
+
// door, the submitter's Person and the abuse checks) is packages/core/src/intake/.
|
|
5
|
+
//
|
|
6
|
+
// Three roles, each on an object of its own:
|
|
7
|
+
//
|
|
8
|
+
// - `form`: what is answered (a Forms form). A publishable record whose questions are a
|
|
9
|
+
// document field with the platform's QUESTIONS_SCHEMA, in its published content, with the
|
|
10
|
+
// fields the host reads to decide whether it takes answers now and from whom.
|
|
11
|
+
// - `submission`: one set of answers (a Forms submission). The host makes it, and nobody else:
|
|
12
|
+
// it points at the form and the version answered, the submitter's Person and how sure the host
|
|
13
|
+
// is of them, and holds the answers (ANSWERS_SCHEMA).
|
|
14
|
+
// - `destination`: another pack's record a form may also make (a Lead), with the fields a
|
|
15
|
+
// form's questions may fill.
|
|
16
|
+
//
|
|
17
|
+
// Only shipped packs and the org's own extensions declare it: it opens a write to the public.
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
20
|
+
import { ANSWERS_SCHEMA, QUESTIONS_SCHEMA } from "./questions.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How sure the host is whose a submission is (ADR 0721): `account`, a signed-in customer;
|
|
24
|
+
* `link`, a personal link; `staff`, entered by staff; `address`, an address a visitor typed,
|
|
25
|
+
* unconfirmed. An anonymous submission has none.
|
|
26
|
+
*/
|
|
27
|
+
export const INTAKE_CERTAINTIES = ["account", "link", "staff", "address"] as const;
|
|
28
|
+
export type IntakeCertainty = (typeof INTAKE_CERTAINTIES)[number];
|
|
29
|
+
|
|
30
|
+
/** Who may answer a form: anyone, signed-in customers, a personal link's holder, or staff. */
|
|
31
|
+
export const INTAKE_ANSWERED_BY = ["public", "customers", "links", "staff"] as const;
|
|
32
|
+
export type IntakeAnsweredBy = (typeof INTAKE_ANSWERED_BY)[number];
|
|
33
|
+
|
|
34
|
+
/** Which way a submission came in. */
|
|
35
|
+
export const INTAKE_VIAS = ["site", "app", "page", "link", "staff"] as const;
|
|
36
|
+
export type IntakeVia = (typeof INTAKE_VIAS)[number];
|
|
37
|
+
|
|
38
|
+
/** What the host writes in a destination's `source` field. */
|
|
39
|
+
export const INTAKE_SOURCE = "website";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What is answered (ADR 0720). Every name is a field of this object.
|
|
43
|
+
*
|
|
44
|
+
* - `questions`: a document field with `QUESTIONS_SCHEMA`, one of `publishable.content`: answers
|
|
45
|
+
* are checked against the published version, and the host checks the questions on every write
|
|
46
|
+
* (`checkQuestions`, with the form's anonymous flag and its destination's fields).
|
|
47
|
+
* - `answeredBy`: a select whose options are among `INTAKE_ANSWERED_BY`. It, `anonymous` and
|
|
48
|
+
* `destination` are in `publishable.content` too: the host reads them from the version answered.
|
|
49
|
+
* - `openIn`: the states of the object's `states` in which it takes answers.
|
|
50
|
+
* - `anonymous` (a boolean field), `destination` (a text or select field holding an object's
|
|
51
|
+
* registry name), `opensAt` and `closesAt` (datetime fields), `dailyCap` (a number field: at
|
|
52
|
+
* most so many in 24 hours) and `notify` (a user field: who is told; left empty, the admins)
|
|
53
|
+
* are optional.
|
|
54
|
+
* - `hourlyCap` (optional): a number setting of this extension, one a person approves
|
|
55
|
+
* (`personApproves`): at most so many submissions an hour across every form of the deployment.
|
|
56
|
+
* Left out, or the setting empty, the platform's 200.
|
|
57
|
+
*
|
|
58
|
+
* A form object with `publishable.slug` is also found by its slug (`intake.open { slug }`): a link
|
|
59
|
+
* or a QR code names the form by its address, never by its id.
|
|
60
|
+
*/
|
|
61
|
+
export interface IntakeFormSpec {
|
|
62
|
+
role: "form";
|
|
63
|
+
questions: string;
|
|
64
|
+
answeredBy: string;
|
|
65
|
+
openIn: readonly string[];
|
|
66
|
+
anonymous?: string;
|
|
67
|
+
destination?: string;
|
|
68
|
+
opensAt?: string;
|
|
69
|
+
closesAt?: string;
|
|
70
|
+
dailyCap?: string;
|
|
71
|
+
notify?: string;
|
|
72
|
+
hourlyCap?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* One set of answers to one version of a form (ADR 0720). The host makes it in the call's batch;
|
|
77
|
+
* no customer or public declaration may make it readable outside the org.
|
|
78
|
+
*
|
|
79
|
+
* - `form`: a relation (one record) to another of this extension's objects that declares
|
|
80
|
+
* `intake` with the role `form`. One submission object per form object.
|
|
81
|
+
* - `version`: a number field: the form's published version answered.
|
|
82
|
+
* - `answers`: a document field with `ANSWERS_SCHEMA`.
|
|
83
|
+
* - `person`: a relation to `person`: the submitter's (none on an anonymous form).
|
|
84
|
+
* - `certainty`: a select with exactly the options `INTAKE_CERTAINTIES`.
|
|
85
|
+
* - `spam`: a state of the object's `states` the host may move to from its initial state: what a
|
|
86
|
+
* submission the host keeps as spam is created in.
|
|
87
|
+
* - `via` (a select among `INTAKE_VIAS`) and `rating` (a number field: the first rating answer,
|
|
88
|
+
* for dashboards) are optional.
|
|
89
|
+
* - `marketing` (optional, a boolean field): set by the host when the person ticked a `marketing`
|
|
90
|
+
* consent line of the version answered ("keep me updated", decision 10), so a list can find
|
|
91
|
+
* them. The words they saw are the version's.
|
|
92
|
+
* - `about` and `aboutObject` (optional, together, text fields): set by the host when the answers
|
|
93
|
+
* came by a personal link about a record (a booking, ADR 0723): the record's id and its object's
|
|
94
|
+
* registry name. A field, not a relation: the record may be any installed pack's (Bookings'),
|
|
95
|
+
* and a pack that is not installed cannot be pointed to.
|
|
96
|
+
*/
|
|
97
|
+
export interface IntakeSubmissionSpec {
|
|
98
|
+
role: "submission";
|
|
99
|
+
form: string;
|
|
100
|
+
version: string;
|
|
101
|
+
answers: string;
|
|
102
|
+
person: string;
|
|
103
|
+
certainty: string;
|
|
104
|
+
spam: string;
|
|
105
|
+
via?: string;
|
|
106
|
+
rating?: string;
|
|
107
|
+
marketing?: string;
|
|
108
|
+
about?: string;
|
|
109
|
+
aboutObject?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A record a form may also make (ADR 0720): its `person` (a relation to `person`), the `fields`
|
|
114
|
+
* a form's questions may fill, and `source` (optional: a text or select field the host sets to
|
|
115
|
+
* `website`). Its owner comes from assignment rules, as for any create.
|
|
116
|
+
*/
|
|
117
|
+
export interface IntakeDestinationSpec {
|
|
118
|
+
role: "destination";
|
|
119
|
+
person: string;
|
|
120
|
+
fields: readonly string[];
|
|
121
|
+
source?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type IntakeSpec = IntakeFormSpec | IntakeSubmissionSpec | IntakeDestinationSpec;
|
|
125
|
+
|
|
126
|
+
const fieldName = z.string().min(1).max(40);
|
|
127
|
+
|
|
128
|
+
export const intakeManifestSchema = z.discriminatedUnion("role", [
|
|
129
|
+
z
|
|
130
|
+
.object({
|
|
131
|
+
role: z.literal("form"),
|
|
132
|
+
questions: fieldName,
|
|
133
|
+
answeredBy: fieldName,
|
|
134
|
+
openIn: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
135
|
+
anonymous: fieldName.optional(),
|
|
136
|
+
destination: fieldName.optional(),
|
|
137
|
+
opensAt: fieldName.optional(),
|
|
138
|
+
closesAt: fieldName.optional(),
|
|
139
|
+
dailyCap: fieldName.optional(),
|
|
140
|
+
notify: fieldName.optional(),
|
|
141
|
+
hourlyCap: fieldName.optional(),
|
|
142
|
+
})
|
|
143
|
+
.strict(),
|
|
144
|
+
z
|
|
145
|
+
.object({
|
|
146
|
+
role: z.literal("submission"),
|
|
147
|
+
form: fieldName,
|
|
148
|
+
version: fieldName,
|
|
149
|
+
answers: fieldName,
|
|
150
|
+
person: fieldName,
|
|
151
|
+
certainty: fieldName,
|
|
152
|
+
spam: z.string().min(1).max(100),
|
|
153
|
+
via: fieldName.optional(),
|
|
154
|
+
rating: fieldName.optional(),
|
|
155
|
+
marketing: fieldName.optional(),
|
|
156
|
+
about: fieldName.optional(),
|
|
157
|
+
aboutObject: fieldName.optional(),
|
|
158
|
+
})
|
|
159
|
+
.strict(),
|
|
160
|
+
z
|
|
161
|
+
.object({
|
|
162
|
+
role: z.literal("destination"),
|
|
163
|
+
person: fieldName,
|
|
164
|
+
fields: z.array(fieldName).min(1).max(40),
|
|
165
|
+
source: fieldName.optional(),
|
|
166
|
+
})
|
|
167
|
+
.strict(),
|
|
168
|
+
]);
|
|
169
|
+
export type IntakeManifest = z.infer<typeof intakeManifestSchema>;
|
|
170
|
+
|
|
171
|
+
/** Whether a document field's declared schema is exactly `schema` (one the platform owns). */
|
|
172
|
+
export function isPlatformSchema(field: FieldManifest | undefined, schema: unknown): boolean {
|
|
173
|
+
return (
|
|
174
|
+
field?.type === "document" &&
|
|
175
|
+
field.schema !== undefined &&
|
|
176
|
+
JSON.stringify(field.schema) === JSON.stringify(schema)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Reports problems with `objects.<name>.intake` through `contract`. */
|
|
181
|
+
export function checkObjectIntake(
|
|
182
|
+
m: ExtensionManifest,
|
|
183
|
+
name: string,
|
|
184
|
+
object: ObjectManifest,
|
|
185
|
+
contract: (path: string, message: string) => void,
|
|
186
|
+
): void {
|
|
187
|
+
const intake = object.intake;
|
|
188
|
+
if (!intake) return;
|
|
189
|
+
const at = `objects.${name}.intake`;
|
|
190
|
+
const own = (local: string): FieldManifest | undefined =>
|
|
191
|
+
Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
|
|
192
|
+
const single = (local: string | undefined, types: readonly string[]) => {
|
|
193
|
+
const field = local === undefined ? undefined : own(local);
|
|
194
|
+
return field !== undefined && types.includes(field.type) && !field.many;
|
|
195
|
+
};
|
|
196
|
+
const need = (key: string, local: string | undefined, types: readonly string[], what: string) => {
|
|
197
|
+
if (local !== undefined && !single(local, types)) {
|
|
198
|
+
contract(`${at}.${key}`, `"${local}" must be ${what} field of ${name}`);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const options = (local: string) => (own(local)?.options ?? []).map((o) => o.value);
|
|
202
|
+
const states = object.states;
|
|
203
|
+
const stateValues = new Set(states ? options(states.field) : []);
|
|
204
|
+
|
|
205
|
+
if (intake.role === "form") {
|
|
206
|
+
const questions = own(intake.questions);
|
|
207
|
+
if (!isPlatformSchema(questions, QUESTIONS_SCHEMA)) {
|
|
208
|
+
contract(
|
|
209
|
+
`${at}.questions`,
|
|
210
|
+
`"${intake.questions}" must be a document field of ${name} with the platform's QUESTIONS_SCHEMA`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (!object.publishable?.content.includes(intake.questions)) {
|
|
214
|
+
contract(
|
|
215
|
+
`${at}.questions`,
|
|
216
|
+
`${name} must be publishable with "${intake.questions}" in its content: answers are checked against the published version`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
// Who may answer, anonymity and the destination are part of what is published: an edit
|
|
220
|
+
// changes how a form treats answers only once a person publishes it (ADR 0720).
|
|
221
|
+
for (const key of ["answeredBy", "anonymous", "destination"] as const) {
|
|
222
|
+
const local = intake[key];
|
|
223
|
+
if (local !== undefined && !object.publishable?.content.includes(local)) {
|
|
224
|
+
contract(
|
|
225
|
+
`${at}.${key}`,
|
|
226
|
+
`"${local}" must be in ${name}'s publishable content: it is read from the version answered`,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
need("answeredBy", intake.answeredBy, ["select"], "a select");
|
|
231
|
+
const answeredBy = options(intake.answeredBy);
|
|
232
|
+
if (
|
|
233
|
+
!answeredBy.length ||
|
|
234
|
+
answeredBy.some((o) => !(INTAKE_ANSWERED_BY as readonly string[]).includes(o))
|
|
235
|
+
) {
|
|
236
|
+
contract(
|
|
237
|
+
`${at}.answeredBy`,
|
|
238
|
+
`The options of "${intake.answeredBy}" are among ${INTAKE_ANSWERED_BY.join(", ")}`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (!states) {
|
|
242
|
+
contract(`${at}.openIn`, `${name} must declare states: a form takes answers in some`);
|
|
243
|
+
} else {
|
|
244
|
+
for (const state of intake.openIn) {
|
|
245
|
+
if (!stateValues.has(state))
|
|
246
|
+
contract(`${at}.openIn`, `"${state}" is not a state of ${name}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
need("anonymous", intake.anonymous, ["boolean"], "a boolean");
|
|
250
|
+
need("destination", intake.destination, ["text", "select"], "a text or select");
|
|
251
|
+
need("opensAt", intake.opensAt, ["datetime"], "a datetime");
|
|
252
|
+
need("closesAt", intake.closesAt, ["datetime"], "a datetime");
|
|
253
|
+
need("dailyCap", intake.dailyCap, ["number"], "a number");
|
|
254
|
+
need("notify", intake.notify, ["user"], "a user");
|
|
255
|
+
if (intake.hourlyCap !== undefined) {
|
|
256
|
+
const setting = Object.hasOwn(m.settings, intake.hourlyCap)
|
|
257
|
+
? m.settings[intake.hourlyCap]
|
|
258
|
+
: undefined;
|
|
259
|
+
if (setting?.type !== "number") {
|
|
260
|
+
contract(`${at}.hourlyCap`, `"${intake.hourlyCap}" must be a number setting of ${m.id}`);
|
|
261
|
+
} else if (setting.personApproves !== true) {
|
|
262
|
+
// How many answers the public may send is an abuse setting: never an AI's to change.
|
|
263
|
+
contract(
|
|
264
|
+
`${at}.hourlyCap`,
|
|
265
|
+
`"${intake.hourlyCap}" must be a setting a person approves (personApproves)`,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (object.customer || object.customerVia) {
|
|
270
|
+
contract(at, "A form is read by the public through its published version: no customer");
|
|
271
|
+
}
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (intake.role === "submission") {
|
|
276
|
+
const form = own(intake.form);
|
|
277
|
+
const target = form?.type === "relation" && !form.many ? form.to : undefined;
|
|
278
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
279
|
+
const formObject = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
280
|
+
if (!formObject || local === name || formObject.intake?.role !== "form") {
|
|
281
|
+
contract(
|
|
282
|
+
`${at}.form`,
|
|
283
|
+
`"${intake.form}" must be a relation field (one record) to another of this extension's objects that declares intake with the role form`,
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
const others = Object.entries(m.objects).filter(
|
|
287
|
+
([other, o]) =>
|
|
288
|
+
other !== name &&
|
|
289
|
+
o.intake?.role === "submission" &&
|
|
290
|
+
o.fields[o.intake.form]?.to === target,
|
|
291
|
+
);
|
|
292
|
+
if (others.length) {
|
|
293
|
+
contract(`${at}.form`, `${target} is answered by ${others[0]?.[0]} already: one each`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
need("version", intake.version, ["number"], "a number");
|
|
297
|
+
if (!isPlatformSchema(own(intake.answers), ANSWERS_SCHEMA)) {
|
|
298
|
+
contract(
|
|
299
|
+
`${at}.answers`,
|
|
300
|
+
`"${intake.answers}" must be a document field of ${name} with the platform's ANSWERS_SCHEMA`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
const person = own(intake.person);
|
|
304
|
+
if (person?.type !== "relation" || person.many || person.to !== "person") {
|
|
305
|
+
contract(`${at}.person`, `"${intake.person}" must be a relation field (one) to person`);
|
|
306
|
+
}
|
|
307
|
+
need("certainty", intake.certainty, ["select"], "a select");
|
|
308
|
+
const certainty = options(intake.certainty);
|
|
309
|
+
if (
|
|
310
|
+
certainty.length !== INTAKE_CERTAINTIES.length ||
|
|
311
|
+
INTAKE_CERTAINTIES.some((c) => !certainty.includes(c))
|
|
312
|
+
) {
|
|
313
|
+
contract(
|
|
314
|
+
`${at}.certainty`,
|
|
315
|
+
`The options of "${intake.certainty}" are exactly ${INTAKE_CERTAINTIES.join(", ")}`,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
if (!states) {
|
|
319
|
+
contract(`${at}.spam`, `${name} must declare states: spam is one of them`);
|
|
320
|
+
} else if (!stateValues.has(intake.spam)) {
|
|
321
|
+
contract(`${at}.spam`, `"${intake.spam}" is not a state of ${name}`);
|
|
322
|
+
} else if (
|
|
323
|
+
intake.spam !== states.initial &&
|
|
324
|
+
!states.create?.in?.[intake.spam]?.includes("host") &&
|
|
325
|
+
!states.moves.some(
|
|
326
|
+
(move) =>
|
|
327
|
+
move.to === intake.spam &&
|
|
328
|
+
(move.from === states.initial ||
|
|
329
|
+
(Array.isArray(move.from) && move.from.includes(states.initial))) &&
|
|
330
|
+
move.by.includes("host"),
|
|
331
|
+
)
|
|
332
|
+
) {
|
|
333
|
+
contract(
|
|
334
|
+
`${at}.spam`,
|
|
335
|
+
`The host must be able to create ${name} in "${intake.spam}" (create.in, or a host move from "${states.initial}")`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
if (intake.via !== undefined) {
|
|
339
|
+
need("via", intake.via, ["select"], "a select");
|
|
340
|
+
if (options(intake.via).some((o) => !(INTAKE_VIAS as readonly string[]).includes(o))) {
|
|
341
|
+
contract(`${at}.via`, `The options of "${intake.via}" are among ${INTAKE_VIAS.join(", ")}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
need("rating", intake.rating, ["number"], "a number");
|
|
345
|
+
need("marketing", intake.marketing, ["boolean"], "a boolean");
|
|
346
|
+
need("about", intake.about, ["text"], "a text");
|
|
347
|
+
need("aboutObject", intake.aboutObject, ["text"], "a text");
|
|
348
|
+
if ((intake.about === undefined) !== (intake.aboutObject === undefined)) {
|
|
349
|
+
contract(`${at}.about`, "Declare about and aboutObject together");
|
|
350
|
+
}
|
|
351
|
+
// Nobody outside the org reads a submission, not even its submitter (ADR 0720).
|
|
352
|
+
if (object.customer || object.customerVia || object.public || object.signedIn) {
|
|
353
|
+
contract(at, "A submission is read by staff only: no customer, public or signedIn");
|
|
354
|
+
}
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const person = own(intake.person);
|
|
359
|
+
if (person?.type !== "relation" || person.many || person.to !== "person") {
|
|
360
|
+
contract(`${at}.person`, `"${intake.person}" must be a relation field (one) to person`);
|
|
361
|
+
}
|
|
362
|
+
intake.fields.forEach((local, i) => {
|
|
363
|
+
const field = own(local);
|
|
364
|
+
if (!field || field.type === "formula" || field.readOnly) {
|
|
365
|
+
contract(`${at}.fields.${i}`, `"${local}" must be a writable field of ${name}`);
|
|
366
|
+
} else if (local === intake.person || local === intake.source || local === states?.field) {
|
|
367
|
+
contract(`${at}.fields.${i}`, `"${local}" is the host's to set`);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
if (new Set(intake.fields).size !== intake.fields.length) {
|
|
371
|
+
contract(`${at}.fields`, "List each field once");
|
|
372
|
+
}
|
|
373
|
+
if (intake.source !== undefined) {
|
|
374
|
+
need("source", intake.source, ["text", "select"], "a text or select");
|
|
375
|
+
const source = own(intake.source);
|
|
376
|
+
if (source?.type === "select" && !options(intake.source).includes(INTAKE_SOURCE)) {
|
|
377
|
+
contract(`${at}.source`, `"${intake.source}" must have the option "${INTAKE_SOURCE}"`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Journey signals (stage 53, ADR 0802): the moments about a Person a shipped pack names, that a
|
|
2
|
+
// journey can start or stop on ("membership started", "class attended"). A signal is a record of
|
|
3
|
+
// one of the pack's objects being created, or entering one of its declared states, and the field
|
|
4
|
+
// that names its Person. The host records, in the write's own batch, the last time each Person had
|
|
5
|
+
// each signal (`core_person_signal`); no pack code runs for it, and a pack cannot hook a write.
|
|
6
|
+
//
|
|
7
|
+
// This module is the contract's part: the declaration's shape and checks, and the pure rule the
|
|
8
|
+
// host uses to decide whether a write is the signal.
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
|
|
11
|
+
/** Most signals one extension declares. */
|
|
12
|
+
export const JOURNEY_SIGNALS_MAX = 12;
|
|
13
|
+
|
|
14
|
+
export interface JourneySignalSpec {
|
|
15
|
+
/** For admins choosing a journey's entry or exit: "Membership started". */
|
|
16
|
+
label: string;
|
|
17
|
+
/** For admins: when it happens, in plain words. */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** An object of this extension (`membership`). */
|
|
20
|
+
object: string;
|
|
21
|
+
/**
|
|
22
|
+
* The relation field naming the Person it is about. Default: the object's customer field. A
|
|
23
|
+
* record with it empty (a guest's held booking) is nobody's signal.
|
|
24
|
+
*/
|
|
25
|
+
person?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The states that are the signal: the record entering one of them. Left out, only creating a
|
|
28
|
+
* record is (a membership started, whatever its first state).
|
|
29
|
+
*/
|
|
30
|
+
enters?: readonly string[];
|
|
31
|
+
/** Only a move out of one of these states counts (a trial ending: `from: ["trialing"]`). */
|
|
32
|
+
from?: readonly string[];
|
|
33
|
+
/** Whether a record created straight into a state in `enters` counts. Default true. */
|
|
34
|
+
created?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const NAME = /^[a-z][a-zA-Z0-9]{0,39}$/;
|
|
38
|
+
const state = z.string().min(1).max(64);
|
|
39
|
+
|
|
40
|
+
export const journeySignalSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
label: z.string().min(1).max(80),
|
|
43
|
+
description: z.string().max(300).optional(),
|
|
44
|
+
object: z.string().min(1).max(30),
|
|
45
|
+
person: z.string().min(1).max(40).optional(),
|
|
46
|
+
enters: z.array(state).min(1).max(20).optional(),
|
|
47
|
+
from: z.array(state).min(1).max(20).optional(),
|
|
48
|
+
created: z.boolean().optional(),
|
|
49
|
+
})
|
|
50
|
+
.strict();
|
|
51
|
+
export type JourneySignalManifest = z.infer<typeof journeySignalSchema>;
|
|
52
|
+
|
|
53
|
+
export const journeySignalsManifestSchema = z.record(
|
|
54
|
+
z.string().regex(NAME, "camelCase letters and digits, starting lowercase"),
|
|
55
|
+
journeySignalSchema,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
type Origins = string | readonly string[];
|
|
59
|
+
|
|
60
|
+
interface CheckObject {
|
|
61
|
+
fields: Record<string, { type: string; to?: string | undefined; many?: boolean | undefined }>;
|
|
62
|
+
states?:
|
|
63
|
+
| {
|
|
64
|
+
field: string;
|
|
65
|
+
initial: string;
|
|
66
|
+
moves: readonly { from: Origins; to: string }[];
|
|
67
|
+
create?: { in?: Record<string, unknown> | undefined } | undefined;
|
|
68
|
+
follows?: { from: readonly string[]; when: Record<string, string> } | undefined;
|
|
69
|
+
after?: readonly { from: Origins; to: string }[] | undefined;
|
|
70
|
+
}
|
|
71
|
+
| undefined;
|
|
72
|
+
customer?: { field: string } | undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface CheckManifest {
|
|
76
|
+
objects: Record<string, CheckObject>;
|
|
77
|
+
journeySignals?: Record<string, JourneySignalManifest> | undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The values a states field can hold: its select's options. */
|
|
81
|
+
function stateValues(object: CheckObject): Set<string> | null {
|
|
82
|
+
const field = object.states ? object.fields[object.states.field] : undefined;
|
|
83
|
+
const options = (field as { options?: readonly unknown[] } | undefined)?.options;
|
|
84
|
+
if (!options) return null;
|
|
85
|
+
return new Set(
|
|
86
|
+
options.map((o) =>
|
|
87
|
+
typeof o === "string" ? o : String((o as { value?: unknown }).value ?? ""),
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Every way a record of `object` changes state: its moves, its timed moves (`after`) and the
|
|
94
|
+
* moves it follows from a related record (`follows`), each as where from and where to.
|
|
95
|
+
*/
|
|
96
|
+
function movesOf(object: CheckObject): { from: readonly string[]; to: string }[] {
|
|
97
|
+
const states = object.states;
|
|
98
|
+
if (!states) return [];
|
|
99
|
+
const list = (from: Origins) => (typeof from === "string" ? [from] : from);
|
|
100
|
+
return [
|
|
101
|
+
...states.moves.map((m) => ({ from: list(m.from), to: m.to })),
|
|
102
|
+
...(states.after ?? []).map((m) => ({ from: list(m.from), to: m.to })),
|
|
103
|
+
...Object.values(states.follows?.when ?? {}).map((to) => ({
|
|
104
|
+
from: states.follows?.from ?? [],
|
|
105
|
+
to,
|
|
106
|
+
})),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The contract's issues with a manifest's `journeySignals`. */
|
|
111
|
+
export function journeySignalIssues(manifest: CheckManifest): { path: string; message: string }[] {
|
|
112
|
+
const issues: { path: string; message: string }[] = [];
|
|
113
|
+
const contract = (path: string, message: string) => issues.push({ path, message });
|
|
114
|
+
const signals = manifest.journeySignals ?? {};
|
|
115
|
+
if (Object.keys(signals).length > JOURNEY_SIGNALS_MAX) {
|
|
116
|
+
contract("journeySignals", `At most ${JOURNEY_SIGNALS_MAX} journey signals`);
|
|
117
|
+
}
|
|
118
|
+
for (const [name, signal] of Object.entries(signals)) {
|
|
119
|
+
const base = `journeySignals.${name}`;
|
|
120
|
+
const object = manifest.objects[signal.object];
|
|
121
|
+
if (!object) {
|
|
122
|
+
contract(`${base}.object`, `"${signal.object}" is not an object of this extension`);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const person = signal.person ?? object.customer?.field;
|
|
126
|
+
if (!person) {
|
|
127
|
+
contract(`${base}.person`, "Name the relation field that holds the Person it is about");
|
|
128
|
+
} else {
|
|
129
|
+
const field = object.fields[person];
|
|
130
|
+
if (!field) contract(`${base}.person`, `"${person}" is not a field of ${signal.object}`);
|
|
131
|
+
else if (field.type !== "relation" || field.to !== "person" || field.many) {
|
|
132
|
+
contract(`${base}.person`, `"${person}" must be a relation to one person`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!signal.enters) {
|
|
136
|
+
if (signal.from) contract(`${base}.from`, "from needs enters: the states it moves into");
|
|
137
|
+
if (signal.created === false) {
|
|
138
|
+
contract(`${base}.created`, "A signal that is not a create needs enters");
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const values = stateValues(object);
|
|
143
|
+
if (!values) {
|
|
144
|
+
contract(`${base}.enters`, `${signal.object} declares no states`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
let known = true;
|
|
148
|
+
for (const [key, list] of [
|
|
149
|
+
["enters", signal.enters],
|
|
150
|
+
["from", signal.from ?? []],
|
|
151
|
+
] as const) {
|
|
152
|
+
list.forEach((value, i) => {
|
|
153
|
+
if (!values.has(value)) {
|
|
154
|
+
known = false;
|
|
155
|
+
contract(`${base}.${key}.${i}`, `"${value}" is not a state of ${signal.object}`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (!known) continue;
|
|
160
|
+
// A signal that can happen: a declared move into one of its states (from one it names), or a
|
|
161
|
+
// create straight into one. A `from` no move leaves for them names nothing.
|
|
162
|
+
const enters = new Set(signal.enters);
|
|
163
|
+
const into = movesOf(object).filter((m) => enters.has(m.to));
|
|
164
|
+
const createdIn = new Set([
|
|
165
|
+
object.states?.initial ?? "",
|
|
166
|
+
...Object.keys(object.states?.create?.in ?? {}),
|
|
167
|
+
]);
|
|
168
|
+
const byCreate = signal.created !== false && signal.enters.some((e) => createdIn.has(e));
|
|
169
|
+
const fromOk = (m: { from: readonly string[]; to: string }) =>
|
|
170
|
+
m.from.some((f) => f !== m.to && (!signal.from || signal.from.includes(f)));
|
|
171
|
+
if (!byCreate && !into.some(fromOk)) {
|
|
172
|
+
contract(
|
|
173
|
+
`${base}.enters`,
|
|
174
|
+
`No declared move or create of ${signal.object} makes this signal: it can never happen`,
|
|
175
|
+
);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
signal.from?.forEach((value, i) => {
|
|
179
|
+
if (!into.some((m) => m.to !== value && m.from.includes(value))) {
|
|
180
|
+
contract(
|
|
181
|
+
`${base}.from.${i}`,
|
|
182
|
+
`No declared move of ${signal.object} leaves "${value}" for ${[...enters].join(" or ")}`,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return issues;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A position value as a record holds it (a select's value). */
|
|
191
|
+
function stateOf(value: unknown): string | null {
|
|
192
|
+
return value === null || value === undefined ? null : String(value);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Whether a write is the signal. `before` is the record's values before (null on create), `after`
|
|
197
|
+
* as the write leaves it; `stateField` the object's states field, when it has one.
|
|
198
|
+
*/
|
|
199
|
+
export function journeySignalFires(
|
|
200
|
+
signal: Pick<JourneySignalSpec, "enters" | "from" | "created">,
|
|
201
|
+
stateField: string | undefined,
|
|
202
|
+
before: Record<string, unknown> | null,
|
|
203
|
+
after: Record<string, unknown>,
|
|
204
|
+
): boolean {
|
|
205
|
+
const now = stateField ? stateOf(after[stateField]) : null;
|
|
206
|
+
if (before === null) {
|
|
207
|
+
if (signal.created === false) return false;
|
|
208
|
+
if (!signal.enters) return true;
|
|
209
|
+
return now !== null && signal.enters.includes(now);
|
|
210
|
+
}
|
|
211
|
+
if (!signal.enters || !stateField || now === null) return false;
|
|
212
|
+
const was = stateOf(before[stateField]);
|
|
213
|
+
if (was === now || !signal.enters.includes(now)) return false;
|
|
214
|
+
return !signal.from || (was !== null && signal.from.includes(was));
|
|
215
|
+
}
|