@composable-os/sdk 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/capacity.d.ts +69 -0
- package/dist/capacity.js +62 -0
- package/dist/contract.d.ts +32 -0
- package/dist/manifest.d.ts +116 -4
- package/dist/manifest.js +75 -1
- package/dist/sellable.d.ts +78 -0
- package/dist/sellable.js +154 -1
- package/dist/states.d.ts +57 -3
- package/dist/states.js +115 -47
- package/package.json +1 -1
- package/src/capacity.ts +102 -0
- package/src/contract.ts +25 -0
- package/src/manifest.ts +77 -1
- package/src/sellable.ts +251 -1
- package/src/states.ts +163 -49
package/dist/capacity.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { ExtensionManifest, ObjectManifest } from "./manifest.ts";
|
|
3
|
+
import { type WindowBound } from "./states.ts";
|
|
3
4
|
/**
|
|
4
5
|
* What customers and the public are told about a record's places (staff always see the real
|
|
5
6
|
* numbers): `exact`, the number left; `low`, available, "only N left" at or below `lowAt`, or sold
|
|
@@ -66,11 +67,79 @@ export interface ClaimsSpec {
|
|
|
66
67
|
on: string;
|
|
67
68
|
held?: readonly string[];
|
|
68
69
|
confirmed?: readonly string[];
|
|
70
|
+
waitlist?: WaitlistSpec;
|
|
69
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* A waitlist on the claimed record's places (stage 31, ADR 0520). A record in `state` waits: it
|
|
74
|
+
* holds no place and spends nothing. It may be made only while the record it claims on is full
|
|
75
|
+
* and before `until`. Until then, a place given back while anyone waits is handed to the waitlist
|
|
76
|
+
* in the same statements that give it back, as a hold of its own that nobody booking directly
|
|
77
|
+
* can take. The host then promotes the first waiter (by when the record was made) from a current
|
|
78
|
+
* read: the move from `state` into `promote` takes the waitlist's hold, and whatever that move
|
|
79
|
+
* spends is spent then. A waiter who cannot be moved in (their spend is refused) is passed over
|
|
80
|
+
* and stays waiting; a hold nobody can take is given back to everyone. From `until`, nobody is
|
|
81
|
+
* promoted and a place given back goes to whoever claims first.
|
|
82
|
+
*
|
|
83
|
+
* - `state` is a state of the object that neither holds nor takes a place, and is not final.
|
|
84
|
+
* - `promote` is one of `confirmed`; a move from `state` to it must be declared for the host.
|
|
85
|
+
* Declared for a customer too (with a window), it lets a waiter take a free place themselves:
|
|
86
|
+
* only the host's promotion takes a place the waitlist holds, so nobody jumps the queue.
|
|
87
|
+
* - `until` is a moment, named as a window's end is (`{ at: "class.startsAt", minutesBefore:
|
|
88
|
+
* { field: "class.classType.promotionMinutes", setting: "promotionMinutes" } }`).
|
|
89
|
+
* - `promotedAt`, `passedOverAt` (read-only datetimes) and `passedOverReason` (read-only text)
|
|
90
|
+
* are what the host writes when it promotes a waiter or passes one over, for messages.
|
|
91
|
+
* - The claimed object has no pool.
|
|
92
|
+
*/
|
|
93
|
+
export interface WaitlistSpec {
|
|
94
|
+
state: string;
|
|
95
|
+
promote: string;
|
|
96
|
+
until: string | WindowBound;
|
|
97
|
+
promotedAt?: string;
|
|
98
|
+
passedOverAt?: string;
|
|
99
|
+
passedOverReason?: string;
|
|
100
|
+
}
|
|
101
|
+
export declare const waitlistManifestSchema: z.ZodObject<{
|
|
102
|
+
state: z.ZodString;
|
|
103
|
+
promote: z.ZodString;
|
|
104
|
+
until: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
105
|
+
at: z.ZodString;
|
|
106
|
+
daysBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
107
|
+
field: z.ZodOptional<z.ZodString>;
|
|
108
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, z.core.$strict>]>>;
|
|
110
|
+
minutesBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
111
|
+
field: z.ZodOptional<z.ZodString>;
|
|
112
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
113
|
+
}, z.core.$strict>]>>;
|
|
114
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$strict>]>;
|
|
116
|
+
promotedAt: z.ZodOptional<z.ZodString>;
|
|
117
|
+
passedOverAt: z.ZodOptional<z.ZodString>;
|
|
118
|
+
passedOverReason: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.core.$strict>;
|
|
70
120
|
export declare const claimsManifestSchema: z.ZodObject<{
|
|
71
121
|
on: z.ZodString;
|
|
72
122
|
held: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
73
123
|
confirmed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
|
+
waitlist: z.ZodOptional<z.ZodObject<{
|
|
125
|
+
state: z.ZodString;
|
|
126
|
+
promote: z.ZodString;
|
|
127
|
+
until: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
128
|
+
at: z.ZodString;
|
|
129
|
+
daysBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
130
|
+
field: z.ZodOptional<z.ZodString>;
|
|
131
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
132
|
+
}, z.core.$strict>]>>;
|
|
133
|
+
minutesBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
134
|
+
field: z.ZodOptional<z.ZodString>;
|
|
135
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strict>]>>;
|
|
137
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.core.$strict>]>;
|
|
139
|
+
promotedAt: z.ZodOptional<z.ZodString>;
|
|
140
|
+
passedOverAt: z.ZodOptional<z.ZodString>;
|
|
141
|
+
passedOverReason: z.ZodOptional<z.ZodString>;
|
|
142
|
+
}, z.core.$strict>>;
|
|
74
143
|
}, z.core.$strict>;
|
|
75
144
|
export type ClaimsManifest = z.infer<typeof claimsManifestSchema>;
|
|
76
145
|
/** Reports problems with `objects.<name>.claims` through `contract`. */
|
package/dist/capacity.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// actor. Its declaration, its manifest schema and its contract checks live here; the host's side
|
|
4
4
|
// is packages/core/src/capacity/.
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { moveOrigins, windowBoundSchema, windowChecks } from "./states.js";
|
|
6
7
|
/**
|
|
7
8
|
* What customers and the public are told about a record's places (staff always see the real
|
|
8
9
|
* numbers): `exact`, the number left; `low`, available, "only N left" at or below `lowAt`, or sold
|
|
@@ -66,11 +67,22 @@ export function checkObjectCapacity(m, name, object, contract) {
|
|
|
66
67
|
contract(`${path}.lowAt`, 'show: "low" needs lowAt, the number at or below which it says so');
|
|
67
68
|
}
|
|
68
69
|
}
|
|
70
|
+
export const waitlistManifestSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
state: z.string().min(1).max(100),
|
|
73
|
+
promote: z.string().min(1).max(100),
|
|
74
|
+
until: windowBoundSchema,
|
|
75
|
+
promotedAt: fieldName.optional(),
|
|
76
|
+
passedOverAt: fieldName.optional(),
|
|
77
|
+
passedOverReason: fieldName.optional(),
|
|
78
|
+
})
|
|
79
|
+
.strict();
|
|
69
80
|
export const claimsManifestSchema = z
|
|
70
81
|
.object({
|
|
71
82
|
on: fieldName,
|
|
72
83
|
held: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
73
84
|
confirmed: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
85
|
+
waitlist: waitlistManifestSchema.optional(),
|
|
74
86
|
})
|
|
75
87
|
.strict();
|
|
76
88
|
/** Reports problems with `objects.<name>.claims` through `contract`. */
|
|
@@ -124,4 +136,54 @@ export function checkObjectClaims(m, name, object, contract) {
|
|
|
124
136
|
contract(`objects.${name}.states.moves.${i}`, `A move from a state that takes a place cannot go back to one that only holds it ("${move.to}")`);
|
|
125
137
|
}
|
|
126
138
|
});
|
|
139
|
+
const waitlist = claims.waitlist;
|
|
140
|
+
if (!waitlist)
|
|
141
|
+
return;
|
|
142
|
+
// A waitlist (ADR 0520).
|
|
143
|
+
const wp = `${path}.waitlist`;
|
|
144
|
+
if (!values.has(waitlist.state)) {
|
|
145
|
+
contract(`${wp}.state`, `"${waitlist.state}" is not a state of ${name}`);
|
|
146
|
+
}
|
|
147
|
+
else if (held.includes(waitlist.state) || confirmed.includes(waitlist.state)) {
|
|
148
|
+
contract(`${wp}.state`, `"${waitlist.state}" waits: it can neither hold nor take a place`);
|
|
149
|
+
}
|
|
150
|
+
else if (states.moves.some((move) => move.final && move.to === waitlist.state)) {
|
|
151
|
+
contract(`${wp}.state`, `"${waitlist.state}" is final: nobody waits in it`);
|
|
152
|
+
}
|
|
153
|
+
else if (states.initial !== waitlist.state &&
|
|
154
|
+
!Object.hasOwn(states.create?.in ?? {}, waitlist.state)) {
|
|
155
|
+
contract(`${wp}.state`, `"${waitlist.state}" must be a state ${name} may be created in (states.create.in): a waiter joins by being made waiting`);
|
|
156
|
+
}
|
|
157
|
+
if (!confirmed.includes(waitlist.promote)) {
|
|
158
|
+
contract(`${wp}.promote`, `"${waitlist.promote}" must be one of claims.confirmed`);
|
|
159
|
+
}
|
|
160
|
+
const promotions = states.moves.filter((move) => move.to === waitlist.promote && moveOrigins(move).includes(waitlist.state));
|
|
161
|
+
if (!promotions.some((move) => move.by.includes("host"))) {
|
|
162
|
+
contract(`${wp}.promote`, `Declare a move from "${waitlist.state}" to "${waitlist.promote}" by the host: promotion is the host's`);
|
|
163
|
+
}
|
|
164
|
+
// A customer may move their own waiting record in, but only onto a free place: the host's
|
|
165
|
+
// promotion alone takes a place the waitlist holds, so nobody moves themselves ahead of it.
|
|
166
|
+
// Their move needs the create's window, so they cannot claim a place booking would refuse.
|
|
167
|
+
promotions.forEach((move) => {
|
|
168
|
+
if (move.by.includes("customer") && !move.window) {
|
|
169
|
+
contract(`${wp}.promote`, `A customer's move from "${waitlist.state}" to "${waitlist.promote}" needs a window (the create's): it books them`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
windowChecks(m, object, name, contract).checkBound(waitlist.until, `${wp}.until`);
|
|
173
|
+
for (const [key, type] of [
|
|
174
|
+
["promotedAt", "datetime"],
|
|
175
|
+
["passedOverAt", "datetime"],
|
|
176
|
+
["passedOverReason", "text"],
|
|
177
|
+
]) {
|
|
178
|
+
const local = waitlist[key];
|
|
179
|
+
if (local === undefined)
|
|
180
|
+
continue;
|
|
181
|
+
const field = Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
|
|
182
|
+
if (field?.type !== type || field.many || !field.readOnly) {
|
|
183
|
+
contract(`${wp}.${key}`, `"${local}" must be a read-only ${type} field of ${name}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (targetObject?.capacity?.pool !== undefined) {
|
|
187
|
+
contract(`${wp}`, `A waitlist is on places with no pool; ${target} has one`);
|
|
188
|
+
}
|
|
127
189
|
}
|
package/dist/contract.d.ts
CHANGED
|
@@ -555,6 +555,13 @@ export interface ToolSpec<In extends z.ZodType = z.ZodType, Out extends z.ZodTyp
|
|
|
555
555
|
* any extension may declare it.
|
|
556
556
|
*/
|
|
557
557
|
humanOnly?: boolean;
|
|
558
|
+
/**
|
|
559
|
+
* A person approves it (ADR 0552): a person on the staff calls it as any tool, and anyone else's
|
|
560
|
+
* call (the assistant, an MCP client, an automation) always waits in the approval queue for a
|
|
561
|
+
* person, whatever the approval policy or preset says, and runs when a person approves it. For
|
|
562
|
+
* what an AI may propose but a person decides (cancelling a class). Staff only, and not a read.
|
|
563
|
+
*/
|
|
564
|
+
personApproves?: boolean;
|
|
558
565
|
handler(input: z.output<In>, ctx: ExtensionContext): Promise<z.input<Out>> | z.input<Out>;
|
|
559
566
|
}
|
|
560
567
|
/**
|
|
@@ -573,6 +580,19 @@ export interface RoleSpec {
|
|
|
573
580
|
permissions: readonly string[];
|
|
574
581
|
/** Objects of this extension (`<id>.<object>`) whose records the role may read. */
|
|
575
582
|
read: readonly string[];
|
|
583
|
+
/**
|
|
584
|
+
* Objects whose records the role reaches only when a datetime on them falls on the
|
|
585
|
+
* day it is on (ADR 0553), by object: the moment, and optionally its end and zone, read through
|
|
586
|
+
* one relation at most: `{ "bookings.class": { at: "startsAt", until: "endsAt", zone:
|
|
587
|
+
* "timezone" } }`. A record is today's when its start falls on today's date in its zone (the
|
|
588
|
+
* organisation's when empty), or it has started and not yet ended. The host holds it on every
|
|
589
|
+
* call the account makes and every call of a tool run it started. Other staff are not limited.
|
|
590
|
+
*/
|
|
591
|
+
today?: Readonly<Record<string, string | {
|
|
592
|
+
at: string;
|
|
593
|
+
until?: string;
|
|
594
|
+
zone?: string;
|
|
595
|
+
}>>;
|
|
576
596
|
}
|
|
577
597
|
/**
|
|
578
598
|
* Who started a tool (ADR 0436), set by the host from the session it verified and never from the
|
|
@@ -700,6 +720,18 @@ export interface CustomerSpec {
|
|
|
700
720
|
* any tool.
|
|
701
721
|
*/
|
|
702
722
|
createOnly?: readonly string[];
|
|
723
|
+
/**
|
|
724
|
+
* The family link (ADR 0540): a signed-in guardian also reads their live dependants' records of
|
|
725
|
+
* this object (a child's bookings), with the same `read` fields. With `write: true` they also
|
|
726
|
+
* make records for a dependant (`my.create`'s `forPersonId`) and change the dependant's, with
|
|
727
|
+
* the same `write` fields. `madeBy` names a relation to one person the host sets, on every
|
|
728
|
+
* record a customer makes, to the Person who made it. Staff link guardians to dependants; the
|
|
729
|
+
* seam checks the link in every read and write. A reviewed change, as `customer` is.
|
|
730
|
+
*/
|
|
731
|
+
guardians?: {
|
|
732
|
+
write?: boolean;
|
|
733
|
+
madeBy?: string;
|
|
734
|
+
};
|
|
703
735
|
}
|
|
704
736
|
/** A tool shown as a button on a record page. */
|
|
705
737
|
export interface RecordActionSpec {
|
package/dist/manifest.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare const fieldManifestSchema: z.ZodObject<{
|
|
|
19
19
|
number: "number";
|
|
20
20
|
boolean: "boolean";
|
|
21
21
|
date: "date";
|
|
22
|
+
relation: "relation";
|
|
22
23
|
text: "text";
|
|
23
24
|
longText: "longText";
|
|
24
25
|
currency: "currency";
|
|
@@ -26,7 +27,6 @@ export declare const fieldManifestSchema: z.ZodObject<{
|
|
|
26
27
|
datetime: "datetime";
|
|
27
28
|
select: "select";
|
|
28
29
|
multiSelect: "multiSelect";
|
|
29
|
-
relation: "relation";
|
|
30
30
|
user: "user";
|
|
31
31
|
email: "email";
|
|
32
32
|
phone: "phone";
|
|
@@ -113,6 +113,7 @@ export declare const objectManifestSchema: z.ZodObject<{
|
|
|
113
113
|
number: "number";
|
|
114
114
|
boolean: "boolean";
|
|
115
115
|
date: "date";
|
|
116
|
+
relation: "relation";
|
|
116
117
|
text: "text";
|
|
117
118
|
longText: "longText";
|
|
118
119
|
currency: "currency";
|
|
@@ -120,7 +121,6 @@ export declare const objectManifestSchema: z.ZodObject<{
|
|
|
120
121
|
datetime: "datetime";
|
|
121
122
|
select: "select";
|
|
122
123
|
multiSelect: "multiSelect";
|
|
123
|
-
relation: "relation";
|
|
124
124
|
user: "user";
|
|
125
125
|
email: "email";
|
|
126
126
|
phone: "phone";
|
|
@@ -239,6 +239,22 @@ export declare const objectManifestSchema: z.ZodObject<{
|
|
|
239
239
|
}, z.core.$strict>>;
|
|
240
240
|
}, z.core.$strict>>;
|
|
241
241
|
onePerPerson: z.ZodOptional<z.ZodString>;
|
|
242
|
+
moves: z.ZodOptional<z.ZodObject<{
|
|
243
|
+
held: z.ZodString;
|
|
244
|
+
paid: z.ZodString;
|
|
245
|
+
expired: z.ZodString;
|
|
246
|
+
refund: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
247
|
+
price: z.ZodOptional<z.ZodObject<{
|
|
248
|
+
field: z.ZodOptional<z.ZodString>;
|
|
249
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
250
|
+
}, z.core.$strict>>;
|
|
251
|
+
title: z.ZodOptional<z.ZodString>;
|
|
252
|
+
order: z.ZodOptional<z.ZodString>;
|
|
253
|
+
guest: z.ZodOptional<z.ZodBoolean>;
|
|
254
|
+
holdCap: z.ZodOptional<z.ZodObject<{
|
|
255
|
+
setting: z.ZodString;
|
|
256
|
+
}, z.core.$strict>>;
|
|
257
|
+
}, z.core.$strict>>;
|
|
242
258
|
tax: z.ZodOptional<z.ZodObject<{
|
|
243
259
|
code: z.ZodString;
|
|
244
260
|
place: z.ZodOptional<z.ZodObject<{
|
|
@@ -257,6 +273,10 @@ export declare const objectManifestSchema: z.ZodObject<{
|
|
|
257
273
|
year: "year";
|
|
258
274
|
}>;
|
|
259
275
|
trialDays: z.ZodOptional<z.ZodString>;
|
|
276
|
+
pause: z.ZodOptional<z.ZodObject<{
|
|
277
|
+
minDays: z.ZodOptional<z.ZodString>;
|
|
278
|
+
maxDays: z.ZodOptional<z.ZodString>;
|
|
279
|
+
}, z.core.$strict>>;
|
|
260
280
|
grants: z.ZodOptional<z.ZodObject<{
|
|
261
281
|
object: z.ZodString;
|
|
262
282
|
set: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
@@ -417,11 +437,37 @@ export declare const objectManifestSchema: z.ZodObject<{
|
|
|
417
437
|
when: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
418
438
|
from: z.ZodArray<z.ZodString>;
|
|
419
439
|
}, z.core.$strict>>;
|
|
440
|
+
after: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
441
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
442
|
+
to: z.ZodString;
|
|
443
|
+
at: z.ZodString;
|
|
444
|
+
minutesAfter: z.ZodOptional<z.ZodNumber>;
|
|
445
|
+
ifAnyIn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
446
|
+
}, z.core.$strict>>>;
|
|
420
447
|
}, z.core.$strip>>;
|
|
421
448
|
claims: z.ZodOptional<z.ZodObject<{
|
|
422
449
|
on: z.ZodString;
|
|
423
450
|
held: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
424
451
|
confirmed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
452
|
+
waitlist: z.ZodOptional<z.ZodObject<{
|
|
453
|
+
state: z.ZodString;
|
|
454
|
+
promote: z.ZodString;
|
|
455
|
+
until: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
456
|
+
at: z.ZodString;
|
|
457
|
+
daysBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
458
|
+
field: z.ZodOptional<z.ZodString>;
|
|
459
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
460
|
+
}, z.core.$strict>]>>;
|
|
461
|
+
minutesBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
462
|
+
field: z.ZodOptional<z.ZodString>;
|
|
463
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
464
|
+
}, z.core.$strict>]>>;
|
|
465
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
466
|
+
}, z.core.$strict>]>;
|
|
467
|
+
promotedAt: z.ZodOptional<z.ZodString>;
|
|
468
|
+
passedOverAt: z.ZodOptional<z.ZodString>;
|
|
469
|
+
passedOverReason: z.ZodOptional<z.ZodString>;
|
|
470
|
+
}, z.core.$strict>>;
|
|
425
471
|
}, z.core.$strict>>;
|
|
426
472
|
unique: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
427
473
|
fields: z.ZodArray<z.ZodString>;
|
|
@@ -468,6 +514,10 @@ export declare const objectManifestSchema: z.ZodObject<{
|
|
|
468
514
|
write: z.ZodArray<z.ZodString>;
|
|
469
515
|
requireAccess: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
470
516
|
createOnly: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
517
|
+
guardians: z.ZodOptional<z.ZodObject<{
|
|
518
|
+
write: z.ZodOptional<z.ZodBoolean>;
|
|
519
|
+
madeBy: z.ZodOptional<z.ZodString>;
|
|
520
|
+
}, z.core.$strict>>;
|
|
471
521
|
}, z.core.$strict>>;
|
|
472
522
|
public: z.ZodOptional<z.ZodObject<{
|
|
473
523
|
read: z.ZodArray<z.ZodString>;
|
|
@@ -569,6 +619,7 @@ export declare const toolManifestSchema: z.ZodObject<{
|
|
|
569
619
|
customerFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
570
620
|
permission: z.ZodOptional<z.ZodString>;
|
|
571
621
|
humanOnly: z.ZodOptional<z.ZodLiteral<true>>;
|
|
622
|
+
personApproves: z.ZodOptional<z.ZodLiteral<true>>;
|
|
572
623
|
inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
573
624
|
outputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
574
625
|
}, z.core.$strip>;
|
|
@@ -579,6 +630,11 @@ export declare const roleManifestSchema: z.ZodObject<{
|
|
|
579
630
|
description: z.ZodString;
|
|
580
631
|
permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
581
632
|
read: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
633
|
+
today: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
634
|
+
at: z.ZodString;
|
|
635
|
+
until: z.ZodOptional<z.ZodString>;
|
|
636
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
637
|
+
}, z.core.$strict>]>>>;
|
|
582
638
|
}, z.core.$strip>;
|
|
583
639
|
export type RoleManifest = z.infer<typeof roleManifestSchema>;
|
|
584
640
|
/** A role's or a tool's permission: `<extension id>:<word>`. */
|
|
@@ -748,6 +804,7 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
748
804
|
number: "number";
|
|
749
805
|
boolean: "boolean";
|
|
750
806
|
date: "date";
|
|
807
|
+
relation: "relation";
|
|
751
808
|
text: "text";
|
|
752
809
|
longText: "longText";
|
|
753
810
|
currency: "currency";
|
|
@@ -755,7 +812,6 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
755
812
|
datetime: "datetime";
|
|
756
813
|
select: "select";
|
|
757
814
|
multiSelect: "multiSelect";
|
|
758
|
-
relation: "relation";
|
|
759
815
|
user: "user";
|
|
760
816
|
email: "email";
|
|
761
817
|
phone: "phone";
|
|
@@ -874,6 +930,22 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
874
930
|
}, z.core.$strict>>;
|
|
875
931
|
}, z.core.$strict>>;
|
|
876
932
|
onePerPerson: z.ZodOptional<z.ZodString>;
|
|
933
|
+
moves: z.ZodOptional<z.ZodObject<{
|
|
934
|
+
held: z.ZodString;
|
|
935
|
+
paid: z.ZodString;
|
|
936
|
+
expired: z.ZodString;
|
|
937
|
+
refund: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
938
|
+
price: z.ZodOptional<z.ZodObject<{
|
|
939
|
+
field: z.ZodOptional<z.ZodString>;
|
|
940
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
941
|
+
}, z.core.$strict>>;
|
|
942
|
+
title: z.ZodOptional<z.ZodString>;
|
|
943
|
+
order: z.ZodOptional<z.ZodString>;
|
|
944
|
+
guest: z.ZodOptional<z.ZodBoolean>;
|
|
945
|
+
holdCap: z.ZodOptional<z.ZodObject<{
|
|
946
|
+
setting: z.ZodString;
|
|
947
|
+
}, z.core.$strict>>;
|
|
948
|
+
}, z.core.$strict>>;
|
|
877
949
|
tax: z.ZodOptional<z.ZodObject<{
|
|
878
950
|
code: z.ZodString;
|
|
879
951
|
place: z.ZodOptional<z.ZodObject<{
|
|
@@ -892,6 +964,10 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
892
964
|
year: "year";
|
|
893
965
|
}>;
|
|
894
966
|
trialDays: z.ZodOptional<z.ZodString>;
|
|
967
|
+
pause: z.ZodOptional<z.ZodObject<{
|
|
968
|
+
minDays: z.ZodOptional<z.ZodString>;
|
|
969
|
+
maxDays: z.ZodOptional<z.ZodString>;
|
|
970
|
+
}, z.core.$strict>>;
|
|
895
971
|
grants: z.ZodOptional<z.ZodObject<{
|
|
896
972
|
object: z.ZodString;
|
|
897
973
|
set: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
@@ -1052,11 +1128,37 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
1052
1128
|
when: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
1053
1129
|
from: z.ZodArray<z.ZodString>;
|
|
1054
1130
|
}, z.core.$strict>>;
|
|
1131
|
+
after: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1132
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
1133
|
+
to: z.ZodString;
|
|
1134
|
+
at: z.ZodString;
|
|
1135
|
+
minutesAfter: z.ZodOptional<z.ZodNumber>;
|
|
1136
|
+
ifAnyIn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1137
|
+
}, z.core.$strict>>>;
|
|
1055
1138
|
}, z.core.$strip>>;
|
|
1056
1139
|
claims: z.ZodOptional<z.ZodObject<{
|
|
1057
1140
|
on: z.ZodString;
|
|
1058
1141
|
held: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1059
1142
|
confirmed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1143
|
+
waitlist: z.ZodOptional<z.ZodObject<{
|
|
1144
|
+
state: z.ZodString;
|
|
1145
|
+
promote: z.ZodString;
|
|
1146
|
+
until: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
1147
|
+
at: z.ZodString;
|
|
1148
|
+
daysBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
1149
|
+
field: z.ZodOptional<z.ZodString>;
|
|
1150
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
1151
|
+
}, z.core.$strict>]>>;
|
|
1152
|
+
minutesBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
1153
|
+
field: z.ZodOptional<z.ZodString>;
|
|
1154
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
1155
|
+
}, z.core.$strict>]>>;
|
|
1156
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
1157
|
+
}, z.core.$strict>]>;
|
|
1158
|
+
promotedAt: z.ZodOptional<z.ZodString>;
|
|
1159
|
+
passedOverAt: z.ZodOptional<z.ZodString>;
|
|
1160
|
+
passedOverReason: z.ZodOptional<z.ZodString>;
|
|
1161
|
+
}, z.core.$strict>>;
|
|
1060
1162
|
}, z.core.$strict>>;
|
|
1061
1163
|
unique: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1062
1164
|
fields: z.ZodArray<z.ZodString>;
|
|
@@ -1103,6 +1205,10 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
1103
1205
|
write: z.ZodArray<z.ZodString>;
|
|
1104
1206
|
requireAccess: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1105
1207
|
createOnly: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1208
|
+
guardians: z.ZodOptional<z.ZodObject<{
|
|
1209
|
+
write: z.ZodOptional<z.ZodBoolean>;
|
|
1210
|
+
madeBy: z.ZodOptional<z.ZodString>;
|
|
1211
|
+
}, z.core.$strict>>;
|
|
1106
1212
|
}, z.core.$strict>>;
|
|
1107
1213
|
public: z.ZodOptional<z.ZodObject<{
|
|
1108
1214
|
read: z.ZodArray<z.ZodString>;
|
|
@@ -1155,6 +1261,7 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
1155
1261
|
number: "number";
|
|
1156
1262
|
boolean: "boolean";
|
|
1157
1263
|
date: "date";
|
|
1264
|
+
relation: "relation";
|
|
1158
1265
|
text: "text";
|
|
1159
1266
|
longText: "longText";
|
|
1160
1267
|
currency: "currency";
|
|
@@ -1162,7 +1269,6 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
1162
1269
|
datetime: "datetime";
|
|
1163
1270
|
select: "select";
|
|
1164
1271
|
multiSelect: "multiSelect";
|
|
1165
|
-
relation: "relation";
|
|
1166
1272
|
user: "user";
|
|
1167
1273
|
email: "email";
|
|
1168
1274
|
phone: "phone";
|
|
@@ -1368,6 +1474,7 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
1368
1474
|
customerFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
1369
1475
|
permission: z.ZodOptional<z.ZodString>;
|
|
1370
1476
|
humanOnly: z.ZodOptional<z.ZodLiteral<true>>;
|
|
1477
|
+
personApproves: z.ZodOptional<z.ZodLiteral<true>>;
|
|
1371
1478
|
inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
1372
1479
|
outputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
1373
1480
|
}, z.core.$strip>>>;
|
|
@@ -1543,6 +1650,11 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
1543
1650
|
description: z.ZodString;
|
|
1544
1651
|
permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1545
1652
|
read: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1653
|
+
today: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
1654
|
+
at: z.ZodString;
|
|
1655
|
+
until: z.ZodOptional<z.ZodString>;
|
|
1656
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
1657
|
+
}, z.core.$strict>]>>>;
|
|
1546
1658
|
}, z.core.$strip>>>;
|
|
1547
1659
|
grantable: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1548
1660
|
}, z.core.$strip>;
|
package/dist/manifest.js
CHANGED
|
@@ -15,7 +15,7 @@ import { checkFormula } from "./formula/compile.js";
|
|
|
15
15
|
import { checkObjectRecurring, recurringManifestSchema } from "./recurring.js";
|
|
16
16
|
import { renamedMessage } from "./renamed.js";
|
|
17
17
|
import { checkObjectSellable, sellableManifestSchema } from "./sellable.js";
|
|
18
|
-
import { checkObjectStates, statesManifestSchema } from "./states.js";
|
|
18
|
+
import { checkObjectStates, resolveFieldPath, statesManifestSchema } from "./states.js";
|
|
19
19
|
import { checkObjectUnique, uniqueManifestSchema } from "./unique.js";
|
|
20
20
|
export const EXTENSION_ID_RE = /^[a-z][a-z0-9]{1,29}$/;
|
|
21
21
|
export const OBJECT_NAME_RE = /^[a-z][a-z0-9]{0,29}$/;
|
|
@@ -181,6 +181,10 @@ export const objectManifestSchema = z.object({
|
|
|
181
181
|
write: z.array(z.string().max(40)).max(100),
|
|
182
182
|
requireAccess: z.array(z.string().max(40)).max(10).optional(),
|
|
183
183
|
createOnly: z.array(z.string().max(40)).max(100).optional(),
|
|
184
|
+
guardians: z
|
|
185
|
+
.object({ write: z.boolean().optional(), madeBy: z.string().max(40).optional() })
|
|
186
|
+
.strict()
|
|
187
|
+
.optional(),
|
|
184
188
|
})
|
|
185
189
|
.strict()
|
|
186
190
|
.optional(),
|
|
@@ -283,6 +287,8 @@ export const toolManifestSchema = z.object({
|
|
|
283
287
|
permission: z.string().max(80).optional(),
|
|
284
288
|
/** Only a person may call it (ADR 0512). */
|
|
285
289
|
humanOnly: z.literal(true).optional(),
|
|
290
|
+
/** A person approves anyone else's call (ADR 0552). */
|
|
291
|
+
personApproves: z.literal(true).optional(),
|
|
286
292
|
inputSchema: jsonSchemaObject,
|
|
287
293
|
outputSchema: jsonSchemaObject,
|
|
288
294
|
});
|
|
@@ -292,6 +298,19 @@ export const roleManifestSchema = z.object({
|
|
|
292
298
|
description: z.string().min(10).max(500),
|
|
293
299
|
permissions: z.array(z.string().max(80)).max(20).default([]),
|
|
294
300
|
read: z.array(z.string().max(80)).max(20).default([]),
|
|
301
|
+
/** Objects whose records the role reaches only on the organisation's local today (ADR 0553). */
|
|
302
|
+
today: z
|
|
303
|
+
.record(z.string().max(80), z.union([
|
|
304
|
+
z.string().max(122),
|
|
305
|
+
z
|
|
306
|
+
.object({
|
|
307
|
+
at: z.string().max(122),
|
|
308
|
+
until: z.string().max(122).optional(),
|
|
309
|
+
zone: z.string().max(122).optional(),
|
|
310
|
+
})
|
|
311
|
+
.strict(),
|
|
312
|
+
]))
|
|
313
|
+
.optional(),
|
|
295
314
|
});
|
|
296
315
|
/** A role's or a tool's permission: `<extension id>:<word>`. */
|
|
297
316
|
export const EXTENSION_PERMISSION_RE = /^([a-z][a-z0-9]{1,29}):([a-z][a-zA-Z0-9]{0,39})$/;
|
|
@@ -532,6 +551,7 @@ export function toManifest(extension) {
|
|
|
532
551
|
...(tool.audiences ? { audiences: [...tool.audiences] } : {}),
|
|
533
552
|
...(tool.permission ? { permission: tool.permission } : {}),
|
|
534
553
|
...(tool.humanOnly ? { humanOnly: true } : {}),
|
|
554
|
+
...(tool.personApproves ? { personApproves: true } : {}),
|
|
535
555
|
...(tool.customerFields
|
|
536
556
|
? {
|
|
537
557
|
customerFields: Object.fromEntries(Object.entries(tool.customerFields).map(([object, fields]) => [
|
|
@@ -567,6 +587,7 @@ export function toManifest(extension) {
|
|
|
567
587
|
description: role.description,
|
|
568
588
|
permissions: [...role.permissions],
|
|
569
589
|
read: [...role.read],
|
|
590
|
+
...(role.today ? { today: { ...role.today } } : {}),
|
|
570
591
|
},
|
|
571
592
|
])),
|
|
572
593
|
};
|
|
@@ -1075,6 +1096,27 @@ export function validateManifest(input, options = {}) {
|
|
|
1075
1096
|
}
|
|
1076
1097
|
}
|
|
1077
1098
|
}
|
|
1099
|
+
// The family link (ADR 0540): who made a record is a relation to one person the host sets, never
|
|
1100
|
+
// one the customer writes.
|
|
1101
|
+
for (const [name, object] of Object.entries(m.objects)) {
|
|
1102
|
+
const madeBy = object.customer?.guardians?.madeBy;
|
|
1103
|
+
if (madeBy === undefined)
|
|
1104
|
+
continue;
|
|
1105
|
+
const path = `objects.${name}.customer.guardians.madeBy`;
|
|
1106
|
+
const field = object.fields[madeBy];
|
|
1107
|
+
if (field?.type !== "relation" || field.to !== "person" || field.many) {
|
|
1108
|
+
contract(path, `"${madeBy}" must be a relation of ${name} to one person`);
|
|
1109
|
+
}
|
|
1110
|
+
else if (!field.readOnly) {
|
|
1111
|
+
contract(path, `"${madeBy}" must be readOnly: the host sets it, nobody edits it`);
|
|
1112
|
+
}
|
|
1113
|
+
else if (madeBy === object.customer?.field) {
|
|
1114
|
+
contract(path, "madeBy cannot be the customer field");
|
|
1115
|
+
}
|
|
1116
|
+
else if (object.customer?.write.includes(madeBy)) {
|
|
1117
|
+
contract(path, `"${madeBy}" is set by the host: customer.write may not list it`);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1078
1120
|
// A customer's write that needs access to what it points to (stage 42, ADR 0478): relations of
|
|
1079
1121
|
// the object to one record of another of this extension's objects that declares `access`.
|
|
1080
1122
|
for (const [name, object] of Object.entries(m.objects)) {
|
|
@@ -1228,6 +1270,9 @@ export function validateManifest(input, options = {}) {
|
|
|
1228
1270
|
if (tool.humanOnly && open.length) {
|
|
1229
1271
|
contract(`tools.${name}.humanOnly`, `A tool only a person on the staff may call cannot be open to ${open.join(" and ")} callers`);
|
|
1230
1272
|
}
|
|
1273
|
+
if (tool.personApproves && (open.length || tool.risk === "read")) {
|
|
1274
|
+
contract(`tools.${name}.personApproves`, "A tool a person approves is a staff tool that changes something: not open to customers or the public, and not a read");
|
|
1275
|
+
}
|
|
1231
1276
|
if (open.length && tool.risk !== "read" && tool.risk !== "write") {
|
|
1232
1277
|
contract(`tools.${name}.risk`, `A tool open to ${open.join(" and ")} callers must have risk read or write, not ${tool.risk}`);
|
|
1233
1278
|
}
|
|
@@ -1307,6 +1352,35 @@ export function validateManifest(input, options = {}) {
|
|
|
1307
1352
|
contract(`${path}.read`, `"${object}" is not an object of this extension: a role reads ${m.id}.<object> only`);
|
|
1308
1353
|
}
|
|
1309
1354
|
}
|
|
1355
|
+
// A role limited to today (ADR 0553): each object its own, each path a datetime on it (or
|
|
1356
|
+
// one relation away, through another of its objects).
|
|
1357
|
+
for (const [object, limit] of Object.entries(role.today ?? {})) {
|
|
1358
|
+
const tp = `${path}.today.${object}`;
|
|
1359
|
+
const local = object.startsWith(`${m.id}.`) ? object.slice(m.id.length + 1) : null;
|
|
1360
|
+
const target = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
1361
|
+
if (!target) {
|
|
1362
|
+
contract(tp, `"${object}" is not an object of this extension`);
|
|
1363
|
+
continue;
|
|
1364
|
+
}
|
|
1365
|
+
const spec = typeof limit === "string" ? { at: limit } : limit;
|
|
1366
|
+
const prefix = (p) => (p.includes(".") ? p.split(".")[0] : null);
|
|
1367
|
+
const paths = [
|
|
1368
|
+
[spec.at, "datetime"],
|
|
1369
|
+
[spec.until, "datetime"],
|
|
1370
|
+
[spec.zone, "timezone"],
|
|
1371
|
+
];
|
|
1372
|
+
for (const [p, type] of paths) {
|
|
1373
|
+
if (p === undefined)
|
|
1374
|
+
continue;
|
|
1375
|
+
const field = p.split(".").length <= 2 ? resolveFieldPath(m, target, p) : undefined;
|
|
1376
|
+
if (field?.type !== type || field.many) {
|
|
1377
|
+
contract(tp, `"${p}" must be a ${type} field of ${object}, or one relation away`);
|
|
1378
|
+
}
|
|
1379
|
+
if (prefix(p) !== prefix(spec.at)) {
|
|
1380
|
+
contract(tp, `"${p}" must be read through the same relation as "${spec.at}"`);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1310
1384
|
}
|
|
1311
1385
|
for (const [name, view] of Object.entries(m.views)) {
|
|
1312
1386
|
if (!FIELD_NAME_RE.test(name))
|