@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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
-- Migration 0690: drop-ins (stage 31a step 8, ADR 0560): a refund the host owes, and a cap on the
|
|
2
|
+
-- unpaid places a class may have held for it.
|
|
3
|
+
--
|
|
4
|
+
-- 1. A refund owed. A record bought through `sellable.moves` (a drop-in booking) whose order was
|
|
5
|
+
-- paid, entering one of its refund states (an in-time cancel, a class the gym cancels), or paid
|
|
6
|
+
-- for after its place went back (a late payment), owes the buyer their money. The move's own
|
|
7
|
+
-- batch writes one row here: the record and its order. Nothing is asked of the payment provider
|
|
8
|
+
-- in that batch: the minute cron asks the payments gatekeeper afterwards (`order.refundDue`), as
|
|
9
|
+
-- the outbound action `payments.refund`, always reviewed and approved only by a person with
|
|
10
|
+
-- `orders:refund`.
|
|
11
|
+
--
|
|
12
|
+
-- One row per order for a refund of the whole order (a cancel), and one per payment for a payment
|
|
13
|
+
-- owed back on its own (`payment_ref` and `amount`: a second payment on a paid order, or one that
|
|
14
|
+
-- arrived after the order closed), so a duplicate payment is refunded alone and the first never.
|
|
15
|
+
-- `state`: `due` (written by the move); `asking` (the cron claimed it, in its
|
|
16
|
+
-- own statement, before it calls the gatekeeper); `asked` (refunds wait in Approvals; their ids
|
|
17
|
+
-- are `rfd_<this row's id>_<attempt>_<n>`, the provider's idempotency key); `done` (the order is
|
|
18
|
+
-- refunded); `lapsed` (every approval asked for was rejected or expired: staff are told once and
|
|
19
|
+
-- re-ask from the order); `skipped` (nothing could be asked, or the cron could not ask: `note`
|
|
20
|
+
-- says why, and staff were told).
|
|
21
|
+
CREATE TABLE core_sellable_refund_due (
|
|
22
|
+
id TEXT PRIMARY KEY,
|
|
23
|
+
order_id TEXT NOT NULL REFERENCES core_order (id) ON DELETE CASCADE,
|
|
24
|
+
-- A payment owed back on its own: its provider reference and amount (minor units). Null: the
|
|
25
|
+
-- whole order.
|
|
26
|
+
payment_ref TEXT,
|
|
27
|
+
amount INTEGER,
|
|
28
|
+
object_type TEXT NOT NULL,
|
|
29
|
+
record_id TEXT NOT NULL,
|
|
30
|
+
-- The state the record entered (or `late`, a payment after its place went back), and why in
|
|
31
|
+
-- staff's words.
|
|
32
|
+
entered TEXT NOT NULL,
|
|
33
|
+
reason TEXT NOT NULL,
|
|
34
|
+
state TEXT NOT NULL DEFAULT 'due'
|
|
35
|
+
CHECK (state IN ('due', 'asking', 'asked', 'done', 'lapsed', 'skipped')),
|
|
36
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
37
|
+
note TEXT,
|
|
38
|
+
created_at TEXT NOT NULL,
|
|
39
|
+
updated_at TEXT NOT NULL
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
CREATE UNIQUE INDEX core_sellable_refund_due_uq
|
|
43
|
+
ON core_sellable_refund_due (order_id, coalesce(payment_ref, ''));
|
|
44
|
+
|
|
45
|
+
-- The cron's reads: what is due, being asked, or waiting for a person, oldest first.
|
|
46
|
+
CREATE INDEX core_sellable_refund_due_state_idx ON core_sellable_refund_due (state, created_at);
|
|
47
|
+
|
|
48
|
+
-- 2. A cap on unpaid guest holds. A guest's drop-in holds a place while its order is unpaid; a class
|
|
49
|
+
-- may carry at most so many such holds at once, worked out by the host from the class's places and
|
|
50
|
+
-- the extension's setting. The trigger counts every held claim on the record but the waiting
|
|
51
|
+
-- list's; the host passes `expected` as the cap plus the signed-in members' unpaid holds it read,
|
|
52
|
+
-- so members' own drop-ins never turn visitors away. Kind 'held_cap' counts the held
|
|
53
|
+
-- claims on the record after the new one; more than `expected` fails the batch
|
|
54
|
+
-- (`core_holds_capped`). core_write_guard stores nothing, so it is made again with the new kind,
|
|
55
|
+
-- as migrations 0560, 0610 and 0670 did.
|
|
56
|
+
DROP TRIGGER core_write_guard_check;
|
|
57
|
+
DROP TABLE core_write_guard;
|
|
58
|
+
|
|
59
|
+
CREATE TABLE core_write_guard (
|
|
60
|
+
kind TEXT NOT NULL
|
|
61
|
+
CHECK (kind IN ('claimed', 'claimant', 'series', 'full', 'unmoved', 'held_cap')),
|
|
62
|
+
object_type TEXT NOT NULL,
|
|
63
|
+
record_id TEXT NOT NULL,
|
|
64
|
+
expected INTEGER NOT NULL
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
CREATE TRIGGER core_write_guard_check
|
|
68
|
+
BEFORE INSERT ON core_write_guard
|
|
69
|
+
BEGIN
|
|
70
|
+
SELECT CASE
|
|
71
|
+
WHEN NEW.kind = 'claimed' AND coalesce((SELECT held + taken FROM core_capacity
|
|
72
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
73
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
74
|
+
WHEN NEW.kind = 'series' AND coalesce((SELECT version FROM core_recurrence_series
|
|
75
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
76
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
77
|
+
WHEN NEW.kind = 'claimant' AND (SELECT count(*) FROM core_capacity_claim
|
|
78
|
+
WHERE for_type = NEW.object_type AND for_id = NEW.record_id
|
|
79
|
+
AND state IN ('held', 'confirmed')) != NEW.expected
|
|
80
|
+
THEN RAISE(ABORT, 'core_claim_live')
|
|
81
|
+
WHEN NEW.kind = 'full' AND NOT EXISTS (SELECT 1 FROM core_capacity
|
|
82
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id
|
|
83
|
+
AND places IS NOT NULL AND held + taken >= places)
|
|
84
|
+
THEN RAISE(ABORT, 'core_waitlist_not_full')
|
|
85
|
+
WHEN NEW.kind = 'unmoved' AND (SELECT count(*) FROM core_transition_history
|
|
86
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id) != NEW.expected
|
|
87
|
+
THEN RAISE(ABORT, 'core_moved_meanwhile')
|
|
88
|
+
WHEN NEW.kind = 'held_cap' AND (SELECT count(*) FROM core_capacity_claim
|
|
89
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id
|
|
90
|
+
AND state = 'held' AND for_type != 'waitlist') > NEW.expected
|
|
91
|
+
THEN RAISE(ABORT, 'core_holds_capped')
|
|
92
|
+
ELSE RAISE(IGNORE)
|
|
93
|
+
END;
|
|
94
|
+
END;
|
|
95
|
+
|
|
96
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
97
|
+
UPDATE core_meta SET value = '690'
|
|
98
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 690;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// is packages/core/src/capacity/.
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
7
|
+
import { moveOrigins, type WindowBound, windowBoundSchema, windowChecks } from "./states.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* What customers and the public are told about a record's places (staff always see the real
|
|
@@ -128,13 +129,56 @@ export interface ClaimsSpec {
|
|
|
128
129
|
on: string;
|
|
129
130
|
held?: readonly string[];
|
|
130
131
|
confirmed?: readonly string[];
|
|
132
|
+
waitlist?: WaitlistSpec;
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
/**
|
|
136
|
+
* A waitlist on the claimed record's places (stage 31, ADR 0520). A record in `state` waits: it
|
|
137
|
+
* holds no place and spends nothing. It may be made only while the record it claims on is full
|
|
138
|
+
* and before `until`. Until then, a place given back while anyone waits is handed to the waitlist
|
|
139
|
+
* in the same statements that give it back, as a hold of its own that nobody booking directly
|
|
140
|
+
* can take. The host then promotes the first waiter (by when the record was made) from a current
|
|
141
|
+
* read: the move from `state` into `promote` takes the waitlist's hold, and whatever that move
|
|
142
|
+
* spends is spent then. A waiter who cannot be moved in (their spend is refused) is passed over
|
|
143
|
+
* and stays waiting; a hold nobody can take is given back to everyone. From `until`, nobody is
|
|
144
|
+
* promoted and a place given back goes to whoever claims first.
|
|
145
|
+
*
|
|
146
|
+
* - `state` is a state of the object that neither holds nor takes a place, and is not final.
|
|
147
|
+
* - `promote` is one of `confirmed`; a move from `state` to it must be declared for the host.
|
|
148
|
+
* Declared for a customer too (with a window), it lets a waiter take a free place themselves:
|
|
149
|
+
* only the host's promotion takes a place the waitlist holds, so nobody jumps the queue.
|
|
150
|
+
* - `until` is a moment, named as a window's end is (`{ at: "class.startsAt", minutesBefore:
|
|
151
|
+
* { field: "class.classType.promotionMinutes", setting: "promotionMinutes" } }`).
|
|
152
|
+
* - `promotedAt`, `passedOverAt` (read-only datetimes) and `passedOverReason` (read-only text)
|
|
153
|
+
* are what the host writes when it promotes a waiter or passes one over, for messages.
|
|
154
|
+
* - The claimed object has no pool.
|
|
155
|
+
*/
|
|
156
|
+
export interface WaitlistSpec {
|
|
157
|
+
state: string;
|
|
158
|
+
promote: string;
|
|
159
|
+
until: string | WindowBound;
|
|
160
|
+
promotedAt?: string;
|
|
161
|
+
passedOverAt?: string;
|
|
162
|
+
passedOverReason?: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const waitlistManifestSchema = z
|
|
166
|
+
.object({
|
|
167
|
+
state: z.string().min(1).max(100),
|
|
168
|
+
promote: z.string().min(1).max(100),
|
|
169
|
+
until: windowBoundSchema,
|
|
170
|
+
promotedAt: fieldName.optional(),
|
|
171
|
+
passedOverAt: fieldName.optional(),
|
|
172
|
+
passedOverReason: fieldName.optional(),
|
|
173
|
+
})
|
|
174
|
+
.strict();
|
|
175
|
+
|
|
133
176
|
export const claimsManifestSchema = z
|
|
134
177
|
.object({
|
|
135
178
|
on: fieldName,
|
|
136
179
|
held: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
137
180
|
confirmed: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
181
|
+
waitlist: waitlistManifestSchema.optional(),
|
|
138
182
|
})
|
|
139
183
|
.strict();
|
|
140
184
|
export type ClaimsManifest = z.infer<typeof claimsManifestSchema>;
|
|
@@ -198,4 +242,62 @@ export function checkObjectClaims(
|
|
|
198
242
|
);
|
|
199
243
|
}
|
|
200
244
|
});
|
|
245
|
+
const waitlist = claims.waitlist;
|
|
246
|
+
if (!waitlist) return;
|
|
247
|
+
// A waitlist (ADR 0520).
|
|
248
|
+
const wp = `${path}.waitlist`;
|
|
249
|
+
if (!values.has(waitlist.state)) {
|
|
250
|
+
contract(`${wp}.state`, `"${waitlist.state}" is not a state of ${name}`);
|
|
251
|
+
} else if (held.includes(waitlist.state) || confirmed.includes(waitlist.state)) {
|
|
252
|
+
contract(`${wp}.state`, `"${waitlist.state}" waits: it can neither hold nor take a place`);
|
|
253
|
+
} else if (states.moves.some((move) => move.final && move.to === waitlist.state)) {
|
|
254
|
+
contract(`${wp}.state`, `"${waitlist.state}" is final: nobody waits in it`);
|
|
255
|
+
} else if (
|
|
256
|
+
states.initial !== waitlist.state &&
|
|
257
|
+
!Object.hasOwn(states.create?.in ?? {}, waitlist.state)
|
|
258
|
+
) {
|
|
259
|
+
contract(
|
|
260
|
+
`${wp}.state`,
|
|
261
|
+
`"${waitlist.state}" must be a state ${name} may be created in (states.create.in): a waiter joins by being made waiting`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (!confirmed.includes(waitlist.promote)) {
|
|
265
|
+
contract(`${wp}.promote`, `"${waitlist.promote}" must be one of claims.confirmed`);
|
|
266
|
+
}
|
|
267
|
+
const promotions = states.moves.filter(
|
|
268
|
+
(move) => move.to === waitlist.promote && moveOrigins(move).includes(waitlist.state),
|
|
269
|
+
);
|
|
270
|
+
if (!promotions.some((move) => move.by.includes("host"))) {
|
|
271
|
+
contract(
|
|
272
|
+
`${wp}.promote`,
|
|
273
|
+
`Declare a move from "${waitlist.state}" to "${waitlist.promote}" by the host: promotion is the host's`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
// A customer may move their own waiting record in, but only onto a free place: the host's
|
|
277
|
+
// promotion alone takes a place the waitlist holds, so nobody moves themselves ahead of it.
|
|
278
|
+
// Their move needs the create's window, so they cannot claim a place booking would refuse.
|
|
279
|
+
promotions.forEach((move) => {
|
|
280
|
+
if (move.by.includes("customer") && !move.window) {
|
|
281
|
+
contract(
|
|
282
|
+
`${wp}.promote`,
|
|
283
|
+
`A customer's move from "${waitlist.state}" to "${waitlist.promote}" needs a window (the create's): it books them`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
windowChecks(m, object, name, contract).checkBound(waitlist.until, `${wp}.until`);
|
|
288
|
+
for (const [key, type] of [
|
|
289
|
+
["promotedAt", "datetime"],
|
|
290
|
+
["passedOverAt", "datetime"],
|
|
291
|
+
["passedOverReason", "text"],
|
|
292
|
+
] as const) {
|
|
293
|
+
const local = waitlist[key];
|
|
294
|
+
if (local === undefined) continue;
|
|
295
|
+
const field = Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
|
|
296
|
+
if (field?.type !== type || field.many || !field.readOnly) {
|
|
297
|
+
contract(`${wp}.${key}`, `"${local}" must be a read-only ${type} field of ${name}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (targetObject?.capacity?.pool !== undefined) {
|
|
301
|
+
contract(`${wp}`, `A waitlist is on places with no pool; ${target} has one`);
|
|
302
|
+
}
|
|
201
303
|
}
|
|
@@ -608,6 +608,13 @@ export interface ToolSpec<In extends z.ZodType = z.ZodType, Out extends z.ZodTyp
|
|
|
608
608
|
* any extension may declare it.
|
|
609
609
|
*/
|
|
610
610
|
humanOnly?: boolean;
|
|
611
|
+
/**
|
|
612
|
+
* A person approves it (ADR 0552): a person on the staff calls it as any tool, and anyone else's
|
|
613
|
+
* call (the assistant, an MCP client, an automation) always waits in the approval queue for a
|
|
614
|
+
* person, whatever the approval policy or preset says, and runs when a person approves it. For
|
|
615
|
+
* what an AI may propose but a person decides (cancelling a class). Staff only, and not a read.
|
|
616
|
+
*/
|
|
617
|
+
personApproves?: boolean;
|
|
611
618
|
handler(input: z.output<In>, ctx: ExtensionContext): Promise<z.input<Out>> | z.input<Out>;
|
|
612
619
|
}
|
|
613
620
|
|
|
@@ -627,6 +634,15 @@ export interface RoleSpec {
|
|
|
627
634
|
permissions: readonly string[];
|
|
628
635
|
/** Objects of this extension (`<id>.<object>`) whose records the role may read. */
|
|
629
636
|
read: readonly string[];
|
|
637
|
+
/**
|
|
638
|
+
* Objects whose records the role reaches only when a datetime on them falls on the
|
|
639
|
+
* day it is on (ADR 0553), by object: the moment, and optionally its end and zone, read through
|
|
640
|
+
* one relation at most: `{ "bookings.class": { at: "startsAt", until: "endsAt", zone:
|
|
641
|
+
* "timezone" } }`. A record is today's when its start falls on today's date in its zone (the
|
|
642
|
+
* organisation's when empty), or it has started and not yet ended. The host holds it on every
|
|
643
|
+
* call the account makes and every call of a tool run it started. Other staff are not limited.
|
|
644
|
+
*/
|
|
645
|
+
today?: Readonly<Record<string, string | { at: string; until?: string; zone?: string }>>;
|
|
630
646
|
}
|
|
631
647
|
|
|
632
648
|
/**
|
|
@@ -760,6 +776,15 @@ export interface CustomerSpec {
|
|
|
760
776
|
* any tool.
|
|
761
777
|
*/
|
|
762
778
|
createOnly?: readonly string[];
|
|
779
|
+
/**
|
|
780
|
+
* The family link (ADR 0540): a signed-in guardian also reads their live dependants' records of
|
|
781
|
+
* this object (a child's bookings), with the same `read` fields. With `write: true` they also
|
|
782
|
+
* make records for a dependant (`my.create`'s `forPersonId`) and change the dependant's, with
|
|
783
|
+
* the same `write` fields. `madeBy` names a relation to one person the host sets, on every
|
|
784
|
+
* record a customer makes, to the Person who made it. Staff link guardians to dependants; the
|
|
785
|
+
* seam checks the link in every read and write. A reviewed change, as `customer` is.
|
|
786
|
+
*/
|
|
787
|
+
guardians?: { write?: boolean; madeBy?: string };
|
|
763
788
|
}
|
|
764
789
|
|
|
765
790
|
/** A tool shown as a button on a record page. */
|
|
@@ -34,7 +34,7 @@ import { checkFormula, type FormulaFieldRef } from "./formula/compile.ts";
|
|
|
34
34
|
import { checkObjectRecurring, recurringManifestSchema } from "./recurring.ts";
|
|
35
35
|
import { renamedMessage } from "./renamed.ts";
|
|
36
36
|
import { checkObjectSellable, sellableManifestSchema } from "./sellable.ts";
|
|
37
|
-
import { checkObjectStates, statesManifestSchema } from "./states.ts";
|
|
37
|
+
import { checkObjectStates, resolveFieldPath, statesManifestSchema } from "./states.ts";
|
|
38
38
|
import { checkObjectUnique, uniqueManifestSchema } from "./unique.ts";
|
|
39
39
|
|
|
40
40
|
export const EXTENSION_ID_RE = /^[a-z][a-z0-9]{1,29}$/;
|
|
@@ -214,6 +214,10 @@ export const objectManifestSchema = z.object({
|
|
|
214
214
|
write: z.array(z.string().max(40)).max(100),
|
|
215
215
|
requireAccess: z.array(z.string().max(40)).max(10).optional(),
|
|
216
216
|
createOnly: z.array(z.string().max(40)).max(100).optional(),
|
|
217
|
+
guardians: z
|
|
218
|
+
.object({ write: z.boolean().optional(), madeBy: z.string().max(40).optional() })
|
|
219
|
+
.strict()
|
|
220
|
+
.optional(),
|
|
217
221
|
})
|
|
218
222
|
.strict()
|
|
219
223
|
.optional(),
|
|
@@ -326,6 +330,8 @@ export const toolManifestSchema = z.object({
|
|
|
326
330
|
permission: z.string().max(80).optional(),
|
|
327
331
|
/** Only a person may call it (ADR 0512). */
|
|
328
332
|
humanOnly: z.literal(true).optional(),
|
|
333
|
+
/** A person approves anyone else's call (ADR 0552). */
|
|
334
|
+
personApproves: z.literal(true).optional(),
|
|
329
335
|
inputSchema: jsonSchemaObject,
|
|
330
336
|
outputSchema: jsonSchemaObject,
|
|
331
337
|
});
|
|
@@ -337,6 +343,22 @@ export const roleManifestSchema = z.object({
|
|
|
337
343
|
description: z.string().min(10).max(500),
|
|
338
344
|
permissions: z.array(z.string().max(80)).max(20).default([]),
|
|
339
345
|
read: z.array(z.string().max(80)).max(20).default([]),
|
|
346
|
+
/** Objects whose records the role reaches only on the organisation's local today (ADR 0553). */
|
|
347
|
+
today: z
|
|
348
|
+
.record(
|
|
349
|
+
z.string().max(80),
|
|
350
|
+
z.union([
|
|
351
|
+
z.string().max(122),
|
|
352
|
+
z
|
|
353
|
+
.object({
|
|
354
|
+
at: z.string().max(122),
|
|
355
|
+
until: z.string().max(122).optional(),
|
|
356
|
+
zone: z.string().max(122).optional(),
|
|
357
|
+
})
|
|
358
|
+
.strict(),
|
|
359
|
+
]),
|
|
360
|
+
)
|
|
361
|
+
.optional(),
|
|
340
362
|
});
|
|
341
363
|
export type RoleManifest = z.infer<typeof roleManifestSchema>;
|
|
342
364
|
|
|
@@ -637,6 +659,7 @@ export function toManifest(extension: Extension): ExtensionManifest {
|
|
|
637
659
|
...(tool.audiences ? { audiences: [...tool.audiences] } : {}),
|
|
638
660
|
...(tool.permission ? { permission: tool.permission } : {}),
|
|
639
661
|
...(tool.humanOnly ? { humanOnly: true as const } : {}),
|
|
662
|
+
...(tool.personApproves ? { personApproves: true as const } : {}),
|
|
640
663
|
...(tool.customerFields
|
|
641
664
|
? {
|
|
642
665
|
customerFields: Object.fromEntries(
|
|
@@ -678,6 +701,7 @@ export function toManifest(extension: Extension): ExtensionManifest {
|
|
|
678
701
|
description: role.description,
|
|
679
702
|
permissions: [...role.permissions],
|
|
680
703
|
read: [...role.read],
|
|
704
|
+
...(role.today ? { today: { ...role.today } } : {}),
|
|
681
705
|
},
|
|
682
706
|
]),
|
|
683
707
|
),
|
|
@@ -1295,6 +1319,24 @@ export function validateManifest(
|
|
|
1295
1319
|
}
|
|
1296
1320
|
}
|
|
1297
1321
|
|
|
1322
|
+
// The family link (ADR 0540): who made a record is a relation to one person the host sets, never
|
|
1323
|
+
// one the customer writes.
|
|
1324
|
+
for (const [name, object] of Object.entries(m.objects)) {
|
|
1325
|
+
const madeBy = object.customer?.guardians?.madeBy;
|
|
1326
|
+
if (madeBy === undefined) continue;
|
|
1327
|
+
const path = `objects.${name}.customer.guardians.madeBy`;
|
|
1328
|
+
const field = object.fields[madeBy];
|
|
1329
|
+
if (field?.type !== "relation" || field.to !== "person" || field.many) {
|
|
1330
|
+
contract(path, `"${madeBy}" must be a relation of ${name} to one person`);
|
|
1331
|
+
} else if (!field.readOnly) {
|
|
1332
|
+
contract(path, `"${madeBy}" must be readOnly: the host sets it, nobody edits it`);
|
|
1333
|
+
} else if (madeBy === object.customer?.field) {
|
|
1334
|
+
contract(path, "madeBy cannot be the customer field");
|
|
1335
|
+
} else if (object.customer?.write.includes(madeBy)) {
|
|
1336
|
+
contract(path, `"${madeBy}" is set by the host: customer.write may not list it`);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1298
1340
|
// A customer's write that needs access to what it points to (stage 42, ADR 0478): relations of
|
|
1299
1341
|
// the object to one record of another of this extension's objects that declares `access`.
|
|
1300
1342
|
for (const [name, object] of Object.entries(m.objects)) {
|
|
@@ -1466,6 +1508,12 @@ export function validateManifest(
|
|
|
1466
1508
|
`A tool only a person on the staff may call cannot be open to ${open.join(" and ")} callers`,
|
|
1467
1509
|
);
|
|
1468
1510
|
}
|
|
1511
|
+
if (tool.personApproves && (open.length || tool.risk === "read")) {
|
|
1512
|
+
contract(
|
|
1513
|
+
`tools.${name}.personApproves`,
|
|
1514
|
+
"A tool a person approves is a staff tool that changes something: not open to customers or the public, and not a read",
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1469
1517
|
if (open.length && tool.risk !== "read" && tool.risk !== "write") {
|
|
1470
1518
|
contract(
|
|
1471
1519
|
`tools.${name}.risk`,
|
|
@@ -1586,6 +1634,34 @@ export function validateManifest(
|
|
|
1586
1634
|
);
|
|
1587
1635
|
}
|
|
1588
1636
|
}
|
|
1637
|
+
// A role limited to today (ADR 0553): each object its own, each path a datetime on it (or
|
|
1638
|
+
// one relation away, through another of its objects).
|
|
1639
|
+
for (const [object, limit] of Object.entries(role.today ?? {})) {
|
|
1640
|
+
const tp = `${path}.today.${object}`;
|
|
1641
|
+
const local = object.startsWith(`${m.id}.`) ? object.slice(m.id.length + 1) : null;
|
|
1642
|
+
const target = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
1643
|
+
if (!target) {
|
|
1644
|
+
contract(tp, `"${object}" is not an object of this extension`);
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
const spec = typeof limit === "string" ? { at: limit } : limit;
|
|
1648
|
+
const prefix = (p: string) => (p.includes(".") ? p.split(".")[0] : null);
|
|
1649
|
+
const paths: [string | undefined, string][] = [
|
|
1650
|
+
[spec.at, "datetime"],
|
|
1651
|
+
[spec.until, "datetime"],
|
|
1652
|
+
[spec.zone, "timezone"],
|
|
1653
|
+
];
|
|
1654
|
+
for (const [p, type] of paths) {
|
|
1655
|
+
if (p === undefined) continue;
|
|
1656
|
+
const field = p.split(".").length <= 2 ? resolveFieldPath(m, target, p) : undefined;
|
|
1657
|
+
if (field?.type !== type || field.many) {
|
|
1658
|
+
contract(tp, `"${p}" must be a ${type} field of ${object}, or one relation away`);
|
|
1659
|
+
}
|
|
1660
|
+
if (prefix(p) !== prefix(spec.at)) {
|
|
1661
|
+
contract(tp, `"${p}" must be read through the same relation as "${spec.at}"`);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1589
1665
|
}
|
|
1590
1666
|
|
|
1591
1667
|
for (const [name, view] of Object.entries(m.views)) {
|