@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.
Files changed (105) hide show
  1. package/dist/acknowledge.d.ts +38 -0
  2. package/dist/acknowledge.js +30 -0
  3. package/dist/agreements.d.ts +80 -0
  4. package/dist/agreements.js +109 -0
  5. package/dist/allowance.d.ts +47 -5
  6. package/dist/allowance.js +59 -4
  7. package/dist/automation-check.d.ts +6 -1
  8. package/dist/automation-check.js +93 -8
  9. package/dist/automation.d.ts +62 -4
  10. package/dist/automation.js +32 -9
  11. package/dist/behaviour.js +25 -6
  12. package/dist/calendar-entry.d.ts +97 -0
  13. package/dist/calendar-entry.js +180 -0
  14. package/dist/capacity.d.ts +69 -0
  15. package/dist/capacity.js +63 -2
  16. package/dist/checklists.d.ts +41 -0
  17. package/dist/checklists.js +75 -0
  18. package/dist/contract.d.ts +527 -26
  19. package/dist/contract.js +21 -3
  20. package/dist/discount.d.ts +135 -0
  21. package/dist/discount.js +281 -0
  22. package/dist/document.d.ts +2 -1
  23. package/dist/document.js +2 -1
  24. package/dist/field-types.d.ts +1 -1
  25. package/dist/field-types.js +5 -0
  26. package/dist/formula/compile.d.ts +15 -0
  27. package/dist/formula/compile.js +9 -0
  28. package/dist/index.d.ts +17 -0
  29. package/dist/index.js +17 -0
  30. package/dist/intake.d.ts +134 -0
  31. package/dist/intake.js +239 -0
  32. package/dist/journey-signals.d.ts +89 -0
  33. package/dist/journey-signals.js +151 -0
  34. package/dist/manifest.d.ts +1060 -60
  35. package/dist/manifest.js +1111 -61
  36. package/dist/mine.d.ts +45 -0
  37. package/dist/mine.js +119 -0
  38. package/dist/occupies.d.ts +64 -0
  39. package/dist/occupies.js +122 -0
  40. package/dist/questions.d.ts +179 -0
  41. package/dist/questions.js +514 -0
  42. package/dist/recurring.d.ts +33 -4
  43. package/dist/recurring.js +50 -3
  44. package/dist/restricted-fields.d.ts +15 -0
  45. package/dist/restricted-fields.js +97 -0
  46. package/dist/rich-text.d.ts +22 -0
  47. package/dist/rich-text.js +91 -0
  48. package/dist/routine-mail.d.ts +400 -0
  49. package/dist/routine-mail.js +955 -0
  50. package/dist/runtime.d.ts +5 -11
  51. package/dist/runtime.js +21 -11
  52. package/dist/screens.d.ts +3 -0
  53. package/dist/screens.js +74 -0
  54. package/dist/sellable.d.ts +231 -2
  55. package/dist/sellable.js +342 -1
  56. package/dist/slug.d.ts +2 -0
  57. package/dist/slug.js +6 -2
  58. package/dist/staffed.d.ts +178 -0
  59. package/dist/staffed.js +287 -0
  60. package/dist/states.d.ts +74 -4
  61. package/dist/states.js +154 -58
  62. package/dist/stock.d.ts +129 -0
  63. package/dist/stock.js +205 -0
  64. package/dist/team.d.ts +28 -0
  65. package/dist/team.js +52 -0
  66. package/dist/testing.d.ts +22 -1
  67. package/dist/testing.js +47 -5
  68. package/dist/worked-on.d.ts +42 -0
  69. package/dist/worked-on.js +79 -0
  70. package/package.json +9 -1
  71. package/src/acknowledge.ts +100 -0
  72. package/src/agreements.ts +185 -0
  73. package/src/allowance.ts +98 -8
  74. package/src/automation-check.ts +120 -9
  75. package/src/automation.ts +78 -10
  76. package/src/behaviour.ts +26 -6
  77. package/src/calendar-entry.ts +258 -0
  78. package/src/capacity.ts +103 -2
  79. package/src/checklists.ts +118 -0
  80. package/src/contract.ts +514 -27
  81. package/src/discount.ts +408 -0
  82. package/src/document.ts +4 -2
  83. package/src/field-types.ts +5 -0
  84. package/src/formula/compile.ts +10 -0
  85. package/src/index.ts +17 -0
  86. package/src/intake.ts +380 -0
  87. package/src/journey-signals.ts +215 -0
  88. package/src/manifest.ts +1313 -66
  89. package/src/mine.ts +161 -0
  90. package/src/occupies.ts +192 -0
  91. package/src/questions.ts +681 -0
  92. package/src/recurring.ts +90 -9
  93. package/src/restricted-fields.ts +129 -0
  94. package/src/rich-text.ts +112 -0
  95. package/src/routine-mail.ts +1272 -0
  96. package/src/runtime.ts +25 -12
  97. package/src/screens.ts +91 -0
  98. package/src/sellable.ts +595 -1
  99. package/src/slug.ts +7 -2
  100. package/src/staffed.ts +474 -0
  101. package/src/states.ts +220 -64
  102. package/src/stock.ts +332 -0
  103. package/src/team.ts +83 -0
  104. package/src/testing.ts +70 -6
  105. package/src/worked-on.ts +134 -0
@@ -1,13 +1,27 @@
1
1
  import type { z } from "zod";
2
+ import type { AcknowledgeSpec } from "./acknowledge.ts";
3
+ import type { AgreementsSpec, HealthNotesSpec } from "./agreements.ts";
2
4
  import type { AllowanceSpec } from "./allowance.ts";
3
5
  import type { AutomationSpec } from "./automation.ts";
6
+ import type { CalendarEntrySpec } from "./calendar-entry.ts";
4
7
  import type { CapacitySpec, ClaimsSpec } from "./capacity.ts";
8
+ import type { ChecklistsSpec } from "./checklists.ts";
9
+ import type { DiscountSpec } from "./discount.ts";
5
10
  import type { DocumentPathSpec, DocumentSchema } from "./document.ts";
6
11
  import type { FieldTypeName } from "./field-types.ts";
12
+ import type { IntakeSpec } from "./intake.ts";
13
+ import type { JourneySignalSpec } from "./journey-signals.ts";
14
+ import type { MineSpec } from "./mine.ts";
15
+ import type { OccupiesSpec } from "./occupies.ts";
7
16
  import type { RecurringScheduleSpec } from "./recurring.ts";
17
+ import type { RoutineMailModule, RoutineMailSpec } from "./routine-mail.ts";
8
18
  import type { SellableSpec } from "./sellable.ts";
19
+ import type { StaffedSpec } from "./staffed.ts";
9
20
  import type { StatesSpec } from "./states.ts";
21
+ import type { StockMovesSpec, StockSpec } from "./stock.ts";
22
+ import type { TeamSpec } from "./team.ts";
10
23
  import type { UniqueSpec } from "./unique.ts";
24
+ import type { WorkedOnSpec } from "./worked-on.ts";
11
25
  /** The contract version this SDK writes. The host accepts this and the previous version. */
12
26
  export declare const CONTRACT_VERSION = 1;
13
27
  /** Contract versions a host built with this SDK runs (current and previous, ADR 0005). */
@@ -20,7 +34,7 @@ export declare const SUPPORTED_CONTRACT_VERSIONS: readonly number[];
20
34
  export declare const GATEKEEPER_MODULES: readonly ["google", "microsoft", "slack", "slack-post", "mcp", "email", "email-send", "zoominfo", "websearch", "webhook", "fake"];
21
35
  export type GatekeeperModuleName = (typeof GATEKEEPER_MODULES)[number];
22
36
  /** Host modules an extension can ask for (ADR 0025). There is no HTTP module. */
23
- export declare const HOST_MODULES: readonly ["ops", "storage", "log", "ai", "google", "microsoft", "slack", "slack-post", "mcp", "email", "email-send", "zoominfo", "websearch", "webhook", "fake"];
37
+ export declare const HOST_MODULES: readonly ["ops", "storage", "log", "ai", "routine-mail", "google", "microsoft", "slack", "slack-post", "mcp", "email", "email-send", "zoominfo", "websearch", "webhook", "fake"];
24
38
  export type HostModuleName = (typeof HOST_MODULES)[number];
25
39
  /** Risk classes an extension tool may declare (schema and extension risks are host-only). */
26
40
  export declare const TOOL_RISKS: readonly ["read", "write", "bulk-write", "destructive"];
@@ -118,6 +132,13 @@ export type FieldSpec = (FieldBase & {
118
132
  */
119
133
  type: "richText";
120
134
  maxBytes?: number;
135
+ }) | (Omit<FieldBase, "default" | "defaultSetting"> & {
136
+ /**
137
+ * A checklist (stage 45 step 4b, ADR 0650): one of the business's checklist templates
138
+ * (Settings → Checklists), by id; only an active one may be picked. Named by an object's
139
+ * `checklists.template`, it gives each record a run of it to tick off.
140
+ */
141
+ type: "checklist";
121
142
  }) | (Omit<FieldBase, "default" | "defaultSetting"> & {
122
143
  /**
123
144
  * A record's address (stage 28, ADR 0442): lowercase letters and digits in words joined
@@ -189,11 +210,30 @@ export interface ObjectSpec {
189
210
  capacity?: CapacitySpec;
190
211
  /** Something that can be bought, and what a paid line grants (see SellableSpec, ADR 0435). */
191
212
  sellable?: SellableSpec;
213
+ /** Things counted on a shelf, sold from a ledger the host keeps (see StockSpec, ADR 0680). */
214
+ stock?: StockSpec;
215
+ /** A record's state moves stock: received adds, a write-off removes, a count sets (see StockMovesSpec, ADR 0681). */
216
+ stockMoves?: StockMovesSpec;
192
217
  /**
193
218
  * Uses a record holds (a pass, a membership), or a record that spends one (a booking): see
194
219
  * AllowanceSpec, ADRs 0493 and 0494. The host counts and refuses a spend past the limit.
195
220
  */
196
221
  allowance?: AllowanceSpec;
222
+ /**
223
+ * Records that are discounts (see DiscountSpec, ADR 0693): a code or a member's price, worked out
224
+ * by the host when it prices an order, one deal per order, limits kept by the database.
225
+ */
226
+ discount?: DiscountSpec;
227
+ /**
228
+ * An agreement point (see AgreementsSpec, ADR 0641): where a business may need a person to have
229
+ * agreed to its documents first. The business attaches the documents; the pack names the place.
230
+ */
231
+ agreements?: AgreementsSpec;
232
+ /**
233
+ * A health-note list (see HealthNotesSpec, ADR 0643): this object's records make a list staff
234
+ * read (a class's bookings), on which the host may mark a yes on someone's health form.
235
+ */
236
+ healthNotes?: HealthNotesSpec;
197
237
  /** A fixed state machine (see StatesSpec, ADR 0425). An object has stages or states, not both. */
198
238
  states?: StatesSpec;
199
239
  /**
@@ -211,6 +251,48 @@ export interface ObjectSpec {
211
251
  * ADR 0500): a timetable's series and its classes.
212
252
  */
213
253
  recurring?: RecurringScheduleSpec;
254
+ /**
255
+ * A shift (see StaffedSpec, ADR 0621): who works the record, when, and on what kind of work.
256
+ * The host refuses, in the database, one account on two overlapping shifts, and answers each
257
+ * write with its warnings (away, not qualified, no one on it).
258
+ */
259
+ staffed?: StaffedSpec;
260
+ /**
261
+ * Time can be recorded against the record (see WorkedOnSpec, ADR 0850): a job. Its time is the
262
+ * staff's time entries against it, read through the host; it keeps no hours of its own.
263
+ */
264
+ workedOn?: WorkedOnSpec;
265
+ /**
266
+ * Who on the staff looks after the Person a record is about (see TeamSpec, ADR 0831): the
267
+ * accounts in its user fields while it is live. A pack role's `looksAfter` reaches records
268
+ * only for those People (ADR 0889). Only shipped extensions and an org's own may declare it.
269
+ */
270
+ team?: TeamSpec;
271
+ /**
272
+ * A claim on a thing (see OccupiesSpec, ADR 0765): while live, the record takes the room (or
273
+ * chair, or hall) it names for its time. The host refuses, in the database, a second live
274
+ * record on the same thing at an overlapping time, whatever object it is.
275
+ */
276
+ occupies?: OccupiesSpec;
277
+ /**
278
+ * Events in the customer's private calendar feed (see CalendarEntrySpec, ADR 0891): the record's
279
+ * start, end, public title and place as paths the customer may read, and the states in which it
280
+ * shows. The host reads them as the customer, through the visibility seam, and shows a live
281
+ * dependant's to their guardian. Only shipped extensions may declare it.
282
+ */
283
+ calendarEntry?: CalendarEntrySpec;
284
+ /**
285
+ * The public-write door (see IntakeSpec, ADR 0720): a form the public answers, the submission
286
+ * the host makes from the answers, or another pack's record a form may also make. Only the
287
+ * host's `intake.submit` creates a submission; nothing else opens a write to the public.
288
+ */
289
+ intake?: IntakeSpec;
290
+ /**
291
+ * A checklist the record's person ticks off (see ChecklistsSpec, ADR 0650): a run of the
292
+ * template its `template` field names, made by the host, ticked by the person (or by someone who
293
+ * rosters, for them), never changed once done, read only by the person and those who roster.
294
+ */
295
+ checklists?: ChecklistsSpec;
214
296
  /**
215
297
  * The record's owner: a `user` field of this object (ADR 0246, stage 14). Assignment rules set
216
298
  * it when a record is created without one, and stage 14's visibility policies read it.
@@ -229,9 +311,9 @@ export interface ObjectSpec {
229
311
  * What the public may read of this object (ADR 0438): the fields in `read`, of the records that
230
312
  * meet `when`. Deny by default: left out, the public sees nothing of it, and a record that does
231
313
  * not meet `when` is not found. A signed-in customer reads it too, unless the object declares a
232
- * `customer` (an object declares one or the other). The public reaches it only through a pack's
233
- * tool open to them (`public.list`, `public.get`). Only shipped extensions and an org's own may
234
- * declare it.
314
+ * `customer` (an object declares one or the other, except a publishable object with an author:
315
+ * see `publishable`). The public reaches it only through a pack's tool open to them
316
+ * (`public.list`, `public.get`). Only shipped extensions and an org's own may declare it.
235
317
  */
236
318
  public?: PublicSpec;
237
319
  /**
@@ -269,6 +351,14 @@ export interface ObjectSpec {
269
351
  * publish permission, never an AI actor); `record.versions` and `record.version` read them;
270
352
  * `record.restoreVersion` copies one back into the working copy. Editing the working copy
271
353
  * never changes a version. Records get read-only `publishedVersion` and `publishedAt`.
354
+ *
355
+ * With an author (ADR 0810): a publishable object may declare a `customer`, the record's author
356
+ * (a review's writer). The author reads and writes their working copy through `customer`; the
357
+ * public reads only the published version through `public` (which may then be declared too),
358
+ * listed by `content.list` and never by an address (no `slug`). The fields in `customer.write`
359
+ * are the author's alone: staff, the assistant, MCP clients, automations and the extension's own
360
+ * code are refused them on every path, so a published version is always the author's words.
361
+ * Staff still publish, unpublish and move the record's states.
272
362
  */
273
363
  publishable?: PublishableSpec;
274
364
  /** Position in the sidebar among extension objects (lower first). Default 100. */
@@ -304,7 +394,8 @@ export type StageType = (typeof STAGE_TYPES)[number];
304
394
  * operations, so it applies to every actor: people, MCP clients, Code Mode, extensions.
305
395
  *
306
396
  * - Entering a stage needs the stage's required fields and `requiredByType[type]` to have values;
307
- * otherwise the write is refused with a structured error naming the missing fields.
397
+ * otherwise the write is refused with a structured error naming the missing fields. A read-only
398
+ * field may be required: a fact the host sets, which no caller can supply (ADR 0750).
308
399
  * - `group` must match the stage's group; a record given only a group starts in its first stage.
309
400
  * - `probability.field` follows the stage's default probability unless it was set by hand
310
401
  * (`probability.overridden` is then true; clearing that flag resets it).
@@ -509,6 +600,11 @@ export interface ExtensionContext {
509
600
  ai: AiModule;
510
601
  /** A gatekeeper declared in permissions.modules, e.g. `ctx.gatekeeper("email-send")`. */
511
602
  gatekeeper(name: GatekeeperModuleName): GatekeeperModule;
603
+ /**
604
+ * Sends a routine email this extension declares (ADR 0590): in an automation of a shipped
605
+ * extension only. Declare the "routine-mail" module.
606
+ */
607
+ routineMail: RoutineMailModule;
512
608
  /** Who started this tool, from the host (ADR 0436). Absent in automations. */
513
609
  caller?: StartedBy;
514
610
  }
@@ -526,7 +622,8 @@ export interface ToolSpec<In extends z.ZodType = z.ZodType, Out extends z.ZodTyp
526
622
  */
527
623
  recordAction?: RecordActionSpec;
528
624
  /**
529
- * Who may call the tool: a non-empty subset of `staff`, `customer`, `public`. Left out, staff
625
+ * Who may call the tool: a non-empty subset of `staff`, `customer`, `public`, or `device` alone
626
+ * (an enrolled device whose device role holds the tool's `permission`, ADR 0781). Left out, staff
530
627
  * only. A tool open to `customer` or `public` must have risk `read` or `write`. Called by a
531
628
  * customer, the tool runs as that customer: `ctx.ops` reaches only their own records, through
532
629
  * `my.list`, `my.get`, `my.create` and `my.update`. Only shipped extensions and an org's own
@@ -544,9 +641,14 @@ export interface ToolSpec<In extends z.ZodType = z.ZodType, Out extends z.ZodTyp
544
641
  * a role of this extension to hold (`roles`, ADR 0436). Admins and members hold it as they hold
545
642
  * any tool (a viewer only when the tool's risk is `read`); a staff account given one of this
546
643
  * extension's roles holds it only when the role lists it. Only shipped extensions and an org's
547
- * own may declare it.
644
+ * own may declare it. A tool open to `device` names the permission a device role holds
645
+ * (`deviceRoles`, ADR 0781), and no staff role, grant or restriction names it.
646
+ *
647
+ * Or a list: any one of them opens the tool (ADR 0600). Bookings' day view is the coach's and
648
+ * the desk's (`["bookings:coach", "bookings:desk"]`): a coach reaches it through the role, held
649
+ * to the role's limits, and a coach granted the desk's permission reaches it through the grant.
548
650
  */
549
- permission?: string;
651
+ permission?: string | readonly string[];
550
652
  /**
551
653
  * Only a person may call it (ADR 0512): the assistant, an MCP client, an automation and other
552
654
  * extensions' code are refused by the host, as a core operation with `actors: ["human"]` is.
@@ -555,6 +657,49 @@ export interface ToolSpec<In extends z.ZodType = z.ZodType, Out extends z.ZodTyp
555
657
  * any extension may declare it.
556
658
  */
557
659
  humanOnly?: boolean;
660
+ /**
661
+ * A person approves it (ADR 0552): a person on the staff calls it as any tool, and anyone else's
662
+ * call (the assistant, an MCP client, an automation) always waits in the approval queue for a
663
+ * person, whatever the approval policy or preset says, and runs when a person approves it. For
664
+ * what an AI may propose but a person decides (cancelling a class). Staff only, and not a read.
665
+ */
666
+ personApproves?: boolean;
667
+ /**
668
+ * A tool naming both a permission one of this extension's roles holds and a grantable one
669
+ * (ADR 0600) says so on purpose: an account given the grant calls it without the role's limits
670
+ * (Bookings' `day`, the desk's any day). Without it, such a tool is refused by the check, so a
671
+ * grantable permission added to a role's own tool never lifts the role's limits by accident.
672
+ */
673
+ grantLiftsRoleLimits?: boolean;
674
+ /**
675
+ * Every staff account may call it, pack roles included (ADR 0652): a cleaner's `rostering.team`,
676
+ * a coach, the door, as well as admins and members. For a tool whose host operation decides
677
+ * who may do what by a rule of its own (Daily checklists' `today` and `tick`: the checklist's
678
+ * own "who may do it"), so no role or grant has to name it. A person's own act (`humanOnly`),
679
+ * for staff only, with no `permission` or `corePermission`. Only shipped extensions and an
680
+ * org's own may declare it.
681
+ */
682
+ anyStaff?: boolean;
683
+ /**
684
+ * A core permission a staff caller needs instead of `records:read` or `records:write` (ADR
685
+ * 0652): one an admin may grant one by one (`checklists:write`). Admins and those granted it
686
+ * call the tool; nobody else does, and no pack role reaches it (a pack role holds no core
687
+ * permission). For staff only, with no `permission`. Only shipped extensions and an org's own
688
+ * may declare it.
689
+ */
690
+ corePermission?: string;
691
+ /**
692
+ * Fields of the input the audit log never keeps (ADR 0626): a note about someone's leave. The
693
+ * call is still audited, with those fields shown as redacted. It only hides more, so any
694
+ * extension may declare it.
695
+ */
696
+ redact?: readonly string[];
697
+ /**
698
+ * Keys of the tool's answer the host never keeps (ADR 0628): a secret shown once, such as a
699
+ * calendar feed's address. Never in the audit log, an approval's stored result or a stored
700
+ * reply an HTTP retry replays. It only hides more, so any extension may declare it.
701
+ */
702
+ redactResult?: readonly string[];
558
703
  handler(input: z.output<In>, ctx: ExtensionContext): Promise<z.input<Out>> | z.input<Out>;
559
704
  }
560
705
  /**
@@ -573,12 +718,72 @@ export interface RoleSpec {
573
718
  permissions: readonly string[];
574
719
  /** Objects of this extension (`<id>.<object>`) whose records the role may read. */
575
720
  read: readonly string[];
721
+ /**
722
+ * Objects whose records the role reaches only when a datetime on them falls on the
723
+ * day it is on (ADR 0553), by object: the moment, and optionally its end and zone, read through
724
+ * one relation at most: `{ "bookings.class": { at: "startsAt", until: "endsAt", zone:
725
+ * "timezone" } }`. A record is today's when its start falls on today's date in its zone (the
726
+ * organisation's when empty), or it has started and not yet ended. The host holds it on every
727
+ * call the account makes and every call of a tool run it started. Other staff are not limited.
728
+ */
729
+ today?: Readonly<Record<string, string | {
730
+ at: string;
731
+ until?: string;
732
+ zone?: string;
733
+ }>>;
734
+ /**
735
+ * Objects whose records the role reaches only for the People its holder looks after (ADR
736
+ * 0889), by object: its relation (one record) to `person`. Its holder looks after a Person
737
+ * when a live record of one of this extension's objects that declares a `team` names them in
738
+ * its staff fields (a client's assignment naming the coach). The host holds it on every call
739
+ * the account makes and every call of a tool run it started: a list holds only those People's
740
+ * records, a read or a change of another's is not found, a new record must be about one of
741
+ * them, and any other operation naming the object is refused. Other staff are not limited.
742
+ */
743
+ looksAfter?: Readonly<Record<string, string>>;
744
+ /**
745
+ * Objects whose records the role reaches only through a live record of this extension naming
746
+ * its holder (ADR 0755), by object: that record's object (`through`), its user field naming the
747
+ * holder (`who`), the relations from it to the object reached (`path`), the states in which it
748
+ * counts (`live`) and a window around its datetimes (`within`). Jobs' crew reaches the jobs on
749
+ * which it has a crew place, from a week before the visit to a week after. The host holds it on
750
+ * every call the account makes and every call of a tool run it started: a list holds only those
751
+ * records, a read or a change of another is not found, and so is a write naming another in a
752
+ * relation, a new record is refused, a change to a field that decides the reach is refused, and
753
+ * so is any other operation. Every field deciding it is `personApproves`. Other staff are not
754
+ * limited.
755
+ */
756
+ mine?: Readonly<Record<string, MineSpec>>;
757
+ }
758
+ /**
759
+ * A device role an extension declares (ADR 0781): what an enrolled device given it may do, with
760
+ * no person signed in. A human admin enrols a device for the role (`device.enrol { use: "role",
761
+ * role: "<id>.<name>" }`); its credential then calls exactly the tools whose permission the role
762
+ * lists (each open to `device` only) and `device.heartbeat`, and nothing else. It reads no
763
+ * record: its tools return only what their outputs declare. Bookings' check-in tablet:
764
+ * `{ permissions: ["bookings:checkin"], screen: { block: "bookings-checkin-tablet", export:
765
+ * "CheckInTablet" } }`. Only a shipped pack may declare one: a runtime extension's fails `cos ext
766
+ * check` and install, and is ignored at run time.
767
+ */
768
+ export interface DeviceRoleSpec {
769
+ label: string;
770
+ /** What the device is for, shown to the admin who enrols it. */
771
+ description: string;
772
+ /** Permissions of this extension's device tools (`<id>:<word>`) the role holds. */
773
+ permissions: readonly string[];
774
+ /** The device's screen: a web block of this pack and the component it exports. */
775
+ screen: {
776
+ block: string;
777
+ export: string;
778
+ };
576
779
  }
577
780
  /**
578
781
  * Who started a tool (ADR 0436), set by the host from the session it verified and never from the
579
- * input: a staff user, a signed-in customer or the public. A tool's own operation calls run as
580
- * the extension (or as the customer, ADR 0414); this is for recording who asked, such as who
581
- * checked a ticket in. Absent in automations and in a manifest evaluation.
782
+ * input: a staff user, a signed-in customer, the public, or an enrolled device holding one of
783
+ * this extension's device roles (ADR 0781: the device's id and the name an admin gave it, "Front
784
+ * door tablet"). A tool's own operation calls run as the extension (or as the customer, ADR
785
+ * 0414); this is for recording who asked, such as who checked a ticket in, or that a booking was
786
+ * ticked at the door. Absent in automations and in a manifest evaluation.
582
787
  */
583
788
  export type StartedBy = {
584
789
  readonly kind: "staff";
@@ -588,26 +793,47 @@ export type StartedBy = {
588
793
  readonly kind: "customer";
589
794
  } | {
590
795
  readonly kind: "public";
796
+ } | {
797
+ readonly kind: "device";
798
+ readonly deviceId: string;
799
+ readonly name: string;
591
800
  };
592
- /** Who may call a tool. `staff` when nothing is declared (ADR 0402). */
593
- export declare const TOOL_AUDIENCES: readonly ["staff", "customer", "public"];
801
+ /**
802
+ * Who may call a tool. `staff` when nothing is declared (ADR 0402). `device` (ADR 0781): an
803
+ * enrolled device whose device role holds the tool's permission, on the desk origin only; a tool
804
+ * open to `device` is open to nobody else.
805
+ */
806
+ export declare const TOOL_AUDIENCES: readonly ["staff", "customer", "public", "device"];
594
807
  export type ToolAudience = (typeof TOOL_AUDIENCES)[number];
595
808
  /**
596
- * What the public may read of an object (ADR 0438). `when` is a condition on a state (a select
597
- * field) of the record itself, or, with `via`, of the record one of its relations points to: an
598
- * event while it is `on_sale`; a ticket type while its event is.
809
+ * One condition of a `public` or `signedIn` declaration's `when` (ADRs 0438 and 0689): a state (a
810
+ * select field) of the record itself, or, with `via`, of the record one of its relations points
811
+ * to; or, `via` alone (in `public` only), that the record it points to is one the public reads
812
+ * (published, if its object is publishable, and meeting its own `when`): a variant while its item
813
+ * is published.
814
+ */
815
+ export type PublicCondition = {
816
+ /** A relation of this object, to another object of this extension: test that record. */
817
+ via?: string;
818
+ /** A select field (of this record, or of the one `via` points to). */
819
+ field: string;
820
+ /** The values for which the record is public. */
821
+ in: readonly string[];
822
+ } | {
823
+ /** A relation of this object, to another object of this extension that declares `public`. */
824
+ via: string;
825
+ field?: undefined;
826
+ in?: undefined;
827
+ };
828
+ /**
829
+ * What the public may read of an object (ADR 0438). `when` is a condition, or a list of up to
830
+ * three that must all hold (ADR 0689): an event while it is `on_sale`; a ticket type while its
831
+ * event is; a variant while it is `active` and its item is published.
599
832
  */
600
833
  export interface PublicSpec {
601
834
  read: readonly string[];
602
835
  /** Left out, every live record is public (a catalogue item). */
603
- when?: {
604
- /** A relation of this object, to another object of this extension: test that record. */
605
- via?: string;
606
- /** A select field (of this record, or of the one `via` points to). */
607
- field: string;
608
- /** The values for which the record is public. */
609
- in: readonly string[];
610
- };
836
+ when?: PublicCondition | readonly PublicCondition[];
611
837
  }
612
838
  /**
613
839
  * What a customer reads of a record their own record points to (ADR 0439): see
@@ -673,7 +899,9 @@ export interface PublishableSpec {
673
899
  /**
674
900
  * The record's address (stage 28, ADR 0442): a `slug` field of the object's own, not in
675
901
  * `content`. The public reads a record by it (`content.get`); a published record whose slug
676
- * changes keeps the old one as a redirect. Needed to declare `public`.
902
+ * changes keeps the old one as a redirect. Left out on an object the public reads, its records
903
+ * are listed only (`content.list`) and `content.get` finds none (ADR 0810). An object with an
904
+ * author (a `customer`) has none.
677
905
  */
678
906
  slug?: string;
679
907
  /**
@@ -682,6 +910,33 @@ export interface PublishableSpec {
682
910
  * Set, it is kept: an imported post keeps its date.
683
911
  */
684
912
  date?: string;
913
+ /**
914
+ * The states in which the record may be published (ADR 0810): values of the object's `states`
915
+ * field. A publish (or a scheduled one coming due) of a record in any other state is refused,
916
+ * and a record that moves out of them is unpublished in the same batch. A review without its
917
+ * author's consent is never published. Left out, any state.
918
+ */
919
+ publishIn?: readonly string[];
920
+ /**
921
+ * Read and understood (stage 38, ADR 0702): the staff who must read a record confirm its
922
+ * current version with one tap, and a person publishing a later version says whether it asks
923
+ * them again (`readAgain`) or is a small fix. `who` names a `document` field of the object's
924
+ * own, outside `content`, with the schema `MUST_READ_SCHEMA`. `manage` names a permission of
925
+ * this extension's tools that is restricted and grantable: who holds it, and admins, read who
926
+ * has confirmed and change who must read a published record. Not on an object the public or a
927
+ * customer reads. `managed`, `owner` and `notices` (ADR 0706): more fields guarded as who
928
+ * must read is, the user field told weekly who has not confirmed, and the pack's words for the
929
+ * notices the host sends (`AcknowledgeSpec` in `acknowledge.ts`).
930
+ */
931
+ acknowledge?: AcknowledgeSpec;
932
+ /**
933
+ * Staff read (stage 38, ADR 0701): every staff account reads the current published version,
934
+ * never the working copy, through `content.staffGet`, `content.staffList` and `content.search`,
935
+ * pack-role accounts (a coach, a cleaner, the door) included, which read nothing else outside
936
+ * their own pack. What they read is the `content` fields and the slug. Editors still edit the
937
+ * working copy on the record's page.
938
+ */
939
+ staffRead?: boolean;
685
940
  }
686
941
  /** An object's customer: see `ObjectSpec.customer`. */
687
942
  export interface CustomerSpec {
@@ -700,6 +955,24 @@ export interface CustomerSpec {
700
955
  * any tool.
701
956
  */
702
957
  createOnly?: readonly string[];
958
+ /**
959
+ * Whether a customer may put one of their own records in the Trash, through a pack tool's
960
+ * `my.delete` (ADR 0414, amended 2026-11-24): a logged set ticked by mistake. Left out, they
961
+ * cannot. A reviewed change, as `customer` is.
962
+ */
963
+ delete?: boolean;
964
+ /**
965
+ * The family link (ADR 0540): a signed-in guardian also reads their live dependants' records of
966
+ * this object (a child's bookings), with the same `read` fields. With `write: true` they also
967
+ * make records for a dependant (`my.create`'s `forPersonId`) and change the dependant's, with
968
+ * the same `write` fields. `madeBy` names a relation to one person the host sets, on every
969
+ * record a customer makes, to the Person who made it. Staff link guardians to dependants; the
970
+ * seam checks the link in every read and write. A reviewed change, as `customer` is.
971
+ */
972
+ guardians?: {
973
+ write?: boolean;
974
+ madeBy?: string;
975
+ };
703
976
  }
704
977
  /** A tool shown as a button on a record page. */
705
978
  export interface RecordActionSpec {
@@ -801,13 +1074,241 @@ export interface ExtensionSpec {
801
1074
  automations?: Record<string, AutomationSpec<any>>;
802
1075
  /** Fixed staff roles an admin can give to a staff account (ADR 0436). */
803
1076
  roles?: Record<string, RoleSpec>;
1077
+ /**
1078
+ * Device roles an admin can enrol a device for (ADR 0781): the business's own tablet, signed in
1079
+ * as nobody, calling only the tools the role holds (`audiences: ["device"]`).
1080
+ */
1081
+ deviceRoles?: Record<string, DeviceRoleSpec>;
804
1082
  /**
805
1083
  * Permissions of this extension's tools (`<id>:<word>`) a human admin may grant to a staff
806
1084
  * account one by one (ADR 0449), on top of its role: a coach who is a member granted the
807
1085
  * permission of a tool a member could not otherwise call. Only shipped extensions and an org's
808
- * own may declare them.
1086
+ * own may declare them. An account holding one of the installed packs' roles may be granted
1087
+ * them too: what it holds is the role and its grants, added up (ADR 0600). A permission one of
1088
+ * this extension's roles holds cannot be grantable (a grant never lifts a role's limits).
809
1089
  */
810
1090
  grantable?: readonly string[];
1091
+ /**
1092
+ * Routine mail (ADR 0590): fixed emails about this extension's records that the host sends
1093
+ * without a person's approval, each a kind an admin can turn off. Only shipped extensions may
1094
+ * declare it, and only their automations send it (`ctx.routineMail.send`).
1095
+ */
1096
+ routineMail?: Record<string, RoutineMailSpec>;
1097
+ /**
1098
+ * Journey signals (stage 53, ADR 0802): moments about a Person that a journey can start or stop
1099
+ * on, each a record of this extension's objects created or entering a state, and the field
1100
+ * naming its Person (`started: { label: "Membership started", object: "membership" }`). The
1101
+ * host records the last time each Person had each one, in the write's own batch. Only shipped
1102
+ * extensions may declare them.
1103
+ */
1104
+ journeySignals?: Record<string, JourneySignalSpec>;
1105
+ /**
1106
+ * What each grantable permission gives, in plain words, shown to the admin who ticks it
1107
+ * (`{ "bookings:desk": "Works the front desk: ..." }`). Absent: the tools it opens are listed.
1108
+ */
1109
+ grantableLabels?: Readonly<Record<string, string>>;
1110
+ /**
1111
+ * Permissions of this extension's tools (`<id>:<word>`) that are **restricted** (stage 45, ADR
1112
+ * 0625): a tool naming one is held by admins, and by a staff account a human admin granted it
1113
+ * (declare it `grantable` too), and by nobody else. Without it, every member holds every tool
1114
+ * (a tool's own permission only adds a way in). For pay totals and rostering other people. A
1115
+ * tool naming a restricted permission names only restricted ones; no role holds one; it is
1116
+ * never called by an automation or another extension's code. Only shipped extensions and an
1117
+ * org's own may declare them.
1118
+ */
1119
+ restricted?: readonly string[];
1120
+ /**
1121
+ * The roster's rules this extension sets for the host (stage 45, ADR 0626): `rosters`, the
1122
+ * restricted permission whose holders roster other people's shifts (with admins: they are the
1123
+ * rosterers the host tells and lets roster), and the number settings of this extension the
1124
+ * host's rules read (the offer cut-off in minutes, the uncovered window in days). Only a
1125
+ * shipped extension or an org's own may declare it.
1126
+ */
1127
+ staffing?: StaffingRulesSpec;
1128
+ /**
1129
+ * The staff screens of a shipped pack (stage 47, ADR 0660), by key: each a web block of this
1130
+ * pack that the product's admin builds in and shows to whoever could call every tool in its
1131
+ * `opens`. Only a shipped pack may declare them: its blocks are code in the repository,
1132
+ * reviewed like the rest of it. A runtime extension declaring `screens` fails `cos ext check`
1133
+ * and install, and the key is ignored at run time.
1134
+ */
1135
+ screens?: Record<string, ScreenSpec>;
1136
+ /**
1137
+ * The numbers a shipped pack adds to the owner's Today (stage 60, ADR 0870), by key: each a
1138
+ * read-only query over `rec_*` views that the host runs for the business's local day and shows
1139
+ * to whoever could call every tool in its `opens`. Not `today`: that names a pack role's limit
1140
+ * (ADR 0553). Only a shipped pack may declare them, at most 8; a runtime extension declaring
1141
+ * `todayItems` fails `cos ext check` and install, and the key is ignored at run time.
1142
+ */
1143
+ todayItems?: Record<string, TodayItemSpec>;
1144
+ /**
1145
+ * The pack's sections of My account (stage 48, ADR 0710), by key: the customer's own area on
1146
+ * the business's website and in its app. Each names a web and a native block of this pack, the
1147
+ * objects whose records mean "this customer has some" (`has`), and where it sits. The host lists
1148
+ * a section to a customer only when they, or a child linked to them where the object opens to
1149
+ * guardians, have one of those records (`me.portal`); `cos add web-account` copies the blocks and
1150
+ * writes the wiring. Only a shipped pack may declare sections: a runtime extension declaring
1151
+ * `portal` fails `cos ext check` and install, and the key is ignored at run time.
1152
+ */
1153
+ portal?: Record<string, PortalSectionSpec>;
1154
+ }
1155
+ /**
1156
+ * One section of My account a shipped pack adds (stage 48, ADR 0710). The client app's shell
1157
+ * renders `export` of the block, giving it the pack's hooks under the pack's id (`bookings`,
1158
+ * `memberships`) and the page's `returnUrl`: every other prop of the component is optional.
1159
+ */
1160
+ export interface PortalSectionSpec {
1161
+ /** The section's heading: "Memberships and passes". */
1162
+ label: string;
1163
+ /** The website's block: a web block of this pack, and the component it exports. */
1164
+ web?: {
1165
+ block: string;
1166
+ export: string;
1167
+ };
1168
+ /** The app's block: a native block of this pack (`<id>-native-<name>`), and its component. */
1169
+ native?: {
1170
+ block: string;
1171
+ export: string;
1172
+ };
1173
+ /**
1174
+ * Where it sits among the sections, lower first: 1 to 59, so a pack's come before the base
1175
+ * sections (Orders at 60 onward).
1176
+ */
1177
+ order: number;
1178
+ /**
1179
+ * This pack's objects (`<id>.<object>`) that declare a customer, whose records mean the
1180
+ * customer has something here: the section shows only then. Never empty: a page anyone may
1181
+ * open ("Buy a pass") is a page the client links to, not a section.
1182
+ */
1183
+ has: readonly string[];
1184
+ }
1185
+ /** How a Today item's value is shown. Money is never a pack's: it is the host's (stage 52). */
1186
+ export declare const TODAY_ITEM_FORMATS: readonly ["count", "percent"];
1187
+ export type TodayItemFormat = (typeof TODAY_ITEM_FORMATS)[number];
1188
+ /** What a Today item's value is compared with: the same time yesterday or a week ago, or nothing. */
1189
+ export declare const TODAY_ITEM_COMPARES: readonly ["yesterday", "lastWeek", "none"];
1190
+ export type TodayItemCompare = (typeof TODAY_ITEM_COMPARES)[number];
1191
+ /** The parameters the host binds into a Today item's SQL: the local day `[from, to)` and now. */
1192
+ export declare const TODAY_ITEM_PARAMS: readonly ["today_from", "today_to", "now"];
1193
+ /**
1194
+ * One number a shipped pack adds to Today (stage 60, ADR 0870). The host binds `:today_from`,
1195
+ * `:today_to` (the business's local day, as instants) and `:now`, runs `sql` under the widget
1196
+ * rules (one `SELECT` or `WITH` over `rec_*` views, bound parameters, row and time limits) and
1197
+ * shows its one column, `value`. For the comparison it binds the earlier day's window instead.
1198
+ */
1199
+ export interface TodayItemSpec {
1200
+ /** The card's label: "Came today". */
1201
+ label: string;
1202
+ /** Where it sits among every item on Today (lower first). Default 100. */
1203
+ order?: number;
1204
+ /** `count` or `percent`. No money format: a money number is a Finance reports figure. */
1205
+ format: TodayItemFormat;
1206
+ /** Read-only SQL returning one row with one column, `value`. */
1207
+ sql: string;
1208
+ /** Default `yesterday`. */
1209
+ compare?: TodayItemCompare;
1210
+ /** When the card needs attention: its value above or below a number. Left out, never. */
1211
+ attention?: {
1212
+ above: number;
1213
+ } | {
1214
+ below: number;
1215
+ };
1216
+ /**
1217
+ * The rows behind the number, at most 50: read-only SQL with the same parameters returning a
1218
+ * display column (`label`), optionally a secondary line (`detail`) and the id of a record of
1219
+ * `record.object` (one of this pack's objects, `person` or `organisation`) in column
1220
+ * `record.id`. Names and record ids only: never notes, health answers, pay or leave.
1221
+ */
1222
+ rows?: {
1223
+ sql: string;
1224
+ label: string;
1225
+ detail?: string;
1226
+ record: {
1227
+ object: string;
1228
+ id: string;
1229
+ };
1230
+ };
1231
+ /**
1232
+ * This pack's own tools, every one of which the viewer must be able to call to see the item,
1233
+ * as a screen's `opens` (ADR 0660). At least one is for staff only.
1234
+ */
1235
+ opens: readonly string[];
1236
+ /** On the web, a card opens this screen of the pack (stage 47) rather than its rows. */
1237
+ web?: {
1238
+ screen: string;
1239
+ };
1240
+ }
1241
+ /**
1242
+ * One staff screen of a shipped pack (stage 47, ADR 0660). The admin renders `export` of the web
1243
+ * block `block` with the pack's hooks, inside its shell; the host lists the screen for a viewer
1244
+ * only when they could call every tool in `opens` (`screens.mine`).
1245
+ */
1246
+ export interface ScreenSpec {
1247
+ /** The screen's name in the navigation and on its page: "Front desk". */
1248
+ label: string;
1249
+ /** A web block of this pack (`packs/<id>/blocks/<block>/`), never a native one. */
1250
+ block: string;
1251
+ /** The component the block exports that renders the screen: "Desk". */
1252
+ export: string;
1253
+ /**
1254
+ * Where it sits in the admin's navigation: a section headed `group`, in `order`. Left out, the
1255
+ * screen is reached only from a record (`record`) or a link.
1256
+ */
1257
+ nav?: {
1258
+ group: string;
1259
+ order?: number;
1260
+ };
1261
+ /**
1262
+ * The tools that decide who may open the screen: this pack's own, every one of which the viewer
1263
+ * must be able to call. Name those that decide (the screen's main read and the write its main
1264
+ * action makes), not every tool it calls: the host refuses the rest, and the block shows its own
1265
+ * state for that. "Could call these tools" is the gate, not a separate permission. At least one
1266
+ * is for staff only (never a customer's or the public's tool as the only gate), unless `writes`
1267
+ * gates the screen.
1268
+ */
1269
+ opens?: readonly string[];
1270
+ /**
1271
+ * Objects of this pack the screen writes through the host's record operations rather than a
1272
+ * tool (a builder saving a course): the viewer must be able to write them (`record.update`), so
1273
+ * a viewer or a pack role never gets the screen. Gates beside `opens`; one of the two names
1274
+ * something.
1275
+ */
1276
+ writes?: readonly string[];
1277
+ /**
1278
+ * A record screen: a tab on this object's record page (one of this pack's objects, `person` or
1279
+ * `organisation`), given the record's id as the prop `as`. With `nav` too, it is also listed in
1280
+ * the navigation, opened without a record: its block then chooses one itself.
1281
+ */
1282
+ record?: {
1283
+ object: string;
1284
+ as: string;
1285
+ };
1286
+ }
1287
+ /** The roster's rules an extension sets for the host (ADR 0626): see `ExtensionSpec.staffing`. */
1288
+ export interface StaffingRulesSpec {
1289
+ /** A restricted permission of this extension's tools: who holds it (and admins) roster. */
1290
+ rosters: string;
1291
+ /**
1292
+ * A restricted, grantable permission of this extension's tools: who holds it (and admins) read
1293
+ * who is counted for pay, the pay periods' totals, and lock, reopen and export them (ADR 0627).
1294
+ */
1295
+ pays?: string;
1296
+ /**
1297
+ * Settings of this extension the host reads, each `personApproves`; the host's defaults when
1298
+ * left out.
1299
+ */
1300
+ settings?: {
1301
+ /** Minutes before a shift starts that offers close (default 60). A number setting. */
1302
+ offerCutoffMinutes?: string;
1303
+ /** Days ahead a shift with nobody on it is warned about and told (default 14). A number. */
1304
+ uncoveredDays?: string;
1305
+ /** The pay period: a select of `weekly`, `fortnightly`, `monthly` (ADR 0627). */
1306
+ payPeriod?: string;
1307
+ /** The local date (YYYY-MM-DD) one weekly or fortnightly period starts: a text setting. */
1308
+ payPeriodStart?: string;
1309
+ /** The day of the month (1 to 28) a monthly period starts: a number setting. */
1310
+ payPeriodDay?: string;
1311
+ };
811
1312
  }
812
1313
  declare const EXTENSION: unique symbol;
813
1314
  export type Extension<E extends ExtensionSpec = ExtensionSpec> = E & {