@composable-os/cli 0.1.0-beta.11 → 0.1.0-beta.13
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-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-DE4RRWPJ.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-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-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-MBIKVRAC.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-PDD2ETVF.js → chunk-QQ3YSL5F.js} +172 -16
- 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-NNUCHQ2Y.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The `recurring` behaviour (stage 31, ADR 0500): a record (a series: one line of a timetable)
|
|
2
|
-
// declares a
|
|
3
|
-
// generates (its classes) ahead of time. Its declaration, its manifest schema and its contract
|
|
2
|
+
// declares a rule in local wall-clock time (weekly, or every N weeks, months or years: ADR 0860),
|
|
3
|
+
// and the host makes the dated records it generates (its classes) ahead of time. Its declaration, its manifest schema and its contract
|
|
4
4
|
// checks live here; the host's side is packages/core/src/recurring/.
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
@@ -9,13 +9,19 @@ import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifes
|
|
|
9
9
|
export const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] as const;
|
|
10
10
|
export type Weekday = (typeof WEEKDAYS)[number];
|
|
11
11
|
|
|
12
|
+
/** The values a rule's `unit` field may use (ADR 0860): every N weeks, months or years. */
|
|
13
|
+
export const RECURRING_UNITS = ["week", "month", "year"] as const;
|
|
14
|
+
export type RecurringUnit = (typeof RECURRING_UNITS)[number];
|
|
15
|
+
/** The largest N of "every N units". */
|
|
16
|
+
export const RECURRING_EVERY_MAX = 100;
|
|
17
|
+
|
|
12
18
|
/** How far ahead the host makes records when a series does not say (days). */
|
|
13
19
|
export const RECURRING_HORIZON_DAYS = 56;
|
|
14
20
|
/** The most days ahead a series may ask for. */
|
|
15
21
|
export const RECURRING_HORIZON_MAX = 366;
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
|
-
* A
|
|
24
|
+
* A schedule that generates dated records (ADR 0500; the interval rule, ADR 0860). The rule is kept in local
|
|
19
25
|
* wall-clock time in the series' zone: 06:00 is 06:00 on both sides of a clock change. A local
|
|
20
26
|
* time that does not exist on a change day (02:30 when clocks go forward) moves forward by the
|
|
21
27
|
* gap; one that happens twice is the first of the two.
|
|
@@ -25,7 +31,16 @@ export const RECURRING_HORIZON_MAX = 366;
|
|
|
25
31
|
* - `rule` names this object's fields: `weekdays` (a multiSelect whose option values are
|
|
26
32
|
* `mon`…`sun`), `time` (a text field, `HH:MM`), `length` (a number field, minutes), `from` and
|
|
27
33
|
* `until` (date fields; `until` empty for ongoing) and `zone` (a timezone field; empty is the
|
|
28
|
-
* organisation's zone).
|
|
34
|
+
* organisation's zone). Without `unit` the rule is weekly, as it always was.
|
|
35
|
+
* - The interval rule (ADR 0860) adds, all optional: `unit` (a select whose option values are
|
|
36
|
+
* some of `week`, `month`, `year`; empty is `week`), `every` (a number field: every N units,
|
|
37
|
+
* empty is 1), `day` (a number field: the day of the month, 1 to 31, for months and years; the
|
|
38
|
+
* month's last day when it is shorter; empty is `from`'s day), `month` (a number field: the
|
|
39
|
+
* month, 1 to 12, for years; empty is `from`'s month) and `lengthDays` (a number field: the
|
|
40
|
+
* length in whole days, ending at the same wall-clock time; instead of `length`). Dates are
|
|
41
|
+
* fixed on the calendar, counted from `from`: every 2 weeks from `from`'s week, every 3 months
|
|
42
|
+
* from `from`'s month, every year from `from`'s year, never from when the last was done.
|
|
43
|
+
* `weekdays` is needed only when `unit` may be `week`.
|
|
29
44
|
* - `into` names the generated object's fields the host fills: `starts` (datetime), `ends`
|
|
30
45
|
* (datetime, starts plus the length), `zone` (timezone) and `changed` (a read-only boolean the
|
|
31
46
|
* host sets when someone other than the host edits the record).
|
|
@@ -43,6 +58,9 @@ export const RECURRING_HORIZON_MAX = 366;
|
|
|
43
58
|
* - `horizonAtLeast` (optional): another of this extension's objects and a number field of it in
|
|
44
59
|
* days (a class type's booking window): the horizon is never less than the largest value any
|
|
45
60
|
* live record of it holds, so a class can be booked as soon as its window opens.
|
|
61
|
+
* - `horizonSetting` (optional, ADR 0626): a number setting of this extension, in days, that
|
|
62
|
+
* sets the horizon instead of `horizonDays` (a business choosing how far ahead its duties are
|
|
63
|
+
* made); `horizonDays` stays the default while the setting is empty.
|
|
46
64
|
*
|
|
47
65
|
* Made records are never made twice (the host keys each on the series and its local date). A
|
|
48
66
|
* record edited by staff (its time, copied fields or state) is never overwritten or made again;
|
|
@@ -52,12 +70,17 @@ export interface RecurringScheduleSpec {
|
|
|
52
70
|
generates: string;
|
|
53
71
|
link: string;
|
|
54
72
|
rule: {
|
|
55
|
-
weekdays
|
|
73
|
+
weekdays?: string;
|
|
56
74
|
time: string;
|
|
57
75
|
length?: string;
|
|
58
76
|
from: string;
|
|
59
77
|
until?: string;
|
|
60
78
|
zone?: string;
|
|
79
|
+
unit?: string;
|
|
80
|
+
every?: string;
|
|
81
|
+
day?: string;
|
|
82
|
+
month?: string;
|
|
83
|
+
lengthDays?: string;
|
|
61
84
|
};
|
|
62
85
|
into: { starts: string; ends?: string; zone?: string; changed?: string };
|
|
63
86
|
copy?: Readonly<Record<string, string>>;
|
|
@@ -66,6 +89,7 @@ export interface RecurringScheduleSpec {
|
|
|
66
89
|
closures?: { object: string; from: string; until: string };
|
|
67
90
|
horizonDays?: number;
|
|
68
91
|
horizonAtLeast?: { object: string; field: string };
|
|
92
|
+
horizonSetting?: string;
|
|
69
93
|
}
|
|
70
94
|
|
|
71
95
|
const fieldName = z.string().max(40);
|
|
@@ -76,12 +100,17 @@ export const recurringManifestSchema = z
|
|
|
76
100
|
link: fieldName,
|
|
77
101
|
rule: z
|
|
78
102
|
.object({
|
|
79
|
-
weekdays: fieldName,
|
|
103
|
+
weekdays: fieldName.optional(),
|
|
80
104
|
time: fieldName,
|
|
81
105
|
length: fieldName.optional(),
|
|
82
106
|
from: fieldName,
|
|
83
107
|
until: fieldName.optional(),
|
|
84
108
|
zone: fieldName.optional(),
|
|
109
|
+
unit: fieldName.optional(),
|
|
110
|
+
every: fieldName.optional(),
|
|
111
|
+
day: fieldName.optional(),
|
|
112
|
+
month: fieldName.optional(),
|
|
113
|
+
lengthDays: fieldName.optional(),
|
|
85
114
|
})
|
|
86
115
|
.strict(),
|
|
87
116
|
into: z
|
|
@@ -107,6 +136,7 @@ export const recurringManifestSchema = z
|
|
|
107
136
|
.optional(),
|
|
108
137
|
horizonDays: z.number().int().min(1).max(RECURRING_HORIZON_MAX).optional(),
|
|
109
138
|
horizonAtLeast: z.object({ object: fieldName, field: fieldName }).strict().optional(),
|
|
139
|
+
horizonSetting: z.string().max(64).optional(),
|
|
110
140
|
})
|
|
111
141
|
.strict();
|
|
112
142
|
export type RecurringScheduleManifest = z.infer<typeof recurringManifestSchema>;
|
|
@@ -121,10 +151,12 @@ export function checkObjectRecurring(
|
|
|
121
151
|
const recurring = object.recurring;
|
|
122
152
|
if (!recurring) return;
|
|
123
153
|
const path = `objects.${name}.recurring`;
|
|
124
|
-
|
|
154
|
+
// An object, or the fields this extension adds to another extension's object.
|
|
155
|
+
type Fields = Pick<ObjectManifest, "fields">;
|
|
156
|
+
const own = (o: Fields, local: string): FieldManifest | undefined =>
|
|
125
157
|
Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
126
158
|
const expect = (
|
|
127
|
-
o:
|
|
159
|
+
o: Fields,
|
|
128
160
|
oName: string,
|
|
129
161
|
at: string,
|
|
130
162
|
local: string | undefined,
|
|
@@ -141,6 +173,33 @@ export function checkObjectRecurring(
|
|
|
141
173
|
};
|
|
142
174
|
|
|
143
175
|
const rule = recurring.rule;
|
|
176
|
+
// The interval rule's unit (ADR 0860): a select of some of week, month and year.
|
|
177
|
+
const unit = expect(object, name, `${path}.rule.unit`, rule.unit, ["select"], "a select field");
|
|
178
|
+
const units = (unit?.options ?? []).map((o) => o.value);
|
|
179
|
+
if (unit) {
|
|
180
|
+
const wrong = units.filter((v) => !(RECURRING_UNITS as readonly string[]).includes(v));
|
|
181
|
+
if (wrong.length || !units.length) {
|
|
182
|
+
contract(
|
|
183
|
+
`${path}.rule.unit`,
|
|
184
|
+
`"${rule.unit}"'s options must be units (${RECURRING_UNITS.join(", ")})`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (unit.editableOptions) {
|
|
188
|
+
contract(`${path}.rule.unit`, "The unit field cannot have editableOptions");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const key of ["every", "day", "month"] as const) {
|
|
192
|
+
const local = rule[key];
|
|
193
|
+
if (local === undefined) continue;
|
|
194
|
+
if (rule.unit === undefined) {
|
|
195
|
+
contract(`${path}.rule.${key}`, `"${key}" needs a unit field (rule.unit)`);
|
|
196
|
+
}
|
|
197
|
+
expect(object, name, `${path}.rule.${key}`, local, ["number"], "a number field");
|
|
198
|
+
}
|
|
199
|
+
// Weekdays are needed while the rule can be weekly: no unit, or a unit that may be "week".
|
|
200
|
+
if (rule.weekdays === undefined && (rule.unit === undefined || units.includes("week"))) {
|
|
201
|
+
contract(`${path}.rule.weekdays`, "A rule that can be weekly needs a weekdays field");
|
|
202
|
+
}
|
|
144
203
|
const weekdays = expect(
|
|
145
204
|
object,
|
|
146
205
|
name,
|
|
@@ -164,6 +223,17 @@ export function checkObjectRecurring(
|
|
|
164
223
|
}
|
|
165
224
|
expect(object, name, `${path}.rule.time`, rule.time, ["text"], "a text field (HH:MM)");
|
|
166
225
|
expect(object, name, `${path}.rule.length`, rule.length, ["number"], "a number field (minutes)");
|
|
226
|
+
expect(
|
|
227
|
+
object,
|
|
228
|
+
name,
|
|
229
|
+
`${path}.rule.lengthDays`,
|
|
230
|
+
rule.lengthDays,
|
|
231
|
+
["number"],
|
|
232
|
+
"a number field (days)",
|
|
233
|
+
);
|
|
234
|
+
if (rule.length !== undefined && rule.lengthDays !== undefined) {
|
|
235
|
+
contract(`${path}.rule.lengthDays`, "A rule's length is in minutes or in days, not both");
|
|
236
|
+
}
|
|
167
237
|
expect(object, name, `${path}.rule.from`, rule.from, ["date"], "a date field");
|
|
168
238
|
expect(object, name, `${path}.rule.until`, rule.until, ["date"], "a date field");
|
|
169
239
|
expect(object, name, `${path}.rule.zone`, rule.zone, ["timezone"], "a timezone field");
|
|
@@ -279,13 +349,24 @@ export function checkObjectRecurring(
|
|
|
279
349
|
);
|
|
280
350
|
}
|
|
281
351
|
}
|
|
352
|
+
if (recurring.horizonSetting !== undefined) {
|
|
353
|
+
const setting = Object.hasOwn(m.settings, recurring.horizonSetting)
|
|
354
|
+
? m.settings[recurring.horizonSetting]
|
|
355
|
+
: undefined;
|
|
356
|
+
if (setting?.type !== "number") {
|
|
357
|
+
contract(
|
|
358
|
+
`${path}.horizonSetting`,
|
|
359
|
+
`"${recurring.horizonSetting}" must be a number setting of this extension (days)`,
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
282
363
|
if (recurring.horizonAtLeast) {
|
|
283
364
|
const h = recurring.horizonAtLeast;
|
|
284
365
|
// One of this extension's objects, or another extension's object with a number field this
|
|
285
366
|
// extension adds to it (a class type of Programs' carrying Bookings' window, ADR 0505).
|
|
286
367
|
const added = h.object.includes(".") ? m.fields?.[h.object] : undefined;
|
|
287
368
|
const target = added
|
|
288
|
-
?
|
|
369
|
+
? { fields: added }
|
|
289
370
|
: Object.hasOwn(m.objects, h.object)
|
|
290
371
|
? m.objects[h.object]
|
|
291
372
|
: undefined;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Restricted fields (stage 54 step 2, ADR 0811): a text field only people with a named grant
|
|
2
|
+
// read. `restricted: "<pack>:<word>"` names one of the pack's restricted permissions (ADR 0625).
|
|
3
|
+
// The host keeps the value in a core table of its own (core_restricted_value, migration 1190),
|
|
4
|
+
// never in the object's x_* table, so it is in no rec_* view, search entry, export, dashboard,
|
|
5
|
+
// embedding, summary or audit row. The record's customer writes it and reads their own; staff
|
|
6
|
+
// read it only through one of the pack's tools that names the permission, a person only, every
|
|
7
|
+
// read audited (`record.readRestricted`). Its contract checks live here; the host's side is
|
|
8
|
+
// packages/core/src/records/restricted.ts.
|
|
9
|
+
import type { ExtensionManifest, FieldManifest } from "./manifest.ts";
|
|
10
|
+
|
|
11
|
+
/** The field types a restricted field may have: words a person writes. */
|
|
12
|
+
export const RESTRICTED_FIELD_TYPES = ["text", "longText"] as const;
|
|
13
|
+
|
|
14
|
+
/** The most characters a restricted value holds (the store's own check, migration 1190). */
|
|
15
|
+
export const RESTRICTED_MAX_CHARS = 4000;
|
|
16
|
+
|
|
17
|
+
/** Whether `field` is declared restricted. */
|
|
18
|
+
export function isRestrictedField(field: Pick<FieldManifest, "restricted">): boolean {
|
|
19
|
+
return typeof field.restricted === "string";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reports problems with restricted fields through `contract`: each is a text field of one of the
|
|
24
|
+
* pack's own objects, which declares a customer who reads and writes it; it names one of the
|
|
25
|
+
* pack's restricted permissions; nothing else of the object names it (its title, an index, a
|
|
26
|
+
* uniqueness rule, what the public or every signed-in customer reads, a version's content, a
|
|
27
|
+
* seed); and it is on no other object.
|
|
28
|
+
*/
|
|
29
|
+
export function checkRestrictedFields(
|
|
30
|
+
m: ExtensionManifest,
|
|
31
|
+
contract: (path: string, message: string) => void,
|
|
32
|
+
): void {
|
|
33
|
+
const restricted = new Set(m.restricted ?? []);
|
|
34
|
+
for (const [target, fields] of Object.entries(m.fields)) {
|
|
35
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
36
|
+
if (isRestrictedField(field)) {
|
|
37
|
+
contract(
|
|
38
|
+
`fields.${target}.${name}.restricted`,
|
|
39
|
+
"A restricted field is a field of one of this extension's own objects, never one added to another object",
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const [objectName, object] of Object.entries(m.objects)) {
|
|
45
|
+
const names = Object.entries(object.fields)
|
|
46
|
+
.filter(([, field]) => isRestrictedField(field))
|
|
47
|
+
.map(([name]) => name);
|
|
48
|
+
if (!names.length) continue;
|
|
49
|
+
const path = `objects.${objectName}`;
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
const field = object.fields[name] as FieldManifest;
|
|
52
|
+
const at = `${path}.fields.${name}`;
|
|
53
|
+
if (!(RESTRICTED_FIELD_TYPES as readonly string[]).includes(field.type)) {
|
|
54
|
+
contract(`${at}.type`, "A restricted field is a text or longText field");
|
|
55
|
+
}
|
|
56
|
+
if (!restricted.has(field.restricted as string)) {
|
|
57
|
+
contract(
|
|
58
|
+
`${at}.restricted`,
|
|
59
|
+
`"${field.restricted}" must be one of this extension's restricted permissions (restricted)`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
for (const key of [
|
|
63
|
+
"required",
|
|
64
|
+
"readOnly",
|
|
65
|
+
"default",
|
|
66
|
+
"defaultSetting",
|
|
67
|
+
"track",
|
|
68
|
+
"personApproves",
|
|
69
|
+
"renamedFrom",
|
|
70
|
+
] as const) {
|
|
71
|
+
if (field[key] !== undefined) {
|
|
72
|
+
contract(
|
|
73
|
+
`${at}.${key}`,
|
|
74
|
+
`A restricted field takes no ${key}: its author writes it, and nothing else sees it`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const customer = object.customer;
|
|
79
|
+
if (!customer) {
|
|
80
|
+
contract(
|
|
81
|
+
`${at}.restricted`,
|
|
82
|
+
"A restricted field is on an object that declares a customer: its author writes it",
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
if (customer.field === name) {
|
|
86
|
+
contract(`${at}.restricted`, "The customer field cannot be restricted");
|
|
87
|
+
}
|
|
88
|
+
if (!customer.write.includes(name) || !customer.read.includes(name)) {
|
|
89
|
+
contract(
|
|
90
|
+
`${at}.restricted`,
|
|
91
|
+
"A restricted field is one the customer reads and writes (customer.read and customer.write)",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const named = (where: string, list: readonly string[] | undefined) => {
|
|
97
|
+
for (const name of names) {
|
|
98
|
+
if (list?.includes(name)) {
|
|
99
|
+
contract(
|
|
100
|
+
`${path}.${where}`,
|
|
101
|
+
`"${name}" is restricted: it is kept out of every list, view and read but its own`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
named("titleField", [object.titleField]);
|
|
107
|
+
object.indexes?.forEach((index, i) => {
|
|
108
|
+
named(`indexes.${i}`, index);
|
|
109
|
+
});
|
|
110
|
+
object.unique?.forEach((rule, i) => {
|
|
111
|
+
named(`unique.${i}.fields`, rule.fields);
|
|
112
|
+
});
|
|
113
|
+
object.requireOneOf?.forEach((group, i) => {
|
|
114
|
+
named(`requireOneOf.${i}`, group);
|
|
115
|
+
});
|
|
116
|
+
named("public.read", object.public?.read);
|
|
117
|
+
named("signedIn.read", object.signedIn?.read);
|
|
118
|
+
named("customerVia.read", object.customerVia?.read);
|
|
119
|
+
named("publishable.content", object.publishable?.content);
|
|
120
|
+
for (const [fieldName, field] of Object.entries(object.fields)) {
|
|
121
|
+
for (const option of field.options ?? []) {
|
|
122
|
+
named(`fields.${fieldName}.options`, option.requires);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const [key, values] of Object.entries(object.seed ?? {})) {
|
|
126
|
+
named(`seed.${key}`, Object.keys(values));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// host and both renderers read this one declaration. Changing it changes what every product
|
|
15
15
|
// stores; a block type added here must be added to both renderers (stage 28, step 6).
|
|
16
16
|
import type { DocumentNode, DocumentObjectNode, DocumentSchema } from "./document.ts";
|
|
17
|
+
import { hyphenate } from "./slug.ts";
|
|
17
18
|
|
|
18
19
|
/** The block types, in the order a renderer lists them. */
|
|
19
20
|
export const RICH_TEXT_BLOCKS = [
|
|
@@ -219,3 +220,114 @@ export function documentMaxBytesOf(field: {
|
|
|
219
220
|
if (field.maxBytes !== undefined) return field.maxBytes;
|
|
220
221
|
return field.type === "richText" ? RICH_TEXT_DEFAULT_BYTES : undefined;
|
|
221
222
|
}
|
|
223
|
+
|
|
224
|
+
// --- Sections and anchors (stage 38, ADR 0700) ---------------------------------------------------
|
|
225
|
+
//
|
|
226
|
+
// A heading starts a section. Its anchor is made from its text and its place among the document's
|
|
227
|
+
// headings, never stored: the host's published-text index, `content.search`'s results and both
|
|
228
|
+
// renderers (a heading's `id` on the web, its `nativeID` in the app) all call `headingAnchors`, so
|
|
229
|
+
// a link to `#<anchor>` lands on the heading the search found. Two headings with the same words
|
|
230
|
+
// are told apart by their order (`-2`, `-3`); a heading with no letters or digits is `section`.
|
|
231
|
+
|
|
232
|
+
/** The longest a heading's anchor is, before a `-<n>` that tells two apart. */
|
|
233
|
+
export const ANCHOR_MAX = 60;
|
|
234
|
+
|
|
235
|
+
interface RichTextLike {
|
|
236
|
+
blocks?: readonly unknown[] | null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
type Runs = readonly { type?: unknown; text?: unknown }[] | undefined;
|
|
240
|
+
|
|
241
|
+
/** The words of inline runs, without marks. A line break is a space. */
|
|
242
|
+
function runsText(content: Runs): string {
|
|
243
|
+
return (content ?? [])
|
|
244
|
+
.map((run) => (run?.type === "text" && typeof run.text === "string" ? run.text : " "))
|
|
245
|
+
.join("")
|
|
246
|
+
.replace(/\s+/g, " ")
|
|
247
|
+
.trim();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function anchorBase(text: string): string {
|
|
251
|
+
return hyphenate(text, ANCHOR_MAX) || "section";
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Each heading block's anchor, in the order the headings come in the document. */
|
|
255
|
+
export function headingAnchors(value: RichTextLike | null | undefined): string[] {
|
|
256
|
+
const taken = new Set<string>();
|
|
257
|
+
const out: string[] = [];
|
|
258
|
+
for (const block of value?.blocks ?? []) {
|
|
259
|
+
const b = block as { type?: unknown; content?: Runs };
|
|
260
|
+
if (b?.type !== "heading") continue;
|
|
261
|
+
const base = anchorBase(runsText(b.content));
|
|
262
|
+
let anchor = base;
|
|
263
|
+
for (let n = 2; taken.has(anchor); n += 1) anchor = `${base}-${n}`;
|
|
264
|
+
taken.add(anchor);
|
|
265
|
+
out.push(anchor);
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** One section of a document: what comes before the first heading, or a heading and its blocks. */
|
|
271
|
+
export interface RichTextSection {
|
|
272
|
+
/** The heading's anchor; null for what comes before the first heading. */
|
|
273
|
+
anchor: string | null;
|
|
274
|
+
/** The heading's words; empty before the first heading. */
|
|
275
|
+
heading: string;
|
|
276
|
+
/** The words of the section's blocks, the heading's own left out. */
|
|
277
|
+
text: string;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** A block's words (a list's items, a picture's caption, a button's label). */
|
|
281
|
+
function blockText(block: unknown): string {
|
|
282
|
+
const b = block as Record<string, unknown> & { type?: unknown };
|
|
283
|
+
const list = (body: unknown): string[] =>
|
|
284
|
+
((body as { items?: unknown[] } | undefined)?.items ?? []).flatMap((item) => {
|
|
285
|
+
const i = item as { content?: Runs; list?: unknown };
|
|
286
|
+
return [runsText(i.content), ...(i.list ? list(i.list) : [])];
|
|
287
|
+
});
|
|
288
|
+
switch (b?.type) {
|
|
289
|
+
case "paragraph":
|
|
290
|
+
case "heading":
|
|
291
|
+
case "quote":
|
|
292
|
+
case "callout":
|
|
293
|
+
return runsText(b.content as Runs);
|
|
294
|
+
case "list":
|
|
295
|
+
return list(b).filter(Boolean).join(" ");
|
|
296
|
+
case "image":
|
|
297
|
+
return runsText(b.caption as Runs);
|
|
298
|
+
case "embed":
|
|
299
|
+
return typeof b.caption === "string" ? b.caption : "";
|
|
300
|
+
case "button":
|
|
301
|
+
return typeof b.label === "string" ? b.label : "";
|
|
302
|
+
default:
|
|
303
|
+
return "";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* A document split at its headings: the blocks before the first heading (only when they hold
|
|
309
|
+
* words), then one section per heading, with the anchor `headingAnchors` gives it.
|
|
310
|
+
*/
|
|
311
|
+
export function richTextSections(value: RichTextLike | null | undefined): RichTextSection[] {
|
|
312
|
+
const anchors = headingAnchors(value);
|
|
313
|
+
const sections: { anchor: string | null; heading: string; parts: string[] }[] = [
|
|
314
|
+
{ anchor: null, heading: "", parts: [] },
|
|
315
|
+
];
|
|
316
|
+
let heading = 0;
|
|
317
|
+
for (const block of value?.blocks ?? []) {
|
|
318
|
+
if ((block as { type?: unknown })?.type === "heading") {
|
|
319
|
+
sections.push({
|
|
320
|
+
anchor: anchors[heading] ?? null,
|
|
321
|
+
heading: blockText(block),
|
|
322
|
+
parts: [],
|
|
323
|
+
});
|
|
324
|
+
heading += 1;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const text = blockText(block);
|
|
328
|
+
if (text) sections.at(-1)?.parts.push(text);
|
|
329
|
+
}
|
|
330
|
+
return sections
|
|
331
|
+
.map((s) => ({ anchor: s.anchor, heading: s.heading, text: s.parts.join("\n") }))
|
|
332
|
+
.filter((s) => s.anchor !== null || s.text);
|
|
333
|
+
}
|