create-freeholder 0.2.0-beta.3 → 0.2.0-beta.4

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 (965) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/template/.changeset/abuse-imagery-matching.md +4 -0
  4. package/dist/template/.changeset/abuse-scan-unchecked-images.md +11 -0
  5. package/dist/template/.changeset/admin-first-run-ux.md +32 -0
  6. package/dist/template/.changeset/booking-opening-date.md +4 -0
  7. package/dist/template/.changeset/busy-demo-business.md +6 -0
  8. package/dist/template/.changeset/c11-10-access-control-20261021.md +5 -0
  9. package/dist/template/.changeset/c9-37-newsletter-journey.md +10 -0
  10. package/dist/template/.changeset/c9-38-card-trial.md +8 -0
  11. package/dist/template/.changeset/cli-launch-hardening.md +4 -0
  12. package/dist/template/.changeset/cli-launch-npx.md +4 -0
  13. package/dist/template/.changeset/cli-launch.md +4 -0
  14. package/dist/template/.changeset/community-preset.md +5 -0
  15. package/dist/template/.changeset/demo-booking-and-admin-polish.md +4 -0
  16. package/dist/template/.changeset/demo-prelaunch-polish.md +4 -0
  17. package/dist/template/.changeset/demo-scenario-versions.md +4 -0
  18. package/dist/template/.changeset/docker-selfhost-https.md +4 -0
  19. package/dist/template/.changeset/event-admission-tax.md +11 -0
  20. package/dist/template/.changeset/event-hold-sweep.md +8 -0
  21. package/dist/template/.changeset/event-registration-and-pages.md +17 -0
  22. package/dist/template/.changeset/form-file-fields.md +4 -0
  23. package/dist/template/.changeset/form-screening-lead-sink.md +4 -0
  24. package/dist/template/.changeset/gateway-project-header.md +4 -0
  25. package/dist/template/.changeset/generic-short-zone-names.md +5 -0
  26. package/dist/template/.changeset/invoice-text-encoding.md +5 -0
  27. package/dist/template/.changeset/launch-spec-v2.md +4 -0
  28. package/dist/template/.changeset/launch-template-private-preview.md +4 -0
  29. package/dist/template/.changeset/link-in-bio.md +5 -0
  30. package/dist/template/.changeset/managed-platform-client-address.md +4 -0
  31. package/dist/template/.changeset/measurement-provider.md +4 -0
  32. package/dist/template/.changeset/media-migration-checksums.md +19 -0
  33. package/dist/template/.changeset/media-migration-transport.md +6 -0
  34. package/dist/template/.changeset/media-refuse-stored-svg.md +16 -0
  35. package/dist/template/.changeset/member-adult-content.md +4 -0
  36. package/dist/template/.changeset/member-attachments.md +4 -0
  37. package/dist/template/.changeset/member-bookings.md +4 -0
  38. package/dist/template/.changeset/member-call-removal.md +4 -0
  39. package/dist/template/.changeset/member-calls-cross-browser.md +4 -0
  40. package/dist/template/.changeset/member-calls.md +4 -0
  41. package/dist/template/.changeset/member-data-rights.md +4 -0
  42. package/dist/template/.changeset/member-demo-community.md +4 -0
  43. package/dist/template/.changeset/member-device-verification.md +4 -0
  44. package/dist/template/.changeset/member-e2ee.md +4 -0
  45. package/dist/template/.changeset/member-federation.md +4 -0
  46. package/dist/template/.changeset/member-fediverse-moves.md +4 -0
  47. package/dist/template/.changeset/member-follow-fediverse.md +4 -0
  48. package/dist/template/.changeset/member-graph.md +4 -0
  49. package/dist/template/.changeset/member-group-calls.md +4 -0
  50. package/dist/template/.changeset/member-history-transfer.md +4 -0
  51. package/dist/template/.changeset/member-listings.md +4 -0
  52. package/dist/template/.changeset/member-market-policy.md +4 -0
  53. package/dist/template/.changeset/member-messages.md +4 -0
  54. package/dist/template/.changeset/member-notifications.md +4 -0
  55. package/dist/template/.changeset/member-passkeys.md +4 -0
  56. package/dist/template/.changeset/member-payout-providers.md +4 -0
  57. package/dist/template/.changeset/member-payouts.md +4 -0
  58. package/dist/template/.changeset/member-posts.md +4 -0
  59. package/dist/template/.changeset/member-profile-sections.md +4 -0
  60. package/dist/template/.changeset/member-protection.md +4 -0
  61. package/dist/template/.changeset/member-reports.md +4 -0
  62. package/dist/template/.changeset/member-reviews.md +4 -0
  63. package/dist/template/.changeset/member-sealed-attachments.md +4 -0
  64. package/dist/template/.changeset/member-subscriptions.md +4 -0
  65. package/dist/template/.changeset/member-web-push.md +4 -0
  66. package/dist/template/.changeset/members-join.md +4 -0
  67. package/dist/template/.changeset/neutral-provider-names.md +5 -0
  68. package/dist/template/.changeset/node-22-23-4-october-2026-advisories.md +5 -0
  69. package/dist/template/.changeset/owner-feed-seed-noise.md +4 -0
  70. package/dist/template/.changeset/paid-event-admission.md +5 -0
  71. package/dist/template/.changeset/paradise-mail-adapter.md +4 -0
  72. package/dist/template/.changeset/payment-provider-boundary.md +23 -0
  73. package/dist/template/.changeset/payout-refund-retry-safety.md +16 -0
  74. package/dist/template/.changeset/personal-agent-keys.md +4 -0
  75. package/dist/template/.changeset/playground-capacity.md +7 -0
  76. package/dist/template/.changeset/playground-checkout-fictional-email.md +4 -0
  77. package/dist/template/.changeset/playground-public-site-and-honest-refusals.md +8 -0
  78. package/dist/template/.changeset/plugin-compat-ranges.md +9 -0
  79. package/dist/template/.changeset/portal-booking-end-time.md +4 -0
  80. package/dist/template/.changeset/preview-mail.md +4 -0
  81. package/dist/template/.changeset/preview-stripe-webhooks.md +4 -0
  82. package/dist/template/.changeset/provider-calls-outside-transactions.md +32 -0
  83. package/dist/template/.changeset/public-beta-4.md +5 -0
  84. package/dist/template/.changeset/redirect-site-origin.md +4 -0
  85. package/dist/template/.changeset/refuse-next-image-optimizer.md +5 -0
  86. package/dist/template/.changeset/service-intake-delivery.md +4 -0
  87. package/dist/template/.changeset/single-source-local-time.md +10 -0
  88. package/dist/template/.changeset/storefront-checkout-completes.md +12 -0
  89. package/dist/template/.changeset/web-auth-hardening.md +5 -0
  90. package/dist/template/.changeset/wevibesites-colophon.md +1 -1
  91. package/dist/template/.changeset/wordpress-import-media-redirects.md +32 -0
  92. package/dist/template/.changeset/zod-4-6-7-array-memory.md +9 -0
  93. package/dist/template/.env.example +86 -5
  94. package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +56 -0
  95. package/dist/template/.github/ISSUE_TEMPLATE/config.yml +10 -0
  96. package/dist/template/.github/trufflehog-exclude.txt +6 -0
  97. package/dist/template/.github/workflows/ci.yml +84 -28
  98. package/dist/template/.github/workflows/screenshots.yml +115 -0
  99. package/dist/template/.github/workflows/security-scheduled.yml +4 -1
  100. package/dist/template/.node-version +1 -1
  101. package/dist/template/.railway/railway.ts +3 -0
  102. package/dist/template/AGENTS.md +57 -26
  103. package/dist/template/CLAUDE.md +4 -2
  104. package/dist/template/CONTRIBUTING.md +33 -0
  105. package/dist/template/Dockerfile +3 -3
  106. package/dist/template/LICENSING.md +2 -1
  107. package/dist/template/MASTER.md +2689 -83
  108. package/dist/template/README.md +17 -7
  109. package/dist/template/app/(admin)/action-helpers.ts +61 -0
  110. package/dist/template/app/(admin)/actions.ts +2 -2
  111. package/dist/template/app/(admin)/admin/ActionErrorFallback.tsx +52 -0
  112. package/dist/template/app/(admin)/admin/AdminNav.tsx +182 -24
  113. package/dist/template/app/(admin)/admin/BlockEditor.tsx +73 -2
  114. package/dist/template/app/(admin)/admin/PlaygroundReadOnlyNotice.tsx +20 -0
  115. package/dist/template/app/(admin)/admin/PreviewCanvas.tsx +4 -2
  116. package/dist/template/app/(admin)/admin/RichField.tsx +5 -2
  117. package/dist/template/app/(admin)/admin/actorLabel.ts +20 -0
  118. package/dist/template/app/(admin)/admin/adminTitle.ts +31 -0
  119. package/dist/template/app/(admin)/admin/collections/page.tsx +6 -2
  120. package/dist/template/app/(admin)/admin/contacts/ContactForm.tsx +16 -4
  121. package/dist/template/app/(admin)/admin/contacts/[id]/page.tsx +7 -2
  122. package/dist/template/app/(admin)/admin/contacts/contactLabels.ts +2 -0
  123. package/dist/template/app/(admin)/admin/contacts/new/page.tsx +6 -1
  124. package/dist/template/app/(admin)/admin/describeAction.ts +403 -0
  125. package/dist/template/app/(admin)/admin/editorLabels.ts +1 -0
  126. package/dist/template/app/(admin)/admin/events/[id]/page.tsx +5 -3
  127. package/dist/template/app/(admin)/admin/forms/FieldBuilder.tsx +78 -0
  128. package/dist/template/app/(admin)/admin/forms/[id]/edit/page.tsx +3 -0
  129. package/dist/template/app/(admin)/admin/forms/[id]/page.tsx +63 -3
  130. package/dist/template/app/(admin)/admin/forms/builderLabels.ts +13 -1
  131. package/dist/template/app/(admin)/admin/forms/files/[id]/route.ts +53 -0
  132. package/dist/template/app/(admin)/admin/forms/new/page.tsx +1 -0
  133. package/dist/template/app/(admin)/admin/guard.ts +14 -0
  134. package/dist/template/app/(admin)/admin/health/page.tsx +41 -1
  135. package/dist/template/app/(admin)/admin/imports/ImportForms.tsx +106 -1
  136. package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +47 -0
  137. package/dist/template/app/(admin)/admin/inbox/[id]/page.tsx +5 -0
  138. package/dist/template/app/(admin)/admin/inbox/page.tsx +10 -1
  139. package/dist/template/app/(admin)/admin/inventory/page.tsx +2 -1
  140. package/dist/template/app/(admin)/admin/invitations/page.tsx +1 -1
  141. package/dist/template/app/(admin)/admin/invoices/[id]/page.tsx +22 -9
  142. package/dist/template/app/(admin)/admin/invoices/format.ts +25 -0
  143. package/dist/template/app/(admin)/admin/invoices/new/page.tsx +4 -3
  144. package/dist/template/app/(admin)/admin/layout.tsx +157 -97
  145. package/dist/template/app/(admin)/admin/link-in-bio/page.tsx +374 -0
  146. package/dist/template/app/(admin)/admin/mail/HeldMailReader.tsx +53 -0
  147. package/dist/template/app/(admin)/admin/mail/page.tsx +95 -0
  148. package/dist/template/app/(admin)/admin/media/page.tsx +21 -10
  149. package/dist/template/app/(admin)/admin/media/upload-client.ts +22 -5
  150. package/dist/template/app/(admin)/admin/members/actions.ts +163 -0
  151. package/dist/template/app/(admin)/admin/members/page.tsx +386 -0
  152. package/dist/template/app/(admin)/admin/newsletters/broadcasts/[id]/page.tsx +34 -2
  153. package/dist/template/app/(admin)/admin/newsletters/broadcasts/page.tsx +34 -1
  154. package/dist/template/app/(admin)/admin/newsletters/templates/page.tsx +23 -2
  155. package/dist/template/app/(admin)/admin/notifications/page.tsx +19 -12
  156. package/dist/template/app/(admin)/admin/orders/page.tsx +7 -8
  157. package/dist/template/app/(admin)/admin/page.tsx +46 -15
  158. package/dist/template/app/(admin)/admin/pages/[id]/PageComments.tsx +21 -2
  159. package/dist/template/app/(admin)/admin/pages/[id]/PagePresence.tsx +6 -2
  160. package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +6 -0
  161. package/dist/template/app/(admin)/admin/pos/page.tsx +23 -3
  162. package/dist/template/app/(admin)/admin/price-lists/page.tsx +3 -2
  163. package/dist/template/app/(admin)/admin/products/[id]/page.tsx +7 -4
  164. package/dist/template/app/(admin)/admin/projects/[id]/page.tsx +61 -2
  165. package/dist/template/app/(admin)/admin/promotions/page.tsx +1 -1
  166. package/dist/template/app/(admin)/admin/reports/page.tsx +16 -5
  167. package/dist/template/app/(admin)/admin/settings/MailSettingsCard.tsx +71 -6
  168. package/dist/template/app/(admin)/admin/settings/page.tsx +41 -1
  169. package/dist/template/app/(admin)/admin/traffic/page.tsx +12 -2
  170. package/dist/template/app/(admin)/admin/unavailable/page.tsx +60 -0
  171. package/dist/template/app/(admin)/admin/voice-video/page.tsx +22 -7
  172. package/dist/template/app/(admin)/admin-flash-actions.ts +18 -0
  173. package/dist/template/app/(admin)/broadcast-actions.ts +6 -2
  174. package/dist/template/app/(admin)/catalog-actions.ts +23 -5
  175. package/dist/template/app/(admin)/cms-actions.ts +4 -2
  176. package/dist/template/app/(admin)/event-actions.ts +8 -3
  177. package/dist/template/app/(admin)/first-party-plugin-actions.ts +4 -1
  178. package/dist/template/app/(admin)/forms-actions.ts +2 -0
  179. package/dist/template/app/(admin)/import-actions.ts +2 -1
  180. package/dist/template/app/(admin)/linkinbio-actions.ts +196 -0
  181. package/dist/template/app/(admin)/mail-preview-actions.ts +37 -0
  182. package/dist/template/app/(admin)/percent.ts +34 -0
  183. package/dist/template/app/(admin)/project-actions.ts +36 -0
  184. package/dist/template/app/(admin)/security/verify/page.tsx +2 -2
  185. package/dist/template/app/(admin)/security-actions.ts +2 -1
  186. package/dist/template/app/(admin)/template-actions.ts +22 -3
  187. package/dist/template/app/(preview)/canvas-bridge.ts +37 -9
  188. package/dist/template/app/(public)/AnalyticsConsentControl.tsx +31 -2
  189. package/dist/template/app/(public)/[[...slug]]/page.tsx +27 -1
  190. package/dist/template/app/(public)/book/actions.ts +10 -2
  191. package/dist/template/app/(public)/book/chosen.ts +20 -0
  192. package/dist/template/app/(public)/book/opening-date.ts +146 -0
  193. package/dist/template/app/(public)/book/page.tsx +68 -20
  194. package/dist/template/app/(public)/buy/AddToCart.tsx +78 -53
  195. package/dist/template/app/(public)/buy/AddedNotice.tsx +58 -0
  196. package/dist/template/app/(public)/buy/buy-actions.ts +3 -1
  197. package/dist/template/app/(public)/c/[slug]/CollectionGrid.tsx +26 -0
  198. package/dist/template/app/(public)/c/[slug]/page.tsx +11 -10
  199. package/dist/template/app/(public)/call/CallRoom.tsx +166 -0
  200. package/dist/template/app/(public)/call/IncomingCall.tsx +41 -0
  201. package/dist/template/app/(public)/call/[id]/page.tsx +49 -0
  202. package/dist/template/app/(public)/call/actions.ts +74 -0
  203. package/dist/template/app/(public)/call/group/GroupCallRoom.tsx +191 -0
  204. package/dist/template/app/(public)/call/group/[id]/page.tsx +64 -0
  205. package/dist/template/app/(public)/call/group/actions.ts +30 -0
  206. package/dist/template/app/(public)/cart/page.tsx +3 -3
  207. package/dist/template/app/(public)/checkout/DeliveryMethods.tsx +44 -15
  208. package/dist/template/app/(public)/checkout/checkout-actions.ts +60 -10
  209. package/dist/template/app/(public)/checkout/page.tsx +69 -4
  210. package/dist/template/app/(public)/event-actions.ts +91 -0
  211. package/dist/template/app/(public)/feed/page.tsx +112 -0
  212. package/dist/template/app/(public)/form-actions.ts +88 -12
  213. package/dist/template/app/(public)/inbound-actions.ts +52 -9
  214. package/dist/template/app/(public)/join/actions.ts +80 -0
  215. package/dist/template/app/(public)/join/page.tsx +64 -0
  216. package/dist/template/app/(public)/layout.tsx +43 -0
  217. package/dist/template/app/(public)/m/MediaAttach.tsx +78 -0
  218. package/dist/template/app/(public)/m/PostCard.tsx +146 -0
  219. package/dist/template/app/(public)/m/[handle]/page.tsx +269 -0
  220. package/dist/template/app/(public)/m/actions.ts +54 -0
  221. package/dist/template/app/(public)/m/attachment-form.ts +13 -0
  222. package/dist/template/app/(public)/m/post-actions.ts +86 -0
  223. package/dist/template/app/(public)/market/page.tsx +54 -0
  224. package/dist/template/app/(public)/market/policy/page.tsx +37 -0
  225. package/dist/template/app/(public)/memberships/actions.ts +75 -7
  226. package/dist/template/app/(public)/memberships/page.tsx +8 -4
  227. package/dist/template/app/(public)/memberships/trial-return/page.tsx +60 -0
  228. package/dist/template/app/(public)/messages/SecureConversation.tsx +395 -0
  229. package/dist/template/app/(public)/messages/[id]/page.tsx +142 -0
  230. package/dist/template/app/(public)/messages/actions.ts +72 -0
  231. package/dist/template/app/(public)/messages/e2ee-actions.ts +71 -0
  232. package/dist/template/app/(public)/messages/page.tsx +92 -0
  233. package/dist/template/app/(public)/newsletter-actions.ts +35 -3
  234. package/dist/template/app/(public)/orders/confirm/page.tsx +13 -6
  235. package/dist/template/app/(public)/p/[id]/page.tsx +105 -0
  236. package/dist/template/app/(public)/report/actions.ts +49 -0
  237. package/dist/template/app/(public)/report/page.tsx +59 -0
  238. package/dist/template/app/(public)/search/page.tsx +47 -9
  239. package/dist/template/app/(public)/tags/[tag]/page.tsx +35 -0
  240. package/dist/template/app/(public)/utility-metadata.ts +44 -0
  241. package/dist/template/app/.well-known/webfinger/route.ts +21 -0
  242. package/dist/template/app/ap/notes/[id]/route.ts +16 -0
  243. package/dist/template/app/ap/shared.ts +15 -0
  244. package/dist/template/app/ap/users/[handle]/followers/route.ts +13 -0
  245. package/dist/template/app/ap/users/[handle]/inbox/route.ts +65 -0
  246. package/dist/template/app/ap/users/[handle]/outbox/route.ts +13 -0
  247. package/dist/template/app/ap/users/[handle]/route.ts +15 -0
  248. package/dist/template/app/api/ads/creative/[id]/route.ts +50 -0
  249. package/dist/template/app/api/ads/third-party-consent/route.ts +2 -1
  250. package/dist/template/app/api/analytics/consent/route.ts +2 -1
  251. package/dist/template/app/api/analytics/vitals/route.ts +5 -0
  252. package/dist/template/app/api/health/db/route.ts +17 -0
  253. package/dist/template/app/api/imports/source/chunk/route.ts +20 -0
  254. package/dist/template/app/api/member-blobs/route.ts +14 -0
  255. package/dist/template/app/api/payouts/[provider]/webhook/route.ts +35 -0
  256. package/dist/template/app/go/link/[id]/route.ts +104 -0
  257. package/dist/template/app/layout.tsx +41 -6
  258. package/dist/template/app/member-blobs/[id]/route.ts +30 -0
  259. package/dist/template/app/member-files/[id]/route.ts +35 -0
  260. package/dist/template/app/portal/(account)/[section]/page.tsx +7 -3
  261. package/dist/template/app/portal/(account)/connections/page.tsx +84 -0
  262. package/dist/template/app/portal/(account)/layout.tsx +5 -9
  263. package/dist/template/app/portal/(account)/listings/actions.ts +50 -0
  264. package/dist/template/app/portal/(account)/listings/booking-actions.ts +47 -0
  265. package/dist/template/app/portal/(account)/listings/page.tsx +214 -0
  266. package/dist/template/app/portal/(account)/listings/plan-actions.ts +30 -0
  267. package/dist/template/app/portal/(account)/member/ImageUpload.tsx +55 -0
  268. package/dist/template/app/portal/(account)/member/MemberKeys.tsx +75 -0
  269. package/dist/template/app/portal/(account)/member/MemberPasskeys.tsx +117 -0
  270. package/dist/template/app/portal/(account)/member/page.tsx +283 -0
  271. package/dist/template/app/portal/(account)/member/profile-actions.ts +90 -0
  272. package/dist/template/app/portal/(account)/notifications/PushToggle.tsx +74 -0
  273. package/dist/template/app/portal/(account)/notifications/actions.ts +90 -0
  274. package/dist/template/app/portal/(account)/notifications/page.tsx +136 -0
  275. package/dist/template/app/portal/(account)/notifications/topics.ts +3 -0
  276. package/dist/template/app/portal/(account)/payouts/actions.ts +55 -0
  277. package/dist/template/app/portal/(account)/payouts/page.tsx +108 -0
  278. package/dist/template/app/portal/(account)/purchases/[orderId]/[sellerId]/page.tsx +16 -0
  279. package/dist/template/app/portal/(account)/purchases/page.tsx +39 -0
  280. package/dist/template/app/portal/(account)/records/[section]/[id]/page.tsx +2 -2
  281. package/dist/template/app/portal/(account)/sales/SaleView.tsx +164 -0
  282. package/dist/template/app/portal/(account)/sales/[orderId]/[sellerId]/page.tsx +16 -0
  283. package/dist/template/app/portal/(account)/sales/actions.ts +44 -0
  284. package/dist/template/app/portal/(account)/sales/page.tsx +39 -0
  285. package/dist/template/app/portal/(account)/subscriptions/[id]/page.tsx +21 -3
  286. package/dist/template/app/portal/agreements/actions.ts +2 -21
  287. package/dist/template/app/portal/appointments/[token]/page.tsx +15 -7
  288. package/dist/template/app/portal/appointments/actions.ts +9 -2
  289. package/dist/template/app/portal/invoices/InvoiceView.tsx +1 -1
  290. package/dist/template/app/portal/key-actions.ts +42 -0
  291. package/dist/template/app/portal/login/PortalPasskeySignIn.tsx +38 -0
  292. package/dist/template/app/portal/login/page.tsx +32 -7
  293. package/dist/template/app/portal/magic/route.ts +4 -1
  294. package/dist/template/app/portal/passkey-actions.ts +105 -0
  295. package/dist/template/app/portal/subscription-actions.ts +1 -1
  296. package/dist/template/app/robots.txt/route.ts +11 -0
  297. package/dist/template/app/share/route.ts +2 -1
  298. package/dist/template/app/sitemap.xml/route.ts +6 -1
  299. package/dist/template/app/theme.ts +2 -3
  300. package/dist/template/db/migrations/0025_members.sql +50 -0
  301. package/dist/template/db/migrations/0026_member_graph.sql +73 -0
  302. package/dist/template/db/migrations/0027_member_posts.sql +87 -0
  303. package/dist/template/db/migrations/0028_member_messages.sql +54 -0
  304. package/dist/template/db/migrations/0029_member_calls.sql +40 -0
  305. package/dist/template/db/migrations/0030_member_listings.sql +30 -0
  306. package/dist/template/db/migrations/0031_member_payouts.sql +58 -0
  307. package/dist/template/db/migrations/0032_member_buyer_protection.sql +59 -0
  308. package/dist/template/db/migrations/0033_member_reviews.sql +32 -0
  309. package/dist/template/db/migrations/0034_member_reports.sql +36 -0
  310. package/dist/template/db/migrations/0035_member_adult_content.sql +12 -0
  311. package/dist/template/db/migrations/0036_member_market_policy.sql +10 -0
  312. package/dist/template/db/migrations/0037_member_profile_avatar_sections.sql +27 -0
  313. package/dist/template/db/migrations/0038_web_push_quiet_hours.sql +32 -0
  314. package/dist/template/db/migrations/0039_member_attachments.sql +26 -0
  315. package/dist/template/db/migrations/0040_member_subscription_payouts.sql +13 -0
  316. package/dist/template/db/migrations/0041_personal_api_keys.sql +10 -0
  317. package/dist/template/db/migrations/0042_member_federation.sql +47 -0
  318. package/dist/template/db/migrations/0043_member_e2ee.sql +82 -0
  319. package/dist/template/db/migrations/0044_member_group_calls.sql +39 -0
  320. package/dist/template/db/migrations/0045_member_call_key_generations.sql +7 -0
  321. package/dist/template/db/migrations/0046_member_sealed_blobs.sql +26 -0
  322. package/dist/template/db/migrations/0047_member_history_transfers.sql +38 -0
  323. package/dist/template/db/migrations/0048_member_remote_follows.sql +36 -0
  324. package/dist/template/db/migrations/0049_member_fediverse_moves.sql +6 -0
  325. package/dist/template/db/migrations/0050_member_payout_transfers.sql +29 -0
  326. package/dist/template/db/migrations/0051_abuse_reports.sql +26 -0
  327. package/dist/template/db/migrations/0052_event_paid_admission.sql +8 -0
  328. package/dist/template/db/migrations/0053_member_payout_attempts.sql +11 -0
  329. package/dist/template/db/migrations/0054_member_payout_attempts_backfill.sql +16 -0
  330. package/dist/template/db/migrations/0055_event_registration_submission_token.sql +7 -0
  331. package/dist/template/db/migrations/0056_nonshipping_variant_backfill.sql +14 -0
  332. package/dist/template/db/migrations/0057_paradise_mail_provider.sql +58 -0
  333. package/dist/template/db/migrations/0058_service_intake_delivery.sql +12 -0
  334. package/dist/template/db/migrations/0059_form_submission_files.sql +21 -0
  335. package/dist/template/db/migrations/0060_mail_preview_outbox.sql +20 -0
  336. package/dist/template/db/migrations/meta/_journal.json +252 -0
  337. package/dist/template/deploy/README.md +3 -0
  338. package/dist/template/deploy/agent-launch.md +36 -1
  339. package/dist/template/deploy/analytics-governance.md +15 -0
  340. package/dist/template/deploy/background-jobs.md +7 -0
  341. package/dist/template/deploy/c11-08-restore-drill-2026-09-28.log +8 -8
  342. package/dist/template/deploy/c11-08-restore-summary.md +5 -5
  343. package/dist/template/deploy/c313-live-acceptance-2026-09-28.log +2 -2
  344. package/dist/template/deploy/c313-live-acceptance-2026-09-28.md +1 -1
  345. package/dist/template/deploy/client-readiness.md +67 -2
  346. package/dist/template/deploy/content-security-policy.md +11 -0
  347. package/dist/template/deploy/customer-surfaces-2026-10-07.md +10 -7
  348. package/dist/template/deploy/digitalocean-app/infra/app.yaml +6 -0
  349. package/dist/template/deploy/digitalocean-droplet/README.md +17 -0
  350. package/dist/template/deploy/digitalocean-droplet/deploy.md +1 -1
  351. package/dist/template/deploy/digitalocean-droplet/infra/Caddyfile +13 -1
  352. package/dist/template/deploy/digitalocean-droplet/infra/compose.yml +3 -0
  353. package/dist/template/deploy/doc-claim-mapping.md +40 -5
  354. package/dist/template/deploy/docker-selfhost/.env.example +3 -0
  355. package/dist/template/deploy/docker-selfhost/README.md +54 -10
  356. package/dist/template/deploy/docker-selfhost/docker-updater/Caddyfile +13 -1
  357. package/dist/template/deploy/docker-selfhost/docker-updater/compose.yml +2 -0
  358. package/dist/template/deploy/docker-selfhost/infra/Caddyfile.https +19 -0
  359. package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +70 -0
  360. package/dist/template/deploy/docker-selfhost/playground/README.md +91 -9
  361. package/dist/template/deploy/docker-selfhost/playground/compose.yml +69 -10
  362. package/dist/template/deploy/docker-selfhost/playground/demo.freeholder.ai.caddy +32 -1
  363. package/dist/template/deploy/docker-selfhost/playground/freeholder-playground-heal.service +10 -0
  364. package/dist/template/deploy/docker-selfhost/playground/freeholder-playground-heal.timer +9 -0
  365. package/dist/template/deploy/docker-selfhost/playground/reset.sh +105 -6
  366. package/dist/template/deploy/docker-selfhost/recipe.yaml +3 -0
  367. package/dist/template/deploy/f-criteria-matrix.md +850 -33
  368. package/dist/template/deploy/first-party-plugins.md +7 -5
  369. package/dist/template/deploy/launch-template.md +172 -0
  370. package/dist/template/deploy/link-in-bio.md +121 -0
  371. package/dist/template/deploy/mail-delivery.md +13 -0
  372. package/dist/template/deploy/media-lifecycle.md +28 -0
  373. package/dist/template/deploy/members-platform.md +430 -0
  374. package/dist/template/deploy/members-vibe-coding.md +93 -0
  375. package/dist/template/deploy/migration-runbook.md +8 -1
  376. package/dist/template/deploy/paradise-modern.md +254 -0
  377. package/dist/template/deploy/perf-reference-run-2026-09-27.log +3 -3
  378. package/dist/template/deploy/provider-recording-erasure.md +6 -8
  379. package/dist/template/deploy/release-channels.md +3 -1
  380. package/dist/template/deploy/release-notes-2026-10-16.md +142 -0
  381. package/dist/template/deploy/release-notes-2026-10-17.md +110 -0
  382. package/dist/template/deploy/release-notes-2026-10-23.md +421 -0
  383. package/dist/template/deploy/release-readiness.md +17 -0
  384. package/dist/template/deploy/screenshots-gallery.md +45 -0
  385. package/dist/template/deploy/spec-reconciliation.md +6 -3
  386. package/dist/template/deploy/update-preflight.md +4 -1
  387. package/dist/template/eslint.config.mjs +66 -18
  388. package/dist/template/gitignore.template +3 -0
  389. package/dist/template/instrumentation.node.ts +6 -0
  390. package/dist/template/locales/ar.json +1364 -35
  391. package/dist/template/locales/en.json +1364 -35
  392. package/dist/template/locales/es.json +1364 -35
  393. package/dist/template/locales/fr.json +1364 -35
  394. package/dist/template/next.config.ts +26 -1
  395. package/dist/template/package.json +28 -23
  396. package/dist/template/packages/cli/README.md +96 -2
  397. package/dist/template/packages/cli/package.json +4 -3
  398. package/dist/template/packages/cli/recipes/digitalocean-droplet/Caddyfile +24 -0
  399. package/dist/template/packages/cli/recipes/digitalocean-droplet/backup.sh +52 -0
  400. package/dist/template/packages/cli/recipes/digitalocean-droplet/cloud-init.yml +46 -0
  401. package/dist/template/packages/cli/recipes/digitalocean-droplet/compose.yml +68 -0
  402. package/dist/template/packages/cli/scripts/copy-recipe.mjs +14 -0
  403. package/dist/template/packages/cli/src/index.ts +5 -2
  404. package/dist/template/packages/cli/src/launch/args.ts +41 -0
  405. package/dist/template/packages/cli/src/launch/command.ts +47 -0
  406. package/dist/template/packages/cli/src/launch/digitalocean.ts +207 -0
  407. package/dist/template/packages/cli/src/launch/image.ts +23 -0
  408. package/dist/template/packages/cli/src/launch/launch.ts +339 -0
  409. package/dist/template/packages/cli/src/launch/remote.ts +38 -0
  410. package/dist/template/packages/cli/src/launch/s3.ts +78 -0
  411. package/dist/template/packages/cli/src/launch/secrets.ts +36 -0
  412. package/dist/template/packages/cli/src/launch/state.ts +66 -0
  413. package/dist/template/packages/cli/src/launch/types.ts +90 -0
  414. package/dist/template/packages/create-freeholder/package.json +1 -1
  415. package/dist/template/packages/create-freeholder/src/index.ts +1 -1
  416. package/dist/template/packages/freeholder-app/package.json +1 -1
  417. package/dist/template/packages/freeholder-app/src/branding.ts +8 -3
  418. package/dist/template/packages/mobile-app/package.json +1 -1
  419. package/dist/template/packages/plugin-kit/package.json +1 -1
  420. package/dist/template/packages/sdk/package.json +1 -1
  421. package/dist/template/packages/sdk/src/generated.ts +1131 -93
  422. package/dist/template/packages/sdk/src/version.ts +1 -1
  423. package/dist/template/packages/templates/package.json +1 -1
  424. package/dist/template/packages/templates/src/presets.ts +66 -1
  425. package/dist/template/playwright.a11y.config.ts +7 -0
  426. package/dist/template/plugins/community/manifest.ts +1 -1
  427. package/dist/template/plugins/community/plugin.json +1 -1
  428. package/dist/template/plugins/gift-registry/manifest.ts +1 -1
  429. package/dist/template/plugins/gift-registry/plugin.json +1 -1
  430. package/dist/template/plugins/marketplace/manifest.ts +1 -1
  431. package/dist/template/plugins/marketplace/plugin.json +1 -1
  432. package/dist/template/plugins/print-on-demand/manifest.ts +1 -1
  433. package/dist/template/plugins/print-on-demand/plugin.json +1 -1
  434. package/dist/template/plugins/social-fixture/manifest.ts +1 -1
  435. package/dist/template/plugins/social-fixture/plugin.json +1 -1
  436. package/dist/template/plugins/voice-video/adapter.ts +8 -4
  437. package/dist/template/plugins/voice-video/manifest.ts +1 -1
  438. package/dist/template/plugins/voice-video/plugin.json +1 -1
  439. package/dist/template/plugins/voice-video/settings.ts +23 -4
  440. package/dist/template/pnpm-lock.yaml +685 -803
  441. package/dist/template/pnpm-workspace.yaml +10 -0
  442. package/dist/template/proxy.ts +138 -3
  443. package/dist/template/public/push-sw.js +28 -0
  444. package/dist/template/scripts/fast-gates.mjs +4 -1
  445. package/dist/template/scripts/launch-prepare.d.mts +3 -0
  446. package/dist/template/scripts/launch-prepare.mjs +30 -7
  447. package/dist/template/scripts/license-headers.mjs +11 -1
  448. package/dist/template/scripts/media-transfer.d.mts +9 -2
  449. package/dist/template/scripts/media-transfer.mjs +77 -11
  450. package/dist/template/scripts/package-artifact-gate.mjs +54 -4
  451. package/dist/template/scripts/plan-gate.mjs +7 -4
  452. package/dist/template/scripts/preview-link.d.mts +9 -0
  453. package/dist/template/scripts/preview-link.mjs +47 -0
  454. package/dist/template/scripts/public-gates.sh +1 -1
  455. package/dist/template/scripts/release-packages.d.mts +8 -0
  456. package/dist/template/scripts/release-packages.mjs +47 -0
  457. package/dist/template/scripts/runtime-balanced-sequencer.ts +1 -1
  458. package/dist/template/scripts/screenshots-gallery.d.mts +30 -0
  459. package/dist/template/scripts/screenshots-gallery.mjs +277 -0
  460. package/dist/template/scripts/screenshots-index.mjs +52 -0
  461. package/dist/template/scripts/seo-gate.d.mts +7 -0
  462. package/dist/template/scripts/seo-gate.mjs +28 -6
  463. package/dist/template/scripts/standalone-artifact-gate.mjs +5 -2
  464. package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
  465. package/dist/template/security/independent-review-packet.md +16 -3
  466. package/dist/template/security/pre-launch-audit-2026-10-21.md +58 -0
  467. package/dist/template/seed/demo/busy/activity.ts +864 -0
  468. package/dist/template/seed/demo/busy/calendar.ts +845 -0
  469. package/dist/template/seed/demo/busy/content.ts +879 -0
  470. package/dist/template/seed/demo/busy/crm.ts +231 -0
  471. package/dist/template/seed/demo/busy/index.ts +49 -0
  472. package/dist/template/seed/demo/busy/ledger.ts +42 -0
  473. package/dist/template/seed/demo/busy/sales.ts +1164 -0
  474. package/dist/template/seed/demo/busy/world.ts +258 -0
  475. package/dist/template/seed/demo/content.ts +374 -49
  476. package/dist/template/seed/demo/illustrations.ts +191 -0
  477. package/dist/template/seed/launch/example-v2.json +123 -0
  478. package/dist/template/seed/launch/example.json +43 -0
  479. package/dist/template/src/adapters/abuse-scan/index.ts +53 -0
  480. package/dist/template/src/adapters/abuse-scan/photodna.ts +43 -0
  481. package/dist/template/src/adapters/abuse-scan/safer.ts +15 -0
  482. package/dist/template/src/adapters/abuse-scan/types.ts +24 -0
  483. package/dist/template/src/adapters/agent/aliases.ts +14 -0
  484. package/dist/template/src/adapters/agent/gateway.ts +233 -0
  485. package/dist/template/src/adapters/agent/index.ts +4 -3
  486. package/dist/template/src/adapters/agent/types.ts +1 -1
  487. package/dist/template/src/adapters/agent/workforce-openai.ts +63 -27
  488. package/dist/template/src/adapters/agent/workforce-types.ts +20 -1
  489. package/dist/template/src/adapters/agent/workforce.ts +67 -4
  490. package/dist/template/src/adapters/form-screening/index.ts +39 -0
  491. package/dist/template/src/adapters/form-screening/paradise.ts +32 -0
  492. package/dist/template/src/adapters/form-screening/types.ts +33 -0
  493. package/dist/template/src/adapters/lead-sink/index.ts +26 -0
  494. package/dist/template/src/adapters/lead-sink/paradise.ts +23 -0
  495. package/dist/template/src/adapters/lead-sink/types.ts +33 -0
  496. package/dist/template/src/adapters/mail/index.ts +38 -4
  497. package/dist/template/src/adapters/mail/paradise.ts +231 -0
  498. package/dist/template/src/adapters/mail/types.ts +53 -1
  499. package/dist/template/src/adapters/malware/index.ts +62 -6
  500. package/dist/template/src/adapters/malware/types.ts +2 -1
  501. package/dist/template/src/adapters/measurement/config.ts +113 -0
  502. package/dist/template/src/adapters/measurement/index.ts +36 -0
  503. package/dist/template/src/adapters/measurement/paradise.ts +96 -0
  504. package/dist/template/src/adapters/measurement/types.ts +28 -0
  505. package/dist/template/src/adapters/paradise/config.ts +48 -0
  506. package/dist/template/src/adapters/paradise/http.ts +186 -0
  507. package/dist/template/src/adapters/payments/http.ts +3 -0
  508. package/dist/template/src/adapters/payments/stripe.ts +52 -0
  509. package/dist/template/src/adapters/payments/types.ts +31 -0
  510. package/dist/template/src/adapters/payouts/http.ts +19 -0
  511. package/dist/template/src/adapters/payouts/index.ts +29 -0
  512. package/dist/template/src/adapters/payouts/paypal-payouts.ts +149 -0
  513. package/dist/template/src/adapters/payouts/razorpay-route.ts +154 -0
  514. package/dist/template/src/adapters/payouts/stripe-connect.ts +149 -0
  515. package/dist/template/src/adapters/payouts/types.ts +77 -0
  516. package/dist/template/src/core/agents/service.ts +31 -7
  517. package/dist/template/src/core/agents/writes.ts +210 -40
  518. package/dist/template/src/core/apikeys/personal.ts +134 -0
  519. package/dist/template/src/core/apikeys/schema.ts +6 -0
  520. package/dist/template/src/core/apikeys/service.ts +8 -7
  521. package/dist/template/src/core/apikeys/tokens.ts +4 -1
  522. package/dist/template/src/core/attestations/service.ts +34 -1
  523. package/dist/template/src/core/audit-origin.ts +47 -0
  524. package/dist/template/src/core/auth/magic-links/service.ts +14 -0
  525. package/dist/template/src/core/auth/reset.ts +1 -0
  526. package/dist/template/src/core/auth/service.ts +12 -1
  527. package/dist/template/src/core/auth/session-management/service.ts +1 -0
  528. package/dist/template/src/core/boot.ts +3 -0
  529. package/dist/template/src/core/briefing/service.ts +11 -0
  530. package/dist/template/src/core/config.test.ts +12 -3
  531. package/dist/template/src/core/config.ts +11 -8
  532. package/dist/template/src/core/connections/calendar-sync.ts +320 -175
  533. package/dist/template/src/core/connections/mail-import.ts +143 -76
  534. package/dist/template/src/core/contacts/service.ts +53 -25
  535. package/dist/template/src/core/db/buckets.ts +37 -0
  536. package/dist/template/src/core/db/index.ts +13 -0
  537. package/dist/template/src/core/demo/playground-cache.ts +70 -0
  538. package/dist/template/src/core/demo/playground-policy.ts +277 -3
  539. package/dist/template/src/core/demo/playground.ts +75 -2
  540. package/dist/template/src/core/doctor/index.ts +84 -2
  541. package/dist/template/src/core/doctor/service.ts +4 -0
  542. package/dist/template/src/core/doctor/timezone.ts +128 -0
  543. package/dist/template/src/core/env.ts +187 -8
  544. package/dist/template/src/core/events/service.ts +58 -3
  545. package/dist/template/src/core/guidance/first-win.ts +55 -0
  546. package/dist/template/src/core/guidance/service.ts +20 -2
  547. package/dist/template/src/core/http/actor.ts +18 -0
  548. package/dist/template/src/core/http/csp.ts +16 -3
  549. package/dist/template/src/core/http/local-path.ts +36 -0
  550. package/dist/template/src/core/http/public-form-return.ts +120 -0
  551. package/dist/template/src/core/http/request-metadata.ts +32 -2
  552. package/dist/template/src/core/i18n/index.ts +149 -0
  553. package/dist/template/src/core/i18n/zoned.ts +228 -17
  554. package/dist/template/src/core/import/contacts-service.ts +58 -9
  555. package/dist/template/src/core/import/parsers.ts +13 -21
  556. package/dist/template/src/core/import/service.ts +924 -89
  557. package/dist/template/src/core/import/source-upload.ts +450 -0
  558. package/dist/template/src/core/import/wordpress.ts +1521 -0
  559. package/dist/template/src/core/invitations/service.ts +1 -0
  560. package/dist/template/src/core/jobs/core-jobs.ts +90 -0
  561. package/dist/template/src/core/jobs/index.ts +21 -3
  562. package/dist/template/src/core/mail/permission.ts +315 -0
  563. package/dist/template/src/core/mail/preview.ts +234 -0
  564. package/dist/template/src/core/mail/privacy.ts +115 -0
  565. package/dist/template/src/core/mail/schema.ts +64 -6
  566. package/dist/template/src/core/mail/service.ts +184 -28
  567. package/dist/template/src/core/manifest.ts +12 -1
  568. package/dist/template/src/core/media/abuse-evidence.ts +36 -0
  569. package/dist/template/src/core/media/abuse-schema.ts +37 -0
  570. package/dist/template/src/core/media/capture.ts +474 -148
  571. package/dist/template/src/core/media/service.ts +180 -42
  572. package/dist/template/src/core/media/validation.ts +86 -1
  573. package/dist/template/src/core/media/variants.ts +7 -0
  574. package/dist/template/src/core/media/watermark.ts +11 -0
  575. package/dist/template/src/core/messaging/chat.ts +44 -2
  576. package/dist/template/src/core/messaging/inbox.ts +26 -3
  577. package/dist/template/src/core/messaging/service.ts +8 -1
  578. package/dist/template/src/core/messaging/sms.ts +425 -106
  579. package/dist/template/src/core/migrate.ts +1 -1
  580. package/dist/template/src/core/notes/service.ts +1 -0
  581. package/dist/template/src/core/notifications/schema.ts +45 -0
  582. package/dist/template/src/core/notifications/service.ts +174 -7
  583. package/dist/template/src/core/notifications/web-push.ts +133 -0
  584. package/dist/template/src/core/plugins/service.ts +1 -1
  585. package/dist/template/src/core/portability/ownership-export.mjs +15 -0
  586. package/dist/template/src/core/portal/nav.ts +34 -0
  587. package/dist/template/src/core/portal/record-service.ts +2 -2
  588. package/dist/template/src/core/portal/return-path.ts +9 -3
  589. package/dist/template/src/core/portal/sections.ts +8 -1
  590. package/dist/template/src/core/portal/service.ts +1 -0
  591. package/dist/template/src/core/preview/private-preview.ts +129 -0
  592. package/dist/template/src/core/preview/route-gate.ts +49 -0
  593. package/dist/template/src/core/privacy/service.ts +7 -1
  594. package/dist/template/src/core/runs/schema.ts +6 -1
  595. package/dist/template/src/core/runtime/schema-probe.ts +42 -0
  596. package/dist/template/src/core/scheduling/bookings.ts +5 -1
  597. package/dist/template/src/core/scheduling/business-day.ts +77 -0
  598. package/dist/template/src/core/scheduling/policy.ts +17 -0
  599. package/dist/template/src/core/scheduling/portal.ts +1 -1
  600. package/dist/template/src/core/scheduling/resolver-service.ts +15 -0
  601. package/dist/template/src/core/scheduling/resolver.ts +28 -8
  602. package/dist/template/src/core/search/service.ts +2 -2
  603. package/dist/template/src/core/security/rate-limit.ts +72 -1
  604. package/dist/template/src/core/seo/indexnow.ts +10 -2
  605. package/dist/template/src/core/seo/meta.ts +18 -1
  606. package/dist/template/src/core/seo/service.ts +5 -5
  607. package/dist/template/src/core/seo/sitemap.ts +4 -0
  608. package/dist/template/src/core/service.ts +126 -15
  609. package/dist/template/src/core/services.ts +16 -0
  610. package/dist/template/src/core/settings/service.ts +26 -1
  611. package/dist/template/src/core/tables.ts +4 -0
  612. package/dist/template/src/core/tasks/service.ts +1 -0
  613. package/dist/template/src/core/update/preflight.ts +5 -3
  614. package/dist/template/src/core/update/release-declaration.json +1 -1
  615. package/dist/template/src/core/views/registry.ts +4 -6
  616. package/dist/template/src/core/views/service.ts +14 -3
  617. package/dist/template/src/core/webhooks/service.ts +7 -7
  618. package/dist/template/src/core/webhooks/transport.ts +20 -4
  619. package/dist/template/src/mcp/server.ts +48 -0
  620. package/dist/template/src/mcp/tools.ts +3 -3
  621. package/dist/template/src/modules/ads/blocks.tsx +33 -9
  622. package/dist/template/src/modules/ads/service.ts +55 -4
  623. package/dist/template/src/modules/ads/tags.ts +57 -4
  624. package/dist/template/src/modules/analytics/measurement.ts +57 -0
  625. package/dist/template/src/modules/analytics/service.ts +129 -49
  626. package/dist/template/src/modules/assessments/service.ts +2 -2
  627. package/dist/template/src/modules/assistant/service.ts +290 -53
  628. package/dist/template/src/modules/builder/code-delivery.ts +33 -15
  629. package/dist/template/src/modules/builder/code-service.ts +330 -74
  630. package/dist/template/src/modules/builder/service.ts +163 -39
  631. package/dist/template/src/modules/catalog/browse.ts +2 -1
  632. package/dist/template/src/modules/catalog/cart-access.ts +14 -0
  633. package/dist/template/src/modules/catalog/cart.ts +18 -2
  634. package/dist/template/src/modules/catalog/checkout-fields.ts +101 -0
  635. package/dist/template/src/modules/catalog/inventory.ts +1 -0
  636. package/dist/template/src/modules/catalog/listing-gate.ts +22 -0
  637. package/dist/template/src/modules/catalog/market.ts +189 -0
  638. package/dist/template/src/modules/catalog/merchandising.ts +105 -0
  639. package/dist/template/src/modules/catalog/orders.ts +56 -14
  640. package/dist/template/src/modules/catalog/promotions.ts +106 -25
  641. package/dist/template/src/modules/catalog/public-booking.ts +72 -20
  642. package/dist/template/src/modules/catalog/schema.ts +8 -0
  643. package/dist/template/src/modules/catalog/service.ts +21 -2
  644. package/dist/template/src/modules/catalog/shipping-quote.ts +31 -4
  645. package/dist/template/src/modules/catalog/storefront.ts +31 -0
  646. package/dist/template/src/modules/catalog/variants.ts +40 -0
  647. package/dist/template/src/modules/cms/a11y-hints.ts +12 -3
  648. package/dist/template/src/modules/cms/blocks/fields.ts +14 -2
  649. package/dist/template/src/modules/cms/blocks/library.tsx +135 -27
  650. package/dist/template/src/modules/cms/blocks/store-sections.tsx +18 -3
  651. package/dist/template/src/modules/cms/blocks/surfaces.tsx +46 -18
  652. package/dist/template/src/modules/cms/blocks/types.ts +8 -0
  653. package/dist/template/src/modules/cms/chrome-nav.ts +75 -0
  654. package/dist/template/src/modules/cms/defaults.ts +1 -1
  655. package/dist/template/src/modules/cms/history.ts +1 -1
  656. package/dist/template/src/modules/cms/inbound.ts +1 -1
  657. package/dist/template/src/modules/cms/layout-service.ts +6 -1
  658. package/dist/template/src/modules/cms/lifecycle.ts +2 -0
  659. package/dist/template/src/modules/cms/render.tsx +44 -0
  660. package/dist/template/src/modules/cms/schema.ts +1 -0
  661. package/dist/template/src/modules/cms/service.ts +172 -22
  662. package/dist/template/src/modules/cms/templates.ts +40 -3
  663. package/dist/template/src/modules/cms/translation-workflow.ts +109 -35
  664. package/dist/template/src/modules/contracts/service.ts +9 -7
  665. package/dist/template/src/modules/documents/service.ts +36 -9
  666. package/dist/template/src/modules/events/SubmissionTokenField.tsx +28 -0
  667. package/dist/template/src/modules/events/blocks.tsx +236 -21
  668. package/dist/template/src/modules/events/jobs.ts +22 -0
  669. package/dist/template/src/modules/events/manifest.ts +11 -1
  670. package/dist/template/src/modules/events/schema.ts +9 -0
  671. package/dist/template/src/modules/events/service.ts +759 -61
  672. package/dist/template/src/modules/forms/FileField.tsx +181 -0
  673. package/dist/template/src/modules/forms/block.tsx +239 -8
  674. package/dist/template/src/modules/forms/conversion.ts +34 -0
  675. package/dist/template/src/modules/forms/fields.ts +106 -3
  676. package/dist/template/src/modules/forms/lead-sink.ts +90 -0
  677. package/dist/template/src/modules/forms/schema.ts +47 -0
  678. package/dist/template/src/modules/forms/screening.ts +183 -0
  679. package/dist/template/src/modules/forms/service.ts +413 -29
  680. package/dist/template/src/modules/forms/tables.ts +1 -1
  681. package/dist/template/src/modules/galleries/service.ts +162 -43
  682. package/dist/template/src/modules/index.ts +4 -0
  683. package/dist/template/src/modules/invoicing/contract.ts +1 -0
  684. package/dist/template/src/modules/invoicing/customer-service.ts +14 -5
  685. package/dist/template/src/modules/invoicing/invoice-service.ts +19 -2
  686. package/dist/template/src/modules/invoicing/payment-provider-service.ts +326 -63
  687. package/dist/template/src/modules/invoicing/pos-service.ts +191 -89
  688. package/dist/template/src/modules/invoicing/recurring-service.ts +1 -0
  689. package/dist/template/src/modules/invoicing/schema.ts +1 -1
  690. package/dist/template/src/modules/linkinbio/availability.ts +71 -0
  691. package/dist/template/src/modules/linkinbio/blocks.tsx +307 -0
  692. package/dist/template/src/modules/linkinbio/links.ts +519 -0
  693. package/dist/template/src/modules/linkinbio/manifest.ts +26 -0
  694. package/dist/template/src/modules/linkinbio/service.ts +1010 -0
  695. package/dist/template/src/modules/members/abuse.ts +143 -0
  696. package/dist/template/src/modules/members/adult.ts +45 -0
  697. package/dist/template/src/modules/members/attachment-store.ts +80 -0
  698. package/dist/template/src/modules/members/attachments.ts +103 -0
  699. package/dist/template/src/modules/members/call-seats.ts +49 -0
  700. package/dist/template/src/modules/members/calls.ts +347 -0
  701. package/dist/template/src/modules/members/data-rights.ts +249 -0
  702. package/dist/template/src/modules/members/demo.ts +188 -0
  703. package/dist/template/src/modules/members/e2ee/engine.ts +656 -0
  704. package/dist/template/src/modules/members/e2ee/history.ts +176 -0
  705. package/dist/template/src/modules/members/e2ee/idb-store.ts +89 -0
  706. package/dist/template/src/modules/members/e2ee/service.ts +504 -0
  707. package/dist/template/src/modules/members/e2ee/wire.ts +210 -0
  708. package/dist/template/src/modules/members/federation/core.ts +386 -0
  709. package/dist/template/src/modules/members/federation/following.ts +394 -0
  710. package/dist/template/src/modules/members/federation/signatures.ts +97 -0
  711. package/dist/template/src/modules/members/graph.ts +498 -0
  712. package/dist/template/src/modules/members/group-calls.ts +201 -0
  713. package/dist/template/src/modules/members/jobs.ts +64 -0
  714. package/dist/template/src/modules/members/listings.ts +269 -0
  715. package/dist/template/src/modules/members/manifest.ts +49 -0
  716. package/dist/template/src/modules/members/member-services.ts +211 -0
  717. package/dist/template/src/modules/members/member-subscriptions.ts +256 -0
  718. package/dist/template/src/modules/members/message-crypto.ts +56 -0
  719. package/dist/template/src/modules/members/messages.ts +483 -0
  720. package/dist/template/src/modules/members/notify.ts +60 -0
  721. package/dist/template/src/modules/members/onboarding.ts +46 -0
  722. package/dist/template/src/modules/members/payouts.ts +477 -0
  723. package/dist/template/src/modules/members/policy.ts +71 -0
  724. package/dist/template/src/modules/members/posts.ts +644 -0
  725. package/dist/template/src/modules/members/profile-kinds.ts +4 -0
  726. package/dist/template/src/modules/members/profile.ts +230 -0
  727. package/dist/template/src/modules/members/protection.ts +402 -0
  728. package/dist/template/src/modules/members/provider-payouts.ts +546 -0
  729. package/dist/template/src/modules/members/report-kinds.ts +6 -0
  730. package/dist/template/src/modules/members/reports.ts +277 -0
  731. package/dist/template/src/modules/members/reputation.ts +247 -0
  732. package/dist/template/src/modules/members/schema.ts +966 -0
  733. package/dist/template/src/modules/members/sealed-blobs.ts +188 -0
  734. package/dist/template/src/modules/members/service.ts +493 -0
  735. package/dist/template/src/modules/members/sfu.ts +89 -0
  736. package/dist/template/src/modules/members/status.ts +36 -0
  737. package/dist/template/src/modules/members/subscriber-check.ts +30 -0
  738. package/dist/template/src/modules/members/tables.ts +46 -0
  739. package/dist/template/src/modules/members/visibility.ts +5 -0
  740. package/dist/template/src/modules/newsletters/blocks.tsx +27 -2
  741. package/dist/template/src/modules/newsletters/broadcast-service.ts +169 -7
  742. package/dist/template/src/modules/newsletters/service.ts +53 -6
  743. package/dist/template/src/modules/popups/service.ts +9 -2
  744. package/dist/template/src/modules/projects/manifest.ts +1 -0
  745. package/dist/template/src/modules/projects/portal.ts +70 -5
  746. package/dist/template/src/modules/projects/publishing-service.ts +1 -0
  747. package/dist/template/src/modules/projects/schema.ts +6 -0
  748. package/dist/template/src/modules/projects/service.ts +320 -2
  749. package/dist/template/src/modules/proof/manifest.ts +1 -1
  750. package/dist/template/src/modules/quotes/service.ts +5 -1
  751. package/dist/template/src/modules/referrals/commission-service.ts +82 -2
  752. package/dist/template/src/modules/referrals/service.ts +1 -0
  753. package/dist/template/src/modules/rentals/service.ts +85 -2
  754. package/dist/template/src/modules/reporting/export-service.ts +27 -40
  755. package/dist/template/src/modules/reporting/service.ts +64 -22
  756. package/dist/template/src/modules/seed/boot.ts +87 -5
  757. package/dist/template/src/modules/seed/business.ts +350 -0
  758. package/dist/template/src/modules/seed/busy.ts +109 -0
  759. package/dist/template/src/modules/seed/launch.ts +574 -0
  760. package/dist/template/src/modules/seed/manifest.ts +1 -1
  761. package/dist/template/src/modules/seed/onboarding.ts +8 -6
  762. package/dist/template/src/modules/seed/service.ts +82 -5
  763. package/dist/template/src/modules/share/service.ts +6 -2
  764. package/dist/template/src/modules/social/capabilities.ts +1 -0
  765. package/dist/template/src/modules/social/compose.ts +24 -1
  766. package/dist/template/src/modules/social/render.ts +87 -19
  767. package/dist/template/src/modules/subscriptions/billing.ts +165 -47
  768. package/dist/template/src/modules/subscriptions/public-signup.ts +213 -19
  769. package/dist/template/src/modules/subscriptions/schema.ts +4 -0
  770. package/dist/template/src/modules/subscriptions/service.ts +141 -30
  771. package/dist/template/src/ui/pickers.tsx +98 -0
  772. package/dist/template/src/ui/primitives.tsx +2 -2
  773. package/dist/template/tests/adapters/abuse-scan.test.ts +87 -0
  774. package/dist/template/tests/adapters/payout-providers.test.ts +155 -0
  775. package/dist/template/tests/browser/accessibility.spec.ts +11 -0
  776. package/dist/template/tests/browser/c11-01-visitor-to-paid.spec.ts +9 -1
  777. package/dist/template/tests/browser/customer-surfaces.spec.ts +23 -1
  778. package/dist/template/tests/browser/editor-media-tools.spec.ts +7 -2
  779. package/dist/template/tests/browser/editor-store-sections.spec.ts +1 -4
  780. package/dist/template/tests/browser/events.spec.ts +106 -3
  781. package/dist/template/tests/browser/first-party-plugins.spec.ts +5 -3
  782. package/dist/template/tests/browser/journeys.spec.ts +48 -3
  783. package/dist/template/tests/browser/member-calls.spec.ts +75 -0
  784. package/dist/template/tests/browser/member-group-calls.spec.ts +119 -0
  785. package/dist/template/tests/browser/member-journey.spec.ts +275 -0
  786. package/dist/template/tests/browser/members.spec.ts +1132 -0
  787. package/dist/template/tests/browser/newsletters.spec.ts +234 -0
  788. package/dist/template/tests/browser/playground.spec.ts +78 -0
  789. package/dist/template/tests/browser/screenshots.spec.ts +244 -0
  790. package/dist/template/tests/browser/storefront-checkout.spec.ts +8 -5
  791. package/dist/template/tests/browser/storefront-merch-blocks.spec.ts +3 -5
  792. package/dist/template/tests/core/admin-first-run.test.ts +245 -0
  793. package/dist/template/tests/core/admin-nav-layout.test.ts +123 -0
  794. package/dist/template/tests/core/agent-launch.test.ts +59 -1
  795. package/dist/template/tests/core/agents-approvals.test.ts +75 -0
  796. package/dist/template/tests/core/agents-schedule.test.ts +78 -1
  797. package/dist/template/tests/core/agents-workforce-adapter.test.ts +419 -3
  798. package/dist/template/tests/core/analytics-consent.test.ts +24 -2
  799. package/dist/template/tests/core/analytics.test.ts +46 -1
  800. package/dist/template/tests/core/attestations.test.ts +23 -0
  801. package/dist/template/tests/core/audit-labels.test.ts +203 -1
  802. package/dist/template/tests/core/bootstrap-security.test.ts +53 -0
  803. package/dist/template/tests/core/briefing.test.ts +16 -1
  804. package/dist/template/tests/core/builder-code-lane.test.ts +71 -1
  805. package/dist/template/tests/core/builder-content-lane.test.ts +67 -2
  806. package/dist/template/tests/core/c11-03-booking-journey.test.ts +25 -12
  807. package/dist/template/tests/core/c11-06-agent-journey.test.ts +4 -3
  808. package/dist/template/tests/core/calendar-sync.test.ts +18 -0
  809. package/dist/template/tests/core/cart-access.test.ts +66 -2
  810. package/dist/template/tests/core/cart-storefront.test.ts +246 -7
  811. package/dist/template/tests/core/catalog-orders.test.ts +51 -2
  812. package/dist/template/tests/core/change-password.test.ts +30 -1
  813. package/dist/template/tests/core/checkout-fields.test.ts +49 -0
  814. package/dist/template/tests/core/client-readiness-security.test.ts +17 -9
  815. package/dist/template/tests/core/cms-blocks.test.ts +2 -2
  816. package/dist/template/tests/core/cms-chrome.test.ts +138 -1
  817. package/dist/template/tests/core/cms-translation-workflow.test.ts +65 -1
  818. package/dist/template/tests/core/colour-literals.test.ts +60 -0
  819. package/dist/template/tests/core/contact-import.test.ts +21 -0
  820. package/dist/template/tests/core/contract-templates.test.ts +5 -2
  821. package/dist/template/tests/core/csp.test.ts +9 -0
  822. package/dist/template/tests/core/customer-invoices.test.ts +59 -0
  823. package/dist/template/tests/core/customer-magic-links.test.ts +21 -4
  824. package/dist/template/tests/core/customer-return-path.test.ts +33 -0
  825. package/dist/template/tests/core/dashboard.test.ts +88 -0
  826. package/dist/template/tests/core/demo-scenarios.test.ts +6 -1
  827. package/dist/template/tests/core/deploy-recipe.test.ts +161 -0
  828. package/dist/template/tests/core/doctor.test.ts +127 -0
  829. package/dist/template/tests/core/editor-canvas-drag.test.ts +90 -0
  830. package/dist/template/tests/core/editor-inline-edit.test.ts +1 -0
  831. package/dist/template/tests/core/editor-media-tools.test.ts +1 -0
  832. package/dist/template/tests/core/editor-preview-draft.test.ts +1 -0
  833. package/dist/template/tests/core/editor-reorder.test.ts +1 -0
  834. package/dist/template/tests/core/editor-store-sections.test.ts +1 -0
  835. package/dist/template/tests/core/events-public-render.test.ts +147 -0
  836. package/dist/template/tests/core/events-submission-token.test.ts +40 -0
  837. package/dist/template/tests/core/events.test.ts +691 -9
  838. package/dist/template/tests/core/f-matrix.test.ts +2 -2
  839. package/dist/template/tests/core/first-party-plugins.test.ts +13 -0
  840. package/dist/template/tests/core/form-intake-screening.test.ts +80 -0
  841. package/dist/template/tests/core/form-screening-lead-sink.test.ts +446 -0
  842. package/dist/template/tests/core/guidance-definitions.test.ts +18 -0
  843. package/dist/template/tests/core/i18n.test.ts +118 -0
  844. package/dist/template/tests/core/ics-and-writeback.test.ts +10 -2
  845. package/dist/template/tests/core/inbox.test.ts +13 -0
  846. package/dist/template/tests/core/intake-waivers-reminders.test.ts +5 -3
  847. package/dist/template/tests/core/internal-services.test.ts +141 -0
  848. package/dist/template/tests/core/invoicing-pos.test.ts +137 -2
  849. package/dist/template/tests/core/launch-cli.test.ts +342 -0
  850. package/dist/template/tests/core/launch-template.test.ts +197 -0
  851. package/dist/template/tests/core/lint-gates.test.ts +54 -0
  852. package/dist/template/tests/core/list-assets-limits.test.ts +30 -0
  853. package/dist/template/tests/core/local-time-sql.test.ts +149 -0
  854. package/dist/template/tests/core/long-running-service-boundary.test.ts +258 -109
  855. package/dist/template/tests/core/mail-import.test.ts +18 -0
  856. package/dist/template/tests/core/mail-service.test.ts +280 -0
  857. package/dist/template/tests/core/mail-ui.test.ts +17 -0
  858. package/dist/template/tests/core/mcp.test.ts +48 -0
  859. package/dist/template/tests/core/measurement-form-action.test.ts +94 -0
  860. package/dist/template/tests/core/measurement-provider.test.ts +258 -0
  861. package/dist/template/tests/core/media-capture.test.ts +163 -1
  862. package/dist/template/tests/core/media-markdown.test.ts +26 -0
  863. package/dist/template/tests/core/media-raster-guard.test.ts +309 -0
  864. package/dist/template/tests/core/media-transfer-transport.test.ts +83 -0
  865. package/dist/template/tests/core/media-transfer.test.ts +108 -0
  866. package/dist/template/tests/core/media.test.ts +69 -0
  867. package/dist/template/tests/core/merch-blocks.test.ts +40 -0
  868. package/dist/template/tests/core/merge-completeness.test.ts +142 -26
  869. package/dist/template/tests/core/newsletters.test.ts +93 -0
  870. package/dist/template/tests/core/onboarding-definitions-frozen.test.ts +63 -0
  871. package/dist/template/tests/core/onboarding-definitions.frozen.json +20 -0
  872. package/dist/template/tests/core/paradise-http.test.ts +185 -0
  873. package/dist/template/tests/core/paradise-mail.test.ts +296 -0
  874. package/dist/template/tests/core/payment-adapters.test.ts +103 -0
  875. package/dist/template/tests/core/payment-provider-service.test.ts +262 -3
  876. package/dist/template/tests/core/personal-keys.test.ts +73 -0
  877. package/dist/template/tests/core/playground-cache.test.ts +109 -0
  878. package/dist/template/tests/core/playground-feedback.test.ts +160 -0
  879. package/dist/template/tests/core/playground-reset.test.ts +195 -0
  880. package/dist/template/tests/core/playground.test.ts +353 -5
  881. package/dist/template/tests/core/plugin-provider-boundary.test.ts +21 -11
  882. package/dist/template/tests/core/preview-mail.test.ts +294 -0
  883. package/dist/template/tests/core/private-preview-webhooks.test.ts +152 -0
  884. package/dist/template/tests/core/private-preview.test.ts +167 -0
  885. package/dist/template/tests/core/proxy-locale.test.ts +1 -0
  886. package/dist/template/tests/core/quotes.test.ts +15 -1
  887. package/dist/template/tests/core/rate-limit.test.ts +146 -2
  888. package/dist/template/tests/core/redirect-origin.test.ts +40 -0
  889. package/dist/template/tests/core/release-packages.test.ts +38 -0
  890. package/dist/template/tests/core/rentals.test.ts +88 -0
  891. package/dist/template/tests/core/resolver.test.ts +39 -0
  892. package/dist/template/tests/core/saved-views.test.ts +28 -1
  893. package/dist/template/tests/core/screenshots-gallery.test.ts +95 -0
  894. package/dist/template/tests/core/security-headers.test.ts +13 -1
  895. package/dist/template/tests/core/seed-demo-busy.test.ts +564 -0
  896. package/dist/template/tests/core/seed-demo.test.ts +166 -7
  897. package/dist/template/tests/core/seo-gate.test.ts +20 -1
  898. package/dist/template/tests/core/seo-surface.test.ts +9 -0
  899. package/dist/template/tests/core/seo.test.ts +1 -0
  900. package/dist/template/tests/core/service-composition.test.ts +45 -2
  901. package/dist/template/tests/core/service-intake-delivery.test.ts +313 -0
  902. package/dist/template/tests/core/settings.test.ts +13 -0
  903. package/dist/template/tests/core/shipping-quote.test.ts +50 -0
  904. package/dist/template/tests/core/site-chat.test.ts +97 -5
  905. package/dist/template/tests/core/sms.test.ts +268 -0
  906. package/dist/template/tests/core/spec-reconciliation.test.ts +7 -3
  907. package/dist/template/tests/core/storefront-commerce.test.ts +64 -1
  908. package/dist/template/tests/core/templates.test.ts +10 -0
  909. package/dist/template/tests/core/text-encoding.test.ts +35 -0
  910. package/dist/template/tests/core/transactional-jobs.test.ts +57 -0
  911. package/dist/template/tests/core/update-preflight.test.ts +46 -0
  912. package/dist/template/tests/core/voice-video-provider-choice.test.ts +47 -0
  913. package/dist/template/tests/core/waitlists-and-policy.test.ts +11 -0
  914. package/dist/template/tests/core/web-push.test.ts +165 -0
  915. package/dist/template/tests/core/wordpress-import-flow.test.ts +216 -0
  916. package/dist/template/tests/core/wordpress-import-upload.test.ts +217 -0
  917. package/dist/template/tests/core/wordpress-import.test.ts +260 -0
  918. package/dist/template/tests/core/zoned.test.ts +156 -1
  919. package/dist/template/tests/fixtures/wordpress/sample-export.xml +228 -0
  920. package/dist/template/tests/helpers/e2ee.ts +69 -0
  921. package/dist/template/tests/helpers/open-transactions.ts +14 -0
  922. package/dist/template/tests/load/members-load.test.ts +99 -0
  923. package/dist/template/tests/modules/ads-third-party.test.ts +58 -2
  924. package/dist/template/tests/modules/assistant.test.ts +36 -0
  925. package/dist/template/tests/modules/booking-opening-date.test.ts +290 -0
  926. package/dist/template/tests/modules/broadcasts.test.ts +92 -0
  927. package/dist/template/tests/modules/customer-surfaces.test.ts +110 -2
  928. package/dist/template/tests/modules/documents.test.ts +22 -0
  929. package/dist/template/tests/modules/form-file-fields.test.ts +317 -0
  930. package/dist/template/tests/modules/linkinbio-links.test.ts +277 -0
  931. package/dist/template/tests/modules/linkinbio.test.ts +410 -0
  932. package/dist/template/tests/modules/member-abuse.test.ts +114 -0
  933. package/dist/template/tests/modules/member-adult.test.ts +109 -0
  934. package/dist/template/tests/modules/member-attachments.test.ts +92 -0
  935. package/dist/template/tests/modules/member-calls.test.ts +138 -0
  936. package/dist/template/tests/modules/member-data-rights.test.ts +119 -0
  937. package/dist/template/tests/modules/member-demo.test.ts +40 -0
  938. package/dist/template/tests/modules/member-e2ee.test.ts +240 -0
  939. package/dist/template/tests/modules/member-federation.test.ts +249 -0
  940. package/dist/template/tests/modules/member-graph.test.ts +113 -0
  941. package/dist/template/tests/modules/member-group-calls.test.ts +178 -0
  942. package/dist/template/tests/modules/member-listings.test.ts +88 -0
  943. package/dist/template/tests/modules/member-messages.test.ts +107 -0
  944. package/dist/template/tests/modules/member-notifications.test.ts +70 -0
  945. package/dist/template/tests/modules/member-payouts.test.ts +125 -0
  946. package/dist/template/tests/modules/member-posts.test.ts +118 -0
  947. package/dist/template/tests/modules/member-profile-sections.test.ts +75 -0
  948. package/dist/template/tests/modules/member-protection.test.ts +118 -0
  949. package/dist/template/tests/modules/member-provider-payouts.test.ts +463 -0
  950. package/dist/template/tests/modules/member-reports.test.ts +94 -0
  951. package/dist/template/tests/modules/member-reputation.test.ts +114 -0
  952. package/dist/template/tests/modules/member-services.test.ts +97 -0
  953. package/dist/template/tests/modules/member-subscriptions.test.ts +97 -0
  954. package/dist/template/tests/modules/members.test.ts +99 -0
  955. package/dist/template/tests/modules/popups.test.ts +30 -0
  956. package/dist/template/tests/modules/referrals-commission.test.ts +54 -0
  957. package/dist/template/tests/modules/reporting-exports.test.ts +56 -0
  958. package/dist/template/tests/modules/reporting.test.ts +56 -1
  959. package/dist/template/tests/modules/share.test.ts +21 -3
  960. package/dist/template/tests/modules/social-composer.test.ts +48 -0
  961. package/dist/template/tests/modules/social-render-ffmpeg.test.ts +133 -0
  962. package/dist/template/tests/modules/subscription-billing.test.ts +297 -2
  963. package/dist/template-manifest.json +3319 -1069
  964. package/package.json +1 -1
  965. package/dist/template/src/adapters/agent/pm-brain.ts +0 -125
@@ -0,0 +1,656 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // C12.23: one device's side of end-to-end encrypted messages. The same code
4
+ // runs in the browser (IndexedDB store, server-action transport) and in tests
5
+ // (memory store, services called directly), so what the tests prove is what
6
+ // members run.
7
+ //
8
+ // The device keeps its keys, each conversation's MLS group state, and the
9
+ // messages it has read; the server sees only ciphertext. Before sending, a
10
+ // device makes the group hold exactly the devices the server says should read
11
+ // it — but it accepts a device only if its credential carries the signature
12
+ // key the directory published for it.
13
+ import {
14
+ createApplicationMessage,
15
+ createCommit,
16
+ createGroup,
17
+ decodeGroupState,
18
+ decodeMlsMessage,
19
+ defaultCapabilities,
20
+ defaultLifetime,
21
+ emptyPskIndex,
22
+ encodeGroupState,
23
+ encodeMlsMessage,
24
+ generateKeyPackageWithKey,
25
+ joinGroup,
26
+ processPrivateMessage,
27
+ type ClientState,
28
+ type Credential,
29
+ type PrivateKeyPackage,
30
+ } from "ts-mls";
31
+ import { defaultClientConfig } from "ts-mls/clientConfig.js";
32
+ import { b64, deviceCode, digitGroups, frankTag, historyStatement, identityOf, openCallKey, openPayload, parseIdentity, sameTag, sealCallKey, sealPayload, suite, unb64, utf8, type SealedFile } from "./wire";
33
+
34
+ export interface DeviceRecord {
35
+ deviceId: string;
36
+ userId: string;
37
+ signKey: Uint8Array;
38
+ publicKey: Uint8Array;
39
+ /** Until the server confirms, the packages to register it with. */
40
+ pending?: { keyPackageIds: string[]; lastResortId: string };
41
+ }
42
+
43
+ export interface StoredKeyPackage {
44
+ id: string;
45
+ publicPackage: string;
46
+ privatePackage: PrivateKeyPackage;
47
+ lastResort: boolean;
48
+ }
49
+
50
+ /** A message this device has read, or could not. */
51
+ export interface ReadMessage {
52
+ body: string;
53
+ /** The franking key; revealing it with the body is how a recipient reports. */
54
+ fk: string;
55
+ senderUserId: string;
56
+ /** False when it failed to decrypt or did not match its franking tag. */
57
+ ok: boolean;
58
+ /** C12.36: encrypted files, with the keys to open them. */
59
+ files?: SealedFile[];
60
+ }
61
+
62
+ export interface E2eeStore {
63
+ device(): Promise<DeviceRecord | null>;
64
+ saveDevice(device: DeviceRecord): Promise<void>;
65
+ keyPackage(id: string): Promise<StoredKeyPackage | null>;
66
+ saveKeyPackages(packages: StoredKeyPackage[]): Promise<void>;
67
+ dropKeyPackage(id: string): Promise<void>;
68
+ group(conversationId: string): Promise<{ state: Uint8Array | null; cursor: number } | null>;
69
+ saveGroup(conversationId: string, state: Uint8Array | null, cursor: number): Promise<void>;
70
+ messages(conversationId: string): Promise<Map<string, ReadMessage>>;
71
+ saveMessage(conversationId: string, id: string, message: ReadMessage): Promise<void>;
72
+ dropMessage(conversationId: string, id: string): Promise<void>;
73
+ /** C12.24: a group call's media key, base64. */
74
+ callKey(callId: string): Promise<string | null>;
75
+ saveCallKey(callId: string, key: string): Promise<void>;
76
+ /** C12.34: the private half of this device's history request key, while one is open. */
77
+ historyKey(): Promise<Uint8Array | null>;
78
+ saveHistoryKey(key: Uint8Array | null): Promise<void>;
79
+ /** Conversations this device has read messages in. */
80
+ conversations(): Promise<string[]>;
81
+ /** C12.35: the devices this member last saw verified in a conversation. */
82
+ seenDevices(conversationId: string): Promise<string[] | null>;
83
+ saveSeenDevices(conversationId: string, devices: string[]): Promise<void>;
84
+ /** Forget everything: the device was removed. */
85
+ clear(): Promise<void>;
86
+ }
87
+
88
+ type DeviceEntry = { deviceId: string; userId: string; signatureKey: string };
89
+ type LogEntry = { seq: number; epoch: number; kind: "commit" | "welcome" | "application" | "control"; senderDeviceId: string | null; keyPackageId: string | null; messageId: string | null; callId: string | null; callGeneration: number | null; frankTag: string | null; payload: string };
90
+ export interface SyncResult {
91
+ available: boolean;
92
+ missing: string[];
93
+ epoch: number | null;
94
+ inGroup: boolean;
95
+ roster: string[];
96
+ entitled: DeviceEntry[];
97
+ directory: DeviceEntry[];
98
+ log: LogEntry[];
99
+ more: boolean;
100
+ unclaimed: number;
101
+ calls: { callId: string; generation: number; needsKey: boolean }[];
102
+ }
103
+
104
+ /** The services, however they are reached. Failures throw an error with a `code`. */
105
+ export interface E2eeTransport {
106
+ register(input: { deviceId: string; label: string; signatureKey: string; keyPackages: { id: string; keyPackage: string }[]; lastResort: { id: string; keyPackage: string } }): Promise<unknown>;
107
+ publish(input: { deviceId: string; keyPackages: { id: string; keyPackage: string }[] }): Promise<unknown>;
108
+ sync(input: { conversationId: string; deviceId: string; after: number }): Promise<SyncResult>;
109
+ claim(input: { conversationId: string; deviceId: string; devices: string[] }): Promise<{ packages: { deviceId: string; keyPackageId: string; keyPackage: string }[] }>;
110
+ commit(input: { conversationId: string; deviceId: string; create: boolean; fromEpoch: number; commit: string; welcome?: string; added: { deviceId: string; keyPackageId: string }[]; removed: string[] }): Promise<{ epoch: number }>;
111
+ send(input: { conversationId: string; deviceId: string; epoch: number; ciphertext: string; frankTag: string; attachments: { assetId: string; altText: string }[]; sealedFiles?: string[] }): Promise<{ id: string }>;
112
+ sendCallKey(input: { conversationId: string; deviceId: string; epoch: number; callId: string; generation: number; fresh: boolean; ciphertext: string }): Promise<unknown>;
113
+ requestHistory(input: { deviceId: string; publicKey: string; sig: string }): Promise<{ id: string }>;
114
+ historyRequests(input: { deviceId: string }): Promise<{ requests: { id: string; deviceId: string; label: string; signatureKey: string; publicKey: string; sig: string }[] }>;
115
+ sendHistory(input: { requestId: string; deviceId: string; conversationId: string; enc: string; ct: string }): Promise<unknown>;
116
+ closeHistory(input: { requestId: string }): Promise<unknown>;
117
+ receivedHistory(input: { deviceId: string }): Promise<{ transfers: { id: string; requestId: string; conversationId: string; enc: string; ct: string }[] }>;
118
+ ackHistory(input: { deviceId: string; ids: string[] }): Promise<unknown>;
119
+ }
120
+
121
+ export interface ConversationState {
122
+ /** Everyone has a device, so the conversation is (or can be) encrypted. */
123
+ available: boolean;
124
+ /** This device is in the group and can read and send. */
125
+ ready: boolean;
126
+ missing: string[];
127
+ messages: Map<string, ReadMessage>;
128
+ /** C12.24/37: calls going on here, and which key generation each is on. */
129
+ calls: { callId: string; generation: number }[];
130
+ }
131
+
132
+ const BATCH = 50;
133
+ const LOW_WATER = 10;
134
+ const RETRIES = 4;
135
+
136
+ export interface VerifiedDevice {
137
+ userId: string;
138
+ deviceId: string;
139
+ signatureKey: string;
140
+ /** Groups of five digits identifying this one device's key. */
141
+ fingerprint: string;
142
+ }
143
+
144
+ export interface Verification {
145
+ /** Groups of five digits; the same for everyone who sees the same devices. */
146
+ number: string;
147
+ devices: VerifiedDevice[];
148
+ changed: { added: string[]; removed: string[] };
149
+ }
150
+
151
+ /** C12.34: one of the member's other devices asking for their history. */
152
+ export interface HistoryAsk {
153
+ id: string;
154
+ label: string;
155
+ /** The code the asking device shows; the member compares it before approving. */
156
+ code: string;
157
+ publicKey: string;
158
+ }
159
+
160
+ const HISTORY_INFO = utf8("freeholder:history:v1");
161
+ /** Kept well under a server action's body limit once sealed and base64-encoded. */
162
+ const HISTORY_CHUNK_BYTES = 400_000;
163
+
164
+ /** Where a call's key for one generation is kept on the device. */
165
+ const keySlot = (callId: string, generation: number) => (generation === 0 ? callId : `${callId}#${generation}`);
166
+
167
+ const codeOf = (error: unknown): string | undefined => (error && typeof error === "object" && "code" in error ? String(error.code) : undefined);
168
+
169
+ export class E2eeDevice {
170
+ private queue = new Map<string, Promise<unknown>>();
171
+
172
+ constructor(
173
+ private readonly userId: string,
174
+ private readonly store: E2eeStore,
175
+ private readonly transport: E2eeTransport,
176
+ private readonly label: string,
177
+ ) {}
178
+
179
+ /** One operation at a time per conversation: group state moves strictly forward. */
180
+ private serial<T>(key: string, work: () => Promise<T>): Promise<T> {
181
+ const next = (this.queue.get(key) ?? Promise.resolve()).catch(() => undefined).then(work);
182
+ this.queue.set(key, next);
183
+ return next;
184
+ }
185
+
186
+ private async newKeyPackages(device: DeviceRecord, count: number, lastResort = false): Promise<StoredKeyPackage[]> {
187
+ const cs = await suite();
188
+ const credential: Credential = { credentialType: "basic", identity: utf8(identityOf(device.userId, device.deviceId)) };
189
+ const made: StoredKeyPackage[] = [];
190
+ for (let i = 0; i < count; i++) {
191
+ const kp = await generateKeyPackageWithKey(credential, defaultCapabilities(), defaultLifetime, [], { signKey: device.signKey, publicKey: device.publicKey }, cs);
192
+ const publicPackage = b64(encodeMlsMessage({ keyPackage: kp.publicPackage, wireformat: "mls_key_package", version: "mls10" }));
193
+ made.push({ id: crypto.randomUUID(), publicPackage, privatePackage: kp.privatePackage, lastResort });
194
+ }
195
+ return made;
196
+ }
197
+
198
+ /** This browser's device, registering it the first time. */
199
+ async device(): Promise<DeviceRecord> {
200
+ return this.serial("device", async () => {
201
+ const existing = await this.store.device();
202
+ if (existing && existing.userId === this.userId && !existing.pending) return existing;
203
+ let device = existing?.userId === this.userId ? existing : null;
204
+ if (!device) {
205
+ if (existing) await this.store.clear();
206
+ const keys = await (await suite()).signature.keygen();
207
+ const fresh: DeviceRecord = { deviceId: crypto.randomUUID(), userId: this.userId, signKey: keys.signKey, publicKey: keys.publicKey };
208
+ const packages = await this.newKeyPackages(fresh, BATCH);
209
+ const [lastResort] = await this.newKeyPackages(fresh, 1, true);
210
+ // Everything is kept on the device before anything is published, so a
211
+ // page that closes mid-way resumes this device instead of making another.
212
+ await this.store.saveKeyPackages([...packages, lastResort!]);
213
+ device = { ...fresh, pending: { keyPackageIds: packages.map((p) => p.id), lastResortId: lastResort!.id } };
214
+ await this.store.saveDevice(device);
215
+ }
216
+ const pending = device.pending!;
217
+ const stored = await Promise.all([...pending.keyPackageIds, pending.lastResortId].map((id) => this.store.keyPackage(id)));
218
+ const publish = stored.filter((p): p is StoredKeyPackage => Boolean(p)).map((p) => ({ id: p.id, keyPackage: p.publicPackage, lastResort: p.lastResort }));
219
+ const lastResort = publish.find((p) => p.lastResort);
220
+ if (!lastResort) throw new Error("This device's keys are incomplete.");
221
+ await this.transport.register({
222
+ deviceId: device.deviceId,
223
+ label: this.label,
224
+ signatureKey: b64(device.publicKey),
225
+ keyPackages: publish.filter((p) => !p.lastResort).map(({ id, keyPackage }) => ({ id, keyPackage })),
226
+ lastResort: { id: lastResort.id, keyPackage: lastResort.keyPackage },
227
+ });
228
+ const registered: DeviceRecord = { deviceId: device.deviceId, userId: device.userId, signKey: device.signKey, publicKey: device.publicKey };
229
+ await this.store.saveDevice(registered);
230
+ return registered;
231
+ });
232
+ }
233
+
234
+ private config(directory: DeviceEntry[]) {
235
+ const keys = new Map(directory.map((d) => [d.deviceId, d]));
236
+ return {
237
+ ...defaultClientConfig,
238
+ authService: {
239
+ // Only a device the directory vouches for, carrying exactly the key it published.
240
+ async validateCredential(credential: Credential, signaturePublicKey: Uint8Array): Promise<boolean> {
241
+ if (credential.credentialType !== "basic") return false;
242
+ const who = parseIdentity(credential.identity);
243
+ const known = who ? keys.get(who.deviceId) : undefined;
244
+ return Boolean(known && known.userId === who!.userId && known.signatureKey === b64(signaturePublicKey));
245
+ },
246
+ },
247
+ };
248
+ }
249
+
250
+ private async load(conversationId: string, directory: DeviceEntry[]): Promise<{ state: ClientState | null; cursor: number }> {
251
+ const saved = await this.store.group(conversationId);
252
+ if (!saved?.state) return { state: null, cursor: saved?.cursor ?? 0 };
253
+ const decoded = decodeGroupState(saved.state, 0);
254
+ if (!decoded) return { state: null, cursor: saved.cursor };
255
+ return { state: { ...decoded[0], clientConfig: this.config(directory) }, cursor: saved.cursor };
256
+ }
257
+
258
+ private async save(conversationId: string, state: ClientState | null, cursor: number) {
259
+ await this.store.saveGroup(conversationId, state ? encodeGroupState(state) : null, cursor);
260
+ }
261
+
262
+ /** Apply everything new in the log, then make the group match who should read it. */
263
+ async sync(conversationId: string): Promise<ConversationState> {
264
+ const device = await this.device();
265
+ return this.serial(conversationId, async () => {
266
+ let result: SyncResult | null = null;
267
+ for (let attempt = 0; attempt < RETRIES; attempt++) {
268
+ result = await this.catchUp(conversationId, device);
269
+ if (!result.available) break;
270
+ try {
271
+ if (!(await this.reconcile(conversationId, device, result))) break;
272
+ } catch (error) {
273
+ if (codeOf(error) !== "conflict") throw error;
274
+ }
275
+ }
276
+ if (result && result.unclaimed < LOW_WATER) await this.topUp(device);
277
+ if (result?.available) await this.tendCallKeys(conversationId, device, result.calls);
278
+ const { state } = await this.load(conversationId, result?.directory ?? []);
279
+ const fresh = result ? await this.transport.sync({ conversationId, deviceId: device.deviceId, after: Number.MAX_SAFE_INTEGER }) : null;
280
+ return {
281
+ available: fresh?.available ?? false,
282
+ ready: Boolean(state && fresh?.inGroup),
283
+ missing: fresh?.missing ?? [],
284
+ messages: await this.store.messages(conversationId),
285
+ calls: (fresh?.calls ?? []).map(({ callId, generation }) => ({ callId, generation })),
286
+ };
287
+ });
288
+ }
289
+
290
+ private async topUp(device: DeviceRecord) {
291
+ const packages = await this.newKeyPackages(device, BATCH);
292
+ await this.store.saveKeyPackages(packages);
293
+ await this.transport.publish({ deviceId: device.deviceId, keyPackages: packages.map((p) => ({ id: p.id, keyPackage: p.publicPackage })) });
294
+ }
295
+
296
+ private async catchUp(conversationId: string, device: DeviceRecord): Promise<SyncResult> {
297
+ const cs = await suite();
298
+ let result: SyncResult;
299
+ let { state, cursor } = await this.load(conversationId, []);
300
+ do {
301
+ result = await this.transport.sync({ conversationId, deviceId: device.deviceId, after: cursor });
302
+ const config = this.config(result.directory);
303
+ if (state) state = { ...state, clientConfig: config };
304
+ const keys = new Map(result.directory.map((d) => [d.deviceId, d]));
305
+ for (const entry of result.log) {
306
+ cursor = entry.seq;
307
+ if (entry.senderDeviceId === device.deviceId && entry.kind !== "welcome") {
308
+ await this.save(conversationId, state, cursor);
309
+ continue;
310
+ }
311
+ const decoded = decodeMlsMessage(unb64(entry.payload), 0)?.[0];
312
+ try {
313
+ if (entry.kind === "welcome") {
314
+ const kp = entry.keyPackageId ? await this.store.keyPackage(entry.keyPackageId) : null;
315
+ const welcome = decoded?.wireformat === "mls_welcome" ? decoded.welcome : null;
316
+ const published = kp ? decodeMlsMessage(unb64(kp.publicPackage), 0)?.[0] : undefined;
317
+ if (kp && welcome && published?.wireformat === "mls_key_package") {
318
+ state = await joinGroup(welcome, published.keyPackage, kp.privatePackage, emptyPskIndex, cs, undefined, undefined, config);
319
+ if (!kp.lastResort) await this.store.dropKeyPackage(kp.id);
320
+ }
321
+ } else if (state && decoded?.wireformat === "mls_private_message") {
322
+ const processed = await processPrivateMessage(state, decoded.privateMessage, emptyPskIndex, cs);
323
+ state = processed.newState;
324
+ if (state.groupActiveState.kind === "removedFromGroup") state = null;
325
+ if (processed.kind === "applicationMessage" && entry.kind === "control" && entry.callId) {
326
+ const sender = entry.senderDeviceId ? keys.get(entry.senderDeviceId) : undefined;
327
+ const generation = entry.callGeneration ?? 0;
328
+ const key = sender ? await openCallKey(conversationId, entry.callId, generation, processed.message, { deviceId: sender.deviceId, signatureKey: unb64(sender.signatureKey) }) : null;
329
+ if (key) await this.store.saveCallKey(keySlot(entry.callId, generation), key);
330
+ } else if (processed.kind === "applicationMessage" && entry.messageId) {
331
+ const sender = entry.senderDeviceId ? keys.get(entry.senderDeviceId) : undefined;
332
+ const payload = sender ? await openPayload(conversationId, processed.message, { deviceId: sender.deviceId, signatureKey: unb64(sender.signatureKey) }) : null;
333
+ const matches = Boolean(payload && sender && entry.frankTag && sameTag(await frankTag(unb64(payload.fk), conversationId, sender.userId, payload.body), entry.frankTag));
334
+ await this.store.saveMessage(conversationId, entry.messageId, matches ? { body: payload!.body, fk: payload!.fk, senderUserId: sender!.userId, ok: true, ...(payload!.files ? { files: payload!.files } : {}) } : { body: "", fk: "", senderUserId: sender?.userId ?? "", ok: false });
335
+ }
336
+ }
337
+ } catch {
338
+ // A message this device cannot open (sent before it joined, or
339
+ // malformed) is shown as unreadable; the log moves on.
340
+ if (entry.kind === "application" && entry.messageId) await this.store.saveMessage(conversationId, entry.messageId, { body: "", fk: "", senderUserId: "", ok: false });
341
+ }
342
+ await this.save(conversationId, state, cursor);
343
+ }
344
+ } while (result.more);
345
+ return result;
346
+ }
347
+
348
+ /** Make the group hold exactly the entitled devices. True when it committed a change. */
349
+ private async reconcile(conversationId: string, device: DeviceRecord, sync: SyncResult): Promise<boolean> {
350
+ const cs = await suite();
351
+ const { state, cursor } = await this.load(conversationId, sync.directory);
352
+ const entitled = new Set(sync.entitled.map((d) => d.deviceId));
353
+ if (sync.epoch === null) {
354
+ // Nobody has made the group yet: this device does, with everyone in it.
355
+ const others = sync.entitled.filter((d) => d.deviceId !== device.deviceId).map((d) => d.deviceId);
356
+ if (!others.length) return false;
357
+ const [own] = await this.newKeyPackages(device, 1);
358
+ const ownPackage = decodeMlsMessage(unb64(own!.publicPackage), 0)![0];
359
+ if (ownPackage.wireformat !== "mls_key_package") return false;
360
+ const created = await createGroup(utf8(conversationId), ownPackage.keyPackage, own!.privatePackage, [], cs, this.config(sync.directory));
361
+ return this.change(conversationId, device, created, cursor, true, others, []);
362
+ }
363
+ if (!sync.inGroup || !state) return false;
364
+ const add = sync.entitled.map((d) => d.deviceId).filter((id) => !sync.roster.includes(id));
365
+ const remove = sync.roster.filter((id) => !entitled.has(id));
366
+ if (!add.length && !remove.length) return false;
367
+ return this.change(conversationId, device, state, cursor, false, add, remove);
368
+ }
369
+
370
+ private async change(conversationId: string, device: DeviceRecord, state: ClientState, cursor: number, create: boolean, add: string[], remove: string[]): Promise<boolean> {
371
+ const cs = await suite();
372
+ const claimed = add.length ? (await this.transport.claim({ conversationId, deviceId: device.deviceId, devices: add })).packages : [];
373
+ const proposals = [];
374
+ for (const c of claimed) {
375
+ const decoded = decodeMlsMessage(unb64(c.keyPackage), 0)?.[0];
376
+ if (decoded?.wireformat !== "mls_key_package") throw new Error("A key package could not be read.");
377
+ proposals.push({ proposalType: "add" as const, add: { keyPackage: decoded.keyPackage } });
378
+ }
379
+ for (const id of remove) {
380
+ const leaf = state.ratchetTree.findIndex((n) => n?.nodeType === "leaf" && parseIdentity((n.leaf.credential as { identity: Uint8Array }).identity)?.deviceId === id);
381
+ if (leaf >= 0) proposals.push({ proposalType: "remove" as const, remove: { removed: leaf / 2 } });
382
+ }
383
+ const result = await createCommit({ state, cipherSuite: cs }, { extraProposals: proposals, ratchetTreeExtension: true });
384
+ await this.transport.commit({
385
+ conversationId,
386
+ deviceId: device.deviceId,
387
+ create,
388
+ fromEpoch: Number(state.groupContext.epoch),
389
+ commit: b64(encodeMlsMessage(result.commit)),
390
+ welcome: result.welcome ? b64(encodeMlsMessage({ welcome: result.welcome, wireformat: "mls_welcome", version: "mls10" })) : undefined,
391
+ added: claimed.map((c) => ({ deviceId: c.deviceId, keyPackageId: c.keyPackageId })),
392
+ removed: remove,
393
+ });
394
+ // Only an accepted commit moves this device to the next epoch.
395
+ await this.save(conversationId, result.newState, cursor);
396
+ return true;
397
+ }
398
+
399
+ private async sendControl(conversationId: string, device: DeviceRecord, callId: string, generation: number, key: string, fresh: boolean) {
400
+ const cs = await suite();
401
+ const { state, cursor } = await this.load(conversationId, []);
402
+ if (!state) throw Object.assign(new Error("not ready"), { code: "conflict" });
403
+ const message = await createApplicationMessage(state, await sealCallKey(conversationId, callId, generation, key, device), cs);
404
+ await this.save(conversationId, message.newState, cursor);
405
+ await this.transport.sendCallKey({
406
+ conversationId,
407
+ deviceId: device.deviceId,
408
+ epoch: Number(state.groupContext.epoch),
409
+ callId,
410
+ generation,
411
+ fresh,
412
+ ciphertext: b64(encodeMlsMessage({ privateMessage: message.privateMessage, wireformat: "mls_private_message", version: "mls10" })),
413
+ });
414
+ }
415
+
416
+ /**
417
+ * Keep every running call's current key with every device that should
418
+ * have it: send it again to devices that joined since, and when the call
419
+ * moved to a new generation (someone left, C12.37), a device that held the
420
+ * previous key makes the new one. The server takes the first and refuses
421
+ * the rest, so all devices end up on one key.
422
+ */
423
+ private async tendCallKeys(conversationId: string, device: DeviceRecord, calls: SyncResult["calls"]) {
424
+ for (const call of calls) {
425
+ if (!call.needsKey) continue;
426
+ const tolerate = (error: unknown) => { if (codeOf(error) !== "conflict") throw error; };
427
+ const current = await this.store.callKey(keySlot(call.callId, call.generation));
428
+ if (current) {
429
+ await this.sendControl(conversationId, device, call.callId, call.generation, current, false).catch(tolerate);
430
+ continue;
431
+ }
432
+ let heldBefore = false;
433
+ for (let g = call.generation - 1; g >= 0 && !heldBefore; g--) heldBefore = Boolean(await this.store.callKey(keySlot(call.callId, g)));
434
+ if (!heldBefore) continue;
435
+ const key = b64(crypto.getRandomValues(new Uint8Array(32)));
436
+ try {
437
+ await this.sendControl(conversationId, device, call.callId, call.generation, key, true);
438
+ await this.store.saveCallKey(keySlot(call.callId, call.generation), key);
439
+ } catch (error) {
440
+ tolerate(error);
441
+ }
442
+ }
443
+ }
444
+
445
+ /**
446
+ * C12.24: make a fresh media key for a call and send it to everyone's
447
+ * devices in the conversation. Returns the key for this device's own use.
448
+ */
449
+ async startCallKey(conversationId: string, callId: string): Promise<string> {
450
+ const existing = await this.store.callKey(callId);
451
+ if (existing) return existing;
452
+ const device = await this.device();
453
+ const key = b64(crypto.getRandomValues(new Uint8Array(32)));
454
+ for (let attempt = 0; attempt < RETRIES; attempt++) {
455
+ const status = await this.sync(conversationId);
456
+ if (!status.ready) throw Object.assign(new Error("This device has not been added to the conversation yet."), { code: "not_ready" });
457
+ try {
458
+ await this.serial(conversationId, () => this.sendControl(conversationId, device, callId, 0, key, true));
459
+ await this.store.saveCallKey(callId, key);
460
+ return key;
461
+ } catch (error) {
462
+ if (codeOf(error) !== "conflict") throw error;
463
+ }
464
+ }
465
+ throw Object.assign(new Error("The conversation kept changing; try again."), { code: "conflict" });
466
+ }
467
+
468
+ /** C12.24/37: the call's current key generation, and its key once a device in the call has sent it here. */
469
+ async currentCallKey(conversationId: string, callId: string): Promise<{ generation: number; key: string | null }> {
470
+ const status = await this.sync(conversationId);
471
+ const generation = status.calls.find((c) => c.callId === callId)?.generation ?? 0;
472
+ return { generation, key: await this.store.callKey(keySlot(callId, generation)) };
473
+ }
474
+
475
+ async callKey(conversationId: string, callId: string): Promise<string | null> {
476
+ return (await this.currentCallKey(conversationId, callId)).key;
477
+ }
478
+
479
+ /**
480
+ * C12.35: who is really in this conversation's group, read from this
481
+ * device's own MLS tree — not from what the server says — with a safety
482
+ * number two people can compare. The number is the same on every device
483
+ * of every person iff they all see the same set of devices and keys, so a
484
+ * device added without someone's knowledge changes it for everyone.
485
+ * `changed` lists devices that came or went since this member last
486
+ * confirmed what they saw.
487
+ */
488
+ async verification(conversationId: string): Promise<Verification | null> {
489
+ await this.sync(conversationId);
490
+ const { state } = await this.load(conversationId, []);
491
+ if (!state) return null;
492
+ const devices: VerifiedDevice[] = [];
493
+ for (const node of state.ratchetTree) {
494
+ if (node?.nodeType !== "leaf" || node.leaf.credential.credentialType !== "basic") continue;
495
+ const who = parseIdentity(node.leaf.credential.identity);
496
+ if (!who) continue;
497
+ devices.push({ userId: who.userId, deviceId: who.deviceId, signatureKey: b64(node.leaf.signaturePublicKey), fingerprint: "" });
498
+ }
499
+ devices.sort((a, b) => (a.userId + a.deviceId).localeCompare(b.userId + b.deviceId));
500
+ const digest = async (text: string) => new Uint8Array(await crypto.subtle.digest("SHA-256", utf8(text) as BufferSource));
501
+ for (const d of devices) d.fingerprint = await deviceCode(d.userId, d.deviceId, d.signatureKey);
502
+ const number = digitGroups(await digest(`freeholder:safety:v1\n${conversationId}\n${devices.map((d) => `${d.userId}:${d.deviceId}:${d.signatureKey}`).join("\n")}`), 12);
503
+ const current = devices.map((d) => `${d.userId}:${d.deviceId}`);
504
+ const seen = await this.store.seenDevices(conversationId);
505
+ if (!seen) await this.store.saveSeenDevices(conversationId, current);
506
+ const before = new Set(seen ?? current);
507
+ const now = new Set(current);
508
+ return {
509
+ number,
510
+ devices,
511
+ changed: { added: current.filter((d) => !before.has(d)), removed: [...before].filter((d) => !now.has(d)) },
512
+ };
513
+ }
514
+
515
+ /** C12.35: the member has looked at the devices and accepts them as they are. */
516
+ async confirmDevices(conversationId: string): Promise<void> {
517
+ const v = await this.verification(conversationId);
518
+ if (v) await this.store.saveSeenDevices(conversationId, v.devices.map((d) => `${d.userId}:${d.deviceId}`));
519
+ }
520
+
521
+ /** C12.34/35: this device's own code, shown so the member can match it on another device. */
522
+ async code(): Promise<string> {
523
+ const device = await this.device();
524
+ return deviceCode(this.userId, device.deviceId, b64(device.publicKey));
525
+ }
526
+
527
+ /** C12.34: ask the member's other devices for earlier history. Returns this device's code. */
528
+ async askForHistory(): Promise<string> {
529
+ const device = await this.device();
530
+ const cs = await suite();
531
+ const pair = await cs.hpke.generateKeyPair();
532
+ const publicKey = b64(await cs.hpke.exportPublicKey(pair.publicKey));
533
+ await this.store.saveHistoryKey(await cs.hpke.exportPrivateKey(pair.privateKey));
534
+ const sig = b64(await cs.signature.sign(device.signKey, historyStatement(this.userId, device.deviceId, publicKey)));
535
+ await this.transport.requestHistory({ deviceId: device.deviceId, publicKey, sig });
536
+ return this.code();
537
+ }
538
+
539
+ /** C12.34: requests from the member's other devices, each checked against that device's own key. */
540
+ async historyAsks(): Promise<HistoryAsk[]> {
541
+ const device = await this.device();
542
+ const cs = await suite();
543
+ const { requests } = await this.transport.historyRequests({ deviceId: device.deviceId });
544
+ const asks: HistoryAsk[] = [];
545
+ for (const r of requests) {
546
+ const ok = await cs.signature.verify(unb64(r.signatureKey), historyStatement(this.userId, r.deviceId, r.publicKey), unb64(r.sig)).catch(() => false);
547
+ if (ok) asks.push({ id: r.id, label: r.label, code: await deviceCode(this.userId, r.deviceId, r.signatureKey), publicKey: r.publicKey });
548
+ }
549
+ return asks;
550
+ }
551
+
552
+ /** C12.34: the member approved: seal every conversation this device has read to the asking device. */
553
+ async giveHistory(ask: HistoryAsk): Promise<number> {
554
+ const device = await this.device();
555
+ const cs = await suite();
556
+ const to = await cs.hpke.importPublicKey(unb64(ask.publicKey));
557
+ let sent = 0;
558
+ for (const conversationId of await this.store.conversations()) {
559
+ // Up to date first, so the new device gets everything this one can read.
560
+ await this.sync(conversationId).catch(() => undefined);
561
+ const entries = [...(await this.store.messages(conversationId))].filter(([, m]) => m.ok);
562
+ let chunk: [string, ReadMessage][] = [];
563
+ let size = 0;
564
+ const flush = async () => {
565
+ if (!chunk.length) return;
566
+ const plaintext = utf8(JSON.stringify({ v: 1, conversationId, messages: chunk }));
567
+ const sealed = await cs.hpke.seal(to, plaintext, HISTORY_INFO, utf8(`${ask.id}\n${conversationId}`));
568
+ await this.transport.sendHistory({ requestId: ask.id, deviceId: device.deviceId, conversationId, enc: b64(sealed.enc), ct: b64(sealed.ct) });
569
+ sent += chunk.length;
570
+ chunk = [];
571
+ size = 0;
572
+ };
573
+ try {
574
+ for (const entry of entries) {
575
+ const bytes = JSON.stringify(entry).length;
576
+ if (size + bytes > HISTORY_CHUNK_BYTES) await flush();
577
+ chunk.push(entry);
578
+ size += bytes;
579
+ }
580
+ await flush();
581
+ } catch (error) {
582
+ // A conversation the member has since left is skipped, not fatal.
583
+ if (codeOf(error) !== "not_found") throw error;
584
+ }
585
+ }
586
+ await this.transport.closeHistory({ requestId: ask.id });
587
+ return sent;
588
+ }
589
+
590
+ /** C12.34: open history sealed to this device and keep what it did not already have. */
591
+ async takeHistory(): Promise<number> {
592
+ const key = await this.store.historyKey();
593
+ if (!key) return 0;
594
+ const device = await this.device();
595
+ const cs = await suite();
596
+ const privateKey = await cs.hpke.importPrivateKey(key);
597
+ const { transfers } = await this.transport.receivedHistory({ deviceId: device.deviceId });
598
+ let kept = 0;
599
+ const done: string[] = [];
600
+ for (const t of transfers) {
601
+ try {
602
+ const plain = await cs.hpke.open(privateKey, unb64(t.enc), unb64(t.ct), HISTORY_INFO, utf8(`${t.requestId}\n${t.conversationId}`));
603
+ const bundle = JSON.parse(new TextDecoder().decode(plain)) as { v: number; conversationId: string; messages: [string, ReadMessage][] };
604
+ if (bundle.v === 1 && bundle.conversationId === t.conversationId) {
605
+ const have = await this.store.messages(t.conversationId);
606
+ for (const [id, message] of bundle.messages) {
607
+ if (have.get(id)?.ok) continue;
608
+ await this.store.saveMessage(t.conversationId, id, message);
609
+ kept++;
610
+ }
611
+ }
612
+ } catch {
613
+ // Something that does not open with this device's key is dropped.
614
+ }
615
+ done.push(t.id);
616
+ }
617
+ if (done.length) await this.transport.ackHistory({ deviceId: device.deviceId, ids: done });
618
+ return kept;
619
+ }
620
+
621
+ /** Encrypt and send. Returns the message id, or null if the conversation cannot be encrypted. */
622
+ async send(conversationId: string, body: string, attachments: { assetId: string; altText: string }[] = [], files: SealedFile[] = []): Promise<string | null> {
623
+ const device = await this.device();
624
+ for (let attempt = 0; attempt < RETRIES; attempt++) {
625
+ const status = await this.sync(conversationId);
626
+ if (!status.available) return null;
627
+ if (!status.ready) throw Object.assign(new Error("This device has not been added to the conversation yet."), { code: "not_ready" });
628
+ try {
629
+ return await this.serial(conversationId, async () => {
630
+ const cs = await suite();
631
+ const { state, cursor } = await this.load(conversationId, []);
632
+ if (!state) throw Object.assign(new Error("not ready"), { code: "conflict" });
633
+ const sealed = await sealPayload(conversationId, body, device, files);
634
+ const message = await createApplicationMessage(state, sealed.bytes, cs);
635
+ // The ratchet moves forward before anything leaves the device, so a
636
+ // key is never used twice even if the server refuses this message.
637
+ await this.save(conversationId, message.newState, cursor);
638
+ const { id } = await this.transport.send({
639
+ conversationId,
640
+ deviceId: device.deviceId,
641
+ epoch: Number(state.groupContext.epoch),
642
+ ciphertext: b64(encodeMlsMessage({ privateMessage: message.privateMessage, wireformat: "mls_private_message", version: "mls10" })),
643
+ frankTag: await frankTag(unb64(sealed.fk), conversationId, this.userId, body),
644
+ attachments,
645
+ sealedFiles: files.map((f) => f.blob),
646
+ });
647
+ await this.store.saveMessage(conversationId, id, { body, fk: sealed.fk, senderUserId: this.userId, ok: true, ...(files.length ? { files } : {}) });
648
+ return id;
649
+ });
650
+ } catch (error) {
651
+ if (codeOf(error) !== "conflict") throw error;
652
+ }
653
+ }
654
+ throw Object.assign(new Error("The conversation kept changing; try again."), { code: "conflict" });
655
+ }
656
+ }