@composable-os/sdk 0.1.0-beta.10 → 0.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acknowledge.d.ts +38 -0
- package/dist/acknowledge.js +30 -0
- package/dist/agreements.d.ts +80 -0
- package/dist/agreements.js +109 -0
- package/dist/allowance.d.ts +47 -5
- package/dist/allowance.js +59 -4
- package/dist/automation-check.d.ts +6 -1
- package/dist/automation-check.js +93 -8
- package/dist/automation.d.ts +62 -4
- package/dist/automation.js +32 -9
- package/dist/behaviour.js +25 -6
- package/dist/calendar-entry.d.ts +97 -0
- package/dist/calendar-entry.js +180 -0
- package/dist/capacity.d.ts +69 -0
- package/dist/capacity.js +63 -2
- package/dist/checklists.d.ts +41 -0
- package/dist/checklists.js +75 -0
- package/dist/contract.d.ts +527 -26
- package/dist/contract.js +21 -3
- package/dist/discount.d.ts +135 -0
- package/dist/discount.js +281 -0
- package/dist/document.d.ts +2 -1
- package/dist/document.js +2 -1
- package/dist/field-types.d.ts +1 -1
- package/dist/field-types.js +5 -0
- package/dist/formula/compile.d.ts +15 -0
- package/dist/formula/compile.js +9 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/dist/intake.d.ts +134 -0
- package/dist/intake.js +239 -0
- package/dist/journey-signals.d.ts +89 -0
- package/dist/journey-signals.js +151 -0
- package/dist/manifest.d.ts +1060 -60
- package/dist/manifest.js +1111 -61
- package/dist/mine.d.ts +45 -0
- package/dist/mine.js +119 -0
- package/dist/occupies.d.ts +64 -0
- package/dist/occupies.js +122 -0
- package/dist/questions.d.ts +179 -0
- package/dist/questions.js +514 -0
- package/dist/recurring.d.ts +33 -4
- package/dist/recurring.js +50 -3
- package/dist/restricted-fields.d.ts +15 -0
- package/dist/restricted-fields.js +97 -0
- package/dist/rich-text.d.ts +22 -0
- package/dist/rich-text.js +91 -0
- package/dist/routine-mail.d.ts +400 -0
- package/dist/routine-mail.js +955 -0
- package/dist/runtime.d.ts +5 -11
- package/dist/runtime.js +21 -11
- package/dist/screens.d.ts +3 -0
- package/dist/screens.js +74 -0
- package/dist/sellable.d.ts +231 -2
- package/dist/sellable.js +342 -1
- package/dist/slug.d.ts +2 -0
- package/dist/slug.js +6 -2
- package/dist/staffed.d.ts +178 -0
- package/dist/staffed.js +287 -0
- package/dist/states.d.ts +74 -4
- package/dist/states.js +154 -58
- package/dist/stock.d.ts +129 -0
- package/dist/stock.js +205 -0
- package/dist/team.d.ts +28 -0
- package/dist/team.js +52 -0
- package/dist/testing.d.ts +22 -1
- package/dist/testing.js +47 -5
- package/dist/worked-on.d.ts +42 -0
- package/dist/worked-on.js +79 -0
- package/package.json +9 -1
- package/src/acknowledge.ts +100 -0
- package/src/agreements.ts +185 -0
- package/src/allowance.ts +98 -8
- package/src/automation-check.ts +120 -9
- package/src/automation.ts +78 -10
- package/src/behaviour.ts +26 -6
- package/src/calendar-entry.ts +258 -0
- package/src/capacity.ts +103 -2
- package/src/checklists.ts +118 -0
- package/src/contract.ts +514 -27
- package/src/discount.ts +408 -0
- package/src/document.ts +4 -2
- package/src/field-types.ts +5 -0
- package/src/formula/compile.ts +10 -0
- package/src/index.ts +17 -0
- package/src/intake.ts +380 -0
- package/src/journey-signals.ts +215 -0
- package/src/manifest.ts +1313 -66
- package/src/mine.ts +161 -0
- package/src/occupies.ts +192 -0
- package/src/questions.ts +681 -0
- package/src/recurring.ts +90 -9
- package/src/restricted-fields.ts +129 -0
- package/src/rich-text.ts +112 -0
- package/src/routine-mail.ts +1272 -0
- package/src/runtime.ts +25 -12
- package/src/screens.ts +91 -0
- package/src/sellable.ts +595 -1
- package/src/slug.ts +7 -2
- package/src/staffed.ts +474 -0
- package/src/states.ts +220 -64
- package/src/stock.ts +332 -0
- package/src/team.ts +83 -0
- package/src/testing.ts +70 -6
- package/src/worked-on.ts +134 -0
package/dist/team.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// A shipped pack's team (stage 56, ADR 0831; built with Programs' coach role, ADR 0889): the staff
|
|
2
|
+
// named on a live record about a Person look after that Person while the record is live. Its
|
|
3
|
+
// declaration, its manifest schema and its contract checks live here; what a pack role reaches
|
|
4
|
+
// through it (`looksAfter`) is the host's (packages/core/src/pack-role-looks-after.ts).
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const fieldName = z.string().max(40);
|
|
7
|
+
export const teamManifestSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
person: fieldName,
|
|
10
|
+
staff: z.array(fieldName).min(1).max(4),
|
|
11
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20).optional(),
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
/** Reports problems with `objects.<name>.team` through `contract`. */
|
|
15
|
+
export function checkObjectTeam(_m, name, object, contract) {
|
|
16
|
+
const team = object.team;
|
|
17
|
+
if (!team)
|
|
18
|
+
return;
|
|
19
|
+
const at = `objects.${name}.team`;
|
|
20
|
+
const own = (local) => Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
|
|
21
|
+
const person = own(team.person);
|
|
22
|
+
if (person?.type !== "relation" || person.to !== "person" || person.many) {
|
|
23
|
+
contract(`${at}.person`, `"${team.person}" must be a relation field (one record) to person`);
|
|
24
|
+
}
|
|
25
|
+
for (const [i, field] of team.staff.entries()) {
|
|
26
|
+
const staff = own(field);
|
|
27
|
+
if (staff?.type !== "user" || staff.many) {
|
|
28
|
+
contract(`${at}.staff.${i}`, `"${field}" must be a user field of ${name}`);
|
|
29
|
+
}
|
|
30
|
+
else if (staff.personApproves !== true) {
|
|
31
|
+
// Naming someone in it opens a pack role's reach to the Person (ADR 0889): a person's
|
|
32
|
+
// choice, never the assistant's, an automation's or code's on its own.
|
|
33
|
+
contract(`${at}.staff.${i}`, `"${field}" must be a field a person approves (personApproves): who reaches whose records is a person's to change`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (new Set(team.staff).size !== team.staff.length) {
|
|
37
|
+
contract(`${at}.staff`, "Name each field once");
|
|
38
|
+
}
|
|
39
|
+
if (team.live) {
|
|
40
|
+
const states = object.states;
|
|
41
|
+
const known = new Set(states ? (own(states.field)?.options ?? []).map((option) => option.value) : []);
|
|
42
|
+
if (!states) {
|
|
43
|
+
contract(`${at}.live`, `${name} has no states: leave live out (every record counts)`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
for (const [i, state] of team.live.entries()) {
|
|
47
|
+
if (!known.has(state))
|
|
48
|
+
contract(`${at}.live.${i}`, `"${state}" is not a state of ${name}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AutomationEvent, type AutomationTestStep, type NotificationSendInput } from "./automation.ts";
|
|
2
2
|
import { type AiModule, type Extension, type StartedBy } from "./contract.ts";
|
|
3
3
|
import type { ExtensionManifest, ManifestIssue, ValidateOptions } from "./manifest.ts";
|
|
4
|
+
import type { RoutineSendInput, RoutineSendResult } from "./routine-mail.ts";
|
|
4
5
|
type Values = Record<string, unknown> & {
|
|
5
6
|
id: string;
|
|
6
7
|
};
|
|
@@ -34,6 +35,17 @@ export interface TestHostOptions {
|
|
|
34
35
|
method: string;
|
|
35
36
|
args: unknown[];
|
|
36
37
|
}) => unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* What `ctx.routineMail.send` answers (ADR 0590). Every call is recorded in `routineSends`;
|
|
40
|
+
* with no fake each answers one email sent. The host decides who it goes to and what it says,
|
|
41
|
+
* so a pack's test checks which kind, record, message and values it asked for.
|
|
42
|
+
*/
|
|
43
|
+
routineMail?: (send: RoutineSendInput) => RoutineSendResult | Promise<RoutineSendResult>;
|
|
44
|
+
}
|
|
45
|
+
/** A routine email an automation asked the host to send (`ctx.routineMail.send`). */
|
|
46
|
+
export interface RoutineSend extends RoutineSendInput {
|
|
47
|
+
/** The step it was asked in. */
|
|
48
|
+
step: string | null;
|
|
37
49
|
}
|
|
38
50
|
/** A call a tool or automation made through `ctx.gatekeeper(name).call(...)`. */
|
|
39
51
|
export interface GatekeeperCall {
|
|
@@ -70,6 +82,13 @@ export interface AutomationRunOptions {
|
|
|
70
82
|
runId?: string;
|
|
71
83
|
/** `event.test`. Default false: the run writes to the in-memory store. */
|
|
72
84
|
test?: boolean;
|
|
85
|
+
/** `event.originalRunId`: the run a retry's chain began with (ADR 0574). */
|
|
86
|
+
originalRunId?: string;
|
|
87
|
+
/**
|
|
88
|
+
* How many times a `do` step that throws is run again, as the host's Workflow retries a step
|
|
89
|
+
* (the steps before it are not run again). Default 0: a throw fails the run.
|
|
90
|
+
*/
|
|
91
|
+
retries?: number;
|
|
73
92
|
}
|
|
74
93
|
export interface AutomationRunResult {
|
|
75
94
|
/** False when the declared conditions did not match the trigger record (nothing ran). */
|
|
@@ -135,6 +154,8 @@ export interface TestHost {
|
|
|
135
154
|
notifications: SentNotification[];
|
|
136
155
|
/** Every call through a gatekeeper module, in order. */
|
|
137
156
|
gatekeeperCalls: GatekeeperCall[];
|
|
157
|
+
/** Every routine email asked for, in order (ADR 0590). */
|
|
158
|
+
routineSends: RoutineSend[];
|
|
138
159
|
/**
|
|
139
160
|
* Runs automation `name` in memory, start to finish: conditions checked on the trigger
|
|
140
161
|
* record, waits skipped (and recorded), steps held to the declarations.
|
|
@@ -143,7 +164,7 @@ export interface TestHost {
|
|
|
143
164
|
/**
|
|
144
165
|
* Publishes a record of a publishable object as a person would (`record.publish`, which no
|
|
145
166
|
* tool may call): its content fields become the next version, which `record.version` reads.
|
|
146
|
-
* Returns the version's number.
|
|
167
|
+
* Refused outside the object's `publishable.publishIn` states. Returns the version's number.
|
|
147
168
|
*/
|
|
148
169
|
publish(object: string, id: string): number;
|
|
149
170
|
}
|
package/dist/testing.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// to the automation's declarations like the host does. Writes and notifications a step did not
|
|
21
21
|
// declare are listed in `undeclared`.
|
|
22
22
|
import { durationMs, notificationInput, } from "./automation.js";
|
|
23
|
+
import { DEFAULT_WAIT_TIMEOUT, NOTIFY_OPERATION } from "./automation-check.js";
|
|
23
24
|
import { GATEKEEPER_MODULES } from "./contract.js";
|
|
24
25
|
import { validateDocument } from "./document.js";
|
|
25
26
|
import { CORE_OBJECT_NAMES, toManifest, validateManifest } from "./manifest.js";
|
|
@@ -89,6 +90,13 @@ export function createTestHost(extension, options = {}) {
|
|
|
89
90
|
const row = table(object).get(id);
|
|
90
91
|
if (!row)
|
|
91
92
|
throw new ExtensionToolError("not_found", `No ${object} with id ${id}`);
|
|
93
|
+
// Only in the states the object lists (ADR 0810), as the host refuses.
|
|
94
|
+
const spec = manifest.objects[local];
|
|
95
|
+
const stateField = spec?.states?.field;
|
|
96
|
+
const publishIn = spec?.publishable?.publishIn;
|
|
97
|
+
if (publishIn && stateField && !publishIn.includes(String(row[stateField] ?? ""))) {
|
|
98
|
+
throw new ExtensionToolError("invalid_input", `${object} ${id} is ${String(row[stateField] ?? "in no state")}: it is published only when ${publishIn.join(" or ")}`);
|
|
99
|
+
}
|
|
92
100
|
const list = versions.get(`${object}|${id}`) ?? [];
|
|
93
101
|
const version = list.length + 1;
|
|
94
102
|
list.push({
|
|
@@ -333,7 +341,7 @@ export function createTestHost(extension, options = {}) {
|
|
|
333
341
|
const delivered = new Set();
|
|
334
342
|
let currentStep = null;
|
|
335
343
|
let observer = null;
|
|
336
|
-
builtIn[
|
|
344
|
+
builtIn[NOTIFY_OPERATION] = (input) => {
|
|
337
345
|
const notes = [];
|
|
338
346
|
const admins = users.filter((u) => u.role === "admin").map((u) => u.id);
|
|
339
347
|
const ids = [];
|
|
@@ -471,6 +479,28 @@ export function createTestHost(extension, options = {}) {
|
|
|
471
479
|
types: async () => "",
|
|
472
480
|
};
|
|
473
481
|
}
|
|
482
|
+
const routineSends = [];
|
|
483
|
+
if (has("routine-mail")) {
|
|
484
|
+
raw["routine-mail"] = {
|
|
485
|
+
send: async (input) => {
|
|
486
|
+
const send = structuredClone(input);
|
|
487
|
+
routineSends.push({ ...send, step: currentStep });
|
|
488
|
+
try {
|
|
489
|
+
const value = options.routineMail
|
|
490
|
+
? await options.routineMail(send)
|
|
491
|
+
: { sent: 1, held: 0, off: false, none: false };
|
|
492
|
+
return { ok: true, value };
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
const e = error;
|
|
496
|
+
return {
|
|
497
|
+
ok: false,
|
|
498
|
+
error: { code: e.code ?? "internal", message: e.message ?? String(error) },
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
};
|
|
503
|
+
}
|
|
474
504
|
if (has("ai")) {
|
|
475
505
|
const ai = {
|
|
476
506
|
summarise: async (text) => String(text).slice(0, 100),
|
|
@@ -513,6 +543,7 @@ export function createTestHost(extension, options = {}) {
|
|
|
513
543
|
const event = {
|
|
514
544
|
automation: `${manifest.id}.${name}`,
|
|
515
545
|
runId: run.runId ?? "arn_TEST",
|
|
546
|
+
...(run.originalRunId ? { originalRunId: run.originalRunId } : {}),
|
|
516
547
|
trigger: automation.trigger.type,
|
|
517
548
|
...(run.record && row
|
|
518
549
|
? {
|
|
@@ -555,7 +586,7 @@ export function createTestHost(extension, options = {}) {
|
|
|
555
586
|
const where = (stepName) => stepName ? `step ${stepName}` : "run (outside a step)";
|
|
556
587
|
const notificationsBefore = notifications.length;
|
|
557
588
|
observer = (operation, input, value) => {
|
|
558
|
-
if (operation ===
|
|
589
|
+
if (operation === NOTIFY_OPERATION) {
|
|
559
590
|
if (!declaresNotify(currentStep)) {
|
|
560
591
|
result.undeclared.push(`${where(currentStep)} sent a notification (not in its notifies)`);
|
|
561
592
|
}
|
|
@@ -582,7 +613,7 @@ export function createTestHost(extension, options = {}) {
|
|
|
582
613
|
const n = (notifyCounts.get(key) ?? 0) + 1;
|
|
583
614
|
notifyCounts.set(key, n);
|
|
584
615
|
const input = notificationInput(event, to, message, `${key}:${n}`);
|
|
585
|
-
const sent = await base.ops.call(
|
|
616
|
+
const sent = await base.ops.call(NOTIFY_OPERATION, input);
|
|
586
617
|
return { sent: sent.sent };
|
|
587
618
|
},
|
|
588
619
|
};
|
|
@@ -602,7 +633,17 @@ export function createTestHost(extension, options = {}) {
|
|
|
602
633
|
const first = calls.length;
|
|
603
634
|
currentStep = stepName;
|
|
604
635
|
try {
|
|
605
|
-
|
|
636
|
+
let value;
|
|
637
|
+
for (let attempt = 0;; attempt++) {
|
|
638
|
+
try {
|
|
639
|
+
value = await fn();
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
if (attempt >= (run.retries ?? 0))
|
|
644
|
+
throw error;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
606
647
|
result.steps.push({
|
|
607
648
|
name: stepName,
|
|
608
649
|
kind: "do",
|
|
@@ -631,7 +672,7 @@ export function createTestHost(extension, options = {}) {
|
|
|
631
672
|
name: stepName,
|
|
632
673
|
kind: "waitForEvent",
|
|
633
674
|
value,
|
|
634
|
-
skippedMs: durationMs((step.timeout ??
|
|
675
|
+
skippedMs: durationMs((step.timeout ?? DEFAULT_WAIT_TIMEOUT)),
|
|
635
676
|
calls: [],
|
|
636
677
|
});
|
|
637
678
|
return value;
|
|
@@ -665,6 +706,7 @@ export function createTestHost(extension, options = {}) {
|
|
|
665
706
|
records,
|
|
666
707
|
notifications,
|
|
667
708
|
gatekeeperCalls,
|
|
709
|
+
routineSends,
|
|
668
710
|
runAutomation,
|
|
669
711
|
publish,
|
|
670
712
|
async runTool(tool, input, options = {}) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ExtensionManifest, ObjectManifest } from "./manifest.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Time can be recorded against this record (ADR 0850): a job a tradesperson spends three hours
|
|
5
|
+
* on. A staff member's **time entry** is the one record of time worked; an entry against a shift
|
|
6
|
+
* (a `staffed` record) is against the roster, an entry against a `workedOn` record is against the
|
|
7
|
+
* job, and an entry against neither is other work. The record keeps no hours of its own: its
|
|
8
|
+
* time is the entries against it, read through the host (the same entries pay counts), never a
|
|
9
|
+
* second "time spent" record, and never in a `rec_*` view.
|
|
10
|
+
*
|
|
11
|
+
* - `live`: the states of the object's `states` in which time may be recorded against it. A
|
|
12
|
+
* record in any other state, or in the Trash, takes no new time.
|
|
13
|
+
* - `title`: a field of this object, shown on the entry, the timesheet and the export.
|
|
14
|
+
* - `kind` (optional): a relation (one record) of this object, shown as the export's kind.
|
|
15
|
+
* - `place` (optional): a field, or `relation.field`, shown beside the entry.
|
|
16
|
+
* - `readers`: a permission of this extension's tools: who reads the time recorded against a
|
|
17
|
+
* record (person, date, minutes and state; never a note).
|
|
18
|
+
* - `partOf` (optional), on a `staffed` object only (a scheduled visit to a site): a relation (one
|
|
19
|
+
* record) to another of this extension's objects that declares `workedOn` (the job); time
|
|
20
|
+
* recorded against the visit also counts to it.
|
|
21
|
+
*
|
|
22
|
+
* Only shipped packs and the org's own extensions declare it: time worked feeds pay.
|
|
23
|
+
*/
|
|
24
|
+
export interface WorkedOnSpec {
|
|
25
|
+
live: readonly string[];
|
|
26
|
+
title: string;
|
|
27
|
+
kind?: string;
|
|
28
|
+
place?: string;
|
|
29
|
+
readers: string;
|
|
30
|
+
partOf?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const workedOnManifestSchema: z.ZodObject<{
|
|
33
|
+
live: z.ZodArray<z.ZodString>;
|
|
34
|
+
title: z.ZodString;
|
|
35
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
36
|
+
place: z.ZodOptional<z.ZodString>;
|
|
37
|
+
readers: z.ZodString;
|
|
38
|
+
partOf: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
export type WorkedOnManifest = z.infer<typeof workedOnManifestSchema>;
|
|
41
|
+
/** Reports problems with `objects.<name>.workedOn` through `contract`. */
|
|
42
|
+
export declare function checkObjectWorkedOn(m: ExtensionManifest, name: string, object: ObjectManifest, contract: (path: string, message: string) => void): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The `workedOn` declaration (stage 58 step 1, ADR 0850): a record time can be recorded against (a
|
|
2
|
+
// job). Its manifest schema and contract checks live here; the host's side (the time entries,
|
|
3
|
+
// refused by the database when one person's overlap) is packages/core/src/staffing/time.ts.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const fieldName = z.string().max(40);
|
|
6
|
+
export const workedOnManifestSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
9
|
+
title: fieldName,
|
|
10
|
+
kind: fieldName.optional(),
|
|
11
|
+
place: z.string().max(81).optional(),
|
|
12
|
+
readers: z.string().max(80),
|
|
13
|
+
partOf: fieldName.optional(),
|
|
14
|
+
})
|
|
15
|
+
.strict();
|
|
16
|
+
/** Reports problems with `objects.<name>.workedOn` through `contract`. */
|
|
17
|
+
export function checkObjectWorkedOn(m, name, object, contract) {
|
|
18
|
+
const declared = object.workedOn;
|
|
19
|
+
if (!declared)
|
|
20
|
+
return;
|
|
21
|
+
const at = `objects.${name}.workedOn`;
|
|
22
|
+
const own = (o, local) => Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
23
|
+
// The states in which time may be recorded against it.
|
|
24
|
+
const states = object.states;
|
|
25
|
+
if (!states) {
|
|
26
|
+
contract(`${at}.live`, `${name} must declare states: time is recorded in some of them`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const field = own(object, states.field);
|
|
30
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
31
|
+
for (const state of declared.live) {
|
|
32
|
+
if (!values.has(state))
|
|
33
|
+
contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
34
|
+
}
|
|
35
|
+
if (new Set(declared.live).size !== declared.live.length) {
|
|
36
|
+
contract(`${at}.live`, "List each state once");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// What it is called, of what kind, and where.
|
|
40
|
+
const title = own(object, declared.title);
|
|
41
|
+
if (!title || title.many) {
|
|
42
|
+
contract(`${at}.title`, `"${declared.title}" must be a field (one value) of ${name}`);
|
|
43
|
+
}
|
|
44
|
+
if (declared.kind !== undefined) {
|
|
45
|
+
const kind = own(object, declared.kind);
|
|
46
|
+
if (kind?.type !== "relation" || kind.many) {
|
|
47
|
+
contract(`${at}.kind`, `"${declared.kind}" must be a relation field (one record) of ${name}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (declared.place !== undefined) {
|
|
51
|
+
const [first, second, ...rest] = declared.place.split(".");
|
|
52
|
+
const field = first === undefined ? undefined : own(object, first);
|
|
53
|
+
if (!field || rest.length || (second !== undefined && field.type !== "relation")) {
|
|
54
|
+
contract(`${at}.place`, `"${declared.place}" must be a field of ${name}, or a relation of it and a field of what it names`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Who reads its time: a permission this extension's tools declare.
|
|
58
|
+
const permissions = new Set(Object.values(m.tools).flatMap((t) => t.permission === undefined
|
|
59
|
+
? []
|
|
60
|
+
: typeof t.permission === "string"
|
|
61
|
+
? [t.permission]
|
|
62
|
+
: t.permission));
|
|
63
|
+
if (!declared.readers.startsWith(`${m.id}:`) || !permissions.has(declared.readers)) {
|
|
64
|
+
contract(`${at}.readers`, `"${declared.readers}" must be a permission of this extension's tools (${m.id}:<word>)`);
|
|
65
|
+
}
|
|
66
|
+
// What a staffed visit's time also counts to.
|
|
67
|
+
if (declared.partOf !== undefined) {
|
|
68
|
+
if (!object.staffed) {
|
|
69
|
+
contract(`${at}.partOf`, `Only a shift (an object that declares staffed) is part of a job`);
|
|
70
|
+
}
|
|
71
|
+
const via = own(object, declared.partOf);
|
|
72
|
+
const target = via?.type === "relation" && !via.many ? via.to : undefined;
|
|
73
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
74
|
+
const job = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
75
|
+
if (!job || local === name || !job.workedOn || job.workedOn.partOf !== undefined) {
|
|
76
|
+
contract(`${at}.partOf`, `"${declared.partOf}" must be a relation field (one record) to another of this extension's objects that declares workedOn`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/sdk",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
4
|
"license": "FSL-1.1-ALv2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
"types": "./dist/formula/index.d.ts",
|
|
22
22
|
"default": "./dist/formula/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./questions": {
|
|
25
|
+
"types": "./dist/questions.d.ts",
|
|
26
|
+
"default": "./dist/questions.js"
|
|
27
|
+
},
|
|
28
|
+
"./rich-text": {
|
|
29
|
+
"types": "./dist/rich-text.d.ts",
|
|
30
|
+
"default": "./dist/rich-text.js"
|
|
31
|
+
},
|
|
24
32
|
"./testing": {
|
|
25
33
|
"types": "./dist/testing.d.ts",
|
|
26
34
|
"default": "./dist/testing.js"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Read and understood (stage 38, ADR 0702): a publishable object may ask the staff who must read
|
|
2
|
+
// a record to confirm each version that matters, with one tap.
|
|
3
|
+
//
|
|
4
|
+
// publishable: {
|
|
5
|
+
// content: ["title", "body"],
|
|
6
|
+
// acknowledge: { who: "mustRead", manage: "knowledge:manage" },
|
|
7
|
+
// }
|
|
8
|
+
//
|
|
9
|
+
// `who` names a `document` field of the object's own, outside the content, whose schema is
|
|
10
|
+
// MUST_READ_SCHEMA: `{ everyone: true }`, or `{ everyone: false, roles: [...] }` where each entry
|
|
11
|
+
// is a staff role (`admin`, `member`, `viewer`), a pack role (`rostering.team`) or a pack
|
|
12
|
+
// permission an admin grants (`bookings:desk`). The host reads it on the day, against each
|
|
13
|
+
// account's role, pack role and grants. `manage` names a restricted, grantable permission of the
|
|
14
|
+
// extension's tools: who holds it (and admins) reads who has confirmed, and changes who must read
|
|
15
|
+
// once a record has been published.
|
|
16
|
+
import type { DocumentSchema } from "./document.ts";
|
|
17
|
+
|
|
18
|
+
/** What an entry of `roles` may be: a staff role, `<pack>.<role>` or `<pack>:<permission>`. */
|
|
19
|
+
export const MUST_READ_ENTRY_RE =
|
|
20
|
+
/^(?:admin|member|viewer|[a-z][a-z0-9]{1,29}[.:][a-zA-Z0-9]{1,40})$/;
|
|
21
|
+
|
|
22
|
+
/** The most entries one "must read" lists. */
|
|
23
|
+
export const MUST_READ_MAX = 50;
|
|
24
|
+
|
|
25
|
+
/** The one schema of an acknowledged object's "must read" field. */
|
|
26
|
+
export const MUST_READ_SCHEMA: DocumentSchema = {
|
|
27
|
+
root: {
|
|
28
|
+
type: "object",
|
|
29
|
+
fields: {
|
|
30
|
+
everyone: { type: "boolean", description: "Every staff account must read it" },
|
|
31
|
+
roles: {
|
|
32
|
+
type: "array",
|
|
33
|
+
max: MUST_READ_MAX,
|
|
34
|
+
optional: true,
|
|
35
|
+
description: "Staff roles, pack roles and granted pack permissions that must read it",
|
|
36
|
+
of: {
|
|
37
|
+
type: "text",
|
|
38
|
+
min: 1,
|
|
39
|
+
max: 71,
|
|
40
|
+
chars: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// --- The pack's words and what else the host guards (stage 38 step 5, ADR 0706) -----------------
|
|
48
|
+
//
|
|
49
|
+
// acknowledge: {
|
|
50
|
+
// who: "mustRead",
|
|
51
|
+
// manage: "knowledge:manage",
|
|
52
|
+
// managed: ["reviewEvery"],
|
|
53
|
+
// owner: "owner",
|
|
54
|
+
// notices: {
|
|
55
|
+
// asked: { title: "Please read: {record}" },
|
|
56
|
+
// reminder: { title: "Still to read: {record}", afterDays: 7 },
|
|
57
|
+
// outstanding: { title: "Not yet confirmed: {record}" },
|
|
58
|
+
// welcome: { title: "Procedures to read" },
|
|
59
|
+
// },
|
|
60
|
+
// }
|
|
61
|
+
//
|
|
62
|
+
// `managed` names more fields of the object's own, outside the content, that the host guards as
|
|
63
|
+
// it guards who must read: a person's to change, never an AI actor's, and once the record has
|
|
64
|
+
// been published, only an admin's or a holder of `manage`. `owner` names a `user` field: who
|
|
65
|
+
// looks after the record, told each week who has not confirmed it. `notices` are the pack's
|
|
66
|
+
// words; the host sends them, to the people only it can work out (who must read, who has not), and
|
|
67
|
+
// `{record}` stands for the record's published title. Each notice is optional: left out, none.
|
|
68
|
+
|
|
69
|
+
/** One notice's words: `{record}` in either stands for the record's title. */
|
|
70
|
+
export interface AcknowledgeNotice {
|
|
71
|
+
title: string;
|
|
72
|
+
body?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The notices the host sends for an acknowledged object (ADR 0706). */
|
|
76
|
+
export interface AcknowledgeNotices {
|
|
77
|
+
/** A version that asks everyone goes live: to everyone who must read it, once per version. */
|
|
78
|
+
asked?: AcknowledgeNotice;
|
|
79
|
+
/** Still to read `afterDays` after it became theirs to read: to that person, once per version. */
|
|
80
|
+
reminder?: AcknowledgeNotice & { afterDays: number };
|
|
81
|
+
/** Each week while anyone has not confirmed: to the record's `owner`. */
|
|
82
|
+
outstanding?: AcknowledgeNotice;
|
|
83
|
+
/** A new staff account with records to read: to that person, once, listing them. */
|
|
84
|
+
welcome?: AcknowledgeNotice;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `publishable.acknowledge`: see the comment above and ADRs 0702 and 0706. */
|
|
88
|
+
export interface AcknowledgeSpec {
|
|
89
|
+
who: string;
|
|
90
|
+
manage: string;
|
|
91
|
+
managed?: readonly string[];
|
|
92
|
+
owner?: string;
|
|
93
|
+
notices?: AcknowledgeNotices;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The longest a notice's title and body may be. */
|
|
97
|
+
export const ACKNOWLEDGE_NOTICE_TITLE_MAX = 120;
|
|
98
|
+
export const ACKNOWLEDGE_NOTICE_BODY_MAX = 600;
|
|
99
|
+
/** The longest a reminder may wait, in days. */
|
|
100
|
+
export const ACKNOWLEDGE_REMINDER_MAX_DAYS = 60;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// The `agreements` behaviour (stage 44, ADR 0641): an object marks an agreement point, a place a
|
|
2
|
+
// business may need a person to have agreed to its documents first (buying a membership, making a
|
|
3
|
+
// booking). The pack names the point; the business attaches its own documents to it in the admin.
|
|
4
|
+
// Nothing is needed anywhere until a person publishes a document and attaches it. Its declaration,
|
|
5
|
+
// its manifest schema and its contract checks live here; the host's side is
|
|
6
|
+
// packages/core/src/agreements/.
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import type { ExtensionManifest, ObjectManifest } from "./manifest.ts";
|
|
9
|
+
import { moveOrigins } from "./states.ts";
|
|
10
|
+
|
|
11
|
+
/** Kinds of agreement document a business writes (`care` is the platform's own, stage 43). */
|
|
12
|
+
export const AGREEMENT_KINDS = ["terms", "waiver", "health", "guardian", "other"] as const;
|
|
13
|
+
export type AgreementKind = (typeof AGREEMENT_KINDS)[number];
|
|
14
|
+
|
|
15
|
+
/** A point's name: a lowercase word, shared by objects that mean the same place. */
|
|
16
|
+
export const AGREEMENT_POINT_RE = /^[a-z][a-z0-9_]{1,39}$/;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An agreement point (ADR 0641).
|
|
20
|
+
*
|
|
21
|
+
* - `point`: the point's name. Objects may share one (a membership plan and a pass type are both
|
|
22
|
+
* "buying a membership or a pass").
|
|
23
|
+
* - `label`: what the admin shows when attaching documents.
|
|
24
|
+
* - `suggests`: kinds of document the admin offers first. A suggestion, never a requirement.
|
|
25
|
+
* - `enter` and `person`: for a record a caller makes (a booking), the states whose entry is checked
|
|
26
|
+
* and the relation to the Person it is for. Left out, the point is checked where the object is
|
|
27
|
+
* bought (a `sellable` object).
|
|
28
|
+
* - `keeps`: with `enter`, for an object without `claims`, the states a record keeps its entry in
|
|
29
|
+
* (a ticket valid or used at the door), as `claims` says which states hold a place: a record
|
|
30
|
+
* created in one is asked, and a move between two of them is the same entry and is not (staff
|
|
31
|
+
* undoing a check-in). Left out, only `enter`'s states count.
|
|
32
|
+
* - `importMovesOver`: with `enter`, a record the record import makes (a person's door:
|
|
33
|
+
* `cos courses import`) is someone moving over from another system, and is not asked (stage 44,
|
|
34
|
+
* issue #281). A later import that gives it to another Person or makes it count again is asked.
|
|
35
|
+
* Left out, an import is asked as any caller's write.
|
|
36
|
+
* - `inlineStep`: the pack's own screens (its blocks that buy or book this object) show what is
|
|
37
|
+
* due and let a person agree on the way (stage 44 step 5). Left out, nothing on the pack's
|
|
38
|
+
* screens can agree, so a document attached there refuses every purchase or booking until the
|
|
39
|
+
* person agrees elsewhere (My agreements, the desk, paper): the admin is warned when attaching.
|
|
40
|
+
*
|
|
41
|
+
* In stage 44 step 1 the declaration is inert: it is checked and listed, and documents can be
|
|
42
|
+
* attached to it; the host asks it from step 3.
|
|
43
|
+
*/
|
|
44
|
+
export interface AgreementsSpec {
|
|
45
|
+
point: string;
|
|
46
|
+
label: string;
|
|
47
|
+
suggests?: readonly AgreementKind[];
|
|
48
|
+
enter?: readonly string[];
|
|
49
|
+
person?: string;
|
|
50
|
+
keeps?: readonly string[];
|
|
51
|
+
importMovesOver?: boolean;
|
|
52
|
+
inlineStep?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const agreementsManifestSchema = z.object({
|
|
56
|
+
point: z.string().max(40),
|
|
57
|
+
label: z.string().min(1).max(80),
|
|
58
|
+
suggests: z.array(z.enum(AGREEMENT_KINDS)).max(AGREEMENT_KINDS.length).optional(),
|
|
59
|
+
enter: z.array(z.string().max(40)).min(1).max(20).optional(),
|
|
60
|
+
person: z.string().max(40).optional(),
|
|
61
|
+
keeps: z.array(z.string().max(40)).min(1).max(20).optional(),
|
|
62
|
+
importMovesOver: z.boolean().optional(),
|
|
63
|
+
inlineStep: z.boolean().optional(),
|
|
64
|
+
});
|
|
65
|
+
export type AgreementsManifest = z.infer<typeof agreementsManifestSchema>;
|
|
66
|
+
|
|
67
|
+
/** The states an object's `states` declaration names. */
|
|
68
|
+
function stateNames(object: ObjectManifest): Set<string> {
|
|
69
|
+
const states = object.states;
|
|
70
|
+
if (!states) return new Set();
|
|
71
|
+
return new Set([
|
|
72
|
+
states.initial,
|
|
73
|
+
...states.moves.flatMap((move) => [...moveOrigins(move), move.to]),
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The contract checks of an object's `agreements` declaration. */
|
|
78
|
+
export function checkObjectAgreements(
|
|
79
|
+
_m: ExtensionManifest,
|
|
80
|
+
name: string,
|
|
81
|
+
object: ObjectManifest,
|
|
82
|
+
contract: (path: string, message: string) => void,
|
|
83
|
+
): void {
|
|
84
|
+
const declared = object.agreements;
|
|
85
|
+
if (!declared) return;
|
|
86
|
+
const path = `objects.${name}.agreements`;
|
|
87
|
+
if (!AGREEMENT_POINT_RE.test(declared.point)) {
|
|
88
|
+
contract(`${path}.point`, "point must be a lowercase word (letters, digits, _), 2 to 40 long");
|
|
89
|
+
}
|
|
90
|
+
if (declared.suggests && new Set(declared.suggests).size !== declared.suggests.length) {
|
|
91
|
+
contract(`${path}.suggests`, "suggests lists each kind once");
|
|
92
|
+
}
|
|
93
|
+
if (!declared.enter) {
|
|
94
|
+
if (declared.person !== undefined) {
|
|
95
|
+
contract(`${path}.person`, "person is for a point checked when a record enters a state");
|
|
96
|
+
}
|
|
97
|
+
if (declared.keeps !== undefined) {
|
|
98
|
+
contract(`${path}.keeps`, "keeps is for a point checked when a record enters a state");
|
|
99
|
+
}
|
|
100
|
+
if (declared.importMovesOver !== undefined) {
|
|
101
|
+
contract(
|
|
102
|
+
`${path}.importMovesOver`,
|
|
103
|
+
"importMovesOver is for a point checked when a record enters a state",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (!object.sellable) {
|
|
107
|
+
contract(
|
|
108
|
+
path,
|
|
109
|
+
`${name} is not sellable: a point on it needs enter (the states whose entry is checked) and person`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const states = stateNames(object);
|
|
115
|
+
if (!object.states) {
|
|
116
|
+
contract(`${path}.enter`, `enter names states, and ${name} declares none`);
|
|
117
|
+
} else {
|
|
118
|
+
for (const [i, state] of declared.enter.entries()) {
|
|
119
|
+
if (!states.has(state))
|
|
120
|
+
contract(`${path}.enter.${i}`, `"${state}" is not a state of ${name}`);
|
|
121
|
+
}
|
|
122
|
+
for (const [i, state] of (declared.keeps ?? []).entries()) {
|
|
123
|
+
if (!states.has(state))
|
|
124
|
+
contract(`${path}.keeps.${i}`, `"${state}" is not a state of ${name}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (declared.keeps && object.claims) {
|
|
128
|
+
contract(`${path}.keeps`, `${name} holds places (claims): its claims say which states keep it`);
|
|
129
|
+
}
|
|
130
|
+
const person = declared.person;
|
|
131
|
+
const field =
|
|
132
|
+
person !== undefined && Object.hasOwn(object.fields, person)
|
|
133
|
+
? object.fields[person]
|
|
134
|
+
: undefined;
|
|
135
|
+
if (field?.type !== "relation" || field.many || field.to !== "person") {
|
|
136
|
+
contract(`${path}.person`, `person must be a relation field (one record) to person`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A health-note list (stage 44, ADR 0643): records of this object make a list a person on the
|
|
142
|
+
* staff reads (a class's bookings), and the host may mark, beside each Person on it, a yes on
|
|
143
|
+
* their current health form, nothing else. `list` is the relation to the list's own record (the
|
|
144
|
+
* class), `person` the relation to the Person. The host reads the People itself; pack code names
|
|
145
|
+
* only the list's record (`agreement.listHealthNotes`), inside a tool a person called.
|
|
146
|
+
*/
|
|
147
|
+
export interface HealthNotesSpec {
|
|
148
|
+
list: string;
|
|
149
|
+
person: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const healthNotesManifestSchema = z.object({
|
|
153
|
+
list: z.string().max(40),
|
|
154
|
+
person: z.string().max(40),
|
|
155
|
+
});
|
|
156
|
+
export type HealthNotesManifest = z.infer<typeof healthNotesManifestSchema>;
|
|
157
|
+
|
|
158
|
+
/** The contract checks of an object's `healthNotes` declaration. */
|
|
159
|
+
export function checkObjectHealthNotes(
|
|
160
|
+
m: ExtensionManifest,
|
|
161
|
+
name: string,
|
|
162
|
+
object: ObjectManifest,
|
|
163
|
+
contract: (path: string, message: string) => void,
|
|
164
|
+
): void {
|
|
165
|
+
const declared = object.healthNotes;
|
|
166
|
+
if (!declared) return;
|
|
167
|
+
const path = `objects.${name}.healthNotes`;
|
|
168
|
+
const one = (field: string) =>
|
|
169
|
+
Object.hasOwn(object.fields, field) ? object.fields[field] : undefined;
|
|
170
|
+
const list = one(declared.list);
|
|
171
|
+
const self = `${m.id}.${name}`;
|
|
172
|
+
if (
|
|
173
|
+
list?.type !== "relation" ||
|
|
174
|
+
list.many ||
|
|
175
|
+
list.to === "person" ||
|
|
176
|
+
list.to === self ||
|
|
177
|
+
list.to === name
|
|
178
|
+
) {
|
|
179
|
+
contract(`${path}.list`, "list must be a relation field (one record) to another object");
|
|
180
|
+
}
|
|
181
|
+
const person = one(declared.person);
|
|
182
|
+
if (person?.type !== "relation" || person.many || person.to !== "person") {
|
|
183
|
+
contract(`${path}.person`, "person must be a relation field (one record) to person");
|
|
184
|
+
}
|
|
185
|
+
}
|