@composable-os/cli 0.1.0-beta.10 → 0.1.0-beta.11
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-X4CKM3HL.js → accounts-UHYLCLEY.js} +10 -11
- package/dist/{blocks-YWDHEBOK.js → blocks-5IFU25J6.js} +2 -2
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/{chunk-QGGJ2G6Z.js → chunk-2TWV3SVB.js} +3 -3
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/{chunk-YJJHF65I.js → chunk-6WGFA2IV.js} +58 -174
- package/dist/{chunk-A4NTSYWV.js → chunk-6XTU2MTP.js} +196 -10
- package/dist/{chunk-Q4N55M2Z.js → chunk-7D4GKZOX.js} +66 -3
- package/dist/{chunk-GYSGVT6R.js → chunk-7OGCMQXG.js} +9 -9
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/{chunk-LJFLENFC.js → chunk-E64SG24J.js} +1 -1
- package/dist/{chunk-Z3RMMB6S.js → chunk-FJIZGS5Q.js} +45 -15
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/{chunk-LLULPZAJ.js → chunk-LAAL4YGR.js} +4 -4
- package/dist/{chunk-CP6BXI6F.js → chunk-LO6WGU5Y.js} +1338 -974
- package/dist/{chunk-Y7JZFSTQ.js → chunk-MBIKVRAC.js} +6 -6
- package/dist/{chunk-WC5LHBBA.js → chunk-P6UWZ6QQ.js} +1 -1
- package/dist/{chunk-6VXHPKGG.js → chunk-PDD2ETVF.js} +8 -8
- package/dist/{chunk-6UPUF4ML.js → chunk-UB4I2QKR.js} +1957 -380
- package/dist/{chunk-M7A6FR2Z.js → chunk-WHKJGF36.js} +154 -322
- package/dist/{chunk-VY64DMQO.js → chunk-XIDLW3EP.js} +190 -21
- package/dist/{chunk-IFG4FRW5.js → chunk-YFTLIEWU.js} +1 -1
- package/dist/{chunk-JJHHNV46.js → chunk-YNUZRTPH.js} +5 -50
- package/dist/{chunk-WO6D3XP3.js → chunk-ZAWES2UD.js} +31 -18
- package/dist/{chunk-K6T42YCH.js → chunk-ZZFWMVJO.js} +5 -5
- package/dist/{cli-2DFENR62.js → cli-5UNY5G5L.js} +22 -20
- package/dist/{cli-YIOVSKOD.js → cli-UYZMVQMR.js} +16 -13
- package/dist/cli.js +1 -1
- package/dist/{client-repo-PRU3VCQQ.js → client-repo-SE4EKG6W.js} +2 -2
- package/dist/create.js +1 -1
- package/dist/{fields-2NC7LSYE.js → fields-FTWWMD7N.js} +3 -3
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/{order-PUWD65BC.js → order-U4KZLLSJ.js} +2 -2
- package/dist/{person-WIQQ7ITU.js → person-UHLVBVLR.js} +9 -10
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/capacity.ts +102 -0
- package/dist/platform/sdk/contract.ts +25 -0
- package/dist/platform/sdk/manifest.ts +77 -1
- package/dist/platform/sdk/sellable.ts +251 -1
- package/dist/platform/sdk/states.ts +163 -49
- package/dist/{run-RT2HVWMK.js → run-7P4RQALH.js} +2 -2
- package/dist/{run-PZUCSDDL.js → run-PO3W5BFA.js} +1 -1
- package/dist/{run-Y7T4TVOL.js → run-ZCGFMEZF.js} +2 -2
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/{src-XTOD7EXW.js → src-I3IJ4NKC.js} +8 -2
- package/dist/{visibility-DLGHU4YN.js → visibility-TVXZ67FD.js} +12 -4
- package/package.json +2 -2
- package/dist/chunk-6GDEDOV7.js +0 -157
- package/dist/chunk-O2UIZHND.js +0 -249
- package/dist/chunk-R4W5XAUD.js +0 -837
- package/dist/chunk-TQFGGSA4.js +0 -748
- package/dist/grants-QXMKYMGB.js +0 -32
- package/dist/invoke-I3NNNXVL.js +0 -39
- package/dist/plan-on-sale-NB774CQL.js +0 -26
- package/dist/src-GYS6NBQB.js +0 -44
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { customerWritable, spendsOnList } from "./allowance.ts";
|
|
8
8
|
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
9
|
-
import { moveOrigins } from "./states.ts";
|
|
9
|
+
import { moveOrigins, resolveFieldPath } from "./states.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Where a granted record's field gets its value, when the host creates it:
|
|
@@ -107,6 +107,49 @@ export interface SellableSpec {
|
|
|
107
107
|
* "sign_in"`). Such a line holds one, and an order at most one such line. Not on a plan.
|
|
108
108
|
*/
|
|
109
109
|
onePerPerson?: string;
|
|
110
|
+
/**
|
|
111
|
+
* A paid line moves a record that already exists (stage 31a step 8, ADR 0560), see MovesSpec.
|
|
112
|
+
* A record of such an object is bought once, when it is made: `order.startHeld` makes it in
|
|
113
|
+
* `held` and starts its order in one batch. It is never put on `order.start`. Not with
|
|
114
|
+
* `grants`, `deposit`, `recurring`, `onePerPerson`, `maxPerOrder` or `saleWindow`.
|
|
115
|
+
*/
|
|
116
|
+
moves?: MovesSpec;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* What an order does to the record it was started for (ADR 0560): a drop-in booking held while
|
|
121
|
+
* its order is unpaid. The host makes every move, as the host, in the batch that moves the order.
|
|
122
|
+
*
|
|
123
|
+
* - `held`: the state `order.startHeld` makes the record in (`states.create.in` lets the host,
|
|
124
|
+
* and only the host, create it there). A capacity claimant holds its place in it.
|
|
125
|
+
* - `paid`: the order is paid: the record moves `held` -> `paid`.
|
|
126
|
+
* - `expired`: the order expired or was cancelled unpaid: `held` -> `expired`, a final state.
|
|
127
|
+
* A record that leaves `held` any other way (a class the gym cancels) cancels its unpaid order.
|
|
128
|
+
* - `refund`: states that give the money back. A record whose order is paid entering one of them
|
|
129
|
+
* queues the order's refund for a person with `orders:refund` to approve (never an AI).
|
|
130
|
+
* - `price`: where the price of one is read when the record is made: a number field through up
|
|
131
|
+
* to two relations (`class.classType.dropInPrice`), else the extension's number setting. The
|
|
132
|
+
* host writes it into the read-only `price` field, and the order's line is priced from it.
|
|
133
|
+
* - `title`: the order line's title, a text field through up to two relations (`class.title`).
|
|
134
|
+
* - `order`: a read-only text field the host writes the order's id into.
|
|
135
|
+
* - `guest`: a buyer who is not signed in is matched to no Person before payment: their record is
|
|
136
|
+
* held with its customer field empty (so it is no one's, blocks no one's own, and tells the
|
|
137
|
+
* buyer nothing about who has that address), and is given its Person when the payment is
|
|
138
|
+
* verified, by the rule a guest's order uses. The customer field must not be `required`; the
|
|
139
|
+
* host keeps it set in every state but `held`. Without it, a guest cannot buy the object.
|
|
140
|
+
* - `holdCap`: a number setting of the extension: the percent of the claimed record's places that
|
|
141
|
+
* unpaid guest holds may take at once (at least one). Over it a guest is told to try again soon.
|
|
142
|
+
*/
|
|
143
|
+
export interface MovesSpec {
|
|
144
|
+
held: string;
|
|
145
|
+
paid: string;
|
|
146
|
+
expired: string;
|
|
147
|
+
refund?: readonly string[];
|
|
148
|
+
price?: { field?: string; setting?: string };
|
|
149
|
+
title?: string;
|
|
150
|
+
order?: string;
|
|
151
|
+
guest?: boolean;
|
|
152
|
+
holdCap?: { setting: string };
|
|
110
153
|
}
|
|
111
154
|
|
|
112
155
|
/**
|
|
@@ -141,6 +184,14 @@ export interface RecurringSpec {
|
|
|
141
184
|
* `sellable.recurring`, and its `grants` is what the subscription gives while it runs.
|
|
142
185
|
*/
|
|
143
186
|
grants?: RecurringGrantSpec;
|
|
187
|
+
/**
|
|
188
|
+
* Whether staff may pause a subscription to the plan (stage 32b, decision 10, ADR 0531), and
|
|
189
|
+
* for how long: `minDays` and `maxDays` name number fields of the plan holding the shortest and
|
|
190
|
+
* longest pause the company allows (empty: 1 day, and 366 days, the most the host asks the
|
|
191
|
+
* provider for). Left out, a subscription to the plan is never paused. Only staff pause, with
|
|
192
|
+
* `subscriptions:manage`, as a person; while paused nothing is charged, granted or spent.
|
|
193
|
+
*/
|
|
194
|
+
pause?: { minDays?: string; maxDays?: string };
|
|
144
195
|
}
|
|
145
196
|
|
|
146
197
|
/** Where a field of what a subscription grants gets its value (see RecurringSpec.grants). */
|
|
@@ -256,6 +307,23 @@ export const sellableManifestSchema = z
|
|
|
256
307
|
.strict()
|
|
257
308
|
.optional(),
|
|
258
309
|
onePerPerson: fieldName.optional(),
|
|
310
|
+
moves: z
|
|
311
|
+
.object({
|
|
312
|
+
held: z.string().min(1).max(100),
|
|
313
|
+
paid: z.string().min(1).max(100),
|
|
314
|
+
expired: z.string().min(1).max(100),
|
|
315
|
+
refund: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
316
|
+
price: z
|
|
317
|
+
.object({ field: z.string().max(130).optional(), setting: fieldName.optional() })
|
|
318
|
+
.strict()
|
|
319
|
+
.optional(),
|
|
320
|
+
title: z.string().max(130).optional(),
|
|
321
|
+
order: fieldName.optional(),
|
|
322
|
+
guest: z.boolean().optional(),
|
|
323
|
+
holdCap: z.object({ setting: fieldName }).strict().optional(),
|
|
324
|
+
})
|
|
325
|
+
.strict()
|
|
326
|
+
.optional(),
|
|
259
327
|
tax: z
|
|
260
328
|
.object({
|
|
261
329
|
code: z.string().regex(TAX_CODE_PATTERN, "A product tax code: txcd_ and eight digits"),
|
|
@@ -277,6 +345,10 @@ export const sellableManifestSchema = z
|
|
|
277
345
|
.object({
|
|
278
346
|
interval: z.enum(["week", "month", "year"]),
|
|
279
347
|
trialDays: fieldName.optional(),
|
|
348
|
+
pause: z
|
|
349
|
+
.object({ minDays: fieldName.optional(), maxDays: fieldName.optional() })
|
|
350
|
+
.strict()
|
|
351
|
+
.optional(),
|
|
280
352
|
grants: z
|
|
281
353
|
.object({
|
|
282
354
|
object: z.string().max(40),
|
|
@@ -366,6 +438,12 @@ export function checkObjectSellable(
|
|
|
366
438
|
if (trial !== undefined && !single(trial, new Set(["number"]))) {
|
|
367
439
|
contract(`${path}.recurring.trialDays`, `"${trial}" must be a number field of ${name}`);
|
|
368
440
|
}
|
|
441
|
+
for (const key of ["minDays", "maxDays"] as const) {
|
|
442
|
+
const days = sellable.recurring.pause?.[key];
|
|
443
|
+
if (days !== undefined && !single(days, new Set(["number"]))) {
|
|
444
|
+
contract(`${path}.recurring.pause.${key}`, `"${days}" must be a number field of ${name}`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
369
447
|
if (sellable.onePerPerson !== undefined) {
|
|
370
448
|
contract(
|
|
371
449
|
`${path}.onePerPerson`,
|
|
@@ -414,6 +492,7 @@ export function checkObjectSellable(
|
|
|
414
492
|
}
|
|
415
493
|
}
|
|
416
494
|
if (sellable.grants) checkGrants(m, name, object, sellable.grants, `${path}.grants`, contract);
|
|
495
|
+
if (sellable.moves) checkMoves(m, name, object, sellable.moves, `${path}.moves`, contract);
|
|
417
496
|
const place = sellable.tax?.place;
|
|
418
497
|
if (place) {
|
|
419
498
|
let holder: ObjectManifest | undefined = object;
|
|
@@ -451,6 +530,177 @@ export function checkObjectSellable(
|
|
|
451
530
|
}
|
|
452
531
|
}
|
|
453
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Checks `sellable.moves` (ADR 0560): each of these is a way the order's batch could otherwise fail
|
|
535
|
+
* (a payment the host could not apply), or a record someone could hold with no order.
|
|
536
|
+
*/
|
|
537
|
+
function checkMoves(
|
|
538
|
+
m: ExtensionManifest,
|
|
539
|
+
name: string,
|
|
540
|
+
object: ObjectManifest,
|
|
541
|
+
moves: NonNullable<SellableManifest["moves"]>,
|
|
542
|
+
path: string,
|
|
543
|
+
contract: (path: string, message: string) => void,
|
|
544
|
+
): void {
|
|
545
|
+
const sellable = object.sellable as SellableManifest;
|
|
546
|
+
for (const key of [
|
|
547
|
+
"grants",
|
|
548
|
+
"deposit",
|
|
549
|
+
"recurring",
|
|
550
|
+
"onePerPerson",
|
|
551
|
+
"maxPerOrder",
|
|
552
|
+
"saleWindow",
|
|
553
|
+
] as const) {
|
|
554
|
+
if (sellable[key] !== undefined) {
|
|
555
|
+
contract(
|
|
556
|
+
`objects.${name}.sellable.${key}`,
|
|
557
|
+
`A record bought with moves is one record on one order: it has no ${key}`,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const field = (local: string) =>
|
|
562
|
+
Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
|
|
563
|
+
const price = field(sellable.price);
|
|
564
|
+
if (price && !price.readOnly) {
|
|
565
|
+
contract(
|
|
566
|
+
`objects.${name}.fields.${sellable.price}`,
|
|
567
|
+
`"${sellable.price}" holds what the host priced it at: make it readOnly`,
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
if (moves.order !== undefined) {
|
|
571
|
+
const order = field(moves.order);
|
|
572
|
+
if (order?.type !== "text" || order.many || !order.readOnly) {
|
|
573
|
+
contract(`${path}.order`, `"${moves.order}" must be a readOnly text field of ${name}`);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (moves.price) {
|
|
577
|
+
if (moves.price.field === undefined && moves.price.setting === undefined) {
|
|
578
|
+
contract(`${path}.price`, "price names a field, a setting or both");
|
|
579
|
+
}
|
|
580
|
+
if (moves.price.field !== undefined) {
|
|
581
|
+
const at = resolveFieldPath(m, object, moves.price.field);
|
|
582
|
+
if (!at || at.many || (at.type !== "number" && at.type !== "currency")) {
|
|
583
|
+
contract(
|
|
584
|
+
`${path}.price.field`,
|
|
585
|
+
`"${moves.price.field}" must be a number field of ${name}, or <relation>.<field> through up to two relations, every field on the way declared by this extension`,
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (moves.price.setting !== undefined) {
|
|
590
|
+
const settings = m.settings ?? {};
|
|
591
|
+
const setting = Object.hasOwn(settings, moves.price.setting)
|
|
592
|
+
? settings[moves.price.setting]
|
|
593
|
+
: undefined;
|
|
594
|
+
if (setting?.type !== "number") {
|
|
595
|
+
contract(
|
|
596
|
+
`${path}.price.setting`,
|
|
597
|
+
`"${moves.price.setting}" must be a number setting of ${m.id}`,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (moves.title !== undefined) {
|
|
603
|
+
const at = resolveFieldPath(m, object, moves.title);
|
|
604
|
+
if (!at || at.many || at.type !== "text") {
|
|
605
|
+
contract(
|
|
606
|
+
`${path}.title`,
|
|
607
|
+
`"${moves.title}" must be a text field of ${name}, or through up to two relations`,
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (!object.customer) contract(path, `${name} must declare customer: whose record it is`);
|
|
612
|
+
if (moves.guest && object.customer) {
|
|
613
|
+
const owner = field(object.customer.field);
|
|
614
|
+
if (owner?.required) {
|
|
615
|
+
contract(
|
|
616
|
+
`objects.${name}.fields.${object.customer.field}`,
|
|
617
|
+
`A guest's ${name} is held with no ${object.customer.field} until it is paid: it cannot be required (the host keeps it set outside "${moves.held}")`,
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (moves.holdCap) {
|
|
622
|
+
const settings = m.settings ?? {};
|
|
623
|
+
const setting = Object.hasOwn(settings, moves.holdCap.setting)
|
|
624
|
+
? settings[moves.holdCap.setting]
|
|
625
|
+
: undefined;
|
|
626
|
+
if (setting?.type !== "number") {
|
|
627
|
+
contract(
|
|
628
|
+
`${path}.holdCap.setting`,
|
|
629
|
+
`"${moves.holdCap.setting}" must be a number setting of ${m.id}`,
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
if (!moves.guest) contract(`${path}.holdCap`, "holdCap limits guests' holds: declare guest");
|
|
633
|
+
if (!object.claims) contract(`${path}.holdCap`, `${name} must claim places (claims)`);
|
|
634
|
+
}
|
|
635
|
+
const states = object.states;
|
|
636
|
+
if (!states) {
|
|
637
|
+
contract(path, `${name} must declare states: the order moves it`);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const values = new Set((object.fields[states.field]?.options ?? []).map((o) => o.value));
|
|
641
|
+
const finals = new Set(states.moves.filter((mv) => mv.final).map((mv) => mv.to));
|
|
642
|
+
for (const key of ["held", "paid", "expired"] as const) {
|
|
643
|
+
if (!values.has(moves[key])) {
|
|
644
|
+
contract(`${path}.${key}`, `"${moves[key]}" is not a state of ${name}`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (new Set([moves.held, moves.paid, moves.expired]).size !== 3) {
|
|
648
|
+
contract(path, "held, paid and expired are three different states");
|
|
649
|
+
}
|
|
650
|
+
const creators = states.create?.in?.[moves.held] ?? [];
|
|
651
|
+
if (!creators.includes("host")) {
|
|
652
|
+
contract(
|
|
653
|
+
`${path}.held`,
|
|
654
|
+
`states.create.in must let the host create ${name} in "${moves.held}"`,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
if (creators.some((by) => by !== "host")) {
|
|
658
|
+
contract(
|
|
659
|
+
`${path}.held`,
|
|
660
|
+
`Only the host creates ${name} in "${moves.held}": anyone else would hold it with no order`,
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const hostMove = (to: string) =>
|
|
664
|
+
states.moves.some(
|
|
665
|
+
(mv) => mv.to === to && moveOrigins(mv).includes(moves.held) && mv.by.includes("host"),
|
|
666
|
+
);
|
|
667
|
+
for (const key of ["paid", "expired"] as const) {
|
|
668
|
+
if (!hostMove(moves[key])) {
|
|
669
|
+
contract(
|
|
670
|
+
`${path}.${key}`,
|
|
671
|
+
`${name} needs a move from "${moves.held}" to "${moves[key]}" the host may make`,
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (!finals.has(moves.expired)) {
|
|
676
|
+
contract(`${path}.expired`, `"${moves.expired}" must be a final state of ${name}`);
|
|
677
|
+
}
|
|
678
|
+
for (const mv of states.moves) {
|
|
679
|
+
if (!moveOrigins(mv).includes(moves.held)) continue;
|
|
680
|
+
if (mv.by.some((by) => by !== "host")) {
|
|
681
|
+
contract(
|
|
682
|
+
`${path}.held`,
|
|
683
|
+
`Only the host moves ${name} out of "${moves.held}" (to "${mv.to}"): its order says where it goes`,
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
for (const [i, state] of (moves.refund ?? []).entries()) {
|
|
688
|
+
if (!values.has(state) || state === moves.held || state === moves.expired) {
|
|
689
|
+
contract(
|
|
690
|
+
`${path}.refund.${i}`,
|
|
691
|
+
`"${state}" must be a state of ${name} other than held and expired`,
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const allowance = object.allowance;
|
|
696
|
+
if (allowance && "spends" in allowance && !allowance.spends.waived) {
|
|
697
|
+
contract(
|
|
698
|
+
path,
|
|
699
|
+
`${name} spends uses: declare allowance.spends.waived, which the host sets on a record its order pays for`,
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
454
704
|
function checkGrants(
|
|
455
705
|
m: ExtensionManifest,
|
|
456
706
|
name: string,
|
|
@@ -41,18 +41,42 @@ export interface StateMove {
|
|
|
41
41
|
* Tools of this extension that may also make the move for whoever called them (stage 32b,
|
|
42
42
|
* ADR 0513): a move by `["host"]` with `tools: ["voidPass"]` is made by the host and by that
|
|
43
43
|
* tool, and by no other staff write (not `record.update`, not the assistant, not an automation).
|
|
44
|
-
* Each tool must be `humanOnly
|
|
45
|
-
*
|
|
44
|
+
* Each tool must be `humanOnly`, or `personApproves` (ADR 0552: anyone else's call waits for a
|
|
45
|
+
* person's approval), and declare a `permission`, so the move is a person's act with that
|
|
46
|
+
* permission.
|
|
46
47
|
*/
|
|
47
48
|
tools?: readonly string[];
|
|
48
49
|
/**
|
|
49
50
|
* Its window binds staff too (ADR 0507), every staff caller, a person included: a cancel that
|
|
50
51
|
* gives a use back is in time for everyone. The host is not bound. A person who must make the
|
|
51
|
-
* move outside it does so through another move only a person's tool makes (`tools`).
|
|
52
|
+
* move outside it does so through another move only a person's tool makes (`tools`). A move
|
|
53
|
+
* staff alone make may have a window with it (ADR 0551): a coach ticks a name from an hour
|
|
54
|
+
* before the class, not days ahead.
|
|
52
55
|
*/
|
|
53
56
|
bindsStaff?: boolean;
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
/**
|
|
60
|
+
* A move the host makes by itself once a moment has passed (ADR 0550): a booking still `booked`
|
|
61
|
+
* 30 minutes after its class ends becomes a `no_show`, if anyone on the class was ticked. The
|
|
62
|
+
* runner's minute cron finds the records due and moves each as the host, from where it was or not
|
|
63
|
+
* at all. Each needs a declared `host` move from each of `from` to `to`.
|
|
64
|
+
*/
|
|
65
|
+
export interface TimedMove {
|
|
66
|
+
/** The state, or states, the record moves from. */
|
|
67
|
+
from: string | readonly string[];
|
|
68
|
+
to: string;
|
|
69
|
+
/** A datetime field of the record, or `<relation>.<field>` one relation away (`class.endsAt`). */
|
|
70
|
+
at: string;
|
|
71
|
+
/** Minutes after `at` the move is due (0 to 10,080). */
|
|
72
|
+
minutesAfter?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Only while another live record of this object pointing at the same record (through `at`'s
|
|
75
|
+
* relation) is in one of these states: a class whose attendance was taken has someone ticked.
|
|
76
|
+
*/
|
|
77
|
+
ifAnyIn?: readonly string[];
|
|
78
|
+
}
|
|
79
|
+
|
|
56
80
|
/**
|
|
57
81
|
* A number a window is worked out from (ADR 0505): a number; a number field named as a window's
|
|
58
82
|
* `at` is; or `{ field?, setting? }`, the field's value and, when it is empty, this extension's
|
|
@@ -141,6 +165,8 @@ export interface StatesSpec {
|
|
|
141
165
|
when: Readonly<Record<string, string>>;
|
|
142
166
|
from: readonly string[];
|
|
143
167
|
};
|
|
168
|
+
/** Moves the host makes once a moment has passed (ADR 0550), at most four. */
|
|
169
|
+
after?: readonly TimedMove[];
|
|
144
170
|
}
|
|
145
171
|
|
|
146
172
|
const fieldName = z.string().max(40);
|
|
@@ -155,7 +181,7 @@ const windowNumber = (number: z.ZodNumber) =>
|
|
|
155
181
|
.strict()
|
|
156
182
|
.refine((n) => n.field !== undefined || n.setting !== undefined, "Name a field or a setting"),
|
|
157
183
|
]);
|
|
158
|
-
const
|
|
184
|
+
export const windowBoundSchema = z.union([
|
|
159
185
|
fieldPath,
|
|
160
186
|
z
|
|
161
187
|
.object({
|
|
@@ -168,7 +194,7 @@ const windowBound = z.union([
|
|
|
168
194
|
]);
|
|
169
195
|
const staffOnlyPaths = z.union([fieldPath, z.array(fieldPath).min(1).max(4)]);
|
|
170
196
|
const moveWindow = z
|
|
171
|
-
.object({ from:
|
|
197
|
+
.object({ from: windowBoundSchema.optional(), until: windowBoundSchema.optional() })
|
|
172
198
|
.strict()
|
|
173
199
|
.refine((w) => w.from !== undefined || w.until !== undefined, "A window needs from or until");
|
|
174
200
|
|
|
@@ -216,6 +242,21 @@ export const statesManifestSchema = z.object({
|
|
|
216
242
|
})
|
|
217
243
|
.strict()
|
|
218
244
|
.optional(),
|
|
245
|
+
after: z
|
|
246
|
+
.array(
|
|
247
|
+
z
|
|
248
|
+
.object({
|
|
249
|
+
from: z.union([stateValue, z.array(stateValue).min(1).max(20)]),
|
|
250
|
+
to: stateValue,
|
|
251
|
+
at: fieldPath,
|
|
252
|
+
minutesAfter: z.number().int().min(0).max(10_080).optional(),
|
|
253
|
+
ifAnyIn: z.array(stateValue).min(1).max(20).optional(),
|
|
254
|
+
})
|
|
255
|
+
.strict(),
|
|
256
|
+
)
|
|
257
|
+
.min(1)
|
|
258
|
+
.max(4)
|
|
259
|
+
.optional(),
|
|
219
260
|
});
|
|
220
261
|
export type StatesManifest = z.infer<typeof statesManifestSchema>;
|
|
221
262
|
|
|
@@ -317,48 +358,18 @@ export function checkObjectStates(
|
|
|
317
358
|
});
|
|
318
359
|
|
|
319
360
|
// Windows, staff-only rules and requests (ADR 0503; two relations and settings, ADR 0505).
|
|
320
|
-
const checkPath = (
|
|
321
|
-
const field = resolveFieldPath(m, object, at);
|
|
322
|
-
// A staff-only rule may read a formula: the host computes it in the view (a boolean one).
|
|
323
|
-
const formulaOk = type === "boolean" && field?.type === "formula";
|
|
324
|
-
if ((field?.type !== type && !formulaOk) || field?.many) {
|
|
325
|
-
contract(
|
|
326
|
-
path,
|
|
327
|
-
`"${at}" must be a ${type} field of ${name}, or <relation>.<field> through up to two relations (one record each), every field on the way declared by this extension`,
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
const checkNumber = (value: WindowNumber | undefined, path: string) => {
|
|
332
|
-
if (typeof value === "string") checkPath(value, path, "number");
|
|
333
|
-
else if (typeof value === "object") {
|
|
334
|
-
if (value.field !== undefined) checkPath(value.field, `${path}.field`, "number");
|
|
335
|
-
if (value.setting !== undefined) {
|
|
336
|
-
const settings = m.settings ?? {};
|
|
337
|
-
const setting = Object.hasOwn(settings, value.setting)
|
|
338
|
-
? settings[value.setting]
|
|
339
|
-
: undefined;
|
|
340
|
-
if (setting?.type !== "number") {
|
|
341
|
-
contract(`${path}.setting`, `"${value.setting}" must be a number setting of ${m.id}`);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
const checkWindow = (window: MoveWindow | undefined, path: string) => {
|
|
347
|
-
for (const end of ["from", "until"] as const) {
|
|
348
|
-
const bound = window?.[end];
|
|
349
|
-
if (bound === undefined) continue;
|
|
350
|
-
const b = typeof bound === "string" ? { at: bound } : bound;
|
|
351
|
-
checkPath(b.at, `${path}.${end}.at`, "datetime");
|
|
352
|
-
for (const key of ["daysBefore", "minutesBefore"] as const) {
|
|
353
|
-
checkNumber(b[key], `${path}.${end}.${key}`);
|
|
354
|
-
}
|
|
355
|
-
if (b.zone !== undefined) checkPath(b.zone, `${path}.${end}.zone`, "timezone");
|
|
356
|
-
}
|
|
357
|
-
};
|
|
361
|
+
const { checkPath, checkWindow } = windowChecks(m, object, name, contract);
|
|
358
362
|
states.moves.forEach((move, i) => {
|
|
359
363
|
const mp = `${sp}.moves.${i}`;
|
|
360
|
-
|
|
361
|
-
|
|
364
|
+
// A window binds customers, or staff too with bindsStaff (ADR 0551); staffOnly customers.
|
|
365
|
+
if (move.staffOnly && !move.by.includes("customer")) {
|
|
366
|
+
contract(mp, "staffOnly binds customers: the move must list customer in by");
|
|
367
|
+
}
|
|
368
|
+
if (move.window && !move.by.includes("customer") && !move.bindsStaff) {
|
|
369
|
+
contract(
|
|
370
|
+
mp,
|
|
371
|
+
"A window binds customers: the move must list customer in by, or bind staff (bindsStaff)",
|
|
372
|
+
);
|
|
362
373
|
}
|
|
363
374
|
checkWindow(move.window, `${mp}.window`);
|
|
364
375
|
for (const p of staffOnlyPathsOf(move.staffOnly)) checkPath(p, `${mp}.staffOnly`, "boolean");
|
|
@@ -367,15 +378,15 @@ export function checkObjectStates(
|
|
|
367
378
|
const spec = m.tools?.[tool];
|
|
368
379
|
if (!spec) {
|
|
369
380
|
contract(`${mp}.tools`, `"${tool}" is not a tool of this extension`);
|
|
370
|
-
} else if (!spec.humanOnly || !spec.permission) {
|
|
381
|
+
} else if ((!spec.humanOnly && !spec.personApproves) || !spec.permission) {
|
|
371
382
|
contract(
|
|
372
383
|
`${mp}.tools`,
|
|
373
|
-
`"${tool}" must be humanOnly and declare a permission: the move is a person's act with it`,
|
|
384
|
+
`"${tool}" must be humanOnly or personApproves and declare a permission: the move is a person's act with it`,
|
|
374
385
|
);
|
|
375
386
|
}
|
|
376
387
|
}
|
|
377
|
-
if (move.bindsStaff && (!move.window || !move.by.includes("staff"))) {
|
|
378
|
-
contract(`${mp}.bindsStaff`, "bindsStaff needs a window and staff in by");
|
|
388
|
+
if (move.bindsStaff && (!move.window || (!move.by.includes("staff") && !move.tools))) {
|
|
389
|
+
contract(`${mp}.bindsStaff`, "bindsStaff needs a window, and staff in by or named tools");
|
|
379
390
|
}
|
|
380
391
|
if (move.tools && move.by.includes("staff")) {
|
|
381
392
|
contract(
|
|
@@ -413,6 +424,19 @@ export function checkObjectStates(
|
|
|
413
424
|
`"${f.relation}" must be a relation (one record) of ${name} to another of this extension's objects that declares states`,
|
|
414
425
|
);
|
|
415
426
|
} else {
|
|
427
|
+
// A parent whose places other records draw on as a pool: its counter counts claims that
|
|
428
|
+
// are not its own, which the cascade's check at commit cannot read (ADR 0550).
|
|
429
|
+
const pooled = Object.values(m.objects).some((other) => {
|
|
430
|
+
const poolField = other.capacity?.pool;
|
|
431
|
+
const relTo = poolField ? other.fields[poolField]?.to : undefined;
|
|
432
|
+
return relTo === rel?.to || relTo === rel?.to?.slice(m.id.length + 1);
|
|
433
|
+
});
|
|
434
|
+
if (pooled) {
|
|
435
|
+
contract(
|
|
436
|
+
`${fp}.relation`,
|
|
437
|
+
`${rel?.to ?? f.relation} is a pool other records draw places from: a cascade cannot follow it`,
|
|
438
|
+
);
|
|
439
|
+
}
|
|
416
440
|
const parentStates = new Set(
|
|
417
441
|
(target.fields[target.states.field]?.options ?? []).map((o) => o.value),
|
|
418
442
|
);
|
|
@@ -435,6 +459,43 @@ export function checkObjectStates(
|
|
|
435
459
|
}
|
|
436
460
|
}
|
|
437
461
|
}
|
|
462
|
+
// Timed moves (ADR 0550): a declared host move each, and a moment the sweep reads in SQL.
|
|
463
|
+
(states.after ?? []).forEach((rule, i) => {
|
|
464
|
+
const tp = `${sp}.after.${i}`;
|
|
465
|
+
if (!isState(rule.to)) contract(`${tp}.to`, `"${rule.to}" is not an option of ${states.field}`);
|
|
466
|
+
for (const from of moveOrigins(rule)) {
|
|
467
|
+
if (!isState(from)) {
|
|
468
|
+
contract(`${tp}.from`, `"${from}" is not an option of ${states.field}`);
|
|
469
|
+
} else if (
|
|
470
|
+
!states.moves.some(
|
|
471
|
+
(move) =>
|
|
472
|
+
move.to === rule.to && move.by.includes("host") && moveOrigins(move).includes(from),
|
|
473
|
+
)
|
|
474
|
+
) {
|
|
475
|
+
contract(`${tp}.from`, `${name} needs a host move from "${from}" to "${rule.to}"`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const parts = rule.at.split(".");
|
|
479
|
+
const at = parts.length <= 2 ? resolveFieldPath(m, object, rule.at) : undefined;
|
|
480
|
+
const via = parts.length === 2 ? fieldOf(parts[0] as string) : undefined;
|
|
481
|
+
const ownTarget = via?.type === "relation" && !via.many && via.to?.startsWith(`${m.id}.`);
|
|
482
|
+
if (at?.type !== "datetime" || at.many || (parts.length === 2 && !ownTarget)) {
|
|
483
|
+
contract(
|
|
484
|
+
`${tp}.at`,
|
|
485
|
+
`"${rule.at}" must be a datetime field of ${name}, or <relation>.<field> on another of this extension's objects`,
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
if (rule.ifAnyIn) {
|
|
489
|
+
if (parts.length !== 2) {
|
|
490
|
+
contract(`${tp}.ifAnyIn`, "ifAnyIn needs at one relation away: the records it compares");
|
|
491
|
+
}
|
|
492
|
+
for (const state of rule.ifAnyIn) {
|
|
493
|
+
if (!isState(state)) {
|
|
494
|
+
contract(`${tp}.ifAnyIn`, `"${state}" is not an option of ${states.field}`);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
});
|
|
438
499
|
for (const [request, targets] of Object.entries(states.requests ?? {})) {
|
|
439
500
|
const rp = `${sp}.requests.${request}`;
|
|
440
501
|
if (isState(request)) contract(rp, `"${request}" is a state; a request needs its own name`);
|
|
@@ -448,6 +509,59 @@ export function checkObjectStates(
|
|
|
448
509
|
}
|
|
449
510
|
}
|
|
450
511
|
|
|
512
|
+
/**
|
|
513
|
+
* The checks of window paths and numbers (ADRs 0503 and 0505): for a `states` declaration, and
|
|
514
|
+
* for any other declaration that names a moment the same way (a waitlist's cut-off, ADR 0520).
|
|
515
|
+
*/
|
|
516
|
+
export function windowChecks(
|
|
517
|
+
m: ExtensionManifest,
|
|
518
|
+
object: ObjectManifest,
|
|
519
|
+
name: string,
|
|
520
|
+
contract: (path: string, message: string) => void,
|
|
521
|
+
) {
|
|
522
|
+
const checkPath = (at: string, path: string, type: string) => {
|
|
523
|
+
const field = resolveFieldPath(m, object, at);
|
|
524
|
+
// A staff-only rule may read a formula: the host computes it in the view (a boolean one).
|
|
525
|
+
const formulaOk = type === "boolean" && field?.type === "formula";
|
|
526
|
+
if ((field?.type !== type && !formulaOk) || field?.many) {
|
|
527
|
+
contract(
|
|
528
|
+
path,
|
|
529
|
+
`"${at}" must be a ${type} field of ${name}, or <relation>.<field> through up to two relations (one record each), every field on the way declared by this extension`,
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
const checkNumber = (value: WindowNumber | undefined, path: string) => {
|
|
534
|
+
if (typeof value === "string") checkPath(value, path, "number");
|
|
535
|
+
else if (typeof value === "object") {
|
|
536
|
+
if (value.field !== undefined) checkPath(value.field, `${path}.field`, "number");
|
|
537
|
+
if (value.setting !== undefined) {
|
|
538
|
+
const settings = m.settings ?? {};
|
|
539
|
+
const setting = Object.hasOwn(settings, value.setting)
|
|
540
|
+
? settings[value.setting]
|
|
541
|
+
: undefined;
|
|
542
|
+
if (setting?.type !== "number") {
|
|
543
|
+
contract(`${path}.setting`, `"${value.setting}" must be a number setting of ${m.id}`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
const checkBound = (bound: string | WindowBound, path: string) => {
|
|
549
|
+
const b = typeof bound === "string" ? { at: bound } : bound;
|
|
550
|
+
checkPath(b.at, `${path}.at`, "datetime");
|
|
551
|
+
for (const key of ["daysBefore", "minutesBefore"] as const) {
|
|
552
|
+
checkNumber(b[key], `${path}.${key}`);
|
|
553
|
+
}
|
|
554
|
+
if (b.zone !== undefined) checkPath(b.zone, `${path}.zone`, "timezone");
|
|
555
|
+
};
|
|
556
|
+
const checkWindow = (window: MoveWindow | undefined, path: string) => {
|
|
557
|
+
for (const end of ["from", "until"] as const) {
|
|
558
|
+
const bound = window?.[end];
|
|
559
|
+
if (bound !== undefined) checkBound(bound, `${path}.${end}`);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
return { checkPath, checkNumber, checkBound, checkWindow };
|
|
563
|
+
}
|
|
564
|
+
|
|
451
565
|
/**
|
|
452
566
|
* The field a path names (ADR 0503; two relations from ADR 0505): `field` on the object, or
|
|
453
567
|
* `relation.field` / `relation.relation.field` through relations of one record. Every field on
|
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
THEME,
|
|
14
14
|
readCoursesFolder,
|
|
15
15
|
withMedia
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-P6UWZ6QQ.js";
|
|
17
17
|
import {
|
|
18
18
|
confirmer,
|
|
19
19
|
sessionHost,
|
|
20
20
|
signInForRun
|
|
21
21
|
} from "./chunk-E4WCYTCT.js";
|
|
22
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-LO6WGU5Y.js";
|
|
23
23
|
import "./chunk-5KSXSK7Y.js";
|
|
24
24
|
|
|
25
25
|
// src/courses-import/run.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
parseCsv
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-P6UWZ6QQ.js";
|
|
5
5
|
import {
|
|
6
6
|
sessionHost,
|
|
7
7
|
signInForRun
|
|
8
8
|
} from "./chunk-E4WCYTCT.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-LO6WGU5Y.js";
|
|
10
10
|
import "./chunk-5KSXSK7Y.js";
|
|
11
11
|
|
|
12
12
|
// src/offers-import/run.ts
|