@composable-os/cli 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 (173) hide show
  1. package/dist/{accounts-X4CKM3HL.js → accounts-GOCNY6WI.js} +17 -14
  2. package/dist/app-RPRZMLU5.js +43 -0
  3. package/dist/app-upload-YJVEKZC6.js +198 -0
  4. package/dist/{blocks-YWDHEBOK.js → blocks-DE4RRWPJ.js} +207 -25
  5. package/dist/{chunk-VY64DMQO.js → chunk-2B6YUYZV.js} +23576 -11674
  6. package/dist/{run-RT2HVWMK.js → chunk-2CCHB37H.js} +9 -146
  7. package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
  8. package/dist/chunk-5D7BDF4Y.js +141 -0
  9. package/dist/{chunk-WO6D3XP3.js → chunk-6CM3WZG5.js} +13 -2470
  10. package/dist/chunk-CIBJGB5H.js +962 -0
  11. package/dist/chunk-EPDTPGZJ.js +330 -0
  12. package/dist/{chunk-LLULPZAJ.js → chunk-HAYF4G5V.js} +66 -23
  13. package/dist/chunk-HCG6T53D.js +61904 -0
  14. package/dist/chunk-JX4IFWNT.js +330 -0
  15. package/dist/{chunk-A4NTSYWV.js → chunk-KFHKNXGH.js} +786 -386
  16. package/dist/chunk-KMFMD52Z.js +13276 -0
  17. package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
  18. package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
  19. package/dist/{chunk-LJFLENFC.js → chunk-Q6Y45DY6.js} +25 -2
  20. package/dist/{chunk-Y7JZFSTQ.js → chunk-QJZGYJVV.js} +823 -44
  21. package/dist/{chunk-6VXHPKGG.js → chunk-QQ3YSL5F.js} +172 -16
  22. package/dist/chunk-RGKJKC5T.js +876 -0
  23. package/dist/{chunk-IFG4FRW5.js → chunk-RSEWEFAV.js} +12 -2
  24. package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
  25. package/dist/{chunk-CP6BXI6F.js → chunk-U72NEGCT.js} +8818 -3829
  26. package/dist/{chunk-WC5LHBBA.js → chunk-Z4IKF23A.js} +11 -7
  27. package/dist/chunk-Z7OVQ6BC.js +713 -0
  28. package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
  29. package/dist/{cli-2DFENR62.js → cli-OKQHHSOE.js} +17 -23
  30. package/dist/{cli-YIOVSKOD.js → cli-VYSD2S4Z.js} +231 -82
  31. package/dist/cli.js +5 -5
  32. package/dist/{client-repo-PRU3VCQQ.js → client-repo-NNUCHQ2Y.js} +7 -5
  33. package/dist/create.js +5 -5
  34. package/dist/{fields-2NC7LSYE.js → fields-GTHE6TTS.js} +27 -3
  35. package/dist/gateway-DPPEQZT4.js +25 -0
  36. package/dist/grants-6JY4XZO7.js +27 -0
  37. package/dist/invoke-MRONRZ5Q.js +33 -0
  38. package/dist/moves-UAUCMWL5.js +36 -0
  39. package/dist/{order-PUWD65BC.js → order-RKLGT74L.js} +2 -2
  40. package/dist/{person-WIQQ7ITU.js → person-YOZTFV4Q.js} +11 -11
  41. package/dist/plan-on-sale-H4F26YIN.js +26 -0
  42. package/dist/platform/migrations/0610_waitlists.sql +54 -0
  43. package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
  44. package/dist/platform/migrations/0650_person_links.sql +90 -0
  45. package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
  46. package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
  47. package/dist/platform/migrations/0730_practitioners.sql +79 -0
  48. package/dist/platform/migrations/0750_routine_mail.sql +98 -0
  49. package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
  50. package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
  51. package/dist/platform/migrations/0811_staff_time.sql +109 -0
  52. package/dist/platform/migrations/0812_staff_offers.sql +112 -0
  53. package/dist/platform/migrations/0813_pay_periods.sql +241 -0
  54. package/dist/platform/migrations/0814_staff_feed.sql +47 -0
  55. package/dist/platform/migrations/0815_checklists.sql +237 -0
  56. package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
  57. package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
  58. package/dist/platform/migrations/0850_agreements.sql +271 -0
  59. package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
  60. package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
  61. package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
  62. package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
  63. package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
  64. package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
  65. package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
  66. package/dist/platform/migrations/0910_routine_messages.sql +99 -0
  67. package/dist/platform/migrations/0911_texts.sql +60 -0
  68. package/dist/platform/migrations/0913_contact_consent.sql +93 -0
  69. package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
  70. package/dist/platform/migrations/0930_stock_movements.sql +95 -0
  71. package/dist/platform/migrations/0931_stock_low.sql +25 -0
  72. package/dist/platform/migrations/0932_order_delivery.sql +78 -0
  73. package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
  74. package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
  75. package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
  76. package/dist/platform/migrations/0953_discount_uses.sql +183 -0
  77. package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
  78. package/dist/platform/migrations/0970_published_text.sql +59 -0
  79. package/dist/platform/migrations/0971_publish_acks.sql +68 -0
  80. package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
  81. package/dist/platform/migrations/1010_intake_links.sql +148 -0
  82. package/dist/platform/migrations/1030_invoices.sql +747 -0
  83. package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
  84. package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
  85. package/dist/platform/migrations/1090_staff_hours.sql +43 -0
  86. package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
  87. package/dist/platform/migrations/1092_client_guard.sql +26 -0
  88. package/dist/platform/migrations/1095_thing_time.sql +70 -0
  89. package/dist/platform/migrations/1130_devices.sql +162 -0
  90. package/dist/platform/migrations/1135_person_codes.sql +88 -0
  91. package/dist/platform/migrations/1150_finance_periods.sql +316 -0
  92. package/dist/platform/migrations/1151_payouts.sql +202 -0
  93. package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
  94. package/dist/platform/migrations/1170_journeys.sql +318 -0
  95. package/dist/platform/migrations/1171_person_birthday.sql +52 -0
  96. package/dist/platform/migrations/1175_person_signals.sql +29 -0
  97. package/dist/platform/migrations/1190_restricted_values.sql +25 -0
  98. package/dist/platform/migrations/1230_note_levels.sql +113 -0
  99. package/dist/platform/migrations/1231_person_carers.sql +33 -0
  100. package/dist/platform/migrations/1232_note_kinds.sql +122 -0
  101. package/dist/platform/migrations/1270_time_entries.sql +145 -0
  102. package/dist/platform/migrations/1271_leave.sql +249 -0
  103. package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
  104. package/dist/platform/migrations/1330_accounting.sql +260 -0
  105. package/dist/platform/migrations/1350_customer_feed.sql +24 -0
  106. package/dist/platform/migrations/1390_locations.sql +77 -0
  107. package/dist/platform/migrations/1410_outside_copy.sql +213 -0
  108. package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
  109. package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
  110. package/dist/platform/sdk/acknowledge.ts +100 -0
  111. package/dist/platform/sdk/agreements.ts +185 -0
  112. package/dist/platform/sdk/allowance.ts +98 -8
  113. package/dist/platform/sdk/automation-check.ts +120 -9
  114. package/dist/platform/sdk/automation.ts +78 -10
  115. package/dist/platform/sdk/behaviour.ts +26 -6
  116. package/dist/platform/sdk/calendar-entry.ts +258 -0
  117. package/dist/platform/sdk/capacity.ts +103 -2
  118. package/dist/platform/sdk/checklists.ts +118 -0
  119. package/dist/platform/sdk/contract.ts +514 -27
  120. package/dist/platform/sdk/discount.ts +408 -0
  121. package/dist/platform/sdk/document.ts +4 -2
  122. package/dist/platform/sdk/field-types.ts +5 -0
  123. package/dist/platform/sdk/formula/compile.ts +10 -0
  124. package/dist/platform/sdk/index.ts +17 -0
  125. package/dist/platform/sdk/intake.ts +380 -0
  126. package/dist/platform/sdk/journey-signals.ts +215 -0
  127. package/dist/platform/sdk/manifest.ts +1313 -66
  128. package/dist/platform/sdk/mine.ts +161 -0
  129. package/dist/platform/sdk/occupies.ts +192 -0
  130. package/dist/platform/sdk/questions.ts +681 -0
  131. package/dist/platform/sdk/recurring.ts +90 -9
  132. package/dist/platform/sdk/restricted-fields.ts +129 -0
  133. package/dist/platform/sdk/rich-text.ts +112 -0
  134. package/dist/platform/sdk/routine-mail.ts +1272 -0
  135. package/dist/platform/sdk/runtime.ts +25 -12
  136. package/dist/platform/sdk/screens.ts +91 -0
  137. package/dist/platform/sdk/sellable.ts +595 -1
  138. package/dist/platform/sdk/slug.ts +7 -2
  139. package/dist/platform/sdk/staffed.ts +474 -0
  140. package/dist/platform/sdk/states.ts +220 -64
  141. package/dist/platform/sdk/stock.ts +332 -0
  142. package/dist/platform/sdk/team.ts +83 -0
  143. package/dist/platform/sdk/testing.ts +70 -6
  144. package/dist/platform/sdk/worked-on.ts +134 -0
  145. package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
  146. package/dist/run-7ID64RA6.js +65 -0
  147. package/dist/run-FH7OGGTV.js +131 -0
  148. package/dist/run-OYZIAP6M.js +3363 -0
  149. package/dist/{run-Y7T4TVOL.js → run-QOFRRSZV.js} +41 -60
  150. package/dist/{run-PZUCSDDL.js → run-TJAEWR5U.js} +21 -51
  151. package/dist/{src-XTOD7EXW.js → src-52VERUPK.js} +312 -4
  152. package/dist/src-PHRELWN5.js +40 -0
  153. package/dist/visibility-SZCINPP4.js +58 -0
  154. package/package.json +2 -2
  155. package/dist/chunk-6GDEDOV7.js +0 -157
  156. package/dist/chunk-6UPUF4ML.js +0 -29998
  157. package/dist/chunk-7CQGMVDO.js +0 -63
  158. package/dist/chunk-GYSGVT6R.js +0 -284
  159. package/dist/chunk-JJHHNV46.js +0 -227
  160. package/dist/chunk-K6T42YCH.js +0 -704
  161. package/dist/chunk-M7A6FR2Z.js +0 -2586
  162. package/dist/chunk-O2UIZHND.js +0 -249
  163. package/dist/chunk-Q4N55M2Z.js +0 -552
  164. package/dist/chunk-QGGJ2G6Z.js +0 -349
  165. package/dist/chunk-R4W5XAUD.js +0 -837
  166. package/dist/chunk-TQFGGSA4.js +0 -748
  167. package/dist/chunk-YJJHF65I.js +0 -759
  168. package/dist/chunk-Z3RMMB6S.js +0 -668
  169. package/dist/grants-QXMKYMGB.js +0 -32
  170. package/dist/invoke-I3NNNXVL.js +0 -39
  171. package/dist/plan-on-sale-NB774CQL.js +0 -26
  172. package/dist/src-GYS6NBQB.js +0 -44
  173. package/dist/visibility-DLGHU4YN.js +0 -33
@@ -0,0 +1,231 @@
1
+ -- Migration 1430: a conversation's messages and notes (stage 36 step 1, ADR 0740).
2
+ --
3
+ -- core_activity gains the type `chat` and the column conversation_id (core_conversation,
4
+ -- migration 1050). A private conversation's messages and notes leave the SQL views and search for
5
+ -- everyone, as a private activity does (migration 0111) and a note kept from the staff does
6
+ -- (migration 1230); the operations show them to admins and whoever has the conversation.
7
+ --
8
+ -- SQLite cannot change a CHECK, so the table is remade with its rows. The remake carries every
9
+ -- earlier change to core_activity forward (the note levels and kinds of migrations 1230 and 1232:
10
+ -- their columns, triggers, index and the `level = 'staff'` test in the views and search), so it
11
+ -- must sort after them: a fresh database applies migrations in number order, and a lower-numbered
12
+ -- remake would lose them, or have its own views and search triggers remade by them without the
13
+ -- private rule. A later remake of core_activity, its views or its search triggers carries this
14
+ -- one forward the same way and sorts after 1430.
15
+ --
16
+ -- Dropping the table would delete its links by cascade (D1 enforces foreign keys), so they are
17
+ -- kept aside and put back; core_activity_links is the only table that references it. Its
18
+ -- triggers go with it and are made again below. A DROP TABLE fires no trigger, so no search row
19
+ -- and no stored body is touched. The views that read it are dropped first (a rename checks every
20
+ -- view and trigger) and made again: rec_activity as its base view, which the schema reconciler
21
+ -- extends with extension fields on activities the next time it runs (as after migrations 0111,
22
+ -- 0380 and 1230).
23
+ DROP VIEW rec_activity;
24
+ DROP VIEW rec_activity_link;
25
+ DROP VIEW core_base_activities;
26
+
27
+ CREATE TABLE core_activity_links_keep AS SELECT * FROM core_activity_links;
28
+
29
+ CREATE TABLE core_activity_new (
30
+ id TEXT PRIMARY KEY NOT NULL,
31
+ type TEXT NOT NULL CHECK (type IN ('note', 'email', 'call', 'meeting', 'system', 'chat')),
32
+ -- Short headline: an email subject, meeting title, or a system event summary.
33
+ subject TEXT,
34
+ -- Plain-text or Markdown body (notes, email text, call notes). Indexed for search.
35
+ body TEXT,
36
+ -- Typed per `type` (validated by the operation layer), e.g. email headers, call duration,
37
+ -- or a system event's field changes.
38
+ payload TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(payload)),
39
+ occurred_at TEXT NOT NULL,
40
+ -- The user the activity is attributed to (null for automation or system events).
41
+ author_user_id TEXT REFERENCES core_user (id) ON DELETE SET NULL,
42
+ -- Who caused it: human | assistant | mcp | automation | system.
43
+ author_actor TEXT NOT NULL DEFAULT 'human'
44
+ CHECK (author_actor IN ('human', 'assistant', 'mcp', 'automation', 'system')),
45
+ created_at TEXT NOT NULL,
46
+ updated_at TEXT NOT NULL,
47
+ deleted_at TEXT,
48
+ deleted_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
49
+ -- Migration 0111: 'email:<Message-ID>' or 'ical:<UID>' (unique); 'chat:<id>' for chat.
50
+ external_key TEXT,
51
+ thread_key TEXT,
52
+ private_to TEXT,
53
+ body_ref TEXT,
54
+ disclosure TEXT CHECK (disclosure IS NULL OR disclosure IN ('full', 'metadata')),
55
+ -- Migration 1230: a note's level, kind, sharing, sender, evidence and sections.
56
+ level TEXT NOT NULL DEFAULT 'staff' CHECK (level IN ('staff', 'coaches', 'sensitive')),
57
+ kind_id TEXT,
58
+ shared_at TEXT,
59
+ shared_by TEXT,
60
+ from_customer TEXT,
61
+ evidence INTEGER NOT NULL DEFAULT 0 CHECK (evidence IN (0, 1)),
62
+ sections TEXT CHECK (sections IS NULL OR json_valid(sections)),
63
+ -- The conversation a message or a staff note belongs to (stage 36). Null for everything else.
64
+ conversation_id TEXT
65
+ );
66
+ INSERT INTO core_activity_new (
67
+ id, type, subject, body, payload, occurred_at, author_user_id, author_actor, created_at,
68
+ updated_at, deleted_at, deleted_by, external_key, thread_key, private_to, body_ref, disclosure,
69
+ level, kind_id, shared_at, shared_by, from_customer, evidence, sections
70
+ )
71
+ SELECT
72
+ id, type, subject, body, payload, occurred_at, author_user_id, author_actor, created_at,
73
+ updated_at, deleted_at, deleted_by, external_key, thread_key, private_to, body_ref, disclosure,
74
+ level, kind_id, shared_at, shared_by, from_customer, evidence, sections
75
+ FROM core_activity;
76
+ DROP TABLE core_activity;
77
+ ALTER TABLE core_activity_new RENAME TO core_activity;
78
+
79
+ INSERT INTO core_activity_links (activity_id, object_type, record_id)
80
+ SELECT activity_id, object_type, record_id FROM core_activity_links_keep;
81
+ DROP TABLE core_activity_links_keep;
82
+
83
+ CREATE INDEX core_activity_occurred_idx ON core_activity (occurred_at, id);
84
+ CREATE INDEX core_activity_type_idx ON core_activity (type);
85
+ CREATE INDEX core_activity_deleted_idx ON core_activity (deleted_at) WHERE deleted_at IS NOT NULL;
86
+ CREATE UNIQUE INDEX core_activity_external_key_idx ON core_activity (external_key)
87
+ WHERE external_key IS NOT NULL;
88
+ CREATE INDEX core_activity_thread_idx ON core_activity (thread_key, occurred_at)
89
+ WHERE thread_key IS NOT NULL;
90
+ CREATE INDEX core_activity_kept_idx ON core_activity (id) WHERE level != 'staff';
91
+ CREATE INDEX core_activity_conversation_idx ON core_activity (conversation_id, occurred_at, id)
92
+ WHERE conversation_id IS NOT NULL;
93
+
94
+ -- Private activities, notes kept from the staff, and the messages and notes of a private
95
+ -- conversation stay out of SQL views and search; the operations show them to those who may read
96
+ -- them.
97
+ CREATE VIEW core_base_activities AS
98
+ SELECT
99
+ activity.id,
100
+ activity.type,
101
+ activity.subject,
102
+ activity.body,
103
+ activity.payload,
104
+ activity.occurred_at,
105
+ activity.author_user_id,
106
+ activity.author_actor,
107
+ activity.created_at,
108
+ activity.updated_at
109
+ FROM core_activity activity
110
+ WHERE activity.deleted_at IS NULL AND activity.private_to IS NULL AND activity.level = 'staff'
111
+ AND (activity.conversation_id IS NULL OR NOT EXISTS (
112
+ SELECT 1 FROM core_conversation c
113
+ WHERE c.id = activity.conversation_id AND c.private_at IS NOT NULL));
114
+ CREATE VIEW rec_activity AS SELECT b.* FROM core_base_activities b;
115
+
116
+ CREATE VIEW rec_activity_link AS
117
+ SELECT l.activity_id, l.object_type, l.record_id
118
+ FROM core_activity_links l
119
+ JOIN core_activity a ON a.id = l.activity_id AND a.deleted_at IS NULL AND a.private_to IS NULL
120
+ AND a.level = 'staff'
121
+ WHERE a.conversation_id IS NULL OR NOT EXISTS (
122
+ SELECT 1 FROM core_conversation c WHERE c.id = a.conversation_id AND c.private_at IS NOT NULL);
123
+
124
+ CREATE TRIGGER core_activity_search_ai AFTER INSERT ON core_activity
125
+ BEGIN
126
+ DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = NEW.id;
127
+ INSERT INTO core_search_docs (object_type, record_id, title, body)
128
+ SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
129
+ FROM core_activity a
130
+ WHERE a.id = NEW.id AND a.deleted_at IS NULL AND a.private_to IS NULL AND a.level = 'staff'
131
+ AND (a.conversation_id IS NULL OR NOT EXISTS (
132
+ SELECT 1 FROM core_conversation c
133
+ WHERE c.id = a.conversation_id AND c.private_at IS NOT NULL));
134
+ END;
135
+
136
+ CREATE TRIGGER core_activity_search_au AFTER UPDATE OF subject, body, deleted_at, private_to, level
137
+ ON core_activity
138
+ BEGIN
139
+ DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = NEW.id;
140
+ INSERT INTO core_search_docs (object_type, record_id, title, body)
141
+ SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
142
+ FROM core_activity a
143
+ WHERE a.id = NEW.id AND a.deleted_at IS NULL AND a.private_to IS NULL AND a.level = 'staff'
144
+ AND (a.conversation_id IS NULL OR NOT EXISTS (
145
+ SELECT 1 FROM core_conversation c
146
+ WHERE c.id = a.conversation_id AND c.private_at IS NOT NULL));
147
+ END;
148
+
149
+ CREATE TRIGGER core_activity_search_ad AFTER DELETE ON core_activity
150
+ BEGIN
151
+ DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = OLD.id;
152
+ END;
153
+
154
+ -- Any activity that loses its body reference queues the body for deletion (migration 0330).
155
+ CREATE TRIGGER core_activity_body_ad AFTER DELETE ON core_activity
156
+ WHEN OLD.body_ref IS NOT NULL
157
+ BEGIN
158
+ INSERT OR IGNORE INTO core_blob_deletion (key, queued_at)
159
+ VALUES (OLD.body_ref, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
160
+ END;
161
+
162
+ CREATE TRIGGER core_activity_body_au AFTER UPDATE OF body_ref ON core_activity
163
+ WHEN OLD.body_ref IS NOT NULL AND (NEW.body_ref IS NULL OR NEW.body_ref <> OLD.body_ref)
164
+ BEGIN
165
+ INSERT OR IGNORE INTO core_blob_deletion (key, queued_at)
166
+ VALUES (OLD.body_ref, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
167
+ END;
168
+
169
+ -- Only a note is kept from the staff (migration 1230).
170
+ CREATE TRIGGER core_activity_level_note_insert
171
+ BEFORE INSERT ON core_activity
172
+ WHEN NEW.level != 'staff' AND NEW.type != 'note'
173
+ BEGIN
174
+ SELECT RAISE(ABORT, 'core_activity_level_not_note');
175
+ END;
176
+
177
+ CREATE TRIGGER core_activity_level_note_update
178
+ BEFORE UPDATE OF level, type ON core_activity
179
+ WHEN NEW.level != 'staff' AND NEW.type != 'note'
180
+ BEGIN
181
+ SELECT RAISE(ABORT, 'core_activity_level_not_note');
182
+ END;
183
+
184
+ -- A kind is only a note's, and a note is never below its kind's lowest level (migration 1232).
185
+ CREATE TRIGGER core_activity_kind_insert
186
+ BEFORE INSERT ON core_activity
187
+ WHEN NEW.kind_id IS NOT NULL
188
+ BEGIN
189
+ SELECT CASE
190
+ WHEN NEW.type != 'note' THEN RAISE(ABORT, 'core_activity_kind_not_note')
191
+ WHEN NOT EXISTS (SELECT 1 FROM core_note_kind k WHERE k.id = NEW.kind_id)
192
+ THEN RAISE(ABORT, 'core_activity_kind_unknown')
193
+ WHEN (CASE NEW.level WHEN 'staff' THEN 0 WHEN 'coaches' THEN 1 ELSE 2 END) <
194
+ (SELECT CASE k.lowest_level WHEN 'staff' THEN 0 WHEN 'coaches' THEN 1 ELSE 2 END
195
+ FROM core_note_kind k WHERE k.id = NEW.kind_id)
196
+ THEN RAISE(ABORT, 'core_note_below_kind')
197
+ END;
198
+ END;
199
+
200
+ CREATE TRIGGER core_activity_kind_update
201
+ BEFORE UPDATE OF kind_id, level, type ON core_activity
202
+ WHEN NEW.kind_id IS NOT NULL
203
+ BEGIN
204
+ SELECT CASE
205
+ WHEN NEW.type != 'note' THEN RAISE(ABORT, 'core_activity_kind_not_note')
206
+ WHEN NOT EXISTS (SELECT 1 FROM core_note_kind k WHERE k.id = NEW.kind_id)
207
+ THEN RAISE(ABORT, 'core_activity_kind_unknown')
208
+ WHEN (CASE NEW.level WHEN 'staff' THEN 0 WHEN 'coaches' THEN 1 ELSE 2 END) <
209
+ (SELECT CASE k.lowest_level WHEN 'staff' THEN 0 WHEN 'coaches' THEN 1 ELSE 2 END
210
+ FROM core_note_kind k WHERE k.id = NEW.kind_id)
211
+ THEN RAISE(ABORT, 'core_note_below_kind')
212
+ END;
213
+ END;
214
+
215
+ -- Marking a conversation private takes its messages and notes out of search, and unmarking puts
216
+ -- the live ones every staff account reads back.
217
+ CREATE TRIGGER core_conversation_private_search AFTER UPDATE OF private_at ON core_conversation
218
+ WHEN (OLD.private_at IS NULL) <> (NEW.private_at IS NULL)
219
+ BEGIN
220
+ DELETE FROM core_search_docs WHERE object_type = 'activity'
221
+ AND record_id IN (SELECT id FROM core_activity WHERE conversation_id = NEW.id);
222
+ INSERT INTO core_search_docs (object_type, record_id, title, body)
223
+ SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
224
+ FROM core_activity a
225
+ WHERE NEW.private_at IS NULL AND a.conversation_id = NEW.id AND a.deleted_at IS NULL
226
+ AND a.private_to IS NULL AND a.level = 'staff';
227
+ END;
228
+
229
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
230
+ UPDATE core_meta SET value = '1430'
231
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 1430;
@@ -0,0 +1,23 @@
1
+ -- Migration 1450: wrong promo codes (ADR 0940).
2
+ --
3
+ -- An operation that checks a code someone could guess counts wrong codes per caller: a signed-in
4
+ -- customer's account, a guest's order, or a guest's client address when they name no order. A
5
+ -- check reserves its guess before the code is looked up (`wrong = wrong + 1 ... RETURNING`, so
6
+ -- parallel guesses cannot overshoot) and gives it back when the code was right. Counted in fixed
7
+ -- quarter-hour windows; over the limit, `locked_until` refuses that caller's codes for 15 minutes,
8
+ -- right or wrong. One row per group and hour also counts wrong codes host-wide (`host\n...` keys),
9
+ -- the backstop against guessing from many addresses at once. The rate limiting binding cannot be
10
+ -- read without counting, so these counts are here.
11
+ --
12
+ -- `guess_key` is a SHA-256 of who (an account id, or an address's key: itself a keyed hash the
13
+ -- adapter made, so no address reaches the database), the order and the group. The daily
14
+ -- maintenance run deletes a row once its window and lock have passed. No Person, account or audit
15
+ -- row is linked to one. Not in any rec_* view.
16
+ CREATE TABLE core_wrong_guess (
17
+ guess_key TEXT PRIMARY KEY,
18
+ window_start TEXT NOT NULL,
19
+ wrong INTEGER NOT NULL DEFAULT 0 CHECK (wrong >= 0),
20
+ locked_until TEXT
21
+ ) WITHOUT ROWID;
22
+
23
+ CREATE INDEX core_wrong_guess_window ON core_wrong_guess (window_start);
@@ -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
+ }