sanoma 0.11.19 → 0.11.21

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 (1334) hide show
  1. package/README.md +22 -22
  2. package/app/README.md +548 -0
  3. package/app/dist/api.d.ts +984 -0
  4. package/app/dist/api.js +261 -0
  5. package/app/dist/api.js.map +1 -0
  6. package/app/dist/app-bundle.d.ts +81 -0
  7. package/app/dist/app-bundle.js +13 -0
  8. package/app/dist/app-bundle.js.map +1 -0
  9. package/app/dist/build.d.ts +89 -0
  10. package/app/dist/build.js +843 -0
  11. package/app/dist/build.js.map +1 -0
  12. package/app/dist/bundle-build.d.ts +39 -0
  13. package/app/dist/bundle-build.js +585 -0
  14. package/app/dist/bundle-build.js.map +1 -0
  15. package/app/dist/client/assets/ArrowUp.es-DOgvoS0P.js +1 -0
  16. package/app/dist/client/assets/Copy.es-B0D5SwiQ.js +1 -0
  17. package/app/dist/client/assets/DialogTitle-BgjYK22C.js +1 -0
  18. package/app/dist/client/assets/FloppyDisk.es-DnuNe_a8.js +1 -0
  19. package/app/dist/client/assets/Globe.es-B6x2e4-a.js +1 -0
  20. package/app/dist/client/assets/MagnifyingGlass.es-DoNoHEhT.js +1 -0
  21. package/app/dist/client/assets/Play.es-BwXalGBh.js +1 -0
  22. package/app/dist/client/assets/Plug.es-CaZsN5P-.js +1 -0
  23. package/app/dist/client/assets/Plus.es-w9VPpTJB.js +1 -0
  24. package/app/dist/client/assets/Separator-BAhKFgSd.js +1 -0
  25. package/app/dist/client/assets/X.es-DKMYClf-.js +1 -0
  26. package/app/dist/client/assets/_id-BSRAaWtO.js +1 -0
  27. package/app/dist/client/assets/_id-BjDP-cPH.js +1 -0
  28. package/app/dist/client/assets/_id-BudM76zX.js +1 -0
  29. package/app/dist/client/assets/_id-C37U5bBa.js +1 -0
  30. package/app/dist/client/assets/_id-lmg24JVh.js +2 -0
  31. package/app/dist/client/assets/_name-CylqFo_t.js +1 -0
  32. package/app/dist/client/assets/_name-D8Gl8iwy.js +4 -0
  33. package/app/dist/client/assets/_name-DdPCU8pt.js +1 -0
  34. package/app/dist/client/assets/_name-TteWQXe0.js +1 -0
  35. package/app/dist/client/assets/_vendor-BLxW83yk.js +1 -0
  36. package/app/dist/client/assets/_vendor-Bq3uZU4-.js +1 -0
  37. package/app/dist/client/assets/app-chrome-H8uZ4dHI.js +16 -0
  38. package/app/dist/client/assets/app-scope-BeUW_8Qh.js +1 -0
  39. package/app/dist/client/assets/approval-DpgmTc63.js +1 -0
  40. package/app/dist/client/assets/apps-71ZEzcL9.js +1 -0
  41. package/app/dist/client/assets/apps-CoWzNm8M.js +1 -0
  42. package/app/dist/client/assets/change-glance-DbYcBT7H.js +1 -0
  43. package/app/dist/client/assets/changes-DIJvP7wQ.js +1 -0
  44. package/app/dist/client/assets/chat-button-BgpOfYh1.js +1 -0
  45. package/app/dist/client/assets/chat-prompt-hiawXcK0.js +1 -0
  46. package/app/dist/client/assets/clipboard-Zb0yr0Ja.js +3 -0
  47. package/app/dist/client/assets/code-BVYaiQEr.js +32 -0
  48. package/app/dist/client/assets/common-Dw2i6XKZ.js +3 -0
  49. package/app/dist/client/assets/composite-D9GNDzFj.js +1 -0
  50. package/app/dist/client/assets/connect-CIq2KJTz.js +1 -0
  51. package/app/dist/client/assets/connections-iqd2XbWQ.js +5 -0
  52. package/app/dist/client/assets/connectors-rI8_D1n1.js +1 -0
  53. package/app/dist/client/assets/content-DOwCrGXH.js +1 -0
  54. package/app/dist/client/assets/credentials-26vu6Fv5.js +1 -0
  55. package/app/dist/client/assets/data-sDMlKaLV.js +1 -0
  56. package/app/dist/client/assets/decidable-zcYI7bY8.js +1 -0
  57. package/app/dist/client/assets/declaration-form-BtSVvxhq.js +1 -0
  58. package/app/dist/client/assets/dialog-DskpUgkl.js +1 -0
  59. package/app/dist/client/assets/existing-BD3VgJ_8.js +1 -0
  60. package/app/dist/client/assets/fraunces-latin-ext-wght-normal-Ca2vKHc0.woff2 +0 -0
  61. package/app/dist/client/assets/fraunces-latin-wght-normal-ukD16Tqj.woff2 +0 -0
  62. package/app/dist/client/assets/fraunces-vietnamese-wght-normal-CnvboYUG.woff2 +0 -0
  63. package/app/dist/client/assets/graph-BBLU_iSl.css +1 -0
  64. package/app/dist/client/assets/graph-Prxl3c55.js +7 -0
  65. package/app/dist/client/assets/grid-diff-SMsvea6t.js +1 -0
  66. package/app/dist/client/assets/hosting-BBHUppH-.js +1 -0
  67. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-italic-2syK4fUT.woff +0 -0
  68. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-italic-CBJ8pzag.woff2 +0 -0
  69. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  70. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  71. package/app/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  72. package/app/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  73. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-italic-B4oTjJdl.woff +0 -0
  74. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-italic-CBjNughH.woff2 +0 -0
  75. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  76. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  77. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  78. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  79. package/app/dist/client/assets/ibm-plex-mono-latin-400-italic-66oory27.woff +0 -0
  80. package/app/dist/client/assets/ibm-plex-mono-latin-400-italic-BqAiT5Ww.woff2 +0 -0
  81. package/app/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  82. package/app/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  83. package/app/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  84. package/app/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  85. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-italic-B7_fu1kp.woff2 +0 -0
  86. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-italic-Bg0ZHwF4.woff +0 -0
  87. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  88. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  89. package/app/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  90. package/app/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  91. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-italic-D6eaYXMU.woff +0 -0
  92. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-italic-DRuN92E5.woff2 +0 -0
  93. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  94. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  95. package/app/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  96. package/app/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  97. package/app/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-italic-O9KpBTMP.woff2 +0 -0
  98. package/app/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  99. package/app/dist/client/assets/ibm-plex-sans-cyrillic-wght-italic-BC1D_hcE.woff2 +0 -0
  100. package/app/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  101. package/app/dist/client/assets/ibm-plex-sans-greek-wght-italic-BOZ1G-_q.woff2 +0 -0
  102. package/app/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  103. package/app/dist/client/assets/ibm-plex-sans-latin-ext-wght-italic-QwKXLQRc.woff2 +0 -0
  104. package/app/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  105. package/app/dist/client/assets/ibm-plex-sans-latin-wght-italic-DKUSOBgV.woff2 +0 -0
  106. package/app/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  107. package/app/dist/client/assets/ibm-plex-sans-vietnamese-wght-italic-CKSJVnJa.woff2 +0 -0
  108. package/app/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  109. package/app/dist/client/assets/import-B92fd4Tl.js +1 -0
  110. package/app/dist/client/assets/inbox-57oGZtxE.js +1 -0
  111. package/app/dist/client/assets/inbox-B2AMNtk5.js +1 -0
  112. package/app/dist/client/assets/index-Bn3XeKy8.js +10 -0
  113. package/app/dist/client/assets/kit-BsK6VZTQ.js +1 -0
  114. package/app/dist/client/assets/lazyRouteComponent-Uri98HNq.js +1 -0
  115. package/app/dist/client/assets/lines-DuFrbGkQ.js +3 -0
  116. package/app/dist/client/assets/motion-C8lNeYvK.js +1 -0
  117. package/app/dist/client/assets/names-COx1nqcj.js +1 -0
  118. package/app/dist/client/assets/people-ISOMYCTu.js +1 -0
  119. package/app/dist/client/assets/permissions-Cenat84K.js +2 -0
  120. package/app/dist/client/assets/permissions-grid-B2GtGwzv.js +1 -0
  121. package/app/dist/client/assets/route-BP1XwaTB.js +1 -0
  122. package/app/dist/client/assets/route-KVU6QgwJ.js +1 -0
  123. package/app/dist/client/assets/runs-table-35lNzKLn.js +1 -0
  124. package/app/dist/client/assets/scenario-DSwsavxS.js +1 -0
  125. package/app/dist/client/assets/scenario-graph-CAzWOtqV.js +1 -0
  126. package/app/dist/client/assets/schema-BpqanhX0.js +1 -0
  127. package/app/dist/client/assets/separator-BlwkzEY0.js +1 -0
  128. package/app/dist/client/assets/sheet-BYL9XU5s.js +1 -0
  129. package/app/dist/client/assets/site-icon-DZvOfBvU.js +1 -0
  130. package/app/dist/client/assets/sites.index-CcNo6N8u.js +1 -0
  131. package/app/dist/client/assets/spinner-BGy6LWIW.js +1 -0
  132. package/app/dist/client/assets/start-form-Bgo9I63s.js +1 -0
  133. package/app/dist/client/assets/store-BGu0d2Ld.js +57 -0
  134. package/app/dist/client/assets/style-CCDLLPgG.css +2 -0
  135. package/app/dist/client/assets/table-DjbI5VTn.js +1 -0
  136. package/app/dist/client/assets/textarea-DXO0eUdp.js +1 -0
  137. package/app/dist/client/assets/useLoaderData-BQd5yMlA.js +1 -0
  138. package/app/dist/client/assets/useOpenInteractionType-Bin8RjM5.js +1 -0
  139. package/app/dist/client/assets/useRegisterFieldControl-CQPTOU7Z.js +1 -0
  140. package/app/dist/client/assets/useValueChanged-DMkuvFZG.js +1 -0
  141. package/app/dist/client/assets/utils-CMsCvwYQ.js +1 -0
  142. package/app/dist/client/assets/who-are-you-Bt1WI3Cz.js +1 -0
  143. package/app/dist/client/assets/workflow-BJpO61A-.js +1 -0
  144. package/app/dist/client/assets/workflow-view-DP-UlRiH.js +1 -0
  145. package/app/dist/client/assets/workflows-BLCBgxbx.js +1 -0
  146. package/app/dist/components/grid/plan.d.ts +373 -0
  147. package/app/dist/components/grid/plan.js +347 -0
  148. package/app/dist/components/grid/plan.js.map +1 -0
  149. package/app/dist/content-files.d.ts +59 -0
  150. package/app/dist/content-files.js +218 -0
  151. package/app/dist/content-files.js.map +1 -0
  152. package/app/dist/content-types.d.ts +39 -0
  153. package/app/dist/content-types.js +16 -0
  154. package/app/dist/content-types.js.map +1 -0
  155. package/app/dist/context.d.ts +92 -0
  156. package/app/dist/context.js +2 -0
  157. package/app/dist/context.js.map +1 -0
  158. package/app/dist/handler.d.ts +72 -0
  159. package/app/dist/handler.js +179 -0
  160. package/app/dist/handler.js.map +1 -0
  161. package/app/dist/index.d.ts +81 -0
  162. package/app/dist/index.js +345 -0
  163. package/app/dist/index.js.map +1 -0
  164. package/app/dist/lib/apply-plan.d.ts +29 -0
  165. package/app/dist/lib/apply-plan.js +65 -0
  166. package/app/dist/lib/apply-plan.js.map +1 -0
  167. package/app/dist/lib/chat.d.ts +104 -0
  168. package/app/dist/lib/chat.js +72 -0
  169. package/app/dist/lib/chat.js.map +1 -0
  170. package/app/dist/lib/names.d.ts +4 -0
  171. package/app/dist/lib/names.js +11 -0
  172. package/app/dist/lib/names.js.map +1 -0
  173. package/app/dist/login/admission.d.ts +16 -0
  174. package/app/dist/login/admission.js +63 -0
  175. package/app/dist/login/admission.js.map +1 -0
  176. package/app/dist/login/keys.d.ts +32 -0
  177. package/app/dist/login/keys.js +60 -0
  178. package/app/dist/login/keys.js.map +1 -0
  179. package/app/dist/login/page.d.ts +23 -0
  180. package/app/dist/login/page.js +95 -0
  181. package/app/dist/login/page.js.map +1 -0
  182. package/app/dist/login/public.d.ts +30 -0
  183. package/app/dist/login/public.js +101 -0
  184. package/app/dist/login/public.js.map +1 -0
  185. package/app/dist/login/staff.d.ts +23 -0
  186. package/app/dist/login/staff.js +330 -0
  187. package/app/dist/login/staff.js.map +1 -0
  188. package/app/dist/loopback.d.ts +32 -0
  189. package/app/dist/loopback.js +84 -0
  190. package/app/dist/loopback.js.map +1 -0
  191. package/app/dist/seo.d.ts +33 -0
  192. package/app/dist/seo.js +66 -0
  193. package/app/dist/seo.js.map +1 -0
  194. package/app/dist/server/assets/_id-BViXAagq.js +689 -0
  195. package/app/dist/server/assets/_id-Dt9tTylX.js +19 -0
  196. package/app/dist/server/assets/_id-ce1EGp7Y.js +30 -0
  197. package/app/dist/server/assets/_id-wB8khGTz.js +82 -0
  198. package/app/dist/server/assets/_id-wuJIq2ZZ.js +13 -0
  199. package/app/dist/server/assets/_name-BGagGBjX.js +371 -0
  200. package/app/dist/server/assets/_name-BqFwnyf7.js +30 -0
  201. package/app/dist/server/assets/_name-D_-MhjNf.js +2951 -0
  202. package/app/dist/server/assets/_name-DntbHE-b.js +350 -0
  203. package/app/dist/server/assets/_tanstack-start-manifest_v-BljuBM-G.js +259 -0
  204. package/app/dist/server/assets/_vendor-CNB03LWX.js +137 -0
  205. package/app/dist/server/assets/_vendor-CcEviOki.js +20 -0
  206. package/app/dist/server/assets/actor-D6iA0pDg.js +94 -0
  207. package/app/dist/server/assets/app-chrome-BYS81Vnx.js +1410 -0
  208. package/app/dist/server/assets/app-scope-CXIgOFmi.js +79 -0
  209. package/app/dist/server/assets/apply-plan-ybBda6vQ.js +265 -0
  210. package/app/dist/server/assets/approval-Su315ikC.js +315 -0
  211. package/app/dist/server/assets/apps-Dbg2f5Lh.js +6 -0
  212. package/app/dist/server/assets/apps-xwQAehch.js +184 -0
  213. package/app/dist/server/assets/button-f9Lc8qLl.js +906 -0
  214. package/app/dist/server/assets/change-glance-CpArIbGS.js +142 -0
  215. package/app/dist/server/assets/changes-Bc_OiDBD.js +103 -0
  216. package/app/dist/server/assets/chat-DMN_hoKm.js +857 -0
  217. package/app/dist/server/assets/chat-button-LtA80MoR.js +19 -0
  218. package/app/dist/server/assets/chat-prompt-BYwbMxR6.js +10 -0
  219. package/app/dist/server/assets/clipboard-lnKxNXLI.js +70 -0
  220. package/app/dist/server/assets/code-COyt8L-n.js +123 -0
  221. package/app/dist/server/assets/common-CWHLj7KV.js +1036 -0
  222. package/app/dist/server/assets/connect-BpPiu5s6.js +165 -0
  223. package/app/dist/server/assets/connections-DBgb1bvX.js +1197 -0
  224. package/app/dist/server/assets/connectors-5a5_SlHO.js +186 -0
  225. package/app/dist/server/assets/content-B9KP-eh3.js +3 -0
  226. package/app/dist/server/assets/credentials-ud_Y68hx.js +187 -0
  227. package/app/dist/server/assets/data-aEdhwcqy.js +168 -0
  228. package/app/dist/server/assets/decidable-Dj5xIrIc.js +13 -0
  229. package/app/dist/server/assets/declaration-form-Dfg1yNuY.js +183 -0
  230. package/app/dist/server/assets/dialog-BGjiw3Dx.js +84 -0
  231. package/app/dist/server/assets/dropdown-menu-DAC3LWas.js +97 -0
  232. package/app/dist/server/assets/empty-plugin-adapters-CeuNAGfU.js +4 -0
  233. package/app/dist/server/assets/existing-B4d4NrC8.js +125 -0
  234. package/app/dist/server/assets/field-C0Xx_90s.js +94 -0
  235. package/app/dist/server/assets/functions-BvFYzabD.js +824 -0
  236. package/app/dist/server/assets/graph-qYOdoz2s.js +926 -0
  237. package/app/dist/server/assets/grid-diff-jTvp-8wS.js +171 -0
  238. package/app/dist/server/assets/hosting-bbn9UvDc.js +718 -0
  239. package/app/dist/server/assets/import-DIwvzHb6.js +730 -0
  240. package/app/dist/server/assets/inbox-D6R6sWBB.js +268 -0
  241. package/app/dist/server/assets/inbox-Dj-5FleF.js +65 -0
  242. package/app/dist/server/assets/input-D63gF3G2.js +14 -0
  243. package/app/dist/server/assets/item-BDSXoEr_.js +97 -0
  244. package/app/dist/server/assets/kit-D6EulwBe.js +489 -0
  245. package/app/dist/server/assets/lines-B4w04QZ0.js +27 -0
  246. package/app/dist/server/assets/middleware-B8JRLyxx.js +1420 -0
  247. package/app/dist/server/assets/motion-CAc7ab9u.js +35 -0
  248. package/app/dist/server/assets/names-B04Si-sV.js +9 -0
  249. package/app/dist/server/assets/native-select-DLa-He0n.js +37 -0
  250. package/app/dist/server/assets/people-CkU_AxrV.js +553 -0
  251. package/app/dist/server/assets/permissions-BfMcQqQb.js +256 -0
  252. package/app/dist/server/assets/permissions-grid-DWP9FAAS.js +91 -0
  253. package/app/dist/server/assets/route-BTT7nMJq.js +17 -0
  254. package/app/dist/server/assets/route-CF_8jQYY.js +22 -0
  255. package/app/dist/server/assets/router-BvYtxrVN.js +2334 -0
  256. package/app/dist/server/assets/runs-table-BBudn12Y.js +87 -0
  257. package/app/dist/server/assets/scenario-BXGTSTiP.js +141 -0
  258. package/app/dist/server/assets/scenario-graph-BErXIRgF.js +46 -0
  259. package/app/dist/server/assets/schema-DBT8KJsP.js +204 -0
  260. package/app/dist/server/assets/separator-8MZ7vR3f.js +13 -0
  261. package/app/dist/server/assets/sheet-5Cyp-4UW.js +74 -0
  262. package/app/dist/server/assets/site-icon-DJisMQUK.js +22 -0
  263. package/app/dist/server/assets/sites.index-1l0BtgVf.js +138 -0
  264. package/app/dist/server/assets/spinner-C1ZW08lp.js +15 -0
  265. package/app/dist/server/assets/start-CSU4irVK.js +75 -0
  266. package/app/dist/server/assets/start-form-DI60UOrc.js +399 -0
  267. package/app/dist/server/assets/table-DtPk_h_5.js +51 -0
  268. package/app/dist/server/assets/textarea-f0Ip5ed1.js +12 -0
  269. package/app/dist/server/assets/utils-wksS9pYh.js +138 -0
  270. package/app/dist/server/assets/who-are-you-ZGyMnpVi.js +122 -0
  271. package/app/dist/server/assets/workflow-Z99QWO42.js +115 -0
  272. package/app/dist/server/assets/workflow-view-C8X8U11S.js +1427 -0
  273. package/app/dist/server/assets/workflows-C0kJoGf1.js +344 -0
  274. package/app/dist/server/chat.d.ts +35 -0
  275. package/app/dist/server/chat.js +231 -0
  276. package/app/dist/server/chat.js.map +1 -0
  277. package/app/dist/server/core.d.ts +186 -0
  278. package/app/dist/server/core.js +716 -0
  279. package/app/dist/server/core.js.map +1 -0
  280. package/app/dist/server/go-live.d.ts +90 -0
  281. package/app/dist/server/go-live.js +351 -0
  282. package/app/dist/server/go-live.js.map +1 -0
  283. package/app/dist/server/models.d.ts +24 -0
  284. package/app/dist/server/models.js +42 -0
  285. package/app/dist/server/models.js.map +1 -0
  286. package/app/dist/server/people.d.ts +14 -0
  287. package/app/dist/server/people.js +41 -0
  288. package/app/dist/server/people.js.map +1 -0
  289. package/app/dist/server/secrets.d.ts +3 -0
  290. package/app/dist/server/secrets.js +5 -0
  291. package/app/dist/server/secrets.js.map +1 -0
  292. package/app/dist/server/server.js +7024 -0
  293. package/app/dist/server/setup.d.ts +75 -0
  294. package/app/dist/server/setup.js +308 -0
  295. package/app/dist/server/setup.js.map +1 -0
  296. package/app/dist/server/webhooks.d.ts +11 -0
  297. package/app/dist/server/webhooks.js +40 -0
  298. package/app/dist/server/webhooks.js.map +1 -0
  299. package/app/dist/site-path.d.ts +24 -0
  300. package/app/dist/site-path.js +27 -0
  301. package/app/dist/site-path.js.map +1 -0
  302. package/app/dist/snapshot-build.d.ts +23 -0
  303. package/app/dist/snapshot-build.js +255 -0
  304. package/app/dist/snapshot-build.js.map +1 -0
  305. package/app/dist/snapshot.d.ts +56 -0
  306. package/app/dist/snapshot.js +19 -0
  307. package/app/dist/snapshot.js.map +1 -0
  308. package/app/dist/steps/agent/acp.d.ts +116 -0
  309. package/app/dist/steps/agent/acp.js +788 -0
  310. package/app/dist/steps/agent/acp.js.map +1 -0
  311. package/app/dist/steps/agent/box-session.d.ts +46 -0
  312. package/app/dist/steps/agent/box-session.js +179 -0
  313. package/app/dist/steps/agent/box-session.js.map +1 -0
  314. package/app/dist/steps/agent/carrier.d.ts +56 -0
  315. package/app/dist/steps/agent/carrier.js +215 -0
  316. package/app/dist/steps/agent/carrier.js.map +1 -0
  317. package/app/dist/steps/agent/checkout.d.ts +73 -0
  318. package/app/dist/steps/agent/checkout.js +167 -0
  319. package/app/dist/steps/agent/checkout.js.map +1 -0
  320. package/app/dist/steps/agent/harness.d.ts +5 -0
  321. package/app/dist/steps/agent/harness.js +199 -0
  322. package/app/dist/steps/agent/harness.js.map +1 -0
  323. package/app/dist/steps/agent/local-box.d.ts +16 -0
  324. package/app/dist/steps/agent/local-box.js +37 -0
  325. package/app/dist/steps/agent/local-box.js.map +1 -0
  326. package/app/dist/steps/agent/loop.d.ts +3 -0
  327. package/app/dist/steps/agent/loop.js +60 -0
  328. package/app/dist/steps/agent/loop.js.map +1 -0
  329. package/app/dist/steps/agent/prompt.d.ts +9 -0
  330. package/app/dist/steps/agent/prompt.js +107 -0
  331. package/app/dist/steps/agent/prompt.js.map +1 -0
  332. package/app/dist/steps/agent/tools.d.ts +2814 -0
  333. package/app/dist/steps/agent/tools.js +248 -0
  334. package/app/dist/steps/agent/tools.js.map +1 -0
  335. package/app/dist/steps/agent/transcript.d.ts +19 -0
  336. package/app/dist/steps/agent/transcript.js +66 -0
  337. package/app/dist/steps/agent/transcript.js.map +1 -0
  338. package/app/dist/steps/agent/turn.d.ts +17 -0
  339. package/app/dist/steps/agent/turn.js +59 -0
  340. package/app/dist/steps/agent/turn.js.map +1 -0
  341. package/app/dist/steps/connect.d.ts +25 -0
  342. package/app/dist/steps/connect.js +141 -0
  343. package/app/dist/steps/connect.js.map +1 -0
  344. package/app/dist/steps/go-live.d.ts +40 -0
  345. package/app/dist/steps/go-live.js +310 -0
  346. package/app/dist/steps/go-live.js.map +1 -0
  347. package/app/dist/steps/index.d.ts +3 -0
  348. package/app/dist/steps/index.js +11 -0
  349. package/app/dist/steps/index.js.map +1 -0
  350. package/app/dist/steps/writes.d.ts +29 -0
  351. package/app/dist/steps/writes.js +174 -0
  352. package/app/dist/steps/writes.js.map +1 -0
  353. package/app/dist/stylesheet.json +1 -0
  354. package/app/src/actor.ts +130 -0
  355. package/app/src/api-client.ts +73 -0
  356. package/app/src/api.ts +686 -0
  357. package/app/src/app-bundle.ts +77 -0
  358. package/app/src/build.ts +907 -0
  359. package/app/src/bundle-build.ts +661 -0
  360. package/app/src/components/app-chrome.tsx +107 -0
  361. package/app/src/components/app-scope.tsx +98 -0
  362. package/app/src/components/apply-plan.tsx +191 -0
  363. package/app/src/components/approval.tsx +367 -0
  364. package/app/src/components/base-node.tsx +12 -0
  365. package/app/src/components/boundaries.tsx +64 -0
  366. package/app/src/components/change-decision.tsx +123 -0
  367. package/app/src/components/change-glance.tsx +44 -0
  368. package/app/src/components/chat-button.tsx +20 -0
  369. package/app/src/components/code.tsx +116 -0
  370. package/app/src/components/common.tsx +895 -0
  371. package/app/src/components/connections.tsx +844 -0
  372. package/app/src/components/credentials.tsx +219 -0
  373. package/app/src/components/data-grid.tsx +247 -0
  374. package/app/src/components/declaration-form.tsx +194 -0
  375. package/app/src/components/density.tsx +44 -0
  376. package/app/src/components/field-diff.tsx +91 -0
  377. package/app/src/components/go-live.tsx +669 -0
  378. package/app/src/components/graph.css +14 -0
  379. package/app/src/components/graph.tsx +563 -0
  380. package/app/src/components/grid/cell.tsx +149 -0
  381. package/app/src/components/grid/clipboard.ts +83 -0
  382. package/app/src/components/grid/collection.ts +476 -0
  383. package/app/src/components/grid/columns.tsx +357 -0
  384. package/app/src/components/grid/conflicts.tsx +81 -0
  385. package/app/src/components/grid/gestures.ts +169 -0
  386. package/app/src/components/grid/grid.tsx +760 -0
  387. package/app/src/components/grid/keys.ts +83 -0
  388. package/app/src/components/grid/plan.ts +389 -0
  389. package/app/src/components/grid/review.tsx +340 -0
  390. package/app/src/components/grid/staged.tsx +454 -0
  391. package/app/src/components/import/match.tsx +212 -0
  392. package/app/src/components/import/review.tsx +121 -0
  393. package/app/src/components/import/sheet.ts +166 -0
  394. package/app/src/components/import/upload.tsx +116 -0
  395. package/app/src/components/inspector.tsx +310 -0
  396. package/app/src/components/kit.tsx +276 -0
  397. package/app/src/components/ledger.tsx +344 -0
  398. package/app/src/components/new-run.tsx +114 -0
  399. package/app/src/components/permissions-diff.tsx +66 -0
  400. package/app/src/components/permissions-grid.tsx +133 -0
  401. package/app/src/components/record-form.tsx +208 -0
  402. package/app/src/components/record-history.tsx +119 -0
  403. package/app/src/components/runs-table.tsx +111 -0
  404. package/app/src/components/scenario.tsx +102 -0
  405. package/app/src/components/shell/bar.tsx +285 -0
  406. package/app/src/components/shell/chat-parts.tsx +326 -0
  407. package/app/src/components/shell/chat-prompt.ts +26 -0
  408. package/app/src/components/shell/chat.tsx +375 -0
  409. package/app/src/components/shell/draft-card.tsx +123 -0
  410. package/app/src/components/shell/nav-user.tsx +174 -0
  411. package/app/src/components/shell/prefs.ts +28 -0
  412. package/app/src/components/site-icon.tsx +17 -0
  413. package/app/src/components/store-move.tsx +313 -0
  414. package/app/src/components/ui/alert.tsx +55 -0
  415. package/app/src/components/ui/avatar.tsx +90 -0
  416. package/app/src/components/ui/badge.tsx +48 -0
  417. package/app/src/components/ui/breadcrumb.tsx +92 -0
  418. package/app/src/components/ui/button-group.tsx +78 -0
  419. package/app/src/components/ui/button.tsx +49 -0
  420. package/app/src/components/ui/card.tsx +69 -0
  421. package/app/src/components/ui/checkbox.tsx +25 -0
  422. package/app/src/components/ui/collapsible.tsx +15 -0
  423. package/app/src/components/ui/dialog.tsx +132 -0
  424. package/app/src/components/ui/dropdown-menu.tsx +252 -0
  425. package/app/src/components/ui/empty.tsx +86 -0
  426. package/app/src/components/ui/field.tsx +218 -0
  427. package/app/src/components/ui/input.tsx +19 -0
  428. package/app/src/components/ui/item.tsx +179 -0
  429. package/app/src/components/ui/label.tsx +17 -0
  430. package/app/src/components/ui/native-select.tsx +47 -0
  431. package/app/src/components/ui/popover.tsx +62 -0
  432. package/app/src/components/ui/separator.tsx +18 -0
  433. package/app/src/components/ui/sheet.tsx +102 -0
  434. package/app/src/components/ui/skeleton.tsx +7 -0
  435. package/app/src/components/ui/slider.tsx +40 -0
  436. package/app/src/components/ui/sonner.tsx +41 -0
  437. package/app/src/components/ui/spinner.tsx +17 -0
  438. package/app/src/components/ui/table.tsx +72 -0
  439. package/app/src/components/ui/tabs.tsx +68 -0
  440. package/app/src/components/ui/textarea.tsx +17 -0
  441. package/app/src/components/ui/tooltip.tsx +51 -0
  442. package/app/src/components/who-are-you.tsx +128 -0
  443. package/app/src/components/workflow-runs.tsx +213 -0
  444. package/app/src/components/workflow-view.tsx +293 -0
  445. package/app/src/components/workflow.tsx +142 -0
  446. package/app/src/components/zoom-slider.tsx +69 -0
  447. package/app/src/content-files.ts +248 -0
  448. package/app/src/content-types.ts +49 -0
  449. package/app/src/content.ts +49 -0
  450. package/app/src/context.ts +91 -0
  451. package/app/src/dev-imports.ts +5 -0
  452. package/app/src/env.d.ts +48 -0
  453. package/app/src/form/run-form.tsx +45 -0
  454. package/app/src/form/schema.ts +308 -0
  455. package/app/src/form/secure-fields.ts +42 -0
  456. package/app/src/form/start-form.tsx +427 -0
  457. package/app/src/form/will-ask.tsx +25 -0
  458. package/app/src/functions.ts +300 -0
  459. package/app/src/graph/layout.ts +238 -0
  460. package/app/src/graph/outline-graph.ts +123 -0
  461. package/app/src/graph/run-graph.ts +193 -0
  462. package/app/src/graph/scenario-graph.ts +48 -0
  463. package/app/src/graph/types.ts +144 -0
  464. package/app/src/graph/wildcard.ts +40 -0
  465. package/app/src/handler.ts +257 -0
  466. package/app/src/icon-small.svg +1 -0
  467. package/app/src/icon.svg +1 -0
  468. package/app/src/index.ts +455 -0
  469. package/app/src/lib/apply-plan.ts +79 -0
  470. package/app/src/lib/apps.ts +10 -0
  471. package/app/src/lib/changes.ts +86 -0
  472. package/app/src/lib/chat.ts +146 -0
  473. package/app/src/lib/cn-tables.ts +116 -0
  474. package/app/src/lib/decidable.ts +21 -0
  475. package/app/src/lib/desktop.ts +52 -0
  476. package/app/src/lib/grid-diff.ts +205 -0
  477. package/app/src/lib/inbox.ts +59 -0
  478. package/app/src/lib/lines.ts +31 -0
  479. package/app/src/lib/locales.ts +101 -0
  480. package/app/src/lib/motion.ts +17 -0
  481. package/app/src/lib/names.ts +12 -0
  482. package/app/src/lib/preview.ts +49 -0
  483. package/app/src/lib/records.ts +56 -0
  484. package/app/src/lib/sites.ts +92 -0
  485. package/app/src/lib/time.ts +10 -0
  486. package/app/src/lib/tone.ts +78 -0
  487. package/app/src/lib/utils.ts +13 -0
  488. package/app/src/login/admission.ts +72 -0
  489. package/app/src/login/keys.ts +65 -0
  490. package/app/src/login/page.ts +119 -0
  491. package/app/src/login/public.ts +138 -0
  492. package/app/src/login/staff.ts +399 -0
  493. package/app/src/loopback.ts +96 -0
  494. package/app/src/middleware.ts +26 -0
  495. package/app/src/public-fns.ts +5 -0
  496. package/app/src/queries.ts +859 -0
  497. package/app/src/router.tsx +45 -0
  498. package/app/src/routes/__root.tsx +223 -0
  499. package/app/src/routes/api/call.ts +17 -0
  500. package/app/src/routes/api/chat.ts +15 -0
  501. package/app/src/routes/api/sign-in.ts +14 -0
  502. package/app/src/routes/apps/$name.tsx +380 -0
  503. package/app/src/routes/apps/index.tsx +204 -0
  504. package/app/src/routes/apps/route.tsx +8 -0
  505. package/app/src/routes/changes/$id.tsx +205 -0
  506. package/app/src/routes/changes/index.tsx +103 -0
  507. package/app/src/routes/changes/route.tsx +8 -0
  508. package/app/src/routes/connect/$vendor/callback.ts +9 -0
  509. package/app/src/routes/connectors/$vendor.tsx +184 -0
  510. package/app/src/routes/connectors/index.tsx +194 -0
  511. package/app/src/routes/connectors/route.tsx +8 -0
  512. package/app/src/routes/data/$name/import.tsx +177 -0
  513. package/app/src/routes/data/$name/index.tsx +266 -0
  514. package/app/src/routes/data/$name/route.tsx +18 -0
  515. package/app/src/routes/data/index.tsx +178 -0
  516. package/app/src/routes/data/route.tsx +11 -0
  517. package/app/src/routes/hosting/connect.tsx +156 -0
  518. package/app/src/routes/hosting/existing.tsx +115 -0
  519. package/app/src/routes/hosting/index.tsx +845 -0
  520. package/app/src/routes/hosting/route.tsx +11 -0
  521. package/app/src/routes/inbox.tsx +310 -0
  522. package/app/src/routes/index.tsx +8 -0
  523. package/app/src/routes/people.tsx +624 -0
  524. package/app/src/routes/permissions.tsx +284 -0
  525. package/app/src/routes/resources.tsx +10 -0
  526. package/app/src/routes/runs/$id.tsx +14 -0
  527. package/app/src/routes/runs/index.tsx +8 -0
  528. package/app/src/routes/setup/connect.tsx +10 -0
  529. package/app/src/routes/setup/existing.tsx +8 -0
  530. package/app/src/routes/setup/github/callback.ts +7 -0
  531. package/app/src/routes/setup/github/manifest.ts +7 -0
  532. package/app/src/routes/setup/index.tsx +8 -0
  533. package/app/src/routes/sites.index.tsx +131 -0
  534. package/app/src/routes/start.tsx +15 -0
  535. package/app/src/routes/workflows/$name/index.tsx +140 -0
  536. package/app/src/routes/workflows/$name/new.tsx +11 -0
  537. package/app/src/routes/workflows/$name/route.tsx +58 -0
  538. package/app/src/routes/workflows/$name/runs/$id.tsx +97 -0
  539. package/app/src/routes/workflows/index.tsx +413 -0
  540. package/app/src/routes/workflows/route.tsx +11 -0
  541. package/app/src/seo.ts +94 -0
  542. package/app/src/server/available.ts +89 -0
  543. package/app/src/server/chat.ts +249 -0
  544. package/app/src/server/columns.ts +52 -0
  545. package/app/src/server/connect.ts +89 -0
  546. package/app/src/server/core.ts +889 -0
  547. package/app/src/server/go-live.ts +420 -0
  548. package/app/src/server/host-derived.ts +72 -0
  549. package/app/src/server/models.ts +52 -0
  550. package/app/src/server/people.ts +51 -0
  551. package/app/src/server/secrets.ts +6 -0
  552. package/app/src/server/setup.ts +335 -0
  553. package/app/src/server/webhooks.ts +38 -0
  554. package/app/src/server.ts +4 -0
  555. package/app/src/site-path.ts +35 -0
  556. package/app/src/site-url.ts +53 -0
  557. package/app/src/site.ts +154 -0
  558. package/app/src/snapshot-build.ts +288 -0
  559. package/app/src/snapshot.ts +69 -0
  560. package/app/src/start.ts +63 -0
  561. package/app/src/steps/agent/acp.ts +918 -0
  562. package/app/src/steps/agent/box-session.ts +230 -0
  563. package/app/src/steps/agent/carrier.ts +242 -0
  564. package/app/src/steps/agent/checkout.ts +222 -0
  565. package/app/src/steps/agent/harness.ts +265 -0
  566. package/app/src/steps/agent/local-box.ts +40 -0
  567. package/app/src/steps/agent/loop.ts +80 -0
  568. package/app/src/steps/agent/prompt.ts +124 -0
  569. package/app/src/steps/agent/tools.ts +300 -0
  570. package/app/src/steps/agent/transcript.ts +95 -0
  571. package/app/src/steps/agent/turn.ts +63 -0
  572. package/app/src/steps/connect.ts +151 -0
  573. package/app/src/steps/go-live.ts +358 -0
  574. package/app/src/steps/index.ts +13 -0
  575. package/app/src/steps/writes.ts +200 -0
  576. package/app/src/style.css +69 -0
  577. package/app/src/ui.css +301 -0
  578. package/app/src/ui.ts +147 -0
  579. package/app/src/worker/app.ts +189 -0
  580. package/app/src/worker/assets.ts +12 -0
  581. package/app/src/worker/main.ts +32 -0
  582. package/app/src/worker/missing.js +13 -0
  583. package/app/tsconfig.site.json +20 -0
  584. package/better-auth/README.md +115 -0
  585. package/better-auth/dist/connector.d.ts +5 -0
  586. package/better-auth/dist/connector.js +14 -0
  587. package/better-auth/dist/connector.js.map +1 -0
  588. package/better-auth/dist/db/staff.d.ts +695 -0
  589. package/better-auth/dist/db/staff.js +4 -0
  590. package/better-auth/dist/db/staff.js.map +1 -0
  591. package/better-auth/dist/db/tables.d.ts +702 -0
  592. package/better-auth/dist/db/tables.js +69 -0
  593. package/better-auth/dist/db/tables.js.map +1 -0
  594. package/better-auth/dist/db/visitors.d.ts +695 -0
  595. package/better-auth/dist/db/visitors.js +4 -0
  596. package/better-auth/dist/db/visitors.js.map +1 -0
  597. package/better-auth/dist/index.d.ts +11 -0
  598. package/better-auth/dist/index.js +16 -0
  599. package/better-auth/dist/index.js.map +1 -0
  600. package/better-auth/dist/instance.d.ts +716 -0
  601. package/better-auth/dist/instance.js +210 -0
  602. package/better-auth/dist/instance.js.map +1 -0
  603. package/better-auth/dist/login.d.ts +13 -0
  604. package/better-auth/dist/login.js +139 -0
  605. package/better-auth/dist/login.js.map +1 -0
  606. package/better-auth/dist/staff.d.ts +12 -0
  607. package/better-auth/dist/staff.js +254 -0
  608. package/better-auth/dist/staff.js.map +1 -0
  609. package/better-auth/drizzle/staff/0000_closed_toro.sql +64 -0
  610. package/better-auth/drizzle/staff/meta/0000_snapshot.json +431 -0
  611. package/better-auth/drizzle/staff/meta/_journal.json +13 -0
  612. package/better-auth/drizzle/visitors/0000_natural_dexter_bennett.sql +64 -0
  613. package/better-auth/drizzle/visitors/meta/0000_snapshot.json +431 -0
  614. package/better-auth/drizzle/visitors/meta/_journal.json +13 -0
  615. package/bridge/README.md +146 -0
  616. package/bridge/dist/bin.d.ts +20 -0
  617. package/bridge/dist/bin.js +37 -0
  618. package/bridge/dist/bin.js.map +1 -0
  619. package/bridge/dist/bridge.d.ts +159 -0
  620. package/bridge/dist/bridge.js +189 -0
  621. package/bridge/dist/bridge.js.map +1 -0
  622. package/bridge/dist/client.d.ts +37 -0
  623. package/bridge/dist/client.js +118 -0
  624. package/bridge/dist/client.js.map +1 -0
  625. package/bridge/dist/configure.d.ts +5 -0
  626. package/bridge/dist/configure.js +17 -0
  627. package/bridge/dist/configure.js.map +1 -0
  628. package/bridge/dist/connector.d.ts +164 -0
  629. package/bridge/dist/connector.js +335 -0
  630. package/bridge/dist/connector.js.map +1 -0
  631. package/bridge/dist/fake.d.ts +4 -0
  632. package/bridge/dist/fake.js +4 -0
  633. package/bridge/dist/fake.js.map +1 -0
  634. package/bridge/dist/fixtures.d.ts +36 -0
  635. package/bridge/dist/fixtures.js +18 -0
  636. package/bridge/dist/fixtures.js.map +1 -0
  637. package/bridge/dist/gen/bridge/v1/bridge_pb.d.ts +694 -0
  638. package/bridge/dist/gen/bridge/v1/bridge_pb.js +173 -0
  639. package/bridge/dist/gen/bridge/v1/bridge_pb.js.map +1 -0
  640. package/bridge/dist/index.d.ts +6 -0
  641. package/bridge/dist/index.js +7 -0
  642. package/bridge/dist/index.js.map +1 -0
  643. package/bridge/dist/json.d.ts +7 -0
  644. package/bridge/dist/json.js +5 -0
  645. package/bridge/dist/json.js.map +1 -0
  646. package/bridge/dist/lazy.d.ts +20 -0
  647. package/bridge/dist/lazy.js +60 -0
  648. package/bridge/dist/lazy.js.map +1 -0
  649. package/bridge/dist/pins.d.ts +12 -0
  650. package/bridge/dist/pins.js +17 -0
  651. package/bridge/dist/pins.js.map +1 -0
  652. package/bridge/dist/replies.d.ts +79 -0
  653. package/bridge/dist/replies.js +217 -0
  654. package/bridge/dist/replies.js.map +1 -0
  655. package/bridge/dist/schema.d.ts +65 -0
  656. package/bridge/dist/schema.js +9 -0
  657. package/bridge/dist/schema.js.map +1 -0
  658. package/bridge/dist/tffake.d.ts +57 -0
  659. package/bridge/dist/tffake.js +105 -0
  660. package/bridge/dist/tffake.js.map +1 -0
  661. package/bridge/dist/tfschema/cli.d.ts +10 -0
  662. package/bridge/dist/tfschema/cli.js +57 -0
  663. package/bridge/dist/tfschema/cli.js.map +1 -0
  664. package/bridge/dist/tfschema/ctyToZod.d.ts +20 -0
  665. package/bridge/dist/tfschema/ctyToZod.js +49 -0
  666. package/bridge/dist/tfschema/ctyToZod.js.map +1 -0
  667. package/bridge/dist/tfschema/generate.d.ts +16 -0
  668. package/bridge/dist/tfschema/generate.js +159 -0
  669. package/bridge/dist/tfschema/generate.js.map +1 -0
  670. package/bridge/dist/tfschema/state.d.ts +14 -0
  671. package/bridge/dist/tfschema/state.js +51 -0
  672. package/bridge/dist/tfschema/state.js.map +1 -0
  673. package/bridge/dist/tfschema/types.d.ts +52 -0
  674. package/bridge/dist/tfschema/types.js +2 -0
  675. package/bridge/dist/tfschema/types.js.map +1 -0
  676. package/bridge/dist/tfschema.d.ts +4 -0
  677. package/bridge/dist/tfschema.js +8 -0
  678. package/bridge/dist/tfschema.js.map +1 -0
  679. package/bridge/testdata/README.md +64 -0
  680. package/bridge/testdata/pins.json +27 -0
  681. package/bridge/testdata/replies/integrations_github_6.13.0/github_branch_protection/provider-bridge_main/import.json +32 -0
  682. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/provider-bridge/import.json +30 -0
  683. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/provider-bridge/read.json +29 -0
  684. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma/import.json +30 -0
  685. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma/read.json +29 -0
  686. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test/apply.json +29 -0
  687. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test/plan.json +40 -0
  688. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-delete/apply.json +23 -0
  689. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-delete/plan.json +25 -0
  690. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-update-1/apply.json +33 -0
  691. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-update-1/plan.json +32 -0
  692. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/provider-bridge_notsaltylol/import.json +29 -0
  693. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/provider-bridge_notsaltylol/read.json +28 -0
  694. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/provider-bridge_octocat/import.json +27 -0
  695. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator/apply.json +28 -0
  696. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator/plan.json +29 -0
  697. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-delete/apply.json +21 -0
  698. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-delete/plan.json +23 -0
  699. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-update-1/apply-delete.json +21 -0
  700. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-update-1/apply.json +28 -0
  701. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-update-1/plan.json +33 -0
  702. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test_octocat/import.json +29 -0
  703. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test_octocat/read.json +28 -0
  704. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key/apply.json +27 -0
  705. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key/plan.json +29 -0
  706. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key-delete/apply.json +21 -0
  707. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key-delete/plan.json +23 -0
  708. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test_1000000101/import.json +28 -0
  709. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test_1000000101/read.json +26 -0
  710. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132/import.json +28 -0
  711. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-aede5c47/apply-delete.json +21 -0
  712. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-aede5c47/apply.json +28 -0
  713. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-aede5c47/plan.json +49 -0
  714. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-c0239934/plan.json +27 -0
  715. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/8a4dfc1ebfe1b74d277a6e4017921d06e302d4c10fe6999e8ab5cb1522dcb2ad/import.json +25 -0
  716. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/8a4dfc1ebfe1b74d277a6e4017921d06e302d4c10fe6999e8ab5cb1522dcb2ad-delete/apply.json +21 -0
  717. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/8a4dfc1ebfe1b74d277a6e4017921d06e302d4c10fe6999e8ab5cb1522dcb2ad-delete/plan.json +23 -0
  718. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/create-2463512b/apply.json +28 -0
  719. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/create-2463512b/plan.json +42 -0
  720. package/bridge/testdata/schemas/integrations_github_6.13.0.json +10680 -0
  721. package/bridge/testdata/schemas/kreuzwerker_docker_4.6.0.json +4833 -0
  722. package/bridge/testdata/schemas/stripe_stripe_0.3.0.json +55612 -0
  723. package/bridge/testdata/schemas/supabase_supabase_1.11.0.json +790 -0
  724. package/dev/README.md +33 -0
  725. package/dev/dist/cli.d.ts +5 -0
  726. package/dev/dist/cli.js +120 -0
  727. package/dev/dist/cli.js.map +1 -0
  728. package/dev/dist/links.d.ts +33 -0
  729. package/dev/dist/links.js +86 -0
  730. package/dev/dist/links.js.map +1 -0
  731. package/dist/check.d.ts +1 -1
  732. package/dist/check.js +8 -8
  733. package/dist/check.js.map +1 -1
  734. package/dist/cli.js +29 -25
  735. package/dist/cli.js.map +1 -1
  736. package/dist/config.d.ts +1 -4
  737. package/dist/config.js +2 -4
  738. package/dist/config.js.map +1 -1
  739. package/dist/dev.d.ts +5 -8
  740. package/dist/dev.js +13 -50
  741. package/dist/dev.js.map +1 -1
  742. package/dist/env.js +1 -1
  743. package/dist/env.js.map +1 -1
  744. package/dist/events.d.ts +1 -1
  745. package/dist/identity.js +1 -1
  746. package/dist/identity.js.map +1 -1
  747. package/dist/index.d.ts +3 -3
  748. package/dist/index.js +5 -5
  749. package/dist/index.js.map +1 -1
  750. package/dist/init.d.ts +4 -6
  751. package/dist/init.js +21 -15
  752. package/dist/init.js.map +1 -1
  753. package/dist/key.js +1 -1
  754. package/dist/key.js.map +1 -1
  755. package/dist/ledger.d.ts +1 -1
  756. package/dist/ledger.js +1 -1
  757. package/dist/ledger.js.map +1 -1
  758. package/dist/listen.d.ts +1 -1
  759. package/dist/listen.js +1 -1
  760. package/dist/listen.js.map +1 -1
  761. package/dist/oxlint-plugin.js +2 -2
  762. package/dist/oxlint-plugin.js.map +1 -1
  763. package/dist/postgres.js +1 -1
  764. package/dist/postgres.js.map +1 -1
  765. package/dist/serve.d.ts +4 -4
  766. package/dist/serve.js +9 -10
  767. package/dist/serve.js.map +1 -1
  768. package/dist/sites.d.ts +2 -7
  769. package/dist/sites.js +4 -10
  770. package/dist/sites.js.map +1 -1
  771. package/dist/source.d.ts +1 -1
  772. package/dist/source.js +2 -2
  773. package/dist/source.js.map +1 -1
  774. package/dist/wakeup.js +1 -1
  775. package/dist/wakeup.js.map +1 -1
  776. package/dist/worker-port.d.ts +2 -2
  777. package/dist/worker-port.js +2 -2
  778. package/dist/worker-port.js.map +1 -1
  779. package/oxlint.json +283 -47
  780. package/package.json +321 -34
  781. package/template/AGENTS.md +2 -2
  782. package/testing/README.md +261 -0
  783. package/testing/dist/build.d.ts +16 -0
  784. package/testing/dist/build.js +95 -0
  785. package/testing/dist/build.js.map +1 -0
  786. package/testing/dist/database.d.ts +96 -0
  787. package/testing/dist/database.js +213 -0
  788. package/testing/dist/database.js.map +1 -0
  789. package/testing/dist/features.d.ts +25 -0
  790. package/testing/dist/features.js +176 -0
  791. package/testing/dist/features.js.map +1 -0
  792. package/testing/dist/harness.d.ts +27 -0
  793. package/testing/dist/harness.js +63 -0
  794. package/testing/dist/harness.js.map +1 -0
  795. package/testing/dist/host.d.ts +229 -0
  796. package/testing/dist/host.js +738 -0
  797. package/testing/dist/host.js.map +1 -0
  798. package/testing/dist/index.d.ts +36 -0
  799. package/testing/dist/index.js +41 -0
  800. package/testing/dist/index.js.map +1 -0
  801. package/testing/dist/replay.d.ts +44 -0
  802. package/testing/dist/replay.js +95 -0
  803. package/testing/dist/replay.js.map +1 -0
  804. package/testing/dist/sandbox.d.ts +59 -0
  805. package/testing/dist/sandbox.js +201 -0
  806. package/testing/dist/sandbox.js.map +1 -0
  807. package/testing/dist/scenarios.d.ts +17 -0
  808. package/testing/dist/scenarios.js +64 -0
  809. package/testing/dist/scenarios.js.map +1 -0
  810. package/testing/dist/sentinel.d.ts +19 -0
  811. package/testing/dist/sentinel.js +54 -0
  812. package/testing/dist/sentinel.js.map +1 -0
  813. package/testing/dist/wakeup.d.ts +114 -0
  814. package/testing/dist/wakeup.js +288 -0
  815. package/testing/dist/wakeup.js.map +1 -0
  816. package/workflows/CLOUD-IDENTITY.md +333 -0
  817. package/workflows/KMS-SECRETS.md +167 -0
  818. package/workflows/README.md +990 -0
  819. package/workflows/SECRET-SUPPORT.md +72 -0
  820. package/workflows/dist/app-steps.d.ts +17 -0
  821. package/workflows/dist/app-steps.js +43 -0
  822. package/workflows/dist/app-steps.js.map +1 -0
  823. package/workflows/dist/app-workflows.d.ts +174 -0
  824. package/workflows/dist/app-workflows.js +117 -0
  825. package/workflows/dist/app-workflows.js.map +1 -0
  826. package/workflows/dist/apply-steps.d.ts +8 -0
  827. package/workflows/dist/apply-steps.js +92 -0
  828. package/workflows/dist/apply-steps.js.map +1 -0
  829. package/workflows/dist/apply.d.ts +213 -0
  830. package/workflows/dist/apply.js +634 -0
  831. package/workflows/dist/apply.js.map +1 -0
  832. package/workflows/dist/approvals.d.ts +77 -0
  833. package/workflows/dist/approvals.js +211 -0
  834. package/workflows/dist/approvals.js.map +1 -0
  835. package/workflows/dist/apps-list.d.ts +116 -0
  836. package/workflows/dist/apps-list.js +150 -0
  837. package/workflows/dist/apps-list.js.map +1 -0
  838. package/workflows/dist/apps.d.ts +31 -0
  839. package/workflows/dist/apps.js +138 -0
  840. package/workflows/dist/apps.js.map +1 -0
  841. package/workflows/dist/ast.d.ts +59 -0
  842. package/workflows/dist/ast.js +83 -0
  843. package/workflows/dist/ast.js.map +1 -0
  844. package/workflows/dist/authentication.d.ts +140 -0
  845. package/workflows/dist/authentication.js +190 -0
  846. package/workflows/dist/authentication.js.map +1 -0
  847. package/workflows/dist/bundled.d.ts +39 -0
  848. package/workflows/dist/bundled.js +16 -0
  849. package/workflows/dist/bundled.js.map +1 -0
  850. package/workflows/dist/call-workflow.d.ts +21 -0
  851. package/workflows/dist/call-workflow.js +35 -0
  852. package/workflows/dist/call-workflow.js.map +1 -0
  853. package/workflows/dist/call.d.ts +104 -0
  854. package/workflows/dist/call.js +660 -0
  855. package/workflows/dist/call.js.map +1 -0
  856. package/workflows/dist/cedar.d.ts +109 -0
  857. package/workflows/dist/cedar.js +533 -0
  858. package/workflows/dist/cedar.js.map +1 -0
  859. package/workflows/dist/change-steps.d.ts +10 -0
  860. package/workflows/dist/change-steps.js +200 -0
  861. package/workflows/dist/change-steps.js.map +1 -0
  862. package/workflows/dist/change-workflow.d.ts +54 -0
  863. package/workflows/dist/change-workflow.js +161 -0
  864. package/workflows/dist/change-workflow.js.map +1 -0
  865. package/workflows/dist/change.d.ts +330 -0
  866. package/workflows/dist/change.js +351 -0
  867. package/workflows/dist/change.js.map +1 -0
  868. package/workflows/dist/chat-steps.d.ts +5 -0
  869. package/workflows/dist/chat-steps.js +107 -0
  870. package/workflows/dist/chat-steps.js.map +1 -0
  871. package/workflows/dist/chat-workflow.d.ts +43 -0
  872. package/workflows/dist/chat-workflow.js +47 -0
  873. package/workflows/dist/chat-workflow.js.map +1 -0
  874. package/workflows/dist/chats.d.ts +62 -0
  875. package/workflows/dist/chats.js +109 -0
  876. package/workflows/dist/chats.js.map +1 -0
  877. package/workflows/dist/claims.d.ts +58 -0
  878. package/workflows/dist/claims.js +27 -0
  879. package/workflows/dist/claims.js.map +1 -0
  880. package/workflows/dist/client.d.ts +563 -0
  881. package/workflows/dist/client.js +1464 -0
  882. package/workflows/dist/client.js.map +1 -0
  883. package/workflows/dist/cloud-identity.d.ts +56 -0
  884. package/workflows/dist/cloud-identity.js +160 -0
  885. package/workflows/dist/cloud-identity.js.map +1 -0
  886. package/workflows/dist/collection.d.ts +139 -0
  887. package/workflows/dist/collection.js +522 -0
  888. package/workflows/dist/collection.js.map +1 -0
  889. package/workflows/dist/config.d.ts +328 -0
  890. package/workflows/dist/config.js +857 -0
  891. package/workflows/dist/config.js.map +1 -0
  892. package/workflows/dist/connect-workflow.d.ts +6 -0
  893. package/workflows/dist/connect-workflow.js +35 -0
  894. package/workflows/dist/connect-workflow.js.map +1 -0
  895. package/workflows/dist/connection.d.ts +669 -0
  896. package/workflows/dist/connection.js +1228 -0
  897. package/workflows/dist/connection.js.map +1 -0
  898. package/workflows/dist/constructors.d.ts +38 -0
  899. package/workflows/dist/constructors.js +9 -0
  900. package/workflows/dist/constructors.js.map +1 -0
  901. package/workflows/dist/credentials.d.ts +24 -0
  902. package/workflows/dist/credentials.js +168 -0
  903. package/workflows/dist/credentials.js.map +1 -0
  904. package/workflows/dist/cucumber.d.ts +66 -0
  905. package/workflows/dist/cucumber.js +163 -0
  906. package/workflows/dist/cucumber.js.map +1 -0
  907. package/workflows/dist/data.d.ts +2 -0
  908. package/workflows/dist/data.js +3 -0
  909. package/workflows/dist/data.js.map +1 -0
  910. package/workflows/dist/database.d.ts +83 -0
  911. package/workflows/dist/database.js +95 -0
  912. package/workflows/dist/database.js.map +1 -0
  913. package/workflows/dist/db/company.d.ts +2351 -0
  914. package/workflows/dist/db/company.js +245 -0
  915. package/workflows/dist/db/company.js.map +1 -0
  916. package/workflows/dist/db/dbos.d.ts +111 -0
  917. package/workflows/dist/db/dbos.js +15 -0
  918. package/workflows/dist/db/dbos.js.map +1 -0
  919. package/workflows/dist/db/identity.d.ts +367 -0
  920. package/workflows/dist/db/identity.js +48 -0
  921. package/workflows/dist/db/identity.js.map +1 -0
  922. package/workflows/dist/db/index.d.ts +7 -0
  923. package/workflows/dist/db/index.js +12 -0
  924. package/workflows/dist/db/index.js.map +1 -0
  925. package/workflows/dist/db/kms.d.ts +224 -0
  926. package/workflows/dist/db/kms.js +29 -0
  927. package/workflows/dist/db/kms.js.map +1 -0
  928. package/workflows/dist/db/migrate.d.ts +66 -0
  929. package/workflows/dist/db/migrate.js +39 -0
  930. package/workflows/dist/db/migrate.js.map +1 -0
  931. package/workflows/dist/db/wakeup.d.ts +271 -0
  932. package/workflows/dist/db/wakeup.js +34 -0
  933. package/workflows/dist/db/wakeup.js.map +1 -0
  934. package/workflows/dist/db.d.ts +117 -0
  935. package/workflows/dist/db.js +375 -0
  936. package/workflows/dist/db.js.map +1 -0
  937. package/workflows/dist/deadlines.d.ts +107 -0
  938. package/workflows/dist/deadlines.js +208 -0
  939. package/workflows/dist/deadlines.js.map +1 -0
  940. package/workflows/dist/define.d.ts +288 -0
  941. package/workflows/dist/define.js +152 -0
  942. package/workflows/dist/define.js.map +1 -0
  943. package/workflows/dist/definitions.d.ts +25 -0
  944. package/workflows/dist/definitions.js +16 -0
  945. package/workflows/dist/definitions.js.map +1 -0
  946. package/workflows/dist/deployment-key.d.ts +24 -0
  947. package/workflows/dist/deployment-key.js +54 -0
  948. package/workflows/dist/deployment-key.js.map +1 -0
  949. package/workflows/dist/describe.d.ts +40 -0
  950. package/workflows/dist/describe.js +435 -0
  951. package/workflows/dist/describe.js.map +1 -0
  952. package/workflows/dist/description.d.ts +555 -0
  953. package/workflows/dist/description.js +389 -0
  954. package/workflows/dist/description.js.map +1 -0
  955. package/workflows/dist/direct.d.ts +10 -0
  956. package/workflows/dist/direct.js +26 -0
  957. package/workflows/dist/direct.js.map +1 -0
  958. package/workflows/dist/dns.d.ts +20 -0
  959. package/workflows/dist/dns.js +26 -0
  960. package/workflows/dist/dns.js.map +1 -0
  961. package/workflows/dist/drift.d.ts +136 -0
  962. package/workflows/dist/drift.js +188 -0
  963. package/workflows/dist/drift.js.map +1 -0
  964. package/workflows/dist/env.d.ts +51 -0
  965. package/workflows/dist/env.js +83 -0
  966. package/workflows/dist/env.js.map +1 -0
  967. package/workflows/dist/errors.d.ts +115 -0
  968. package/workflows/dist/errors.js +193 -0
  969. package/workflows/dist/errors.js.map +1 -0
  970. package/workflows/dist/expectations.d.ts +26 -0
  971. package/workflows/dist/expectations.js +171 -0
  972. package/workflows/dist/expectations.js.map +1 -0
  973. package/workflows/dist/fake.d.ts +93 -0
  974. package/workflows/dist/fake.js +280 -0
  975. package/workflows/dist/fake.js.map +1 -0
  976. package/workflows/dist/fill.d.ts +17 -0
  977. package/workflows/dist/fill.js +39 -0
  978. package/workflows/dist/fill.js.map +1 -0
  979. package/workflows/dist/folded.d.ts +7 -0
  980. package/workflows/dist/folded.js +28 -0
  981. package/workflows/dist/folded.js.map +1 -0
  982. package/workflows/dist/follow-steps.d.ts +8 -0
  983. package/workflows/dist/follow-steps.js +113 -0
  984. package/workflows/dist/follow-steps.js.map +1 -0
  985. package/workflows/dist/follow-workflow.d.ts +56 -0
  986. package/workflows/dist/follow-workflow.js +50 -0
  987. package/workflows/dist/follow-workflow.js.map +1 -0
  988. package/workflows/dist/grid.d.ts +34 -0
  989. package/workflows/dist/grid.js +63 -0
  990. package/workflows/dist/grid.js.map +1 -0
  991. package/workflows/dist/host-derive.d.ts +162 -0
  992. package/workflows/dist/host-derive.js +438 -0
  993. package/workflows/dist/host-derive.js.map +1 -0
  994. package/workflows/dist/host.d.ts +158 -0
  995. package/workflows/dist/host.js +112 -0
  996. package/workflows/dist/host.js.map +1 -0
  997. package/workflows/dist/identity-broker.d.ts +14 -0
  998. package/workflows/dist/identity-broker.js +84 -0
  999. package/workflows/dist/identity-broker.js.map +1 -0
  1000. package/workflows/dist/identity-provisioning.d.ts +50 -0
  1001. package/workflows/dist/identity-provisioning.js +304 -0
  1002. package/workflows/dist/identity-provisioning.js.map +1 -0
  1003. package/workflows/dist/identity-service.d.ts +25 -0
  1004. package/workflows/dist/identity-service.js +152 -0
  1005. package/workflows/dist/identity-service.js.map +1 -0
  1006. package/workflows/dist/import-workflow.d.ts +4 -0
  1007. package/workflows/dist/import-workflow.js +120 -0
  1008. package/workflows/dist/import-workflow.js.map +1 -0
  1009. package/workflows/dist/import.d.ts +94 -0
  1010. package/workflows/dist/import.js +161 -0
  1011. package/workflows/dist/import.js.map +1 -0
  1012. package/workflows/dist/index.d.ts +66 -0
  1013. package/workflows/dist/index.js +73 -0
  1014. package/workflows/dist/index.js.map +1 -0
  1015. package/workflows/dist/kms-secrets.d.ts +48 -0
  1016. package/workflows/dist/kms-secrets.js +320 -0
  1017. package/workflows/dist/kms-secrets.js.map +1 -0
  1018. package/workflows/dist/ledger.d.ts +281 -0
  1019. package/workflows/dist/ledger.js +335 -0
  1020. package/workflows/dist/ledger.js.map +1 -0
  1021. package/workflows/dist/lint.d.ts +24 -0
  1022. package/workflows/dist/lint.js +185 -0
  1023. package/workflows/dist/lint.js.map +1 -0
  1024. package/workflows/dist/load.d.ts +85 -0
  1025. package/workflows/dist/load.js +407 -0
  1026. package/workflows/dist/load.js.map +1 -0
  1027. package/workflows/dist/local-sandbox.d.ts +17 -0
  1028. package/workflows/dist/local-sandbox.js +131 -0
  1029. package/workflows/dist/local-sandbox.js.map +1 -0
  1030. package/workflows/dist/lockfile.d.ts +38 -0
  1031. package/workflows/dist/lockfile.js +74 -0
  1032. package/workflows/dist/lockfile.js.map +1 -0
  1033. package/workflows/dist/log.d.ts +24 -0
  1034. package/workflows/dist/log.js +83 -0
  1035. package/workflows/dist/log.js.map +1 -0
  1036. package/workflows/dist/login-code.d.ts +23 -0
  1037. package/workflows/dist/login-code.js +37 -0
  1038. package/workflows/dist/login-code.js.map +1 -0
  1039. package/workflows/dist/oauth.d.ts +112 -0
  1040. package/workflows/dist/oauth.js +301 -0
  1041. package/workflows/dist/oauth.js.map +1 -0
  1042. package/workflows/dist/op.d.ts +465 -0
  1043. package/workflows/dist/op.js +249 -0
  1044. package/workflows/dist/op.js.map +1 -0
  1045. package/workflows/dist/outline.d.ts +186 -0
  1046. package/workflows/dist/outline.js +554 -0
  1047. package/workflows/dist/outline.js.map +1 -0
  1048. package/workflows/dist/paths.d.ts +56 -0
  1049. package/workflows/dist/paths.js +124 -0
  1050. package/workflows/dist/paths.js.map +1 -0
  1051. package/workflows/dist/person.d.ts +66 -0
  1052. package/workflows/dist/person.js +71 -0
  1053. package/workflows/dist/person.js.map +1 -0
  1054. package/workflows/dist/plugin.d.ts +45 -0
  1055. package/workflows/dist/plugin.js +61 -0
  1056. package/workflows/dist/plugin.js.map +1 -0
  1057. package/workflows/dist/policy.d.ts +126 -0
  1058. package/workflows/dist/policy.js +50 -0
  1059. package/workflows/dist/policy.js.map +1 -0
  1060. package/workflows/dist/preview.d.ts +26 -0
  1061. package/workflows/dist/preview.js +29 -0
  1062. package/workflows/dist/preview.js.map +1 -0
  1063. package/workflows/dist/provisioning-identity.d.ts +27 -0
  1064. package/workflows/dist/provisioning-identity.js +81 -0
  1065. package/workflows/dist/provisioning-identity.js.map +1 -0
  1066. package/workflows/dist/renewal.d.ts +102 -0
  1067. package/workflows/dist/renewal.js +186 -0
  1068. package/workflows/dist/renewal.js.map +1 -0
  1069. package/workflows/dist/resource.d.ts +506 -0
  1070. package/workflows/dist/resource.js +600 -0
  1071. package/workflows/dist/resource.js.map +1 -0
  1072. package/workflows/dist/resources.d.ts +97 -0
  1073. package/workflows/dist/resources.js +384 -0
  1074. package/workflows/dist/resources.js.map +1 -0
  1075. package/workflows/dist/run-status.d.ts +10 -0
  1076. package/workflows/dist/run-status.js +27 -0
  1077. package/workflows/dist/run-status.js.map +1 -0
  1078. package/workflows/dist/run.d.ts +173 -0
  1079. package/workflows/dist/run.js +22 -0
  1080. package/workflows/dist/run.js.map +1 -0
  1081. package/workflows/dist/runner-box.d.ts +23 -0
  1082. package/workflows/dist/runner-box.js +181 -0
  1083. package/workflows/dist/runner-box.js.map +1 -0
  1084. package/workflows/dist/runner-protocol.d.ts +73 -0
  1085. package/workflows/dist/runner-protocol.js +34 -0
  1086. package/workflows/dist/runner-protocol.js.map +1 -0
  1087. package/workflows/dist/runtime-ops.d.ts +242 -0
  1088. package/workflows/dist/runtime-ops.js +354 -0
  1089. package/workflows/dist/runtime-ops.js.map +1 -0
  1090. package/workflows/dist/sandbox-contract.d.ts +109 -0
  1091. package/workflows/dist/sandbox-contract.js +26 -0
  1092. package/workflows/dist/sandbox-contract.js.map +1 -0
  1093. package/workflows/dist/sandbox-runner.cjs +7 -0
  1094. package/workflows/dist/sandbox.d.ts +46 -0
  1095. package/workflows/dist/sandbox.js +215 -0
  1096. package/workflows/dist/sandbox.js.map +1 -0
  1097. package/workflows/dist/scenario.d.ts +262 -0
  1098. package/workflows/dist/scenario.js +1281 -0
  1099. package/workflows/dist/scenario.js.map +1 -0
  1100. package/workflows/dist/scenarios.d.ts +59 -0
  1101. package/workflows/dist/scenarios.js +82 -0
  1102. package/workflows/dist/scenarios.js.map +1 -0
  1103. package/workflows/dist/schedules.d.ts +74 -0
  1104. package/workflows/dist/schedules.js +168 -0
  1105. package/workflows/dist/schedules.js.map +1 -0
  1106. package/workflows/dist/schema.d.ts +49 -0
  1107. package/workflows/dist/schema.js +256 -0
  1108. package/workflows/dist/schema.js.map +1 -0
  1109. package/workflows/dist/sdk.d.ts +34 -0
  1110. package/workflows/dist/sdk.js +182 -0
  1111. package/workflows/dist/sdk.js.map +1 -0
  1112. package/workflows/dist/seal.d.ts +42 -0
  1113. package/workflows/dist/seal.js +103 -0
  1114. package/workflows/dist/seal.js.map +1 -0
  1115. package/workflows/dist/secret-store-check.d.ts +11 -0
  1116. package/workflows/dist/secret-store-check.js +76 -0
  1117. package/workflows/dist/secret-store-check.js.map +1 -0
  1118. package/workflows/dist/secret-store.d.ts +142 -0
  1119. package/workflows/dist/secret-store.js +273 -0
  1120. package/workflows/dist/secret-store.js.map +1 -0
  1121. package/workflows/dist/secret.d.ts +54 -0
  1122. package/workflows/dist/secret.js +115 -0
  1123. package/workflows/dist/secret.js.map +1 -0
  1124. package/workflows/dist/shared.d.ts +495 -0
  1125. package/workflows/dist/shared.js +558 -0
  1126. package/workflows/dist/shared.js.map +1 -0
  1127. package/workflows/dist/sites.d.ts +62 -0
  1128. package/workflows/dist/sites.js +498 -0
  1129. package/workflows/dist/sites.js.map +1 -0
  1130. package/workflows/dist/source.d.ts +327 -0
  1131. package/workflows/dist/source.js +99 -0
  1132. package/workflows/dist/source.js.map +1 -0
  1133. package/workflows/dist/ssh-key.d.ts +11 -0
  1134. package/workflows/dist/ssh-key.js +44 -0
  1135. package/workflows/dist/ssh-key.js.map +1 -0
  1136. package/workflows/dist/steps.d.ts +81 -0
  1137. package/workflows/dist/steps.js +23 -0
  1138. package/workflows/dist/steps.js.map +1 -0
  1139. package/workflows/dist/storage-provisioning.d.ts +27 -0
  1140. package/workflows/dist/storage-provisioning.js +222 -0
  1141. package/workflows/dist/storage-provisioning.js.map +1 -0
  1142. package/workflows/dist/store-move-workflow.d.ts +14 -0
  1143. package/workflows/dist/store-move-workflow.js +77 -0
  1144. package/workflows/dist/store-move-workflow.js.map +1 -0
  1145. package/workflows/dist/store-move.d.ts +361 -0
  1146. package/workflows/dist/store-move.js +744 -0
  1147. package/workflows/dist/store-move.js.map +1 -0
  1148. package/workflows/dist/supervisor.d.ts +39 -0
  1149. package/workflows/dist/supervisor.js +68 -0
  1150. package/workflows/dist/supervisor.js.map +1 -0
  1151. package/workflows/dist/tokens.d.ts +45 -0
  1152. package/workflows/dist/tokens.js +120 -0
  1153. package/workflows/dist/tokens.js.map +1 -0
  1154. package/workflows/dist/vendor-info.d.ts +19 -0
  1155. package/workflows/dist/vendor-info.js +49 -0
  1156. package/workflows/dist/vendor-info.js.map +1 -0
  1157. package/workflows/dist/version.d.ts +44 -0
  1158. package/workflows/dist/version.js +92 -0
  1159. package/workflows/dist/version.js.map +1 -0
  1160. package/workflows/dist/wakeup-driver.d.ts +128 -0
  1161. package/workflows/dist/wakeup-driver.js +225 -0
  1162. package/workflows/dist/wakeup-driver.js.map +1 -0
  1163. package/workflows/dist/wakeup-service.d.ts +79 -0
  1164. package/workflows/dist/wakeup-service.js +419 -0
  1165. package/workflows/dist/wakeup-service.js.map +1 -0
  1166. package/workflows/dist/wakeup-type.d.ts +43 -0
  1167. package/workflows/dist/wakeup-type.js +82 -0
  1168. package/workflows/dist/wakeup-type.js.map +1 -0
  1169. package/workflows/dist/wakeup.d.ts +95 -0
  1170. package/workflows/dist/wakeup.js +79 -0
  1171. package/workflows/dist/wakeup.js.map +1 -0
  1172. package/workflows/dist/worker.d.ts +85 -0
  1173. package/workflows/dist/worker.js +535 -0
  1174. package/workflows/dist/worker.js.map +1 -0
  1175. package/workflows/dist/writer.d.ts +83 -0
  1176. package/workflows/dist/writer.js +349 -0
  1177. package/workflows/dist/writer.js.map +1 -0
  1178. package/workflows/drizzle/company/0000_tables.sql +104 -0
  1179. package/workflows/drizzle/company/0001_wakeup_row.sql +2 -0
  1180. package/workflows/drizzle/company/0002_runs_tell_the_app.sql +27 -0
  1181. package/workflows/drizzle/company/0003_ledger_target.sql +2 -0
  1182. package/workflows/drizzle/company/0004_oauth_attempts.sql +19 -0
  1183. package/workflows/drizzle/company/0005_connection_renewals.sql +9 -0
  1184. package/workflows/drizzle/company/0006_secret_moves.sql +35 -0
  1185. package/workflows/drizzle/company/meta/0000_snapshot.json +652 -0
  1186. package/workflows/drizzle/company/meta/0001_snapshot.json +652 -0
  1187. package/workflows/drizzle/company/meta/0002_snapshot.json +819 -0
  1188. package/workflows/drizzle/company/meta/0003_snapshot.json +845 -0
  1189. package/workflows/drizzle/company/meta/0004_snapshot.json +955 -0
  1190. package/workflows/drizzle/company/meta/0005_snapshot.json +1010 -0
  1191. package/workflows/drizzle/company/meta/0006_snapshot.json +1232 -0
  1192. package/workflows/drizzle/company/meta/_journal.json +55 -0
  1193. package/workflows/drizzle/wakeup/0000_tables.sql +26 -0
  1194. package/workflows/drizzle/wakeup/meta/0000_snapshot.json +200 -0
  1195. package/workflows/drizzle/wakeup/meta/_journal.json +13 -0
  1196. package/workflows/oxlint.json +117 -0
  1197. package/workflows/src/app-steps.ts +67 -0
  1198. package/workflows/src/app-workflows.ts +261 -0
  1199. package/workflows/src/apply-steps.ts +108 -0
  1200. package/workflows/src/apply.ts +868 -0
  1201. package/workflows/src/approvals.ts +274 -0
  1202. package/workflows/src/apps-list.ts +168 -0
  1203. package/workflows/src/apps.ts +147 -0
  1204. package/workflows/src/ast.ts +115 -0
  1205. package/workflows/src/authentication.ts +316 -0
  1206. package/workflows/src/bundled.ts +49 -0
  1207. package/workflows/src/call-workflow.ts +53 -0
  1208. package/workflows/src/call.ts +848 -0
  1209. package/workflows/src/cedar.ts +681 -0
  1210. package/workflows/src/change-steps.ts +270 -0
  1211. package/workflows/src/change-workflow.ts +198 -0
  1212. package/workflows/src/change.ts +483 -0
  1213. package/workflows/src/chat-steps.ts +117 -0
  1214. package/workflows/src/chat-workflow.ts +69 -0
  1215. package/workflows/src/chats.ts +179 -0
  1216. package/workflows/src/claims.ts +79 -0
  1217. package/workflows/src/client.ts +1924 -0
  1218. package/workflows/src/cloud-identity.ts +205 -0
  1219. package/workflows/src/collection.ts +688 -0
  1220. package/workflows/src/config.ts +1178 -0
  1221. package/workflows/src/connect-workflow.ts +38 -0
  1222. package/workflows/src/connection.ts +1522 -0
  1223. package/workflows/src/constructors.ts +10 -0
  1224. package/workflows/src/credentials.ts +189 -0
  1225. package/workflows/src/cucumber.ts +243 -0
  1226. package/workflows/src/data.ts +10 -0
  1227. package/workflows/src/database.ts +154 -0
  1228. package/workflows/src/db/company.ts +331 -0
  1229. package/workflows/src/db/dbos.ts +17 -0
  1230. package/workflows/src/db/identity.ts +61 -0
  1231. package/workflows/src/db/index.ts +12 -0
  1232. package/workflows/src/db/kms.ts +41 -0
  1233. package/workflows/src/db/migrate.ts +71 -0
  1234. package/workflows/src/db/wakeup.ts +41 -0
  1235. package/workflows/src/db.ts +430 -0
  1236. package/workflows/src/deadlines.ts +283 -0
  1237. package/workflows/src/define.ts +416 -0
  1238. package/workflows/src/definitions.ts +36 -0
  1239. package/workflows/src/deployment-key.ts +57 -0
  1240. package/workflows/src/describe.ts +525 -0
  1241. package/workflows/src/description.ts +434 -0
  1242. package/workflows/src/direct.ts +31 -0
  1243. package/workflows/src/dns.ts +29 -0
  1244. package/workflows/src/drift.ts +289 -0
  1245. package/workflows/src/env.ts +124 -0
  1246. package/workflows/src/errors.ts +255 -0
  1247. package/workflows/src/expectations.ts +200 -0
  1248. package/workflows/src/fake.ts +364 -0
  1249. package/workflows/src/fill.ts +47 -0
  1250. package/workflows/src/folded.ts +28 -0
  1251. package/workflows/src/follow-steps.ts +129 -0
  1252. package/workflows/src/follow-workflow.ts +88 -0
  1253. package/workflows/src/grid.ts +102 -0
  1254. package/workflows/src/host-derive.ts +540 -0
  1255. package/workflows/src/host.ts +234 -0
  1256. package/workflows/src/identity-broker.ts +94 -0
  1257. package/workflows/src/identity-provisioning.ts +337 -0
  1258. package/workflows/src/identity-service.ts +180 -0
  1259. package/workflows/src/import-workflow.ts +153 -0
  1260. package/workflows/src/import.ts +222 -0
  1261. package/workflows/src/index.ts +415 -0
  1262. package/workflows/src/kms-secrets.ts +385 -0
  1263. package/workflows/src/ledger.ts +559 -0
  1264. package/workflows/src/lint.ts +226 -0
  1265. package/workflows/src/load.ts +489 -0
  1266. package/workflows/src/local-sandbox.ts +133 -0
  1267. package/workflows/src/lockfile.ts +102 -0
  1268. package/workflows/src/log.ts +82 -0
  1269. package/workflows/src/login-code.ts +58 -0
  1270. package/workflows/src/oauth.ts +402 -0
  1271. package/workflows/src/op.ts +646 -0
  1272. package/workflows/src/outline.ts +675 -0
  1273. package/workflows/src/paths.ts +135 -0
  1274. package/workflows/src/person.ts +78 -0
  1275. package/workflows/src/plugin.ts +85 -0
  1276. package/workflows/src/policy.ts +162 -0
  1277. package/workflows/src/preview.ts +57 -0
  1278. package/workflows/src/provisioning-identity.ts +106 -0
  1279. package/workflows/src/renewal.ts +272 -0
  1280. package/workflows/src/resource.ts +964 -0
  1281. package/workflows/src/resources.ts +459 -0
  1282. package/workflows/src/run-status.ts +39 -0
  1283. package/workflows/src/run.ts +179 -0
  1284. package/workflows/src/runner-box.ts +218 -0
  1285. package/workflows/src/runner-protocol.ts +61 -0
  1286. package/workflows/src/runtime-ops.ts +391 -0
  1287. package/workflows/src/sandbox-contract.ts +121 -0
  1288. package/workflows/src/sandbox-runner.ts +187 -0
  1289. package/workflows/src/sandbox.ts +253 -0
  1290. package/workflows/src/scenario.ts +1624 -0
  1291. package/workflows/src/scenarios.ts +125 -0
  1292. package/workflows/src/schedules.ts +219 -0
  1293. package/workflows/src/schema.ts +311 -0
  1294. package/workflows/src/sdk.ts +225 -0
  1295. package/workflows/src/seal.ts +127 -0
  1296. package/workflows/src/secret-store-check.ts +93 -0
  1297. package/workflows/src/secret-store.ts +382 -0
  1298. package/workflows/src/secret.ts +151 -0
  1299. package/workflows/src/shared.ts +798 -0
  1300. package/workflows/src/sites.ts +559 -0
  1301. package/workflows/src/source.ts +353 -0
  1302. package/workflows/src/ssh-key.ts +48 -0
  1303. package/workflows/src/steps.ts +93 -0
  1304. package/workflows/src/storage-provisioning.ts +252 -0
  1305. package/workflows/src/store-move-workflow.ts +80 -0
  1306. package/workflows/src/store-move.ts +870 -0
  1307. package/workflows/src/supervisor.ts +102 -0
  1308. package/workflows/src/tokens.ts +163 -0
  1309. package/workflows/src/vendor-info.ts +53 -0
  1310. package/workflows/src/version.ts +103 -0
  1311. package/workflows/src/wakeup-driver.ts +286 -0
  1312. package/workflows/src/wakeup-service.ts +484 -0
  1313. package/workflows/src/wakeup-type.ts +92 -0
  1314. package/workflows/src/wakeup.ts +145 -0
  1315. package/workflows/src/worker.ts +667 -0
  1316. package/workflows/src/writer.ts +392 -0
  1317. package/dist/claims.d.ts +0 -1
  1318. package/dist/claims.js +0 -6
  1319. package/dist/claims.js.map +0 -1
  1320. package/dist/data.d.ts +0 -1
  1321. package/dist/data.js +0 -4
  1322. package/dist/data.js.map +0 -1
  1323. package/dist/resources.d.ts +0 -1
  1324. package/dist/resources.js +0 -5
  1325. package/dist/resources.js.map +0 -1
  1326. package/dist/secrets.d.ts +0 -2
  1327. package/dist/secrets.js +0 -3
  1328. package/dist/secrets.js.map +0 -1
  1329. package/identity/Dockerfile +0 -14
  1330. package/site.d.ts +0 -3
  1331. package/site.js +0 -3
  1332. package/ui.css +0 -2
  1333. package/ui.d.ts +0 -3
  1334. package/ui.js +0 -3
@@ -0,0 +1,990 @@
1
+ # sanoma/workflows
2
+
3
+ Business processes as TypeScript functions, run durably on [DBOS](https://dbos.dev) with Postgres. Each vendor call is a recorded step, and approvals and sleeps survive worker restarts. An oxlint config and `lintWorkflow` guard workflow code against accidental non-determinism and accidental ways around the policy. They are lint, not a sandbox: code written to get around them can.
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ npm install sanoma
9
+ ```
10
+
11
+ It is a part of [`sanoma`](https://www.npmjs.com/package/sanoma), whose bin runs the worker and the app over a repo's `sanoma.config.ts` and whose root entry re-exports what a workflow imports from `sanoma/workflows`; `startWorker` and `startApp` remain for a custom host.
12
+
13
+ A connector declares a vendor's operations: their inputs, outputs and effect. A workflow lists the operations it `uses`, and its `ctx` exposes those and nothing else.
14
+
15
+ ```ts
16
+ import { defineConnector, defineWorkflow } from "sanoma/workflows";
17
+ import { z } from "zod";
18
+
19
+ const shop = defineConnector("shop", {
20
+ order: {
21
+ get: { effect: "read", input: z.object({ id: z.string() }), output: z.object({ total: z.number() }) },
22
+ refund: { effect: "money", input: z.object({ id: z.string() }), output: z.object({ ok: z.boolean() }) },
23
+ },
24
+ });
25
+
26
+ export default defineWorkflow({
27
+ name: "refund",
28
+ trigger: "manual",
29
+ input: z.object({ id: z.string() }),
30
+ uses: [shop.order.get, shop.order.refund, "approval"],
31
+ run: async (ctx, { id }) => {
32
+ const order = await ctx.shop.order.get({ id });
33
+ // Covers the refund below, so the policy lets it through without asking again.
34
+ await ctx.approval(`Refund ${order.total}`, { approver: "finance-lead", covers: [shop.order.refund] });
35
+ return ctx.shop.order.refund({ id });
36
+ },
37
+ });
38
+ ```
39
+
40
+ A workflow's `trigger` is `"manual"` or `{ schedule, timezone? }` (`Trigger`): a five-field cron expression in an IANA time zone, UTC without one. The worker of the app's latest version keeps DBOS's schedules to the config's, one per scheduled workflow named `<app>/<workflow>` on the app's queue, deleting those no longer declared; a tick missed while the instance was stopped fires once when it starts again. Each tick is a run of the workflow under its own name (run id `sched-<app>/<workflow>-<time>`, its `run.started` record's `scheduledFor`), started by the runtime's `schedule` agent with the input `{}`, so `defineWorkflow` refuses a schedule for a workflow whose input refuses `{}`. The policy decides the start as it would a manual start by that agent (`workflow:<name>`, the principal `schedule`, in `agents`): a deny fails the run with its reason, and so does a hold, since a schedule waits for no approval. `nextFire(schedule, timezone, from)` is when a cron fires next, as DBOS's scheduler finds it, and `nextScheduledFire(resolved, from)` the earliest over a config's workflows. A scheduled workflow can still be started by hand.
41
+
42
+ A third argument says who the vendor is, so the app can show it: `defineConnector("shop", specs, { title: "Shop", logo: { svg, dark }, package, homepage })`. `logo.svg` is the vendor's mark as inline SVG markup, one `<svg>…</svg>` element (`defineConnector` refuses anything else, such as a file path or a URL), and `logo.dark` its variant for dark backgrounds, if it has one. The app shows a logo before each of the vendor's operations, in graphs and lists, and only ever as an image (`<img>` with a `data:` URL), where an SVG's scripts and external references never run or load. A vendor with no logo is shown by its operations' ids alone, as before. `package` is the connector's npm package name (`"@sanoma-ai/connector-resend"`), which the app's Connectors page links to on npm. `homepage` is the connector package's `homepage` from its package.json: where its code and README are, as an https URL (`defineConnector` refuses anything else); the Connectors page links to it as the connector's source. A vendor whose operations are split over several connectors is described by the first connector's info, its package and homepage as well as its title and logo. A connector package writes all of this once, in its package.json, and passes `vendorInfo(import.meta.url)` as the third argument (the nearest package.json is read): it reads the `"sanoma": { "title", "logo", "logoDark"? }` field, whose logos are SVG files in the package (relative `.svg` paths, listed in `files`), and the package's `name` and `homepage`. With the `sanoma-connector` keyword, the same field is how the app lists the package on npm before it is installed.
43
+
44
+ A [driver](#drivers) implements the operations and holds the credentials, and a [fake](#fakes-for-tests) stands in for the vendor in [sandbox runs](#scenarios-and-sandbox-runs). A connector package attaches both to the connector it exports, with `withSetup` (and its [steps](#steps-a-connector-ships) for Gherkin tests, as `steps`), so a config names the connector alone:
45
+
46
+ ```ts
47
+ // The connector package's root, such as @acme/connector-shop.
48
+ export const shop = withSetup(defineConnector("shop", specs, info), {
49
+ driver: shopDriver, // made once per resolved config
50
+ fake: fakeShop, // made once per sandbox run: each has its own
51
+ });
52
+ ```
53
+
54
+ `withSetup` lays what it is given over what the connector already carries, and keeps it on the connector's vendor record, so a spread copy of the connector keeps it too. A config that needs a driver made otherwise (another bridge, other options) swaps the driver and keeps the fake: `withSetup(github, { driver: () => githubDriver({ bridge }) })`. It is for connector packages and configs, not for workflows, which the lint does not let import it. Both are optional: a connector without a driver declares its operations and implements none, so a workflow using one is refused; a connector without a fake has none for sandbox runs, which the app's connector page says.
55
+
56
+ A connector that keeps tables on the company's database (a login's) attaches how to make them, as `prepare`: `withSetup(connector, { prepare: async (databaseUrl) => … })`, a `DatabasePreparation` the worker runs at its start, after the runtime's own tables, with the database's direct URL (never a pooler's: an advisory lock is one connection's); idempotent, and safe for two workers at once. The app never makes a connector's tables, since on a host it may run where it must not migrate: a login opened before the worker prepared them refuses. `startWorker`'s `prepare` option adds preparations no config names, as the `sanoma` bin adds the staff login's.
57
+
58
+ A connector that signs visitors in to a public site attaches a login half too, as `login`: `withSetup(connector, { login: (context) => half })`. The app calls it once per public site whose `site.ts` names the connector (`defineSite({ public: true, login: "<vendor>" })`), when it starts, with a `LoginContext` (`database()`, the client's pool, the app's one on Node and the request's own on a Worker, so a half keeps an instance per pool and nothing else across requests; a key of its own derived from `SANOMA_SIGNING_KEY` to sign its cookies with, a vendor's secrets, the site's origins, `sendCode(email, code)` when the config names a `login.sender`, and `social`, the company's GitHub App's OAuth client when the app is given it), on the tables its `prepare` made. The `LoginHalf` it makes (see its type) answers the provider's stable subject for a request, with the email and the GitHub login when it verified them, never a principal: the app makes the visitor's principal from it, so a connector cannot set a visitor's groups. A visitor's address, for rate limits, is the `CLIENT_IP_HEADER` header the app sets, never `X-Forwarded-For`. One vendor's connectors attach one `login`, as for a driver. [`sanoma/better-auth`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/better-auth/README.md) is one, email and password (and an email code, with a sender) on the company's database; it also exports `betterAuthStaffLogin`, the staff sign-in the app uses on a host (`LoginContext.staff`: who is declared, the GitHub client, and where a sign-in is recorded). The app makes it as it starts and sends it every request to the site's own host ([public sites](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/app/README.md#public-sites)).
59
+
60
+ A model connector attaches a model half, as `model`: `withSetup(connector, { model: (context) => provider })`, an AI SDK provider (`ProviderV4` from `@ai-sdk/provider`) with the vendor's adapter as the transport. The app makes it for its model registry, once per resolved config and client (again after one that throws), where its models are `<vendor>/<model-id>`; it answers `languageModel("default")` with the connector's own default. Its `ModelContext` gives it the secrets as a login's does (the selected store and explicit bindings), which it reads when a model is called; its driver declares the key in `env`, with no operations if it needs none. One vendor's connectors attach one `model`. [`@sanoma-ai/connector-anthropic`](https://www.npmjs.com/package/@sanoma-ai/connector-anthropic) is one.
61
+
62
+ A git host's connector attaches a remote half, as `remote`: `withSetup(connector, { remote: () => half })`, a `RemoteHalf` made once per resolved config and kept in `ResolvedConfig.remotes` by vendor; `remoteFor(remotes, url)` finds the one whose `matches` reads a clone URL, with the repository. `open(repo, { secrets })` gives a `SourceHost`: the repository's pull requests (find, open, squash-merge at a head, close), the `sanoma` commit status, and `enforcement(base)`, whether the host refuses a change to the branch that is not a merge (`HostEnforcement`); its `token(prefer)` is what a push signs in with. `webhook(request, { secrets })` verifies a delivery and says what happened (`RemoteEvent`: a branch pushed, a pull request closed); `owners({ secrets })` lists the accounts the company's app on the host is installed on, and `permissions({ secrets })` what that app may do, as the host lists it (both optional, undefined or empty without the app's keys). It reads its tokens through `secrets` when called, as a model half does. One vendor's connectors attach one `remote`. [`@sanoma-ai/connector-github`](https://www.npmjs.com/package/@sanoma-ai/connector-github#remote-half) is one.
63
+
64
+ `SanomaClient.follow(event)` starts the built-in `follow` workflow on what a webhook says happened (the app's `POST /webhooks/<vendor>` calls it for each event it verified), as the runtime's agent `host-check`, with the run id `follow:<sha256 of the event>`: one run per event, however often it is delivered, and `start` refuses a `follow` under another id or actor. The worker runs it over its repository (`WorkerOptions.source`): an event of another repository, or on a worker with none, is ignored (the run's output says why). A push to `main` fast-forwards the checkout, then starts apply on the declared hosts (`ResolvedConfig.hosts()`) as `host-check`, as the run `deploy:<head>`, so a merge made outside Sanoma deploys too: nothing without a host, nor while a change is merging or deploying, which applies `main` itself; when the checkout cannot follow `main`, the run fails, saying why, and deploys nothing. A push to `draft/<id>` while the change of `id` is open brings the host's commits into the draft (`Source.follow` on its branch, a fast-forward) and tells the change `commits`; a closed pull request of `draft/<id>` tells it `merged` (with the merge commit) or `closed`. The change run checks a merge or a close on the host before it believes it. A delivery repeated does nothing more: the run id, a draft already at the head, and the event's key (`changeEvent`'s `key`, an idempotency key of its message) see to it. `host-check` is not the Publish approval's approver, so it withdraws nothing: a change waiting on Publish reads the event when Publish is decided.
65
+
66
+ A config names the connectors, and the workflows when no launcher finds them (`sanoma` imports every file of `workflows/` and of each [app's](#apps), so a company's config lists none; one it lists is kept, once):
67
+
68
+ ```ts
69
+ import { defineConfig } from "sanoma/workflows";
70
+
71
+ export default defineConfig({
72
+ workflows: [refund],
73
+ connectors: [shop],
74
+ });
75
+ ```
76
+
77
+ That is the whole config; the rest is convention, from its `root` (`defineConfig`'s call site's directory, or `root` where that is not the source's, as in a bundle). Three conventions give what a config no longer says:
78
+
79
+ - **The app's name** is the `name` in `<root>/package.json`, kept whole (`@acme/ops`), when that file exists and names one; otherwise, and for a config with no root, it is `"sanoma"`. Only the root's own file counts, never one above it, so a parent project's name never becomes the app's; a `package.json` that is not JSON is refused, naming it. The name scopes the app's runs, queues and versions in its database.
80
+ - **The [scenarios](#scenarios-and-sandbox-runs)** are the `.feature` files of `<root>/scenarios/` and of each [app's](#apps) `scenarios/`, named by their path from the root (`scenarios/x.feature`, `apps/crm/scenarios/y.feature`); without any such directory the config has none.
81
+ - **The [policy](#policies)** is `<root>/policies/**/*.cedar` and each [app's](#apps) `policies/**/*.cedar`, decided as the [people](#people) the data files declare; without any, every call and start is allowed (`allowAll`).
82
+
83
+ The [data files](#data-files) are `resources/` in the root and in each [app](#apps). `ledger` and `databaseUrl` configure persistence; `secrets`, `connections` and `connectionRules` configure [credential storage and account identity](#credentials). `drivers`, `fakes`, `appName`, `scenarios` and `policy` are typed `never` on `SanomaConfig`, each deprecated with where it went, so the compiler and the editor say so; an untyped config that still names `drivers` or `fakes` is refused at run time rather than run live on what it no longer reads, and one that names `policy` rather than run allowing everything. A worker looks for queued runs every second, DBOS's default; `SANOMA_QUEUE_POLL_MS` sets that in milliseconds, as this repository's tests do.
84
+
85
+ The audit record goes to the ledger, by default `postgresLedger(databaseUrl)` on the config's database (see [Ledger](#ledger)); `ledger: jsonlLedger(dir)` keeps it in files instead, and `memoryLedger()` in this process only, for tests. `resolveConfig(config)` checks a config and derives what the runtime uses from it: the app name, database, version and queue (`sanoma:<appName>`, for every run, [sandbox runs](#scenarios-and-sandbox-runs) included), the operations by id, the driver each vendor's connector attaches, made once for the resolution (`driversByVendor`, in `connectors` order, and their functions by operation id, `drivers`), the makers of their fakes (`fakes`, by vendor), the scenarios directory, the policy (`policy`, the policies it is made from as `policies`, and what is wrong in them as `policyProblems`), and the config's `ledger` when it gives one; it opens nothing and reads no file outside the root: its `package.json`, whether `scenarios/` is a directory, and the policies with the people files. It throws, with one message, whatever the worker would refuse: a workflow or driver naming an operation the `connectors` don't declare, a workflow redeclaring an operation with another effect, an operation with no driver (`` `shop.order.refund` has no driver: the connector package must attach one ``), two different drivers or fakes for one vendor, two workflows with one name, a `ledger` that is not a store, a `drivers`, `fakes` or `policy` an untyped config still names. `startWorker`, `SanomaClient.connect` and `describeConfig` all call it, so they fail the same way. It adds the built-in [`drift`](#drift) and [`apply`](#apply) workflows when the connectors declare resource types, and [`call`](#direct-calls) when an operation may be called directly. The worker takes each operation's effect, schemas and retry setting from `connectors`, never from the workflow.
86
+
87
+ An operation names the instance it acts on with `target`, a function of its parsed input, so a policy can decide per post or per order rather than per operation (its Cedar resource, `Sanoma::Target::"order/ord_1"`). TypeScript types its input `any` there, so annotate it to have it checked:
88
+
89
+ ```ts
90
+ const shop = defineConnector("shop", {
91
+ order: {
92
+ refund: {
93
+ effect: "money",
94
+ input: z.object({ id: z.string() }),
95
+ output,
96
+ target: ({ id }: { id: string }) => `order/${id}`,
97
+ },
98
+ },
99
+ });
100
+ ```
101
+
102
+ The ledger gets one record for the start of the run, each operation call with its decision and the vendor's reply, each approval requested, decided and withdrawn (`approval.withdrawn` with its `reason`; a policy's hold names the call it holds by its `op` and `opSeq`, the `seq` that call's own record has), each message an approval ignored (`approval.refused`: sent by someone who may not decide it, or not a decision), each sleep (`sleep.started` with `until`, when it ends in ms since the epoch: the time asked for, or for a duration, the record's `at` plus the duration, as the runtime saw it; written for a time already past too), and how the run ended, in a JSONL file per run. A decision is recorded with its `reasons` (the ids of the policies behind it) and, with Cedar policies, their `policyVersion`, a hash of their text. Every record carries `v: 1`, the `app` and the `actor`, and one written inside a `ctx.all` member its `group` (see [Built-ins](#built-ins)); each call's record (`op.called`, `approval.requested`, `sleep.started`) carries its step's `name` (see [Step names](#step-names)); an error is recorded as `{ code?, name, message }`, with `retryable` when the error says, the vendor's `status` and `vendorCode` only from a `DriverError`, and `data` only from the runtime's own errors (the operation, the approval, the input's issues), so an HTTP client's error that escapes a driver does not put the vendor's reply in the ledger. A ledger store's failed append is tried again up to three times; a store throws an error with `retryable: false` for a failure that would only repeat. When a call's record still cannot be written after the vendor replied, the call fails with "<op id> succeeded, but the ledger could not record it" and the run makes no further calls (`run_ended`), so a workflow that catches the failure cannot repeat the side effect unrecorded.
103
+
104
+ People are `Principal`s: `{ id, groups?, onBehalfOf? }`. A run is started as one and a decision is sent as one, by id: the groups are the [people files'](#people), never the caller's.
105
+
106
+ ```ts
107
+ const client = await SanomaClient.connect(config);
108
+ const runId = await client.start(refund, { id: "ord_1" }, { startedBy: { id: "alice" } });
109
+ const approval = await client.decide(runId, { decision: "approve", by: { id: "finance-lead" } }); // status: "approved"
110
+ const run = await client.run(runId); // run.status: "queued" | "running" | "waiting" | "finished" | "failed" | "cancelled"
111
+ ```
112
+
113
+ `workflow` is a definition or the name of one in the config's `workflows` (`client.start("refund", …)`); a name the config does not have is refused with `invalid_input`, naming the ones it has. `startedBy` is required. `start(workflow, input, { startedBy, runId })` with a `runId` makes a retried start idempotent: an id that exists returns that run when the workflow, the input (as JSON) and `startedBy` match, and is refused with `invalid_input`, naming what differs, when they do not. Of two starts racing with one new id, the first stands and the second is answered the same way. Errors the runtime and the client throw carry a `code` (`policy_denied`, `approval_rejected`, `approval_withdrawn`: the approval a call or step waited on was [withdrawn](#approvals), `not_approver`, `no_pending_approval`, `already_decided`, `run_not_found`, `driver_failed`, `invalid_input`, `run_ended`, `run_running`: `client.result` timed out with the run still going, `approval_pending`: a [direct call](#direct-calls) is held, `not_admitted`: the data files declare people and not this principal's id) and `data`. Read it with `errorCode(err)`, not `instanceof`: a run's error comes back from the database as a copy, so `errorCode(await client.result(runId).catch((e) => e))` is `"policy_denied"` for a denied call.
114
+
115
+ `startWorker(config, { logLevel })` runs workflows and recovers interrupted runs. `SanomaClient` starts runs, lists them, records approval decisions and reads a run's ledger. `describeConfig(config)`, from `sanoma/workflows/describe`, returns the same config as plain JSON (its version, each workflow's input as JSON Schema, the operations it may call and its [outline](#outline), each operation's effect and contract: its input as a caller sends it, `io: "input"`, and its output as parsed, `io: "output"`), each vendor's title, logo, package and homepage and whether its connector attaches a fake (`vendors`, by vendor id, the logo as `data:image/svg+xml` URLs), the resource types (`resourceTypes`, see [Resources](#resources)), and the resources the data files declare, each with its binding, the lockfile's orphans and what is wrong in them (`resources`, `orphans` and `problems`, see [Data files](#data-files); a workflow's file's problems are on its entry, beside its `file` and `outline`), which is what a UI renders from.
116
+
117
+ The worker, the client and the app find Postgres at the config's `databaseUrl`, else the `SANOMA_DATABASE_URL` environment variable, else `postgresql://postgres:dbos@localhost:5433/sanoma`, the database `pnpm db:up` starts from this repo's docker compose file. The `sanoma` launcher always sets `SANOMA_DATABASE_URL`: when none is named it starts the company's own Postgres ([sanoma's Postgres](../README.md#postgres)). Set one of the first two anywhere but on your own machine.
118
+
119
+ ### Apps
120
+
121
+ A company's apps are the folders of `apps/`, each holding what the root does: `workflows/`, `resources/` (its `data.ts` too), `policies/`, `scenarios/` and `sites/`. An app is merged into the repo from a source repository, or made there; its `app.ts` says which, `export default defineApp({ source: "https://github.com/acme/crm" })` (`defineApp({})` for the company's own), which `readApps(root)` loads (`AppEntry`, `{ name, dir, source?, at? }`, by name; `defineApp` served by the [loader](#data-files)): a default export that is not `defineApp({ source })` with `source` a string, or an `app.ts` that throws, is a problem. A folder's name is the app's (`APP_NAME`: a lowercase letter, then lowercase letters and digits); `describeConfig` refuses another as a problem, and lists the apps as `apps`.
122
+
123
+ What an app's folder declares is named with the folder, from where its file is (`appOfFile`: the nearest directory with a `sanoma.config.ts`, then `apps/<app>/`), never written: a collection `customers` in `apps/crm/resources/data.ts` is `crm.customers`, its operations `data.crm.customers.get` and so on, and a workflow `follow-up` in `apps/crm/workflows/` is `crm.follow-up`, each with `app: "crm"`; what the root declares keeps its name. So two apps may declare one name. A file is an app's while the nearest directory above it with a `sanoma.config.ts` is the company's root (an app may keep its own `package.json`; a `node_modules` ends the search). A workflow calls an app's collection as `ctx.data.crm.customers.get(…)`, and a site as `api.data.crm.customers.list()`; an app's workflow is `api.crmFollowUp` (`apiNameOf`), and its Cedar action `workflow:crm.follow-up`. A site in `apps/crm/sites/pipeline/` is `crm/pipeline`, at `/sites/crm/pipeline`. `describeConfig`'s workflows, collections and sites carry their `app`.
124
+
125
+ The people are the company's: an app's data files declare none (`readPeople` refuses one, naming its file). A workflow may import the root's `resources/data.ts` and any app's. A relative import from one app's files into another's folder is a warning (`crossAppImports(root, apps)`, from `sanoma/workflows/describe`, which `sanoma check` prints), since a company may take one app without the other: reach the other through `ctx` or `api` instead. A collection or site at the root named as an app is a problem: `api.data.<app>` and `/sites/<app>/` are the app's.
126
+
127
+ Taking an app is a git merge into a draft of the company's `Source` (the `sanoma` package's `localGitSource`). `draft.take({ url, ref?, folder?, author })` fetches the source repository, a public company repo holding one `apps/<folder>/` (`folder` names it when it holds more), by https alone, and merges it with its history as one merge commit. `draft.update({ folder, author })` merges the new commits of the default branch of the URL the app's `app.ts` names (`appSourceOf`: an `app.ts` that throws, or is not `defineApp({ source })`, is refused with its problem, and one that names no source as the company's own), and `source.behind(folder)` counts them, fetched now (both refuse a source that shares no history with the checkout). An update reads the source from `main`'s `app.ts`, never the draft's, since a draft's files are never loaded: an app only in a draft is refused until its take is published. Either merge takes `apps/<folder>/` (a take, the source's folder whole) and `package.json` (its connectors, both sides kept); every other file stays the company's, as does a file one side deleted, since the source's root is the starter's. Both return an `AppMerge` (`{ folder, revision, merged, conflicts }`): a line both sides changed is committed with git's markers (diff3: ours, the base, theirs) and its file named in `conflicts`, so the draft's checks fail until the agent resolves it. An update needs the take's merge commit in the history: a draft that takes an app is merged into `main` as a merge, not squashed.
128
+
129
+ ### People
130
+
131
+ People, groups and agents are resources of the built-in `sanoma` connector, declared in a [data file](#data-files) (`resources/people.ts` by convention), loaded as any other:
132
+
133
+ ```ts
134
+ import { sanoma } from "sanoma/resources";
135
+
136
+ export const ada = sanoma.person({ id: "ada", name: "Ada Ortiz", email: "ada@acme.test", github: "ada-ortiz" });
137
+ export const bo = sanoma.person({ id: "bo" });
138
+ export const refundBot = sanoma.agent({ id: "refund-bot", onBehalfOf: bo });
139
+ export const finance = sanoma.group({ name: "finance", members: [ada] });
140
+ ```
141
+
142
+ A membership is written on the group alone. An agent is in the group `agents` besides its own, with `onBehalfOf` the person whose instruction it carries; the runtime's own agents (`scenarios`, `host-check`, `schedule`, `wakeup`, which registers a wakeup, `login`, which sends sign-in codes, and `renewal`, which renews OAuth grants when due) are declared by no file. They have no vendor object: no driver, no drift. `readPeople(root)` loads them from the files that may declare them (`mayDeclarePeople`: those importing `sanoma` from `sanoma/resources`), again only when one of them changed, so a request costs a `stat` per file, and `principalOf(id, people)` is who an id is: its groups, by inverting the members, and its `onBehalfOf`. Once a person is declared, `SanomaClient.start`, `call`, `decide`, `setCredential`, `setSecret`, `clearCredential` and `clearSecret` admit only a declared id (`not_admitted`, "<id> is not declared in resources/people.ts"), as the app's login admits only a declared person; while none is, any id is taken as given; while the people files have problems, nobody is admitted but the runtime's agents.
143
+
144
+ A visitor of a public site is a principal too, which no data file declares: `visitorPrincipal(login, subject)` is one signed in through a visitor login (`visitor:<login>:<subject>`, in the group `visitors`), and `ANONYMOUS_PRINCIPAL` the one a page with nobody signed in runs as (`anonymous`, in no group); `isVisitor(principal)` tells either by its id. `admit` takes a visitor's id whatever the files say and stamps its groups, never the ones given; the staff logins (a sign-in) admit none, and a visitor sets no credential and decides no approval. So `visitors` and `anonymous` are no group's name, and `anonymous` and the `visitor:…` form no person's or agent's id (`readPeople` reports them, as it does `agents`).
145
+
146
+ A script or another service acts through an API token: `client.tokens.mint({ subject, groups })` makes one, `sca_` and 32 random bytes in base64url, and returns `{ id, token }`, the token shown this once (only its SHA-256 is kept, in `sanoma_api_tokens`); `subject` is whom it acts for (`visitor:better-auth:<id>`, say). A public site's host takes it as `Authorization: Bearer <token>`, and the request acts as `token:<id>` in the token's `groups` (admission keeps them, where a visitor's are stamped `visitors`), with no email; `client.tokens.revoke({ id })` ends it, and an unknown or revoked token is a 401.
147
+
148
+ #### Signing in on a host
149
+
150
+ The app on a host signs people in by an email code, an invite link, or GitHub ([the app's README](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/app/README.md#staff-sign-in-on-a-host)). The code goes out through the operation the config names as `login.sender`, a connector's send that takes `{ from, to, subject, text }`, from the address it names as `login.from` (`login@acme.example` or `Acme <login@acme.example>`), on a domain the sender's vendor has verified ([`resend.domain`](https://www.npmjs.com/package/@sanoma-ai/connector-resend#sending-domain) declares one):
151
+
152
+ ```ts
153
+ import { resend } from "@sanoma-ai/connector-resend";
154
+
155
+ export default defineConfig({
156
+ connectors: [resend],
157
+ login: { sender: resend.emails.send, from: "Acme <login@acme.example>" },
158
+ // …
159
+ });
160
+ ```
161
+
162
+ With one, the runtime registers the built-in workflow `login-code` (so a company workflow may not be named that), which the app starts as the agent `login` with the code sealed under `SANOMA_SIGNING_KEY` together with the email it is for (`sealLoginCode(to, code)`, so a copy of a run's input mails it to nobody else); its one call mails "Your <company> sign-in code", under the policy and in the ledger like any send, the mail's `text` recorded as `<text>`. A policy that holds sends exempts it (`unless { … || principal == Sanoma::Principal::"login" }`): otherwise `describeConfig` reports a problem on `policies`, naming the policy and the fix. `resolveConfig` refuses a sender that is no connector's operation, does not send, has no driver, or takes no email from `login.from`, and a `login.from` that is missing or no email address. Each sign-in and each invite is a ledger record outside any run (`signin.recorded { person, method }` under `signin:<person>`, `invite.minted { person, by, expiresAt }` under `invite:<person>`), written by `client.recordSignIn(person, method)` and `client.recordInvite(person, { by, expiresAt })`; `client.lastSignIns(people)` reads when each last signed in and how, and `client.lastInvite(person)` who minted their latest invite, when and until when (`{ by, at, expiresAt }`, undefined while none was), which the invite's landing page names. `sealInvite({ email })` seals an invite request for five minutes under `SANOMA_SIGNING_KEY` (`openInvite` opens one), which an instance holding the same key answers with a one-use invite link at `POST /auth/invite`.
163
+
164
+ ### Policies
165
+
166
+ The policy is [Cedar](https://docs.cedarpolicy.com): `policies/**/*.cedar` in the root, evaluated in process with `@cedar-policy/cedar-wasm` against a schema built from the resolved config and the people (`schemaOf`). Everything is allowed unless a `forbid` refuses it: the runtime adds the one `permit`, so a company's policies are `forbid`s. That permit leaves [visitors](#people) out at a run's start and at a direct call: a visitor may do neither until a company `permit` names it, the one kind of `permit` a company file may hold, its principal exactly `in Sanoma::Group::"visitors"` or `== Sanoma::Principal::"anonymous"`. Inside a run a visitor was let start, its calls are allowed as anyone's, the forbids still holding, so one permit per workflow is enough and the run's operations stay out of a visitor's direct reach. A visitor's start or direct call no permit allows is denied ("A visitor may do nothing until a policy permits it", `VISITOR_DENIED`), never held; `allowAll`, a repo with no policies, denies them the same, and a visitor starts none of the runtime's own workflows but `call`.
167
+
168
+ ```cedar
169
+ @hold("finance")
170
+ @title("Refunds need finance")
171
+ forbid (principal, action in Sanoma::Action::"effect:money", resource)
172
+ unless { principal in Sanoma::Group::"finance" };
173
+
174
+ @id("no-agent-refunds")
175
+ @reason("Agents do not refund")
176
+ forbid (principal in Sanoma::Group::"agents", action == Sanoma::Action::"shop.order.refund", resource);
177
+
178
+ // A public site's visitors may sign up; nobody signed in may list the posts.
179
+ permit (principal in Sanoma::Group::"visitors", action == Sanoma::Action::"workflow:signup", resource);
180
+ permit (principal == Sanoma::Principal::"anonymous", action == Sanoma::Action::"data.posts.list", resource);
181
+ ```
182
+
183
+ - **The schema**, namespace `Sanoma`: `Principal` in `Group` (an enum of the declared groups, `agents` and `visitors`, so a misspelt group fails validation), with `onBehalfOf`; each operation's id an action in its effect's group (`effect:money`), on a `Target` (its `target`, else its id; a collection's in `Collection::"<name>"`), with `context.input` from its input schema and, for a collection's save or delete, `context.before`; `sanoma.change.merge` on a `Change` instead, whose attributes are the change's facts; `workflow:<name>` in the group `start`, on a `Workflow`, with the run's input. `schemaText` prints it; the `sanoma` bin writes it to `.sanoma/schema.cedarschema`.
184
+ - **A hold** is a `forbid` with `@hold("<group>" | "<person id>" | "on-behalf-of")`: the call waits for that approver (`on-behalf-of`: whom the agent acts for), with `@title` as the approval's title. The runtime lifts it once an approval addressed to that approver and covering the operation is approved (`approvedFor`), so a workflow's own `ctx.approval` to the same approver, covering the operation, lets it through. Several holds on one call or start are asked one at a time, in the order written: once one is approved, the policy is asked again. **A deny** is a `forbid` without `@hold`, with `@reason` as its message (else `Refused by <id>`). A policy's id is its `@id`, else `<file>#<n>`; a decision's `reasons` carry the ids into the ledger.
185
+ - **Where it runs**: before every operation call, a run's node, a [direct call](#direct-calls) and [apply](#apply)'s changes (`decideCall`), and before a run starts (see [Approvals](#approvals)). `policy.preview(requests)` asks the same with the input unknown, through Cedar's partial evaluation: `allow`, `hold` with its approver, `deny`, or `depends` on the input, each with the rule behind it; the app's run form and Permissions page show it. A request with `inRun: true` asks about an operation inside a run, not a direct call, which only a visitor's answer tells apart.
186
+ - **A change** to the company's repository is decided on its merge, `sanoma.change.merge`, one of four operations of the built-in connector `sanoma` (`changeOps`: `sanoma.change.open`, `.review`, `.merge` and `.close`, effect `write`) that every config has and only the built-in `change` workflow may call, so a policy names it in every repo. The connector's fifth operation, `sanoma.apps.list` (`APPS_LIST`, a read), lists the apps on GitHub (the repositories with the topic `sanoma-app`) with Sanoma's claims about each (`claims.ts`: tier, review, blocked commits, the solutions holding it); a page calls it directly, as the person, so the policy decides it like any direct call, and every config has the built-in `call` workflow for it. Its resource is a `Sanoma::Change` whose attributes are the facts of the change (`ChangeFacts`): `touches` (each path it edits and each parent directory, `touchesOf`: `resources/`, `resources/finance/`, `resources/finance/cards.ts`), `strandedRuns` and `stranded` (the waiting runs of a workflow it edits), `checksOk` and `rules`. Cedar has no quantifier over a set and `like` reads one string, so a rule asks `contains` of a directory, and an app's files are under its own (`apps/crm/resources/`), which a rule on `resources/` does not cover: `forbid (principal, action == Sanoma::Action::"sanoma.change.merge", resource is Sanoma::Change) when { resource.touches.contains("resources/finance/") } unless { principal in Sanoma::Group::"finance" };`. A preview asks with the facts unknown: a rule on any change holds, a rule on the facts depends. Before any policy, the runtime's own rule (`runtimeHold`): a merge of a change to the rules (`rules`: a policy, the root's or an app's, a people file, or a company file `main`'s people files import, `peopleSources`) waits for the group `admin`, with the reason `sanoma:rules-wait-for-admin`, under `allowAll` too, and is denied while no data file declares `admin`; the people are the running instance's, so a change cannot add its author to `admin`. The company's policy is asked once an approval addressed to `admin` covering the merge lifts it. The template's `policies/changes.cedar` holds every change for `admin`.
187
+ - **Problems** (a file that does not parse, two policies with one id, a template, what Cedar's strict validation finds, a `permit` for anyone but the visitors or `anonymous`, or with a `@hold`, a `@hold` naming no declared group or person, `visitors` among them) are `resolveConfig`'s `policyProblems`, one line each, `file:line:col: <policy id>: <message>`. While there are any, the policy refuses every call, start and preview ("The policies do not hold: …"): a repo never runs on part of its rules. `describeConfig(config).policy` carries them as `problems`; `startWorker` warns with them (unless `quiet`), `startApp` lists them and its pages say the policies do not hold, `sanoma check` reports them and runs no scenario, and the `sanoma` bin starts nothing.
188
+
189
+ Later, not yet: the person's numeric GitHub id is stored but unused, so a login renamed and taken by someone else would be admitted as them. The app describes the config when it starts, so a person added while it runs shows in the who-are-you picker and the Permissions grid after a restart (login admits them at once). The Permissions grid asks about workflow starts and direct operations only, not the operations a run calls.
190
+
191
+ ### Ledger
192
+
193
+ The ledger is the audit record of a run: who started it, every operation call with the policy's decision, every approval, and how it ended, as `LedgerRecord`s in `seq` order. `client.ledger(runId)` reads it, and the app's run page shows it. Each `op.called` record names its `target` when the operation declares one (`data:outbound/Acme`: the instance the call acted on, as the policy saw it), and `client.history(target, limit?)` reads the calls that acted on one across every run, direct writes among them, newest first: a run's reads of the record too (each record's `effect` tells them from the writes), never a direct read, which is not recorded. Three stores keep it, each a `LedgerStore` (`append`, `read`, `readByTarget`, and `close` for one that holds a connection), and a config picks one with `ledger`:
194
+
195
+ - `postgresLedger(databaseUrl)`, the default when `ledger` is not set: one table, `sanoma_ledger`, in the config's database beside DBOS's own, which the worker, the app and other processes then share without sharing a disk. The table is made on first use, and the database with it when it is not there (as a worker's launch makes it), so the app may read before any worker has run. The worker and the client (so the app) each make their own store and close it with themselves (`stop`, `client.close()`); `close()` ends its pool for good. A store the config gives is the config's to close: the runtime never closes it.
196
+ - `jsonlLedger(dir)`: `<dir>/<runId>.jsonl`, one record per line, for a ledger on disk or in a repo.
197
+ - `memoryLedger()`: this process only, for tests.
198
+
199
+ Every store keeps the first record of an id: a run replayed after a restart writes its records again, with the same ids, and the store skips them (warning when a later one differs). A failed `append` is tried again three times, unless the store says the failure is final (`retryable: false`): a record that is not JSON, a corrupt file.
200
+
201
+ ### Approvals
202
+
203
+ An approval comes from the workflow (`ctx.approval(title, { approver, covers?, links?, details? })`) or from the policy holding a call (a `@hold`). Each is in `run.approvals` with its `status`, so a later call it covers is let through once it is approved.
204
+
205
+ `covers` says which operations an approval stands for, as op ids in the approval's state. A policy hold covers the operation it held; a workflow's approval covers the operations it names, or none. The runtime lifts a hold with `approvedFor(run.approvals, op.id, approver)`: approved, covering this operation, and addressed to the hold's approver. The last part matters: a workflow can request an approval covering any operation from anyone it names, so a check on `covers` alone would let a workflow launder a sign-off through its own `ctx.approval`. A withdrawn approval is no longer approved, so it lifts nothing. Covers name operations, not inputs: an approval that covers `shop.order.refund` covers every later refund call in the run.
206
+
207
+ The approver is a person's id (`"finance-lead"`), or `{ group: "finance" }` for anyone whose principal lists that group in `groups`. A group's name is not a person: `{ id: "finance" }` is not in the group `finance`. `mayDecide(approval, principal, run, people)` is the check the run, the client and the app's Inbox all use; it also refuses the run's own actor while someone else could decide, that is while the approver is a group with another declared person in `people` (the declared people resources; an agent in the group, declared or the runtime's own, does not count; `own change`: nobody decides on their own change, though a person may decide on a run an agent started for them). When nobody else could (the approver is the starter by id, or a group they alone are in), the starter decides, and the `approval.decided` record and the approval say `alone: true`. A policy hold's title is its `@title`, else `<op id> needs <approver>`, the approver shown as `group finance` for a group.
208
+
209
+ A policy hold's approval also carries the held call: its `op`, its parsed `input`, `opSeq`, the ledger `seq` of the call's `op.called` record, so a UI can show the hold on the call it held, and `reasons`, the ids of the policies that held it.
210
+
211
+ The policy decides a run's start too, as the action `workflow:<name>` with the input as its context, before `client.start` queues it (the built-ins, `call`, `apply`, `drift` and the app's actions among them, are not asked; their calls are, and a visitor starts none but `call`). A deny throws `policy_denied` and starts nothing; a hold starts the run, which waits on the approval (`op: "workflow:<name>"`, no `opSeq`) before its body runs, and fails if it is rejected.
212
+
213
+ `client.decide(runId, { decision, by, note? }, approvalId?, { timeoutSeconds? })` refuses without sending when the approval is decided already (`already_decided`), when the run has finished, failed or been cancelled (`run_ended`: no run would read the decision), when there is nothing pending (`no_pending_approval`, `run_not_found`) or when `by` may not decide (`not_approver`, naming the approver or group). Otherwise it sends the decision and waits for the run to read it, then returns the approval as decided: the run publishes it on the event `decisionEventOf(approvalId)`. If another decision reached the run first (someone else's, or another of yours), it throws `already_decided` with who decided and how: each message carries an `id` (a new one unless `message.id` is given), and the approval records the one it was decided with as `decidedWith`. The id is also the send's idempotency key, scoped to the approval, so a retried send queues one message. If the run does not read the decision within `timeoutSeconds` (30 by default), for instance because no worker is running, it returns the approval still `pending`; the decision stays queued and the run reads it when it next runs. The run checks the sender again and records anything it refuses as `approval.refused`; when it refuses this decision, `decide` throws `not_approver` rather than returning the approval pending.
214
+
215
+ An approval that no longer stands, as when its change gets a new commit, is withdrawn: its `status` becomes `withdrawn`, with `withdrawnReason`, `withdrawnAt` and `withdrawnBy` (who, unless its run withdrew it), and the ledger gets `approval.withdrawn` with the same `reason` and `by`. `client.withdraw(runId, approvalId, reason, { by, timeoutSeconds? })` withdraws a pending one, as the run's starter or someone who may decide it (`not_approver` otherwise; a visitor never), and refuses as `decide` does (`already_decided` once it is not pending); the run reads the withdrawal as it would a decision (an `ApprovalWithdrawal` message, `{ withdraw: reason, by, id? }`, on the approval's topic), checks `by` again (refusing as `approval.refused` otherwise), sets `decidedWith`, and the call or `ctx.approval` waiting on it throws `WithdrawnError` (`approval_withdrawn`, with `approvalId` and `reason`); a held call records it as its failed `op.called`, as a rejection. A decision sent after it is `already_decided`. A built-in withdraws its own approved approvals of an operation from its body, so they lift no later hold on it.
216
+
217
+ ### Changes
218
+
219
+ A change is how an edit to the company's repository goes live once the repository has a remote (`origin`): an agent's draft, reviewed and published in the app. Without a remote there is no change, and the draft's card says to merge its branch by hand.
220
+
221
+ - **The draft.** A chat's edits are commits on the branch `draft/<id>` (the chat's id), in a checkout of its own under `.sanoma/drafts/<id>` (the `sanoma` package's `localGitSource`), never the live one. The chat's card lists the files and the result of `sanoma check` on the draft, and offers **Send for review** once something is committed and the checks pass.
222
+ - **Send for review** starts the built-in `change` workflow on the draft, as the chat's person and titled as the chat (`SanomaClient.openChange({ id, title, page }, { startedBy })`; the run is `change:<id>`, and `change:<id>~2` for the draft's next change once that one has ended). Each round pushes the branch and opens its pull request into `main` (`sanoma.change.open`), runs `sanoma check` on the draft, with its Permissions grid, works out the facts the policy decides the merge on ([Policies](#policies)), asks the policy about the merge ahead, and sets the `sanoma` commit status on the head, linking the change's page (`sanoma.change.review`): pending, or failure while the checks fail or the policy denies. Then it asks one approval, **Publish the change**, covering `sanoma.change.merge`, of whom the policy's hold names, else of the person who drafted it. A deny waits instead, until something happens to the change.
223
+ - **The review.** The app's Changes section, in the bar when the repository has a remote, lists the changes. A change's page shows where it is, its branch at the head it last planned, its pull request, the files it edits by kind, the Permissions grid of `main` against the branch's, and Publish. The Inbox shows Publish as any approval, with the change linked.
224
+ - **New commits** on the draft start a new round at the new head. The agent tells the change after it commits, which withdraws Publish; a push to the branch on the host, told by its webhook, is read when Publish is decided, which then plans again instead of merging. An approval given in an earlier round lifts no hold on the new head.
225
+ - **Publish**, approved, squash-merges the pull request at the head the round planned, titled `<title> (#<number>)`, sets the status to success and deletes the branch (`sanoma.change.merge`); a head that moved meanwhile is planned again, and a merge the host refuses waits. Then the deploy: the checkout follows `main` (a fast-forward, skipped while another branch is checked out, the checkout has uncommitted changes or its `main` has commits the remote's lacks), apply runs on the declared hosts as the run `<run>:deploy`, drift reads them back as `<run>:verify`, and the draft is closed. The page says Published, with the merge commit and what the deploy did. The change run outlives the deploy's restart of the worker on the merged code ([Versions](#versions)).
226
+ - **Reject** on Publish closes the pull request and the change. A pull request merged on the host deploys as Publish does, and one closed there closes the change: the run checks either on the host before it believes it.
227
+ - **Who publishes.** A change to the rules (a policy, the root's or an app's, a people file, or a helper one imports) waits for `admin` whatever the policies say ([Policies](#policies)). A new company's `policies/changes.cedar` holds every other change for `admin` too; replace it with rules on the change's facts when another group should own part of the repository.
228
+ - **The Permissions line.** Under the Permissions grid the app says what the repository's host enforces on `main` (`SourceHost.enforcement`): a pull request, and the `sanoma` check. Where it enforces neither (a private repository on GitHub Free), a push to `main` that does not go through Sanoma is neither reviewed nor decided by the policy.
229
+
230
+ ### The app's actions
231
+
232
+ What the app does to the company's repository is a run of a built-in workflow, never a write in the app's own process, so it works wherever the app is served (a Node process, a Cloudflare Worker) as long as a worker runs: `adopt` (a drifted field's value at the vendor written into its data file), `patch` (a form's Save), `go-live` and `go-live-host` (`infra.ts` written, then `main` pushed) and `connect-existing` (their names are `sanoma/workflows/shared`'s `ADOPT_WORKFLOW` and the rest). `resolveConfig` adds them to every config, so a company workflow may not take their names, and `describeConfig` lists them with `builtin: true`. Each takes a zod input (`AdoptInput`, `PatchInput`, `GoLiveInput`, `GoLiveHostInput`, `ConnectExistingInput`), refused at the start, and its run is a step: the app's page starts it and polls its `.result`.
233
+
234
+ What each does is the app's, given to the worker as `AppSteps` (`startWorker(config, { app, source })`; `sanoma serve` and `sanoma worker` give theirs, `sanoma/app/steps`). The run calls its step in a DBOS step of its own (`app:<name>`) with an `AppStepContext`: the worker's own `SanomaClient` (connected on first use, closed when the worker stops), its `source` and `serially`, the worker's one lock on it, which a step holds around reading, writing and committing the checkout, the config and its resolution, who started the run (`by`) and the run's id. A step refuses by throwing: a `SanomaError` whose code and data the page reads (`invalid_input` with its `issues` or a `field`, `not_approver`), else an error whose message the run fails with. A step that applies after its write answers what to apply (`{ apply }`), which the run starts as its child, `<run>:apply`, as its own actor, and answers that run's id without waiting for it: an apply may wait for its plan's approval in the Inbox. On a worker without app steps each run fails, saying so. The pages call them through `api`, typed as `AppApi`.
235
+
236
+ ### Calls run one at a time
237
+
238
+ A run's ctx calls run one at a time, in program order. Even inside `Promise.all`, each call waits for the one before it to settle, so two calls a policy holds for approval are asked for one after the other. DBOS matches a replayed call to its recorded result by the order calls reach it, so calls left to race would replay out of step. A call that fails rejects its caller. The calls queued after it still run only if the workflow catches the failure and goes on; otherwise the body has ended, and each queued call is refused with `run_ended` (the run has ended, so the call is never made) instead of reaching its vendor, an approver or a sleep. Write calls one after another, as the workflow means them, and a fan-out with `ctx.all`.
239
+
240
+ ### Built-ins
241
+
242
+ A workflow gets these on `ctx` by listing them in `uses`, next to its operations: `"approval"` (see [Approvals](#approvals)), `"sleep"` and `"all"`. `describeConfig` lists them as each workflow's `builtins`.
243
+
244
+ Every workflow has `ctx.runId`, `ctx.startedBy` and `ctx.now()`, without `uses`. `ctx.startedBy` is who started the run, `{ id, email?, github?, subject? }` (`StartedBy`): the principal's id (a person's, `visitor:<login>:<subject>`, `token:<id>`), for a visitor the email and the GitHub login their site's login verified (the login when they signed in with GitHub or linked it, with the company's GitHub App's client), and for an api token the subject its row acts for (`SanomaClient.tokens`, read at the start, never taken from the caller), so a workflow can tell whose a record is. `await ctx.now()` is the time in epoch milliseconds, recorded so a replay reads the same. A date is made from it: with `const now = await ctx.now()`, `new Date(now).toISOString()` is ISO 8601 text, which a collection's `date` field takes (`.slice(0, 10)` for the day alone), and `new Date(now + 86_400_000)` is a day later, from the same reading. The lint refuses only the uses of `Date` that read the clock, `Date.now()`, `new Date()` and `Date()` (and `Date` passed on, which it cannot follow); `new Date(value)`, `Date.parse`, `Date.UTC` and `instanceof Date` read none (see [Keeping workflows replay-safe](#keeping-workflows-replay-safe)). Read a date in UTC (`toISOString`, `getUTCHours`) and parse ISO 8601 text with an offset: the local-time methods (`getHours`, `toLocaleString`) and other text depend on the worker's time zone, which a replay on another worker may not share.
245
+
246
+ `ctx.sleep({ until })` takes an ISO 8601 date-time with an offset (`2026-10-07T09:00:00Z`) or epoch milliseconds, and a time already past does not wait; `ctx.sleep({ minutes: 5 })` takes a duration from `ms`, `seconds`, `minutes`, `hours` and `days`, none negative. A request it can't read fails the run with `invalid_input`, as does an operation input its schema refuses. Each sleep writes a `sleep.started` record before it waits, with `until`: the time asked for, or for a duration, the record's `at` plus the duration, as the runtime saw it.
247
+
248
+ `ctx.all([() => …, () => …])` declares a fan-out: work that could go in any order, such as one post per network. It calls the members one after another, in array order, each awaited before the next starts, and returns their outputs in that order, each typed as its member's. It adds no concurrency: calls through `ctx` run one at a time anyway, and `ctx.all` says what belongs together, so the ledger and a graph of the run can show it. Every record written while a member runs (its operation calls, its approvals, its sleeps) carries `group: { id, index, size, node }`: `id` is `all:<seq>`, the ledger `seq` the run's next record would take when `ctx.all` began (so the same on a replay), `index` the member's position, `size` the member count and `node` the `ctx.all` call's [outline](#outline) node. Records outside a group have no `group`. The first member that throws stops the group: its error is rethrown as it is, and the members after it never run. A `ctx.all` inside a member fails with `invalid_input` (`ctx.all cannot be nested`), as does one started while another is still running (`a ctx.all is already running: await it before the next`) and an argument that is not a list of functions; an empty list returns `[]` and writes nothing.
249
+
250
+ ```ts
251
+ const [post, broadcast] = await ctx.all([
252
+ () => ctx.bluesky.post.create({ text }),
253
+ () => ctx.resend.broadcast.send({ id: email.id }),
254
+ ]);
255
+ const comments = await ctx.all(threads.map((id) => () => ctx.forum.comments.list({ id })));
256
+ ```
257
+
258
+ The lint refuses `Promise.all` and `Promise.allSettled` in workflows, pointing at `ctx.all`, and `Promise.race` and `Promise.any`: calls through `ctx` run one at a time, so nothing races; pick one call, or sleep and then check.
259
+
260
+ #### The runtime's own operations
261
+
262
+ What a workflow cannot do itself, the runtime does as operations of the vendor `sanoma`, in every config with their driver: `import { sanoma } from "sanoma"`, list them in `uses` and call `ctx.sanoma.<group>.<op>`. They are decided by the policy (`Sanoma::Action::"sanoma.secret.generate"`), recorded in the ledger when called in a workflow, and never answer a secret's value. `sanoma.run.inspect` also permits [direct reads](#direct-calls) under the same policy; the other operations below require a workflow. Secret generation, token storage and enrollment destinations cannot use the reserved `SANOMA_…` prefix. `secret.delete` additionally accepts database URL exports named `SANOMA_DATABASE_URL_<EXPORT>`; other runtime bootstrap names remain protected. `secretStore.prepare` may reference a database URL stored under that prefix as its source.
263
+
264
+ | Operation | Input | Output | What it does |
265
+ | ---------------------------- | ------------------------------------------------------------------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
266
+ | `sanoma.run.inspect` | `{ runId }` | `{ runId, status, workflow? }` | Reads run-status metadata in the configured application and database, without inputs, outputs or errors. Effect `read` |
267
+ | `sanoma.secret.generate` | `{ name, kind: "random" \| "ssh-rsa" }` | `{ name, publicKey? }` | Stores a value under `name` (upper case) unless one is stored: `random`, 32 random bytes as a `generate` marker makes; `ssh-rsa`, an RSA key pair as going live's deploy key, its private half (PEM) stored and its public half (`ssh-rsa <base64>`) answered, from what is stored, so a name stored already answers its own. Effect `write` |
268
+ | `sanoma.secret.delete` | `{ name }` | `{}` | Deletes the selected stored value, including a database URL export; none stored is nothing to do. External bindings and read-only stores refuse deletion. Effect `write` |
269
+ | `sanoma.secretStore.prepare` | `{ company, environment, database: { $secret: "NAME" }, store: "RUNTIME_URL" }` | `{ company, environment, role, store }` | Initializes an existing company database's private KMS schema and restricted runtime login; saves its URL under `store`. Retried with the same stored credential; conflicting ownership is refused. Effect `access`. See [database preparation](KMS-SECRETS.md#preparing-the-company-database) |
270
+ | `sanoma.invite.mint` | `{ host, email, key: secret("NAME") }` | `{ url }` | Seals an invite request for `email` (good for five minutes) under the signing key stored as `NAME`, an instance's `SANOMA_SIGNING_KEY` (`sealInvite` with that key), posts it to `<host>/auth/invite` and answers the one-use link it mints; the ledger records `url` as `"<url>"`. Retried on a status worth retrying. Effect `access` |
271
+ | `sanoma.token.mint` | `{ id?, reference?, subject, groups, store: "NAME" }` | `{ id }` | Saves an API token under `store` before registering its hash and authority. An identical active registration can retry; conflicting or revoked registrations are refused. Answers its id alone; a host takes the value as `secret("NAME")`. Idempotent. Effect `access` |
272
+ | `sanoma.token.revoke` | `{ id }` | `{}` | Revokes the token: it resolves to nobody from now on. Effect `access` |
273
+
274
+ `sanoma.token.mint` accepts either a recorded UUID-shaped `id` or a stable non-secret `reference`, never both. Prefer `reference` when the workflow has no token ID yet: record a value unique to that provisioning incarnation (for example, `cloud-signup:<original-run-id>`) in the company record before minting. The runtime derives the same ID from that reference across runs. Reuse it with the same secret name, subject and group membership. Explicit IDs also accept the UUID-shaped hash values returned by minting, without requiring RFC version/variant bits. Without either input, the runtime derives an ID from the call's idempotency key, which is stable for retries of that call but changes in a new run. The bearer is saved in the selected secret store before its hash is registered, so a lost store or database response can reuse the saved value. Only the ID, reference and other non-secret metadata enter workflow inputs, results and the ledger. Do not put credentials in a reference.
275
+
276
+ An existing registration must have the same ID, bearer, subject and group membership and remain active. A conflict never changes its authority, revives a revoked registration or revokes another token. Keep the saved bearer while its registration outcome is uncertain; deleting the secret does not revoke its token. The provisioning workflow still owns its lifecycle claim and recovery checks: a stable token ID is not a lock and does not reconcile another vendor's uncertain creation outcome.
277
+
278
+ For a database URL export, `<EXPORT>` must contain one or more uppercase letters, digits or underscores: for example, `ctx.sanoma.secret.delete({ name: "SANOMA_DATABASE_URL_CLOUD_ACME" })`. This removes only that value from the configured store. It does not delete the database, revoke its login or retire a KMS key. The lifecycle workflow must retire the resource and access first, then remove its stored URL; deleting `SANOMA_DATABASE_URL` or another runtime bootstrap secret remains refused.
279
+
280
+ `sanoma.run.inspect` reports `active` (queued, running or waiting), `finished`, `failed`, `cancelled`, `interrupted` (recovery attempts exhausted) or `missing`; an unknown DBOS status remains `active`. A run outside the configured application is `missing`. Inspection failures throw a sanitized error rather than reporting completion. The result is a snapshot, not a lock or fence: `missing` does not prove completion, and cancellation or exhausted recovery attempts do not prove an in-flight vendor action has stopped. Lifecycle recovery must separately establish resource ownership and reconcile uncertain effects before taking over.
281
+
282
+ A sandbox run calls them over its own secrets and tokens, in memory; `invite.mint` posts nothing and `secretStore.prepare` makes no database connections. `run.inspect` returns `missing` without querying live runs.
283
+
284
+ #### Step names
285
+
286
+ Every call is a step with a name, which a test and the graph name it by: `ctx.github.repository.import(input, { name: "Import the repository" })` and `ctx.sleep({ days: 1 }, { name: "Wait a day" })` give one, and an approval is named by its title. Without one, a call is named by its operation's id (`github.repository.import`), a sleep `Sleep` (`DEFAULT_SLEEP_NAME`, exported from the main entry and `sanoma/workflows/shared`). A name given, and an approval's title, is a string literal or a top-level `const` of the file holding one, so the outline reads it; it is one step's only (`two steps of this workflow are named "Draft"`), and a name given may not be what unnamed calls are called, an operation's id (three dotted words) or `Sleep`, so a name in a test means one call. Unnamed calls may share their default: one operation in two arms of an `if`, a retry in a `catch`, two sleeps. A call in a loop is one step, however often it runs. The outline resolves each call's name (`name` on `op`, `sleep` and `approval` nodes: the name given, the title, the operation's id or `Sleep`), except a call with a computed segment (`ctx[vendor].post.create`) and no name, which the operation it calls names in a run, and an approval whose title is no literal, which its title names in a run. The ledger has the name of every step (`name` on `op.called`, `sleep.started` and `approval.requested`, where a policy hold's is the held call's); records written before steps had names have none. `StepOptions` is the options' type.
287
+
288
+ ### Drivers
289
+
290
+ A driver implements a connector's operations with `defineDriver(connector, { resource: { name: (input, call) => … } })`, typed by the connector's schemas, and its package attaches it to the connector it exports (`withSetup`). `call` carries `idempotencyKey`, the same on every retry and replay of one call: pass it to the vendor (or dedupe on it) so a crash between the vendor's reply and the checkpoint does not repeat the side effect. It carries the authenticated `principal` and selected `connection` metadata, and `secrets` too, the store `secret()` markers name (see [Secrets](#secrets)), and `by`, who the call is made as (`run:<id>` inside a run). A driver reads its credentials when it is called, never from the config, and declares them (see [Credentials](#credentials)).
291
+
292
+ When the vendor says no, throw a `DriverError(message, { retryable, status?, vendorCode? })`. An operation declared `idempotent` is tried up to three times (after 1 and 2 seconds) unless the error says `retryable: false` or the reply fails the output schema; any other operation is tried once. When the tries run out, the run fails with the last try's error, not a wrapper: for a `DriverError`, `errorCode(err)` is `"driver_failed"` and the ledger records the vendor's message, status and code. Anything else a driver throws (a `TypeError`, a plain `Error`) fails the run as it is, with no code. An error that holds a value the driver read (through `call.secrets`, a `secret()` marker, or a variable its `env` declares, eight characters or more) anywhere in its message, stack, cause or properties is replaced before it is recorded or thrown: a `DriverError` with that message, each value as `[redacted]`, keeping only what a `DriverError` said of itself (`status`, `vendorCode`, and `retryable`, which is false otherwise). An error that ends the run (a cancellation) is left as it is. A named connection's driver error is already replaced by `<vendor> operation failed`. A result is recorded as the driver returns it: a driver that returns what it read is trusted to.
293
+
294
+ ### Credentials
295
+
296
+ The runtime separates a secret's storage, a connector's authentication method, and the named account used by a call. `secret("NAME")` remains a logical reference. `SanomaConfig.secrets` selects the store and maps names to locations; `connections` and `connectionRules` declare account requirements. Credential values stay outside code, workflow inputs, durable steps, descriptions and ledger records.
297
+
298
+ The store resolver is used by the worker's `call.secrets`, resource secret resolution, `SanomaClient` reads and mutations, and the app's login/model/remote secret lookup. It does not copy values into `process.env` or fall back to another store. Some shipped connector drivers still declare an `env` schema and read process variables themselves; migrating those drivers and their SDK/bridge sessions to connection-scoped authentication is a separate step. Registering a named connection does not by itself migrate such a driver.
299
+
300
+ `client.setCredential(name, value, { by })` validates a driver-declared name and writes through the configured binding. `client.setSecret(name, value, { by })` also accepts undeclared logical names. `client.clearCredential(name, { by })` conditionally deletes a declared value; `client.clearSecret(name, { by })` also accepts undeclared logical names. These operations refuse an externally managed binding or a read-only store. `client.credentials()` returns statuses, storage location, ownership and available change metadata without values; `client.secrets(names)` returns values to trusted server code only. The provider is validated when the client or worker starts; missing connector credentials can still be entered later.
301
+
302
+ #### Secret store configuration
303
+
304
+ ```ts
305
+ // sanoma.config.ts
306
+ import { defineConfig, type SecretConfiguration } from "sanoma";
307
+
308
+ const secrets = {
309
+ namespace: "local",
310
+ bindings: {
311
+ SUPPORT_AUTH: { path: "mail/support", management: "sanoma" },
312
+ FINANCE_AUTH: { path: "mail/finance", management: "external" },
313
+ BUILD_TOKEN: { env: "CI_BUILD_TOKEN" },
314
+ SANOMA_SIGNING_KEY: { bootstrap: "SANOMA_SIGNING_KEY" },
315
+ SANOMA_SECRETS_KEY: { bootstrap: "SANOMA_SECRETS_KEY" },
316
+ },
317
+ } satisfies SecretConfiguration;
318
+
319
+ export default defineConfig({ connectors: [], secrets });
320
+ ```
321
+
322
+ Without `store`, the runtime uses its encrypted Postgres adapter. Without `namespace`, it uses `default`. An unbound name resolves to the same path in that namespace, managed by Sanoma. A `{ path, management: "external" }` binding is read-only to Sanoma even when its store can write. An `{ env }` binding reads that exact variable, is read-only, and does not fall back when absent. A `{ bootstrap }` binding explicitly exposes one deployment key to trusted host-secret resolution; it reads the corresponding environment or mounted-file input and never stores the key in Postgres. Bootstrap keys and recovery are described [below](#bootstrap-keys).
323
+
324
+ To deliver an additional environment binding to the [declared hosts](#hosts), opt in with `RELAY_TOKEN: { env: "ACME_RELAY_TOKEN", host: true }`. Apply gives each deriving host the logical `secret("RELAY_TOKEN")` marker under `ACME_RELAY_TOKEN`; only the trusted host driver resolves its value. `host` is allowed only on environment bindings. Omitted or `false` adds no delivery beyond the host's existing derived bindings. Two opted-in bindings cannot target the same environment variable, and a binding cannot replace a derived host binding with a different logical secret. An opted-in binding with no value where apply runs is a problem of the plan, before any vendor call: the host is left out, and the problem names the binding and the variable it reads (`RELAY_TOKEN (\`host: true\`) has no value where apply runs, …: set ACME_RELAY_TOKEN, …`).
325
+
326
+ This applies to declared deriving hosts that accept derived bootstrap, not hosts that bind their own bootstrap or company hosts created by workflows. A connector credential needs no host delivery: it is a [named connection](#named-connections)'s bundle in the store, entered on the connector page. Company workflows must deliver only that company's runtime authority. Delivery uses the host's existing rollout behavior: it does not watch local environment changes or restart a host automatically. For Cloudflare secret replacement, advance the non-secret `configurationRevision` and apply the host; see [the Worker](../../../connectors/cloudflare/README.md#the-worker).
327
+
328
+ An external adapter is a `SecretStore` instance supplied as `secrets.store`. A database-backed adapter may instead supply a `SecretStoreFactory`, which the runtime binds to its own company database without opening a second pool. For managed Cloud, `managedKmsStore` from `sanoma/secrets` composes broker authentication and the [KMS-backed Postgres store](KMS-SECRETS.md#runtime-boundary), with a lazy SDK client owned and closed by the runtime. Lower-level `kmsPostgresStore` accepts an explicit caller-owned KMS client; omit `database` to bind it to the runtime database. Factory adapters may expose `close()` for their own lazy clients; caller-supplied store instances remain caller-owned. It authenticates to one deployment's authorized storage before Sanoma can read values. Prefer a scoped workload identity where the adapter supports it; otherwise deliver its bootstrap credential through the host. Do not make that credential depend on reading the same store it unlocks. The [Supabase Vault adapter](../../../connectors/supabase/README.md#supabase-vault-as-the-secret-store) provides this boundary for BYOC. The [support matrix](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/SECRET-SUPPORT.md) lists the stores, what each credential method needs from one, connector coverage, deferred adapters and the trust limits.
329
+
330
+ Keep deployment composition in config code, outside workflows. For example, given an adapter instance already authenticated as `liveStore`:
331
+
332
+ ```ts
333
+ import type { SecretConfiguration, SecretStore } from "sanoma";
334
+
335
+ export function stores(liveStore: SecretStore) {
336
+ return {
337
+ local: { namespace: "local" },
338
+ preview: {
339
+ namespace: "preview",
340
+ bindings: { SUPPORT_AUTH: { env: "PREVIEW_MAIL_AUTH" } },
341
+ },
342
+ live: {
343
+ store: liveStore,
344
+ namespace: "live",
345
+ bindings: { SUPPORT_AUTH: { path: "mail/support", management: "external" } },
346
+ },
347
+ } satisfies Record<"local" | "preview" | "live", SecretConfiguration>;
348
+ }
349
+ ```
350
+
351
+ Pass exactly the selected configuration to `defineConfig`. A namespace is a routing boundary, not authorization: preview identities must be unable to read production values, and a built-in preview should have its own database and encryption key. Cloning the code grants no storage access. The config description exposes store ID, namespace and bindings, never the provider object or its credentials.
352
+
353
+ The adapter contract uses `read({ namespace, path })`, `write(address, value, { expectedVersion, by })`, `delete(address, { expectedVersion, by })` and `validate(namespace)`. A read returns an opaque version beside the value; `expectedVersion: null` creates only when absent, and a version replaces or deletes only that version. `ensure` uses create-if-absent and reads the winner of a concurrent creation. Providers advertise writable access, a byte limit, conditional-write guarantees (`atomic`, `coordinated` or `none`), deletion behavior and change detection. `coordinated` covers cooperating Sanoma writers only; it cannot promise safety against external writers. Unsupported conditional writes are refused, not emulated with an unsafe read followed by a write.
354
+
355
+ The built-in adapter stores one encrypted value or credential bundle per namespace/path, with a fresh version on each write. AES-256-GCM authenticates the complete namespace/path identity. It rejects plaintext rows and ciphertext moved to another address. `SecretStoreError` returns fixed codes without provider responses or secret values. Connector authentication declares its own versioned schema with `defineAuthentication`: `api-key`, `fields`, `oauth2` or `signed`, with storage requirements. Every method keeps a bundle in the store. A credential a named method needs is entered on its connector page (or obtained by consent, for `oauth2`), never an environment variable the config reads: the [GCP provisioning identity](../../../connectors/gcp/README.md#deployment-identity) stores its bootstrap bearer as an `api-key` bundle and declares the identity's other facts in code. Connector authors use `checkAuthenticationStore`, `encodeCredentials` and `decodeCredentials` inside trusted code. The runtime runs the same check for every declared connection and creation rule: a method that writes its credentials (an OAuth refresh) bound to an `{ env }`, `{ bootstrap }` or external binding, one that needs conditional writes in a store without them, or one larger than the store holds, is a setup problem on its connector page card (`storageProblem`) and in `sanoma check`, and its preview is refused. Nothing is copied to another store instead. OAuth consent and renewal are described [below](#connecting-by-oauth-consent).
356
+
357
+ Adapter authors can run `checkSecretStore(store, disposableNamespace)` from `sanoma/workflows`. It checks missing values, ownership, contention, stale versions, namespace separation, size limits and the advertised deletion behavior. It mutates test records; use a scoped test identity and clean up retained versions according to the provider. `memorySecretStore()` is the in-process reference implementation, not persistent deployment storage.
358
+
359
+ #### Moving between stores
360
+
361
+ A config may name other stores beside the selected one, `secrets.stores`: `{ <name>: { store?, namespace? } }`, each a store instance or factory (none is the built-in store) and its namespace, the same shape as the selected store's. Naming one changes nothing by itself; it is where a move may take the secrets, or where a finished move retires them from. The built-in `migrate-store` workflow (registered when `stores` names any) moves them, in this order, each step an operation of `sanoma.storeMigration` that the policy decides and the ledger records, with names, versions and sizes and never a value:
362
+
363
+ 1. `plan` (read, direct): the secrets Sanoma knows, from the connections' declarations and rule-created accounts, OAuth applications, the bindings and the data files' `secret()` references, plus any `names` the input adds (a host's derived secrets are not found by themselves); a data file that does not load is a problem. Each is `copy`, `kept` (an OAuth application whose destination already holds another: its grants are flagged `reauthorize: "client_changed"`), `external`, `bound` (an `{ env }` or `{ bootstrap }` binding, not in a store) or `missing`. A destination value Sanoma did not write is a problem, never overwritten.
364
+ 2. `prepare` (access): `checkSecretStore` on the destination in a disposable namespace (`sanoma-move-check` and `sanoma-move-check-other`; a Vault login needs grants for them), the capabilities against each secret, then the move's receipts (`sanoma_secret_moves`, `sanoma_secret_move_items`). One move at a time.
365
+ 3. `transfer` (write): pauses writes at the source (the fence: every runtime's writes and deletes there are refused `read_only` until the move cuts over or is cancelled), once any OAuth renewal of a grant kept there that has sent its refresh token has stored its grant (the run waits, two seconds at a time), then copies each value with expected versions on both sides. A renewal while the fence holds fails closed (`unavailable`) before it spends the refresh token, and the grant still valid keeps serving. A connect or reconnect fails the same way before it spends its code, and a disconnect or revoke is refused before anything changes. Resumed, it skips what its receipts show copied, replaces only its own earlier copy, and adopts an equal value. A value it did not write ends the move (cancelled, the fence lifted), as does a source value that changes once the code has switched.
366
+ 4. `verify` (read): reads each copy back and compares it with the source in memory. A value that changed at the source since its copy is copied again. The run then waits, checking again from five seconds to five minutes apart, until the deployed code selects the destination; the source stays paused for writes meanwhile, so make the switch soon after the copies verify.
367
+ 5. `cutover` (access): once the code selects the destination (the reviewed change: switch `secrets.store` and `namespace` to the destination's and name the old store under `stores`), and every copy still reads back equal, rebinds each connection to the new location (its fingerprint names the store) and starts the rollback window, `retainHours` (default 168). The old store stays fenced, so an old runtime still running cannot write there.
368
+ 6. `retire` (write): after the window, deletes the old copies Sanoma manages at the versions it copied. One changed since, an externally managed one, or a store that cannot delete is kept and named.
369
+
370
+ `cancel` (write, direct) stops a move before its cutover, while the code still selects the source, and lifts the fence; the copies already made stay at the destination, named. A rollback after the cutover is a move back. The run's id is the move's; a stop anywhere resumes where it was. The app's Secret storage panel starts, follows and cancels moves ([its README](../app/README.md#connection-management)); `client.storeMoves({ actor })` reads them. Vendor tokens are never revoked.
371
+
372
+ #### Named connections
373
+
374
+ A connector declares authentication methods in `withSetup(connector, { authentication: { methodName: definition } })`. Code then declares each account independently, sharing the connector and its driver factory. For a connector `mail` that declares an `apiKey` method:
375
+
376
+ ```ts
377
+ import { defineConfig, defineConnection, defineConnectionRule } from "sanoma";
378
+ import { secret } from "sanoma/resources";
379
+ import { mail } from "@acme/mail";
380
+
381
+ const support = defineConnection(mail, {
382
+ name: "support",
383
+ method: "apiKey",
384
+ credentials: secret("SUPPORT_AUTH"),
385
+ scopes: ["messages:read"],
386
+ account: "support@example.test",
387
+ });
388
+ const sales = defineConnection(mail, {
389
+ name: "sales",
390
+ method: "apiKey",
391
+ credentials: secret("SALES_AUTH"),
392
+ scopes: ["messages:read"],
393
+ });
394
+ const customer = defineConnectionRule(mail, {
395
+ name: "customer",
396
+ method: "apiKey",
397
+ createBy: [{ group: "visitors" }],
398
+ scopes: ["messages:read"],
399
+ });
400
+
401
+ export default defineConfig({
402
+ connectors: [mail],
403
+ connections: [support, sales],
404
+ connectionRules: [customer],
405
+ });
406
+ ```
407
+
408
+ `@acme/mail` is an illustrative connector, not a shipped package. `support` is also a typed `ConnectionRef<"mail">`, with ID `mail/support`. A workflow selects it in operation options, for example `ctx.mail.message.read({ id: "one" }, { connection: { vendor: "mail", $connection: "mail/support" } })`; a server-side direct call passes `connection: support` alongside its `actor`. A connector with authentication methods requires a selector unless exactly one declaration is marked `default: true`; one connected account alone is not an implicit default. Existing business-resource targets remain unchanged. Cedar sees optional `context.connection` metadata: ID, vendor, method, account, scopes and revision.
409
+
410
+ Connection creation rules accept principal IDs or `{ group: "visitors" }` for authenticated customer sign-ups. The runtime uses admitted groups and owns each dynamic connection by the initiating principal. Disconnect invalidates the account revision and blocks new selection; for an OAuth grant it also deletes the stored grant, and Revoke ends it at the provider ([renewal, Reconnect, Disconnect and Revoke](#renewal-reconnect-disconnect-and-revoke)). Visitors also need a Cedar permit for the relevant operation; a creation rule does not bypass policy.
411
+
412
+ `sanoma.connection.bind` is a policy-controlled access operation. Its input contains a declared reference, the granted account and scopes, and `expectedRevision` (`null` for an initial binding). It persists metadata and a new revision, never credential values. `sanoma.connection.create` takes a declared rule ID, account and scopes; the actor must be in `createBy`. It creates an owner-scoped dynamic ID without a repository commit. Trusted code can make a typed reference with `connectionRef(rule, id)`, but the runtime still verifies the stored owner and declaration on use. These low-level metadata operations are not a credential-entry interface or proof of vendor consent. Use the secure intake APIs below for user-entered values; each named invocation also verifies the current bundle.
413
+
414
+ A durable call pins its account revision before policy evaluation. A held direct call carries the same pin into its durable continuation. The runtime checks that the binding and definition still match before execution; rebinding or changing requirements requires a fresh call and authorization. Policy approvals cannot silently authorize a different account. The ledger records connection metadata, not its credential bundle. This changes the durable step layout; old runs are not replayed against the new layout.
415
+
416
+ Named drivers explicitly opt into methods with `defineDriver(connector, implementation, { authentication: ["apiKey"] })`. Each method supplies `verify(credentials)`, which checks the provider and returns `{ account, scopes, expiresAt? }`; expiry is Unix milliseconds. A missing verifier or unsupported driver is refused. After policy allows the operation, the runtime reads only the selected bundle, validates its schema, verifies that its account and grants still match the authorized metadata, and rechecks the binding after verification. Changed grants or expired credentials require reconnection. Verifier exceptions expose no SDK messages or causes.
417
+
418
+ The driver reads `authenticationCredentials("apiKey", definition, call)` inside its operation and creates a client for that invocation. `defineDriver` also accepts a factory `(call) => implementation`, invoked inside that boundary, for operations sharing one SDK client during a call. `call.authentication.credentialVersion` identifies the version read. The runtime keeps no credential or SDK cache: replacement affects the next invocation, while a call already executing retains its original bundle. Never put this material in an operation result. Named calls' `call.secrets` can resolve only auxiliary secret markers in their authorized input, and `ensure` additionally requires a marker with `generate: true`. An operation may declare generated destinations with `createsSecrets(input)`, such as a database connector storing a URL under the authorized resource export's name; these are exact logical names, not wildcard store access. Driver failures retain retryability and HTTP status, with a fixed message and no provider cause. Direct calls and durable calls use the same driver boundary.
419
+
420
+ Resource declarations use the same identity as an option, loaded with the rest of the data file:
421
+
422
+ ```ts
423
+ import { mail } from "@acme/mail/resources";
424
+
425
+ export const inbox = mail.inbox({ name: "support" }, { connection: { vendor: "mail", $connection: "mail/support" } });
426
+ ```
427
+
428
+ The resource type must belong to that connector. Apply and drift pin the selected revision when they read declarations, then carry it through imports, plans and effects. The resource lockfile records the connection alongside the vendor object ID. Changing the account of a bound resource requires an explicit unbind/rebind; a default change or a same-name account replacement cannot redirect a later apply. The app exposes these declarations through its [connection management](../app/README.md#connection-management) forms.
429
+
430
+ Sandbox runs use synthetic identities for declared static connections, with separate fake state, faults and remembered replies for each account and run. They never read production connection records, invoke authentication verifiers or read production credentials. A production revision or an undeclared dynamic account is refused. Scenario steps can select an account in their returned seed, such as `{ op: mail.message.create, input: { title }, connection: support }`; absent a selector, only an explicitly declared default is used. Fault seeds accept the same `connection` field. Standalone driver tests can use `connectionFakes(makeFake)` from `sanoma/workflows/fake`: its `driver` requires `call.connection`, `account(ref)` exposes just that account's fake for seeding and fault injection, and `calls` is the combined log with connection IDs. Rebinding a reference to a different vendor account starts fresh fake state.
431
+
432
+ #### Connecting and managing accounts
433
+
434
+ Use `SanomaClient.previewConnection(target, credentials, { actor, id })` and `connectConnection(review, credentials, { actor })` for secure account intake. These are trusted server APIs, not workflow operations: credential values must never be passed to `client.call`, workflow arguments or an approval. `target` is either `{ connection: ref }` for a declared account or `{ rule: "vendor/rule" }` for an authorized dynamic account. Keep the same request ID while completing one review; a new account or a changed review starts a new request.
435
+
436
+ Preview runs the metadata-only `sanoma.connection.prepare` access gate before reading a store or verifying submitted credentials. The connector verifies the account and granted scopes against the code's requirements. The returned `ConnectionReview` contains metadata only: the verified account and scopes, destination, existing account/destination when present, expected revisions and the authorization fingerprint. It never returns credentials. An externally managed or read-only binding accepts no pasted replacement; preview reads its existing bundle.
437
+
438
+ Save rechecks the review, policy and destination, verifies the credentials again, then calls `sanoma.connection.configure` to reserve a `pending` account revision. It writes a managed bundle directly through the selected store with the reviewed expected version, outside durable execution. An opaque stored-version receipt records a successful write so resuming the same approved setup does not blindly repeat it. `sanoma.connection.activate` is a separate access gate: it verifies the saved bundle before making that revision usable. These gates, Test and Disconnect use ordinary policy decisions and ledger records containing metadata only. When a gate asks for approval, return to the secure form and retry after the decision; an approval never stores the form's credential values for later replay.
439
+
440
+ `pending` and `uncertain` accounts cannot run operations. An ambiguous store write or a failure after writing can leave `uncertain`; it must be inspected and reverified rather than treated as a successful connection or blindly written again. A policy, account, scope, destination or binding revision change invalidates the relevant review and requires fresh verification. Changing a destination does not copy or delete the previous value: the review identifies both locations. To move every value to another store, use [Moving between stores](#moving-between-stores).
441
+
442
+ The read APIs are scoped to the admitted actor:
443
+
444
+ - `client.connections({ actor })` returns `ConnectionCard` metadata for company declarations and that actor's dynamic accounts, including requirements, account, scopes, ownership, current/bound storage location, change attribution and last-tested health. Listing cards does not read credentials or contact a vendor.
445
+ - `client.connectionRules({ actor })` returns creation choices permitted by the current code's `createBy` person IDs or `{ group }` entries. Creating under a rule still passes policy and ownership checks.
446
+ - `client.secretStoreStatus({ actor })` validates the selected store's bootstrap access and reports its ID, namespace, capabilities and a sanitized readiness problem. It neither enumerates nor reads credential values.
447
+
448
+ Call `sanoma.connection.test` with `{ connection }` to verify the current bundle under policy. Its health result is a timestamped observation, not a live guarantee or background monitor: it can report expired, revoked, wrong-account, changed-scope, invalid, unavailable or store-denied states. An external bundle whose opaque version differs from the prior test is marked externally renewed. A later vendor or store change is detected on the next Test or authorized invocation.
449
+
450
+ `sanoma.connection.disconnect` takes `{ connection, expectedRevision }` and makes the binding unusable under a new revision. For any method but `oauth2` it deletes no stored value and revokes nothing at the vendor; externally managed values remain with their owner. An OAuth grant has its own lifecycle: [renewal, Reconnect, Disconnect and Revoke](#renewal-reconnect-disconnect-and-revoke). Moving values to another store is [its own workflow](#moving-between-stores). The app's [connection forms](../app/README.md#connection-management) implement this secure intake and show these states; they do not add a second configuration source.
451
+
452
+ #### Connecting by OAuth consent
453
+
454
+ A method of kind `oauth2` connects an account by the provider's consent instead of a pasted value. The connector owns the flow; the runtime defines the grant's schema (`oauthGrant`: `accessToken`, `tokenType`, optional `refreshToken`, `expiresAt` in Unix milliseconds and `scopes`):
455
+
456
+ ```ts
457
+ export const oauth = defineAuthentication({
458
+ kind: "oauth2",
459
+ version: 1,
460
+ storage: { writable: true, conditionalWrites: true, maxBytes: 16_384 },
461
+ oauth: {
462
+ authorizeUrl: "https://example.test/oauth/authorize",
463
+ tokenUrl: "https://example.test/oauth/token",
464
+ scopes: ["messages:read"],
465
+ pkce: true,
466
+ clientAuthentication: "client_secret_basic",
467
+ },
468
+ verify: async (grant) => ({ account: await accountOf(grant.accessToken), scopes: grant.scopes ?? [] }),
469
+ });
470
+ ```
471
+
472
+ Endpoints are `https`, or `http` on a loopback host for tests. A declaration names two secrets: `credentials`, the grant, and `client`, the company's own OAuth application (`{ clientId, clientSecret }`, schema `oauthClient`). They are separate bundles, so several accounts can share one application and a grant never holds the client secret. `client` is refused on any other kind of method:
473
+
474
+ ```ts
475
+ const ops = defineConnection(mail, {
476
+ name: "ops",
477
+ method: "oauth",
478
+ credentials: secret("MAIL_OPS"),
479
+ client: secret("MAIL_OAUTH_APP"),
480
+ });
481
+ ```
482
+
483
+ The flow has three trusted steps and one workflow:
484
+
485
+ 1. `client.authorizeConnection(target, { actor, id, redirectUri, client? })` runs `sanoma.connection.authorize`, a policy gate that carries metadata only, with `replacesApplication` true when `client` is given, so a policy can hold or deny replacing the OAuth application every account of the connection or rule shares. It then stores the application when `client` is given, or reads the stored one. It makes a single-use state and a PKCE verifier and returns the consent URL, the attempt's opaque ID and its expiry. The state's hash and the sealed verifier are kept in the `sanoma_connection_attempts` row, bound to the actor, connection, setup request, client ID and redirect URI. They never enter workflow history. `redirectUri` must end in `/connect/<vendor>/callback` (`connectionCallbackPath`).
486
+ 2. The provider sends the person back. `client.receiveConnection(vendor, attempt, params, { actor })` checks the attempt's actor, state, expiry and vendor and seals the code into the row. It takes a callback once. Then it starts the built-in `connect` workflow (in a config only when a declared connection or rule connects by OAuth) with the attempt's ID alone (run ID `connect:<attempt>`); if that start fails, the attempt ends `unavailable`. A refused callback throws a `CallbackError` whose `reason` is `expired`, `mismatch`, `replayed`, `declined` or `rejected`.
487
+ 3. `connect` calls `sanoma.connection.exchange`, which only that workflow may call. It takes the code and verifier once, posts them to the token endpoint and verifies the grant. It checks the declared account and scopes, writes the grant with the store's expected version and returns metadata only. Then `sanoma.connection.activate` verifies the stored grant. Both are ordinary policy decisions and ledger records.
488
+ 4. `client.connectionAttempt(attempt, { actor })` reports `waiting`, `exchanging`, `connected` or `failed`, with the problem when it failed and `approval_pending` while a gate waits for approval.
489
+
490
+ A code is never sent twice. If the provider issued a grant and the store did not keep it, the account is `uncertain` and the attempt fails with `uncertain`: connect again for a new grant. An attempt expires ten minutes after it starts, and again ten minutes after its callback: an exchange held for an approval must be approved within that time, as the provider's code expires too. Expired rows are swept an hour later. An `oauth2` method needs a writable store with conditional writes. Any other store is refused before consent, so a person never authorizes a grant the store cannot keep. The protocol is [oauth4webapi](https://github.com/panva/oauth4webapi), which runs on Node and on Cloudflare Workers.
491
+
492
+ #### Renewal, Reconnect, Disconnect and Revoke
493
+
494
+ `refresh: "refresh_token"` on the flow declares that the provider renews grants with a refresh token (RFC 6749 section 6). `tokenRejected` names the HTTP statuses (400 to 499) by which the provider says it refused an access token, such as `[401]`. `refreshTokenLifetime` is how many seconds a refresh token stays usable unused (an hour to ten years), counted from its last renewal, for a provider that publishes it; a provider whose refresh tokens lapse a fixed time after consent, renewed or not, still needs Reconnect then. A method's `revoke(grant, client)` revokes a grant at the provider, for a provider with a revocation endpoint:
495
+
496
+ ```ts
497
+ oauth: { /* ... */ refresh: "refresh_token", tokenRejected: [401], refreshTokenLifetime: 30 * 86_400 },
498
+ revoke: async (grant, client) => { /* the provider's revocation request */ },
499
+ ```
500
+
501
+ A grant renews on use. Renewal is always `refreshGrant` (oauth4webapi's refresh request), written with the store's expected version, as the exchange writes it:
502
+
503
+ - **Near expiry.** A call that authenticates a grant expiring within five minutes renews it first. If the renewal is `unavailable` and the grant has not expired, the call goes on with it, and the next call asks again.
504
+ - **On a declared rejection.** A driver error whose `status` is in `tokenRejected`, or a verifier that answers `rejected`, renews the grant once and retries once. A second rejection fails the call. A status the connector did not declare is never retried.
505
+
506
+ Renewal on use is part of the call that needs it, which the policy already allowed: it is not a policy decision or a ledger record of its own. That is the design.
507
+
508
+ An idle instance is never woken to renew an access token: scale to zero keeps one registered wake. A wake is scheduled only to keep a **refresh token** alive, and only when the flow declares `refreshTokenLifetime`. Then each stored grant's next renewal is a row (`due_at`, when a tenth of the refresh token's lifetime is left). The worker counts the earliest as a deadline (`worker.deadlines`, [Hosts](#hosts)), so a worker that stops when quiet registers it with its wakeup; nothing in process keeps it running. When it comes, the runtime's `renewal` agent calls `sanoma.connection.refresh`, a policy decision and ledger record like any other. A policy that forbids it stops that account's scheduled renewals, and use renews it again. Without `refreshTokenLifetime` (Supabase publishes none), a grant nobody uses is renewed by the next call that uses it, or needs Reconnect if its refresh token lapsed meanwhile.
509
+
510
+ One process renews a connection at a time. A lease in `sanoma_connection_renewals` (one minute, a holder ID fencing every write under it) covers the read, the refresh request and the write; a process that finds the lease held waits for the grant the holder stores. Before the request goes out, the holder marks the lease sent. A refresh token is never sent twice, so these leave the account `uncertain`, under a new revision, and the card asks for **Reconnect**:
511
+
512
+ - The provider answered and the store did not keep the new grant, or another writer changed it in between.
513
+ - The request was sent and had no answer (the connection dropped, or a timeout), since the provider may have rotated the refresh token. A connection that failed before anything was sent (no address, refused, unreachable, a connect timeout, TLS refusing the server) is `unavailable` instead: the grant still in force keeps being used and the renewal is asked again later.
514
+ - A lease lapsed after its holder sent the request (a worker that stopped mid-renewal): the next process does not resend it.
515
+
516
+ A provider's `invalid_grant` is `revoked`; any other refusal is `rejected`, and `429` is `unavailable` (tried again later). Each renewal's outcome and time are kept for the card, never a token. `sanoma.connection.test` reports `expiresAt` and `refreshedAt` beside the health state; `sanoma.connection.refresh` takes `{ connection }` and returns `{ id, refreshed, expiresAt? }`.
517
+
518
+ **Reconnect** is a new consent: its exchange takes the same lease, replaces the grant whole with the expected version and starts the renewal history again. **Disconnect** deletes the grant Sanoma keeps (a store that cannot delete keeps it, unusable under the new revision) and forgets its renewal. The OAuth application stays, since other accounts may share it. **Revoke** (`sanoma.connection.revoke`, `{ connection, expectedRevision }`) is a policy decision of its own: it calls the method's `revoke` with the grant and the company's application, then disconnects as above. It is `unsupported` for a method without `revoke`, and changes nothing when the provider does not confirm (`unavailable`). An externally managed grant is never deleted. Calls already sent with a grant are not undone.
519
+
520
+ #### Bootstrap keys
521
+
522
+ `SANOMA_SIGNING_KEY` signs application sessions and authorization state. `SANOMA_SECRETS_KEY` encrypts rows only for the built-in Postgres store. They are independent 32-byte random values encoded as base64. Each accepts exactly one source: the variable itself or its `_FILE` counterpart, whose file holds that base64 value. Conflicting sources, unreadable files and malformed values fail without printing the key. The launcher creates missing local keys in ignored `.env`; newly created files have mode `0600`. With an external store, it creates only the signing key.
523
+
524
+ For a host deployment, deliver signing material, database authentication and the adapter's bootstrap through that host's secret delivery mechanism; include the encryption key only for the built-in store. A mount path is local to the process reading it: do not send a laptop's `_FILE` path to a remote container. Explicit bootstrap bindings let a host resource receive the key value through its secret channel while code keeps only the reference.
525
+
526
+ On a Cloudflare host, apply resolves each binding on the machine that applies it (a `_FILE` key is read there) and uploads the value as a Worker secret; the container receives the Worker's secrets as its environment when it starts, and keeps them until its next start. There, `{ env }` and `{ bootstrap }` bindings read those values, refuse writes and deletes, and read as missing when the host was not given them. Being in the environment is how a value is delivered, not how it is kept: it is plain to code in the Worker and the container. Cloudflare's account-wide Secrets Store is not a supported store. See [Cloudflare secrets](../../../connectors/cloudflare/README.md#secrets) for what a host is given, the token's permissions and the Supabase setups.
527
+
528
+ The managed Cloud [runtime identity broker](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/CLOUD-IDENTITY.md) supplies refreshable, deployment-bound Google access tokens; its enrollment, bootstrap and rollout requirements are separate from credential storage and provisioning identity.
529
+
530
+ In the trusted control plane, configure `identityProvisioning: { databaseUrl: secret("IDENTITY_WRITER_URL"), maxValidityMs }` to use `sanoma.identity.enroll`, `.retire` and `.revoke` under policy. The restricted enrollment-writer URL is entered under that name on the app's Hosting page (Connect) and read from the store when an enrollment operation first uses it, never at config load. Until it is stored, the page lists it as missing and enrollment fails with "the enrollment writer is not set". Each client and worker owns its lazy writer pool; company runtimes and the broker do not receive it. See [provisioning operations](CLOUD-IDENTITY.md#provisioning-operations) for setup, rotation and the caller-owned adapter option.
531
+
532
+ Back up ciphertext, its namespace/path and version metadata, and the matching encryption key separately. A database-only backup cannot recover encrypted values. Preserve the signing key across ordinary restarts; replacing it invalidates sessions and pending signed authorization state. Changing a vendor token updates a stored value and its version; it does not rotate the row-encryption key. Replacing the encryption key without re-encrypting every retained value makes those values unreadable. Automated encryption-key rotation is not included. A move to another store is the [`migrate-store` workflow](#moving-between-stores), and an OAuth grant that needs new consent is reconnected from its card.
533
+
534
+ ### Resources
535
+
536
+ A resource type is a kind of vendor object a company declares the state of, such as a GitHub repository. `defineResource` declares one, and derives its operations, so the runtime knows only operations:
537
+
538
+ ```ts
539
+ import { defineConnector, defineResource } from "sanoma/workflows";
540
+
541
+ export const repository = defineResource({
542
+ vendor: "github",
543
+ type: "repository",
544
+ title: "Repository",
545
+ identity: "name", // optional, with `find`: how `find` makes the identity, for people
546
+ schema, // a z.object: the fields a read returns, and a data file declares (less the vendor-owned ones)
547
+ fields: { immutable: [], vendorOwned: ["html_url", "node_id"], writeOnly: [], unordered: ["topics"] }, // and `references`, below
548
+ find: ({ name }) => name, // optional: the import id that finds a declared resource before it is bound
549
+ bindingId: (state) => String(state.node_id), // optional: the stable id a binding keeps; default `String(state.id)`
550
+ normalize, // optional: the part of a state a drift check compares; default `compareDeclared`
551
+ writable: true, // optional: apply may change its objects (the change operations, below)
552
+ stateless: true, // optional: its objects hold no data, so apply makes one gone again without asking
553
+ afterCreate: [{ op: "acme.repository.protect", input: ({ id, export: name }) => ({ id }), until: (out) => out.ok }], // optional
554
+ });
555
+ export const github = defineConnector("github", { repository });
556
+ ```
557
+
558
+ A resource type is a connector's group under its own `type`; `defineConnector` refuses one of another vendor, or under another key, or on a connector without `info.package` (data files import the types from `<package>/resources`), and keeps the list on the connector, beside its vendor info. Its operations are `<vendor>.<type>.import` (`{ id }`, an identity or a binding id) and `<vendor>.<type>.read` (`{ id, state?, handle? }`, a state from an earlier call), both answering `{ id, gone: true }` when the vendor has no such object and `{ id, gone: false, state, handle? }` when it has, both effect `read`, idempotent, with the id as the policy's `target`. "Missing" is part of the contract: the driver decides it, so a caller never parses a vendor's error for it. A driver implements them like any other. `handle` is the driver's own data about the object, opaque to everyone else, passed back unchanged (an OpenTofu driver keeps the provider's private data and state version in it); the operations declare it `opaque`, so the ledger records it as `"<handle>"`, never its bytes. Any operation may name such fields (`opaque` in its spec).
559
+
560
+ A `writable` type has four change operations besides. The built-in apply workflow (`APPLY_WORKFLOW`, `"apply"`, a name a config's own workflow may not take) calls them for the declared resources, and only it changes a declared object; any workflow may name them in its `uses` and call them for an object no data file declares, as a control plane makes and deletes a host per customer. Such a call is an ordinary write, held to the policy and recorded in the ledger like any other, and a run of any workflow but apply is refused (`invalid_input`, before the policy is asked) the call aimed at a declared object: an `update` or `delete` whose `id` the lockfile binds, or a `create` whose identity (what the type's `find` makes of `desired`) a data file declares or the lockfile binds. A direct call of one is refused as for any write. `plan` (effect `read`, idempotent) takes `{ id?, state?, handle?, desired? }` (no `id` for a create, no `desired` for a delete) and returns `{ action, planned?, unknown, replace }`: `none`, `create`, `update`, `replace` or `delete`, the new state without write-only fields, the dotted paths known only after apply, and those whose change replaces the object. `create` (effect `write`, `target` `new:<vendor>.<type>`) takes `{ desired }` and returns `{ id, state, handle? }`, `id` its binding id; `update` takes `{ id, state?, handle?, desired, expect? }` and returns the same, refusing with a `DriverError` whose `vendorCode` is `plan_changed` when the fresh plan's `action` or `replace` differs from `expect`; `delete` (idempotent) takes `{ id, state?, handle? }` and returns `{ id, gone: true }`, an object already gone included. `desired` may hold secret markers at write-only fields, which the driver resolves (`resolveSecrets`) just before the vendor call (`plan` stores no generated secret: one not stored yet gets a throwaway value); no output holds a write-only value.
561
+
562
+ Calling the type declares one resource, which is what a data file does: `repository({ owner: "acme", name: "sanoma" })` returns a frozen `Declared`, `{ vendor: "github", type: "repository", name: "acme/sanoma", desired: { owner: "acme", name: "sanoma" }, refs: {} }`, branded with its `<vendor>.<type>` under the `DECLARED` symbol. It refuses a field the schema does not have, a field the vendor owns (unless `identity` names it), a value the schema rejects, or an empty identity. A type without `find` (Stripe's, whose objects Stripe names) declares resources without a `name`: they are found only by their bindings ([below](#bindings)).
563
+
564
+ A field may name another declared resource where the type's `fields.references` says so, by dotted path, with the type it names and, in `by`, the fields of that resource the vendor may hold there instead: GitHub's `branch_protection` has `{ repository_id: { type: "github.repository", by: ["name", "node_id"] } }`, since GitHub holds a rule's repository by its node id. So `branch_protection({ repository_id: site, pattern: "main" })` takes the repository `site`. It stands for that resource's `name`: `desired` holds `repository_id: "acme/website"` (a GitHub repository's identity is `<owner>/<name>`), which the schema and `find` (the rule is `acme/website:main`) read, and a drift check takes any of the repository's `by` values, read in the same run, as that name; and `refs` says where a resource was named, `{ repository_id: "github.repository:acme/website" }` (a list item's path has its index, `teams.0`). Anywhere else, or of another type, a resource is refused, and the constructor's type (`Declaring`) says the same, so the editor marks it first. A resource whose type has no identity (a Neon project, which Neon names) stands for nothing a vendor could read, so only a field the runtime consumes by the reference itself may name it: a host's database, as `cloudflare.host({ database: store })` does, or a `from` reference. Then `desired` holds nothing there and `refs` has the type alone, `{ database: "neon.project" }`, the loaded resource's `refs` the declaration's id, `resources/sanoma/infra.ts#store`.
565
+
566
+ A reference with `from`, a dotted path in the named resource's state, takes that state instead: apply and drift give the field the resource's state at that path, as a whole (a list or an object), read in the same run or made by an earlier step of it. So a sending domain's DNS records go to the zone that holds them, the record set's type declaring `{ records: { type: "resend.domain", from: "dns_records" } }`:
567
+
568
+ ```ts
569
+ export const mail = resend.domain({ name: "sanoma.work" });
570
+ export const mailDns = cloudflare.records({ zone: "sanoma.work", name: "resend", records: mail });
571
+ ```
572
+
573
+ The resource stands for the whole field, never an item of a list (`records: [mail]` is refused), and a literal value is still allowed there; a reference has `from` or `by`, not both, and is refused at a write-only field or one that holds a write-only field. Resolving a config refuses a `from` path that is no field of a type the reference may name (`checkFromRefs`), naming that type's fields. `desired` holds the resource's `name` in its place, which the schema does not judge, and the declaration is applied after it. Where the same apply changes the resource at that path (creates or replaces it, or updates it with the path in its plan's `unknown` or another value planned there; an update that touches other fields, such as a domain's re-verify, changes nothing here), or, for a create, the resource has no state yet or nothing at that path, the value is known only after apply: the plan is given `null` there, so a type that takes a `from` field must accept `null` in its `plan` and report the path in `unknown`, and its `update` must keep what the vendor holds for a field left out of `desired`, and a change the new value makes (a replaced domain's new DKIM key) is planned, and approved, with the rest; an update or replace step carries those paths in its own `unknown`. A plan of a bound object whose resource is absent, gone or unreadable and not about to change is given its fields without it, as drift compares them, and its step runs without it. A step planned with the field `null` is planned again at its step, with the value now known: `none` (the value turned out unchanged) leaves it done without a write, and otherwise its update expects the fresh plan's action and replace, since the approval covered the change in kind. An empty list or object at the path counts as known: a vendor that answers `[]` while still filling the list makes the dependent write an empty one. At its step the field takes the resource's state as the earlier step left it; one planned `null` whose value is still not known, as when the resource's own step failed or waited, fails before its driver is called: `its records come from resources/mail.ts#mail, which has no state yet` (or `whose state has no dns_records yet`), and so does a step down the chain from it. A policy and an approval therefore see `null` for such a field: its value comes from another declared resource's state at the vendor, known after apply. Drift compares the field against the bound resource's state, read in the same run, and leaves it out while that resource is absent, gone, unreadable or has nothing at the path, which its own row reports. A bridge-backed type (`tfConnector`) cannot take a `from` field yet: an OpenTofu provider's plan reads `null` as unset, not as known after apply. `dnsRecord` (`DnsRecord`), from the main entry, is the shape a DNS record passes in between two connectors: `{ type: "TXT" | "MX" | "CNAME" | "CAA", name, content, priority?, ttl? }`, `name` the full name in lower case with no trailing dot, a TXT record's `content` unquoted (each refused otherwise, never rewritten), and `ttl` 1 for automatic. Later, not yet: the cases apply hard-codes, a wakeup's `host` (its host's `outputs(state).url`) and a host's `source` (a repository's clone URL, by its `by` fields), could be `from` references, once `from` can name a host's outputs as well as its state.
574
+
575
+ Only declared fields are compared for drift, as CloudFormation does: `compareDeclared(fields, state, desired)` keeps the fields `desired` declares, minus `vendorOwned` and `writeOnly` ones, picking objects field by field, list items against the declared item at the same index, and the items of an `unordered` list (a set) against what any declared item declares, sorted, so a set is compared as a multiset whatever order the vendor returns it in. A drift check compares `normalize(actual, desired)` with `normalize(desired, desired)`, leaf by leaf: `diffDeclared(resource, state, desired, accept?)` returns each declared field that differs, `{ path, desired, actual }`, where `accept` gives, by a reference's path, the values that stand for the resource it names. `withoutWriteOnly(fields, desired)` drops write-only values from a declaration, keeping a secret's marker, which names a stored value and holds none. So a field left out is never drift, which covers attributes an OpenTofu provider marks `computed` and `optional` (GitHub's `etag`, `topics`): they are the user's to set, so not `vendorOwned`, but the vendor fills them in when nobody does.
576
+
577
+ `describeConfig` lists the resource types as `resourceTypes`, each `{ id: "<vendor>.<type>", vendor, type, title, identity, fields, schema, ops, capabilities?, host? }`: `schema` is its state as JSON Schema, with `$id` `sanoma:resource-type/<id>`, which its operations' contracts `$ref` rather than repeat; `capabilities` the contracts it meets (`host`, `database`, `wakeup`, `source`), absent when it meets none; and `host`, for a host only, `{ lifetime }`, its `HostLifetime` (`long-lived` or `stops-when-quiet`), which Hosting shows on the Host's card. `sanoma/workflows/shared` exports the `Resource`, `ResourceSpec`, `ResourceFields`, `References`, `FieldReference`, `Declared`, `Declaring`, `DeclaredResource` and `ResourceProblem` types.
578
+
579
+ ### Collections
580
+
581
+ A collection holds the company's own records, the state no vendor holds. `collection()`, from `sanoma/data`, declares one with plain values: a name (a lowercase letter, then letters and digits), its key, and typed fields. A company declares its collections in one file, `resources/data.ts` (and each [app](#apps) in its own, whose collections are named with the app):
582
+
583
+ ```ts
584
+ // resources/data.ts
585
+ import { collection } from "sanoma/data";
586
+
587
+ export const outbound = collection({
588
+ name: "outbound",
589
+ key: "company", // a required text field
590
+ fields: {
591
+ company: "text",
592
+ stage: { enum: ["researched", "contacted", "won", "lost"] },
593
+ owner: "person",
594
+ lastTouched: { type: "date", optional: true },
595
+ },
596
+ });
597
+ ```
598
+
599
+ A field is `"text"`, `"number"`, `"boolean"`, `"date"` (ISO 8601: a date, or a date and time with its offset) or `"person"` (a person's id), `{ type, optional: true }`, or `{ enum: [...] }` (optional too). A record is typed by them (`RecordOf<typeof outbound.fields>`), and `save` refuses a field that is not declared. The config's `collections` lists them; `sanoma` adds every collection `resources/data.ts` exports when it loads the config, so a company's config lists none.
600
+
601
+ `resources/data.ts` is the data file the runtime imports as well as loads: the launcher imports it, and so does a workflow that names a collection's operations (`import { outbound } from "../resources/data.ts"`, the one file outside `workflows/` or `policies/` the workflow lint lets them import, found by its real path). So it holds collections only, `collection` imported from `sanoma/data`: a resource declared there, or a collection declared in another data file, is a [problem](#data-files). Their operations are of the vendor `data` (`DATA_VENDOR`, which no connector may take): `data.outbound.get` (`{ key }`: the record, or `null`), `.list` (`{ where?, order?, limit? }`: fields equal to a value or within `{ gt, gte, lt, lte }`, sorted by a field, or `-field` for descending, with missing values last, else by key; values compare as their field's type, text byte by byte (Postgres's `COLLATE "C"`, whatever the database's collation), and one of another type counts as missing; 1 to 1000 records, 100 by default), `.count` (`{ where? }`, as `list` takes it: `{ count }`), `.save` (`{ record, ifAbsent?, ifRecord? }`: added or replaced, optionally guarded by an absent key or matching record), `.saveMany` (`{ records?: [{ record, ifAbsent?, ifRecord? }], deletes?: [{ key, ifRecord? }] }`: saves and deletes together, all or none, see [batches](#batches)) and `.delete` (`{ key, ifRecord? }`: `{ key, deleted }`, refused like a save when `ifRecord` no longer matches). `get`, `list` and `count` are effect `read`, `save`, `saveMany` and `delete` `write`, all idempotent, and the policy's `target` is `data:outbound/<key>` (`data:outbound` for a list, a count or a batch). A workflow names them in `uses` and calls them on `ctx`, as any operation:
602
+
603
+ ```ts
604
+ uses: [outbound.get, outbound.save],
605
+ async run(ctx, { company }) {
606
+ const lead = await ctx.data.outbound.get({ key: company });
607
+ if (lead) await ctx.data.outbound.save({
608
+ record: { ...lead.record, stage: "contacted" },
609
+ ifRecord: lead.record,
610
+ });
611
+ },
612
+ ```
613
+
614
+ Use `save({ record, ifAbsent: true })` to claim a key atomically before creating external resources. An absent key is inserted. If the stored JSON record and `updatedBy` already match, the call returns the original `Saved` receipt, including its timestamp, so a retry after a lost response can recover. A different record or actor is refused with a non-retryable `DriverError` (`vendorCode: "record_exists"`, status `409`) whose `current` is the record there. Object-property order and omitted `undefined` fields do not change JSON equality; the sandbox fake follows the same rule.
615
+
616
+ Use `save({ record: next, ifRecord: previous.record })` to replace an existing record only while its full JSON still matches the record read earlier. A missing or changed record is refused with a non-retryable `DriverError` (`vendorCode: "record_changed"`, status `409`) whose `current` is the record as it stands (a `Saved`), or `null` when it is gone, so the caller can settle the conflict without another read; a policy that lets someone save a record thereby lets them see it, so allow the collection's `get` wherever `save` is allowed. An already-written `next` record from the same actor returns its original receipt, allowing recovery after a lost response. Do not combine `ifRecord` with `ifAbsent`. Omitting both keeps ordinary replacement behavior. A conflict does not automatically reload and overwrite the winner.
617
+
618
+ For a claim belonging to one provisioning run, declare a text field such as `claimRun` and include `claimRun: ctx.runId` in the initial record. Keep that value stable on retries and complete the claim before vendor effects. Subsequent transitions must check ownership and conditionally save the full prior record, retaining a run or generation identifier so a later transition cannot look like an earlier one. `ifRecord` compares contents; it is not a monotonic revision, expiring lease or lock held across vendor calls. Managed Cloud consumer integration and lifecycle verification remain separate work in [#532](https://github.com/Sanoma-AI/sanoma/issues/532).
619
+
620
+ #### Batches
621
+
622
+ `saveMany` takes up to 1000 entries (`BATCH_LIMIT`), records to save (each as `save` takes it, `ifAbsent` or `ifRecord` included) and keys to delete, each key once, and makes them in one transaction: all are kept, or none. It answers the records' receipts then the deletes' answers, in the order sent. The policy never sees a batch: it decides each entry as the collection's `save` or `delete`, with the record it replaces as `before`, and the ledger records each entry as its own `op.called` with its target and decision, so a record's history reads the same whether it was saved alone or in a batch (a `Then` step names `data.outbound.save`, never `saveMany`). One denied entry denies the batch (`policy_denied`, its `data.denied` the denied keys, `data.deniedFor` each one's reason, the reason naming each); one held entry holds it whole, the approval covering the batch and the entries it held (an approved batch denied when the policy is asked again is recorded as the deny); a retry of a `delete` under `ifRecord` (a run's second try, or the same direct call again after its records were cut short) that finds no record answers `deleted: true`, the first try having deleted it; a `Then` step cannot name the batch (`data.outbound.saveMany is recorded as its entries`), and the Permissions grid and the run form's will-ask line ask about its entries, the `save` and the `delete`, since no rule names it; one record an entry's `ifRecord` or `ifAbsent` refuses (changed, missing, or there) refuses it with a non-retryable `DriverError` (`vendorCode: "record_changed"`, status `409`) whose `conflicts` lists every such entry as `{ key, current }`, the record as it stands or `null`. The sandbox fake does the same in memory.
623
+
624
+ `get`, `list` and `save` answer `Saved` records, `{ key, record, updatedAt, updatedBy }`, where `updatedBy` is who the call was made as (`CallContext.by`: `run:<id>` inside a run, the person's id for a [direct call](#direct-calls)). The records are JSON rows of one table the runtime creates beside the ledger, `sanoma_data` (`collection`, `key`, `record`, `updated_at`, `updated_by`), in the config's database. A declaration changes with no migration: a record saved under an older one comes back as it is stored, with `issues` (`{ path, message }`) where the fields no longer accept it. A sandbox run keeps the records in memory, in a fake that starts empty: a scenario seeds a record as it seeds a resource, `Given data.outbound "Acme" has` with a table of fields (the key is the quoted name, and what the table leaves out is made up), and removes one with `Given data.outbound "Acme" is gone`. `describeConfig` lists them as `collections`, each `{ name, title?, key, fields, record, ops, declared? }`, `record` being the JSON Schema `save` accepts, with `$id` `sanoma:collection/<name>`, and `declared` where `resources/data.ts` declares it (`{ id, file, name, at }`, as `loadDataFiles` reads it), whose declaration the app's Hosting page opens. `sanoma/workflows/shared` exports `DATA_VENDOR` and the `Saved` and `ListQuery` types.
625
+
626
+ #### Importing a sheet
627
+
628
+ `import` (`IMPORT_WORKFLOW`) is a built-in workflow `resolveConfig` adds when the config has a collection: a sheet's rows into a collection, as a run of the person who starts it (the app's Import pages do). Its input (`ImportInput`, refused at the start when it names a collection the config lacks, a field the collection lacks, a field twice, or no column for the key) is `{ collection, mapping, rows, people? }`: the rows under the sheet's header, each a list of cells as text, and for each column the field it fills (`{ field, values? }`, `values` turning a cell's text into the field's, such as `"In talks"` into `"meeting"` or a person's name into their id) or `null` to skip it; `people`, the declared ids, makes a person field refuse anyone else (none given or empty, any id is taken). Each cell is trimmed, given its column's `values`, then read as its field's type (a number as JavaScript writes one; yes, no, y, n, true, false, 1 or 0; a date as ISO 8601, a day or a time with its offset; an enum's value as written); an empty cell fills nothing, so an update keeps the record's own value. The run reads the rows (`importRows`, from `sanoma/workflows/shared`, which the app's Review page reads them with too), sorts them by key, and takes them `IMPORT_BATCH` (200) at a time: it lists the batch's range of keys (`gte` the first, `lte` the last, a page of `LIST_LIMIT.max` at a time), decides each row against the record there (`importEntry`: a new key added with `ifAbsent`, a key there updated with `ifRecord`, the row's fields over the record's others, nothing when that changes nothing), and saves the batch with `saveMany`. A row the fields refuse, with no key or a key an earlier row has, one that leaves a new record's required field empty, or one over a record its fields refuse now is left as a problem. An entry the policy denies, or one whose record changed since it was read, refuses its batch; the run leaves it as a problem and saves the batch again without it. An entry the policy holds holds its batch, an approval in the Inbox like any run's; a rejection fails the run, the batches before it saved (the run's ledger lists them), and a record changed while the batch waited saves the batch again without it, which the policy decides again, so a hold asks again. A blank row is skipped, keeping its number. It answers `{ added, updated, unchanged, problems }`, each problem `{ row, key?, reason }`, `row` the sheet's (its header row 1).
629
+
630
+ ### Direct calls
631
+
632
+ An operation may also be called directly, outside a run, as the person on a page: `isDirect(op, types)` says which, the one rule the app and the SDK read (`describeConfig` gives it as each operation's `direct`). A collection's operations may, and a vendor's `read`, but not the runtime's own (`sanoma.source.resolve`) or a resource type's (`isResourceOp`: only drift and apply call those); anything with an effect at a vendor is a workflow's.
633
+
634
+ ```ts
635
+ const saved = await client.call("data.outbound.save", { record }, { actor: { id: "ada" }, id: requestId });
636
+ const customer = await client.call("stripe.customer.get", { id }, { actor: { id: "ada" } });
637
+ ```
638
+
639
+ `client.call(opId, input, { actor, id? })` refuses an unknown operation, one that may not be called directly and input its schema refuses (`invalid_input`). The policy decides the call as the person, in a run `direct:<actor>:<id>` of the workflow `call` with no approvals (`id` is a new UUID unless given). A deny throws `policy_denied` and writes nothing. An allowed call runs the driver once, without DBOS and without a retry, as `CallContext` `{ idempotencyKey, runId }` both that run id and `by` the person's id; a failure is `driver_failed`. A read returns its output and records nothing, so a page polling it does not fill the ledger. A write is one `op.called` record (seq 0) of that run, a [batch](#batches) one per entry (seq 0, 1, ...), and with the default ledger they are in one Postgres transaction with the records it saves: all are kept, or none. The same id with the same input returns the output recorded, without writing again; with another operation or input it is refused (`invalid_input`, `differs`). When the policy asks for an approval, the call becomes a run of the built-in `call` workflow (`CALL_WORKFLOW`), started as the person with run id `call:<actor>:<id>` and input `{ op, input }`: its one call is held like any run's, shows in `client.approvals`, and once approved is made as the person (a save's `updatedBy` is theirs). `client.call` throws `approval_pending` (`ApprovalPendingError`) with `data` `{ runId, workflow: "call", op }`, and so does the same call again (same id) while that run waits; once it has ended, the same call returns what the run returned (or throws its error), without asking the policy again. A write whose driver failed keeps its failure under its id: call again with another id to try again. The `call` workflow `uses` every operation that may be called directly and has a driver; `resolveConfig` adds it when there is one, and a config's own workflow may not be named `call`.
640
+
641
+ `client.latest(workflow)` is the newest finished run of a workflow, `{ runId, output, at }` (`at` when it finished), or `null`: one query, for a page that shows a workflow's last result.
642
+
643
+ ### Data files
644
+
645
+ A company declares the resources it wants in TypeScript data files under `resources/` beside its config, `resources/<area>/<file>.ts`, as its workflows are in `workflows/`. Sanoma loads each one, as Node imports a module, and reads what it exports:
646
+
647
+ ```ts
648
+ // resources/identity/github.ts
649
+ import { github } from "@sanoma-ai/connector-github/resources";
650
+
651
+ export const website = github.repository({ owner: "acme", name: "website", visibility: "public", has_wiki: false });
652
+
653
+ export const websiteMain = github.branch_protection({
654
+ repository_id: website, // a reference: stands for the repository's identity, "acme/website"
655
+ pattern: "main",
656
+ enforce_admins: true,
657
+ });
658
+
659
+ export default [website, websiteMain];
660
+ ```
661
+
662
+ Another data file names `website` by importing it: `import { website } from "./github.ts"`.
663
+
664
+ A data file is TypeScript like any other: it may compute a value, spread a shared object or import a helper of its own. Each exported value that a resource type's constructor made (`<vendor>.<type>({ … })`, the vendor's constructors imported from its connector's `<info.package>/resources` entry, the people's from `sanoma/resources`) is one declaration, `<file>#<export>`, in the file that made it (another file re-exporting it declares nothing), under its non-default name when the file also exports it as `default`; anything else the file exports, such as the list `export default [a, b]` that Sanoma writes, declares nothing. A field the type's `fields.references` allows a resource in is given the declared value itself, and names the declaration that exports that very object. A field the type's `fields.writeOnly` lists takes `secret("NAME")` or `secret("NAME", { generate: true })`, imported from `sanoma/resources` (see [Secrets](#secrets)). `resources/data.ts` is the exception: it holds the [collections](#collections) and nothing else.
665
+
666
+ The loader (`loadModules`) loads synchronously, since `describeConfig` and `readPeople` are: `require` of an ES module, Node's type stripping and `module.registerHooks`, so a data file may not use top-level `await`. It serves the modules a company file imports from the runtime itself, from its own objects: each connector's `<package>/resources` with the config's constructors, `sanoma/resources`, `sanoma/data` (`collection`), `sanoma/site` (`defineSite`) and, to an app's `app.ts`, `sanoma` (`defineApp`); so a data file never needs the package installed, and each value they make records where it was made. Each load is a generation: a file is loaded again, with what it imports, once it, a company file it imports or a directory they are in has changed (by size and modification time), so an edit is read without a restart; every other call answers from the generation, at the cost of a `stat` per file. `liveDescription(config)` (`sanoma/workflows/describe`) keeps a `describeConfig` and makes it again only once a file a load read (`stampsOf`), the lockfile, or a folder a new data file, app or site would appear in has changed: the app reads its description through it, so a saved field shows on the next page without a restart. A superseded generation's modules stay in Node's cache, a copy of the files per edit.
667
+
668
+ The data files are found from the config's root: `defineConfig` records the file it is called from as the config's `file`, and `resolveConfig` gives its directory as `root`. A config bundled into one file sets `root` itself. A config with neither has no data files, and says so, rather than guess the working directory.
669
+
670
+ `loadDataFiles(root, connectors)`, from `sanoma/workflows/describe`, loads every regular `.ts` file under `<root>/resources` and each app's `apps/<app>/resources` (but `*.test.ts`, `*.d.ts` and `node_modules`). It returns `{ resources, bindings, orphans, collections, problems }` (`collections`: where each `resources/data.ts` declares each collection, `{ id, file, name, at }`, never matched to a connector, a type or the lockfile): one `DeclaredResource` per declaration, by file and then in the order made, less any with a problem and any that names one, and the problems. Their shapes are the zod schemas `DeclaredResourceSchema` and `ResourceProblemSchema` in `sanoma/workflows/description`:
671
+
672
+ ```jsonc
673
+ // A DeclaredResource
674
+ {
675
+ "id": "resources/identity/github.ts#websiteMain", // <file>#<export>, the file relative to the root
676
+ "file": "resources/identity/github.ts",
677
+ "vendor": "github",
678
+ "type": "branch_protection",
679
+ "name": "acme/website:main", // what people call it: its identity, else its export's name
680
+ "identity": "acme/website:main", // the import id that finds it unbound, from `find`
681
+ "binding": "BPR_kwDOabc123", // the id of the object the lockfile binds it to
682
+ "at": { "file": "resources/identity/github.ts", "export": "websiteMain" },
683
+ "desired": { "repository_id": "acme/website", "pattern": "main", "enforce_admins": true }, // as its type checked them
684
+ "refs": { "repository_id": "resources/identity/github.ts#website" }, // where it names a resource, that resource's id
685
+ }
686
+ // A ResourceProblem, had `website` been written with `wiki: false`: at the line and column an error's stack gives, else at its export, else at its file
687
+ { "file": "resources/identity/github.ts", "line": 4, "column": 31, "message": "github.repository: no field wiki" }
688
+ ```
689
+
690
+ A problem is, at the line and column the error's stack gives: a file that throws as it loads, a value its type refuses (a resource where it takes none among them) or a type its vendor does not declare, and a syntax error. V8 places a call at its method's name, so the column above is at `repository`. A file stops at its first, so a broken file is one problem, and a file whose import threw is reported once, at the file that threw. At the file: an import Node cannot find (a constructors import of no connector in the config, a file that is not there), top-level `await`, and a resource made but never exported (written inline in a list, say). At `file#export`: one object exported under two names, a reference to a resource no data file exports, a type of no connector in the config, a resource declared in `resources/data.ts` or a collection in another data file, two resources of one type with one identity (and connection), and, from the lockfile ([below](#bindings)), a binding of another type than its declaration's or two declarations bound to one object; a lockfile that is not JSON or not bindings is the lockfile's. `describeConfig` lists them, as `resources` and `problems` (and the lockfile's `orphans`), so the app starts with the resources it could read and shows what is wrong in the rest; `sanoma check` prints them. No lint holds a data file to a form: what loads is read. `readResources(config)` is the strict reading, for a test or CI: it returns the resources, or throws one error listing every problem as `problemLine` prints it (`file:line:column`, `file#export` or `file`).
691
+
692
+ #### Bindings
693
+
694
+ Which vendor object a declaration means lives in a lockfile beside the data files, `resources/sanoma.lock.json` (`LOCKFILE`), not in the declaration, as `package-lock.json` is beside `package.json`: data files hold intent only, so an edit to a field cannot point a declaration at another object, copying a declaration copies no binding, and a rename is an update. Only apply writes it; it is committed.
695
+
696
+ ```jsonc
697
+ {
698
+ "resources/identity/github.ts#website": { "type": "github.repository", "id": "R_kgDOabc123" },
699
+ "resources/billing/stripe.ts#pro": { "type": "stripe.product", "id": "prod_Rx2" },
700
+ }
701
+ ```
702
+
703
+ `loadDataFiles` joins each declaration to its binding by its key, `<file>#<export>`, as `binding`, returns the lockfile's `bindings`, and lists as `orphans` (`{ key, type, id }`) the bindings no data file declares, but those of a file that failed to load, whose declarations are not known. A missing lockfile binds nothing. `sanoma/workflows/describe` exports `readLockfile(root)` (`{ bindings, problems }`), `serializeLockfile(bindings)` (keys sorted, two-space JSON, a trailing newline), `writeLockfile(root, bindings)` (whole or not at all: written beside it, then renamed), and `diffLockfiles(before, after)`, each change a `Rebind`: `{ key, type, kind: "bind" | "rebind" | "unbind", from?, to? }`.
704
+
705
+ #### Writing a data file
706
+
707
+ Sanoma writes company files too, from `sanoma/workflows/describe`, by parsing them (with oxc-parser), not loading them: a written file must keep every byte it does not change. `setFields(text, exportName, fields, options)` returns the file's text with fields of one declaration set, by dotted path as a drift report names them (`{ has_wiki: true, "metadata.owner": "ops" }`; a field the declaration lacks is added). The declaration is the object literal of `export const <exportName> = …`, or of `export default …` for `"default"`: the object itself, or the first argument of the call it is (`github.repository({ … })`, `collection({ … })`, `defineSite({ … })`, `defineApp({ … })`). Only that statement changes, formatted with [oxfmt](https://oxc.rs/docs/guide/usage/formatter), and every other byte of the file stays as it was. It writes literals only: a value the file computes (a name, a reference to another resource among them; a call but `secret(…)`; a spread; a template with `${}`), a path into an object or list that holds a spread, and a declaration that is no object literal throw `NotLiteral`, whose `reason` says what to edit in code instead (`the value of has_wiki is computed in the file`) and whose `field` names the field the file computes (none for a declaration that is no object literal). It refuses with a plain `Error` a file that does not parse, an export the file does not have, and a path through a value that is not an object or a list; a path whose segments name a field with a dot in its key (`metadata: { "app.owner": … }`) finds that field. `renderDataFile({ imports, exports }, options)` renders a whole new file, which, loaded, declares what it was given; a reference is a `Reference`, and a secret's marker is written as `secret("NAME")` (or with `{ generate: true }`), the file then importing `secret` from `"sanoma/resources"` (`setFields` adds that import after the file's own when it sets one). `formatOptions(root)` reads the options from `<root>/.oxfmtrc.json`, oxfmt's defaults without one. oxfmt is a dependency of this package, loaded only when a file is written. The app's Adopt and its forms' Save write through it ([the app's Hosting page](../app/README.md#screens)).
708
+
709
+ #### Where Sanoma parses instead
710
+
711
+ Everything a company file declares is read by loading it, but for these, which parse source with oxc and never run it: the workflow [outline](#outline) and the workflow lint ([Keeping workflows replay-safe](#keeping-workflows-replay-safe)), since a run is held to its code's shape, not to what it did once; a site's pages and what they call (`readSites`: `routes/**` and `components/**` are browser JSX, read as the site's outline), though its `site.ts` is loaded; `crossAppImports`, a lint over imports; a draft's files, never loaded, since a draft is someone's unreviewed code: a change's facts are told from their text (`mayDeclarePeople`, `isRules`), and updating an app reads `main`'s `app.ts`, never the draft's; `sanoma`'s template, inside the installed package under `node_modules` where Node strips no types, whose people's ids `sanoma` reads from its text when it starts a company; and the writer above.
712
+
713
+ ### Drift
714
+
715
+ `drift` is a built-in workflow: `resolveConfig` adds it to every config whose connectors declare resource types, so the worker runs it, `describeConfig` lists it (its entry has `builtin: true`, a label) and it starts like any other workflow, with the input `{}`. A config's own workflow may not take its name. It `uses` the `import` of each resource type that has a driver, so its version moves with the connectors and drivers, not with the data files, and it is held to the same lint as any workflow: every vendor call goes through `ctx`, so the policy sees each as effect `read` and the ledger records it.
716
+
717
+ ```ts
718
+ const runId = await client.drift({ startedBy: { id: "alice" } }); // start(drift, {}, …)
719
+ const report = await client.driftReport(runId); // waits for it, as `result` does
720
+ // { startedAt, finishedAt, problems: [], resources: [{ id, type, vendor, name, binding, status: "drifted", fields: [{ path: "has_wiki", desired: false, actual: true }] }, …] }
721
+ ```
722
+
723
+ The run reads the data files and the lockfile itself, in its first step (`drift:data-files`, recorded, so a replay checks the same list): its input is `{}`, and any other is refused, so no caller can hand it other resources. The step records each resource without its write-only values, and the files' problems, which the report carries (`problems`; a file with problems contributes no resources, as in `describeConfig`). The worker loads the reader only then. Then the run imports each resource by its binding, else by its identity, one vendor call each (none for a resource with neither), in the files' order (every run imports: no state is kept between runs yet), and compares the declared fields with `diffDeclared` (above), a reference against the state of the resource it names from the same run. Each resource's `status` is `clean`, `drifted` (with `fields`, each leaf that differs: `{ path, desired, actual }`, a list item's path with its index, a list whose length changed or an `unordered` one whole), `gone` (the import of its binding says so), `absent` (it is not bound; `found` is the binding id of the object its identity found, if any, which apply may bind it to) or `error` (with `error`: the vendor's error, a policy denial, or no driver for its type); one resource's failure does not stop the others, but a failure that ends the run (`isRunControlError`: DBOS cancelling or stopping it) does. `client.drift` throws `invalid_input` when the connectors declare no resource types; `client.driftReport(runId)` throws `invalid_input` for another workflow's run. `DriftReport`, `DriftResult`, `DriftField` and `DriftStatus` are the report's types, also in `sanoma/workflows/shared`; `client.runs({ workflow: "drift" })` lists drift runs.
724
+
725
+ A host's revision is drift too (see [Hosts](#hosts)): the run resolves its ref with the built-in `sanoma.source.resolve`, and a host whose state runs another commit is `drifted`, with a field at its `revision` path (`desired` the commit the ref names now).
726
+
727
+ ### Apply
728
+
729
+ `apply` is the built-in workflow that makes the vendors match the data files, beside `drift` and listed the same way (`builtin: true`). It `uses` the `import` of each resource type with a driver, the change operations of each writable one, and `approval`; it is the only workflow that may call a change operation on a declared resource. Its input is `{ only?, bind?, answers? }` (any other field refused): `only` the declared ids (`<file>#<export>`) or orphaned lockfile keys to plan, else all; `bind`, a declared id to the vendor's id of the object to bind it to; `answers`, by id or key, `recreate` or `forget` for a gone object, `forget` or `delete` for an orphaned binding.
730
+
731
+ ```ts
732
+ const runId = await client.apply(
733
+ { answers: { "resources/infra.ts#store": "recreate" } },
734
+ { startedBy: { id: "alice" } },
735
+ );
736
+ const report = await client.applyReport(runId); // { plan: { problems, rebinds, steps }, results, lockfile: { written, revision?, bindings } }
737
+ ```
738
+
739
+ The run reads the data files and the lockfile in its first step (`apply:data-files`; a secret's marker stays in `desired`, a plain write-only value does not), with the lockfile's `rebinds`: what changed in it since apply last wrote it (`diffLockfiles` against the bindings the latest live apply run's last `apply:lockfile` step wrote), changes someone else made. It imports each declared resource as drift does (by the binding `bind` gives, else the lockfile's, else its identity), then plans each one `only` wants, each after the resources it names, as a `PlanStep` (`{ id, vendor, type, action, … }`): `bind` (to the object `bind` gives, or the one its identity `found`, by its binding id), `create` (unbound and nothing found: `planned` and `unknown` from its type's `plan`), `update` or `replace` (its bound object as `plan` says, with drift's `fields`, the paths that force a replace, and any `unknown` until it is done), `none`, `gone` (its bound object is no longer there: skipped unless answered, since a recreated database looks fine and has lost its data; a type with `stateless: true`, holding no data, is planned as a `create` instead, unless answered), and `orphan` for each binding no declaration has (skipped unless answered: deleting a declaration never deletes its object). What cannot be planned (a read-only type that is absent or drifted, an answer that cannot be done, an id the input names that nothing declares) is one of the plan's `problems`, with no step.
740
+
741
+ When the policy would hold any change call the plan makes (asked ahead, in the step `apply:policy`, as each call would ask it), the run asks one approval of the first approver it names, titled "Apply resource changes", covering every change operation in the plan, with the plan as JSON in its `details`; a policy that lets a covered call through once approved (`approvedFor`) then holds none of them again. Then each step runs, in order: `create`, `update` (with `expect`, the plan's action and replace, so a vendor that now plans otherwise refuses with `plan_changed`), `delete`, or only the lockfile changed. A reference to a resource the vendor holds by another field (`by`) is given that resource's binding id, one made earlier in the run included, and a `from` reference that resource's state at its path, as found or as an earlier step left it (see [Resources](#resources)). Right after any step that changes a binding, that binding is changed on the lockfile as it is then (so another run's change made meanwhile stays), written whole and committed through the worker's `source` (`apply:lockfile`: `Apply: create resources/infra.ts#store (supabase.project abcd…)`, by the person who started the run), so an object made is never left unbound. Right after a create's binding is written, the run calls its type's `afterCreate` operations in order, by id, each given the new object's binding id and its export (a Supabase project waits for its health, then stores its database URL); one with `until` is called again every 5 seconds until its output passes, for up to 10 minutes, and one that never does fails the step, its object still bound. The approval covers the `write` ones among them too. Each step's result is `done`, `skipped` (unanswered) or `failed` (with `error`; the run goes on); a host's that it made or changed carries `host`, its `outputs`. A sandbox run writes nothing: the report's `lockfile.bindings` is its copy. `ApplyPlan`, `PlanStep`, `ApplyReport` and `ApplyResult` are the types, also in `sanoma/workflows/describe` and `/shared`.
742
+
743
+ This package knows nothing of OpenTofu. Resource types from an OpenTofu provider are generated by [`sanoma/internal/bridge/tfschema`](../bridge/src/tfschema/AGENTS.md), which turns the provider's schema document into zod schemas and flagged fields (`resources.gen.ts`); `sanoma/internal/bridge` depends on this package, never the other way round.
744
+
745
+ ### Hosts
746
+
747
+ A host is a resource type that runs the company (a container, a Render service, a Fly app): `defineResource({ …, writable: true, host })`, where `host` (`HostSpec`) says where the type takes the runtime's inputs, by dotted path into its fields (`inputs: { source, ref, secrets, port, domains?, hostname? }`, `secrets` a write-only field; `domains`, when the type takes it, a public site's domain by site name, which the host hands the app as `SANOMA_DOMAINS` and `describeConfig` reports a problem for, at the declaration, when it names a site that is not public or gives one domain two sites: `sanoma.example is the domain of both www and docs`; `hostname`, when the type takes it, the hostname the app itself is served at, never one of the sites' domains, nor another host's hostname or domain (`describeConfig` reports one that is), so a host with one reports its `url` as `https://<hostname>`, the vendor's URL otherwise, and its vendor's URL as `wakeUrl`, where its wakeup reaches it, so a wake never waits on a custom domain's DNS or certificate; `wakeUrlOf(outputs)` is its `wakeUrl`, else its `url`), which field apply fills with the commit (`revision`, which a data file may not declare: it names a branch, never a commit), what it can do (`capabilities: { lifetime, publicUrl, buildsFromGit, staticEgress }`, `lifetime` `long-lived` or `stops-when-quiet`, `HostLifetime`), and how its state reads (`outputs(state) → { url, wakeUrl?, revision?, healthy }`). `defineResource` refuses a `host` that names no field, or whose `secrets` is not write-only. A host whose vendor mints the instance's bootstrap (its database URL, keys and tokens) and binds it itself declares `bindsBootstrap: true` and takes no `secrets` (Sanoma Cloud's `cloud.host`); `defineResource` refuses one that gives both, or neither. A write-only field may be a map of secrets (`secrets: { SANOMA_DATABASE_URL: secret("DATABASE_URL") }`): its markers are kept as one at the field is. A host type is `stateless` (a `ResourceSpec` field, default true for a host): its objects keep no data, so replacing or recreating one is routine. `source` is a clone URL, or a reference to a declared repository with a `by` field holding one.
748
+
749
+ A host that derives (`derives: true`, `cloudflare.host` and `cloud.host`) is declared by its decisions alone, its `name`, `hostname` and `database` (`inputs.database`, a write-only reference to the declared database it runs on), and apply fills the rest before it plans, in the data-file step, as it fills the revision (`deriveHosts`, from `hostFacts`): `name` (when its type takes `inputs.name`, as `cloudflare.host` does) the name it is bound by (so a renamed repository never replaces it), else the repository's name, made lower-case letters, digits and dashes, its identity `UNNAMED` until then; `image` (when its type takes one) the installed `sanoma`'s runtime image, `runtimeImage(version)`, `ghcr.io/sanoma-ai/runtime:<version>` (`RUNTIME_IMAGE`); `source` the declared repository that is the app's `origin` (else the one its data file declares, `sourceRepository`), else `origin`'s URL with no credentials (`originUrl`, `cloneUrl`); `ref` the repository's default branch, resolved with the revision; `domains` each public site's `defineSite({ public: true, domain })`; and, unless it binds its own bootstrap, `secrets` as markers only: `SANOMA_DATABASE_URL` (`databaseUrlSecret` of the database's export), `SANOMA_SIGNING_KEY` (the config's when it binds one, `{ env }` or `{ bootstrap }`, else the host's own, `secret("SANOMA_HOST_SIGNING_KEY", { generate: true })`, `HOST_SIGNING_KEY`, generated into the store at its create), with the built-in store `SANOMA_SECRETS_KEY` (which cannot live in the store it unlocks: always bound), `SANOMA_SOURCE_KEY` for a GitHub repository where the config has the `github.repository_deploy_key` type (without it, the host clones over HTTPS, a public repository only), the wakeup's token (and URL for `sanoma.wakeup`) when a wakeup names the host, the variables the drivers of its data file's vendors and of the login's sender read (an optional one once stored), and the GitHub App's keys that are stored (`GITHUB_APP`, the one list of them, which the staff login and the app's Connect page use too). `image`, `source` and `ref` stay as overrides; `port` is the image's (`RUNTIME_PORT`), never declared; a data file that writes `secrets` or `domains` is refused. A live apply mints what it gives the host when none is stored: the source key pair (where the deploy-key type is), its private half as `SANOMA_SOURCE_KEY`, and the wakeup's token (`swi_…`). For a GitHub repository, apply then declares the deploy key itself, `<file>#host.sourceKey` (`sourceKeyId`), a read-only `github.repository_deploy_key` of the key's public half, before the host, with its type's identity (`<owner>/<repository>:<key>`), so a key GitHub holds already is bound, never made again (GitHub takes a key once). Problems, each leaving the host out of the plan with what names it (its wakeup, and what names that) until fixed, so apply changes nothing it cannot give all it needs: no `database`, no installed `sanoma` without an `image`, no `origin` without a `source`, no name to tell, a name another host of its type has, a credential a vendor's driver reads from this machine's environment that nothing binds (`ACME_TOKEN is read from the environment here, and has no binding, …`: bind it `{ env }` in `sanoma.config.ts`, or store it on the connector page), a binding the config gives the host (`host: true`, see [Secret store configuration](#secret-store-configuration)) with no value where apply runs, a private repository with no deploy-key type to clone it with (`hostFacts` asks GitHub, with no token, whether the repository a host may clone, `origin`'s or a declared `source`'s, is public), and two hosts that would attach the sites' domains. At plan time, a host whose state has domains attached while no site declares one is a problem too, with no step: a change would detach them (put `domain` on each site). Apply's `bind` of an object its identity found that an orphaned binding of the same type holds takes that binding over (`from` on the step, written in the same commit, `Apply: rebind … from …`): the orphan is none, as for an export renamed, or a deploy key a data file declared before (`#deployKey`) that apply now declares as `#host.sourceKey`. A type renamed keeps its objects: `formerly` (a `ResourceSpec` field, `["cloudflare.container"]` on `cloudflare.host`) lists the ids whose lockfile bindings bind its declarations.
750
+
751
+ A config whose connectors declare a host type has the built-in operation `sanoma.source.resolve` (`SOURCE_RESOLVE`, effect `read`): `{ url, ref? } → { revision, ref }`, by `git ls-remote` on this machine (a branch, then a tag, peeled; a full commit id is itself; with no `ref`, the default branch its `HEAD` names, `defaultBranch(url)`). Apply calls it for each host it plans, and gives the host the commit as its `revision` and the clone URL as its `source` (a referenced repository's, from its `by` field); a host whose ref does not resolve, or whose repository has no clone URL yet (apply the repository first), is a problem of the plan. The drift run calls it for every host it reads. A sandbox run calls its fake instead (`fakeSourceDriver`), with no git or network: a full commit id is itself, any other ref the SHA-1 of `<url>#<ref>`, the same on every run, and the default branch `main`. A host's `secrets` map may name sanoma's own secrets (`SANOMA_…`), and no other field of any type may. `resolveRevision(url, ref)` is the same, outside a run.
752
+
753
+ A wakeup is a resource type that starts a stopped instance at a time, for what is due while its host is stopped: `defineResource({ …, writable: true, wakeup })`, where `wakeup` (`WakeupSpec`) names the field that references the host (`inputs.host`), the type's own operation the runtime registers each deadline through (`register`, called with `{ at }`, which replaces whatever the wakeup held) and how its state reads (`outputs(state) → { healthy }`); `defineResource` and `resolveConfig` refuse one that does not meet it. Declaring one in a data file is the switch, with no mode flag: `declaredWakeup(config)` reads it, and several are a problem of the data files. A wake is `GET {url}/wake`, with no query: resume if stopped. A config with `wakeup: true` runs the wakeup service itself and must not stop, so `startWorker` refuses it beside a declared wakeup. With none declared, a worker given `onStopped` takes the wakeup its environment names (`envWakeup(process.env)`, an `EnvWakeup` of `{ url, token }` when both `SANOMA_HOST_URL` (`HOST_URL`, an http(s) URL as the wakeup service keeps one) and `SANOMA_WAKEUP_TOKEN` are set, as a host Sanoma Cloud made sets them) and registers each deadline itself: `PUT {url}/__sanoma/wake` (`WAKE_PATH`) with the token as a bearer and `{ at }`, answered 204, no driver. An instance with `wakeup: true` ignores it.
754
+
755
+ A config whose connectors declare a host type also has the runtime's own wakeup, `sanoma.wakeup({ host })` (`import { sanoma } from "sanoma/resources"` in a data file), no connector named: an instance of a [wakeup service](#the-wakeup-service) for a `cloudflare.host`, `cloudflare.container`, `docker.container` or `testhost.app`, the fallback for a host with no clock of its own (a host's own vendor's wakeup comes first). Its driver creates, reads and deletes the instance at `SANOMA_WAKEUP_URL` with the account's `SANOMA_WAKEUP_ACCOUNT_TOKEN`, registering the instance's own `SANOMA_WAKEUP_TOKEN`, and `sanoma.wakeup.register` sends `PUT {url}/wakeup/wake { at }` with that token; `fakeSanomaWakeup()` from `sanoma/workflows/fake` is the service in memory, which sends `GET {host}/wake` at `at`.
756
+
757
+ A worker whose data files declare a wakeup, started with `onStopped` (whoever starts the next one; without it the worker never stops), stops itself when nothing it would run can run soon. Every 15 s (`stopCheckMs`) it asks `worker.idle()`: no run is executing or replaying; none of its version is queued, on its queue or on DBOS's own, where recovery puts runs; every unfinished run of its version is blocked in a `ctx.sleep` or a `ctx.approval`; and the next deadline (the earliest sleep's end, or a source added with `worker.deadlines.addSource`, such as a schedule's next fire) is more than `idleHorizonMs` away (60 s), so short waits never stop it. An approval has no deadline: its decision comes from a request, which starts the worker. Runs of another version or queue are not this worker's and never keep it up. The worker registers the next deadline through the wakeup type's `register` (`{ at }` as the agent `wakeup`, idempotency key `wakeup:<binding or declaration id>:<uuid>`, fresh per registration so a repeated `at` re-arms, no ledger record), replacing what the wakeup held, records `at` and `stopped_at` on the `sanoma_wakeup` row, stops, and calls `onStopped({ at })`; with no deadline at all it registers nothing. A failed registration is recorded as `last_error` and logged, and the worker keeps running and tries again at the next check.
758
+
759
+ A stopped worker cannot launch again in its process, so whoever supervises it starts a fresh `startWorker(config)` on the next request, or when the wakeup calls `GET /wake`. A wake is resume if stopped: one that arrives for a registration replaced since starts at most a worker with nothing to do soon, which stops again. `superviseWorker(config, options)` is that supervisor, as `sanoma serve` runs it: one worker at a time, started with `onStopped` (its own `onStopped` hears each stop; `selfStop: false` gives none, so the worker never stops itself), and a fresh one on `resume()` (a write that needs one) or `wake()` once the last stopped itself, a no-op while one starts or runs; a write heard while one starts or runs may land after its last idle check, so a worker that stops after one starts again at once. `SanomaClient.connect(config, { onWrite })` calls `onWrite` right before each change a worker must run (a start, drift, apply and a held call among them, and a decision), never for a read: the app passes it, to resume its process's worker. Apply gives a declared wakeup its host's URL: its `inputs.host` field holds what the host's `outputs(state)` says (its `wakeUrl`, else its `url`), from the host's state found in the run or made by it, where any other reference resolved `by` holds the binding id. The row holds `at`, the deadline last registered (null until one is), `stopped_at` and `last_error`. Every start costs each unfinished run of its version one of DBOS's recovery attempts, so the runtime raises them from DBOS's 100 to 100,000; and a `ctx.sleep` for a duration takes its start from DBOS's clock, so a recovered run keeps the deadline it registered.
760
+
761
+ #### The wakeup service
762
+
763
+ `startWakeupService({ databaseUrl, now?, fetch?, log? })` from `sanoma/workflows/wakeup-service` (server-side only, refused in workflow files like `/scenario`) is the service a wakeup type registers with: `sanoma wakeup` runs it, and `sanoma serve` does with `wakeup: true` ([the sanoma package](../README.md#the-wakeup-service) says how an instance registers). It makes its two tables in `databaseUrl` (and the database, when missing) and returns `{ routes, mintAccount(label), revokeAccount(id), stop() }`: `routes` is one route answering everything under `/wakeup` (a body over 64 KiB is a 413), the shape of the app's `IngressRoute` with `prefix`, for `startApp`'s `ingress` or a server of your own; `mintAccount` returns `{ id, token }`, the token shown that once; `revokeAccount` refuses the account's token and its instances' and wakes them no more. One loop sleeps until the next registered `at` (at most 60 s, or until a `PUT` takes a registration), takes each due instance for 30 s (so two services on one database never call it twice), calls its `GET {url}/wake` with a 10 s timeout, eight at a time, and on anything but a 2xx (a redirect, which it never follows, among them) tries again after `min(2^attempts s, 5 min)`, never giving up. Each `PUT` replaces what the instance registered before, and a registration replaced during its call is called again. `stop` ends the loop, abandoning the calls in flight (called again once their 30 s lapse), and closes its pool. `mintWakeupAccount(databaseUrl, label)` mints an account without starting the service, for `sanoma wakeup account`. The service never mints an instance's token: `mintInstanceToken()` makes one (`swi_…`) for the company to keep, which it registers with `POST /wakeup/instances { url, token }`. `now` and `fetch` are for tests; `log` takes an `info` line per call and a `warn` per failure (the runtime's logger by default).
764
+
765
+ ### Databases
766
+
767
+ A database is a resource type that holds the company's database (a Neon project, a Supabase project): `defineResource({ …, writable: true, afterCreate, database })`, where `database` (`DatabaseSpec`) says what it can do (`capabilities: { pauses, branch }`: its compute scales to zero and wakes on a connection; it makes copy-on-write branches that carry the data), where it takes going live's choices, by dotted path into its fields (`inputs: { region, size? }`), the regions it takes when known (`regions`), the operation that stores its URL (`storeUrl`) and how its state reads (`outputs(state) → { healthy }`). `storeUrl` is an operation of the type's own vendor, in the type's own group (`neon.project.storeUrl`) or another (`supabase.database.storeUrl`), never one of a resource type's own: it takes `{ ref | id, export }` and stores the URL that carries `LISTEN` as `SANOMA_DATABASE_URL_<EXPORT>` (`databaseUrlSecret(export)`; `storeDatabaseUrl` stores it so, refusing a secret that holds another), never returning it, and the type's `afterCreate` calls it. A database type is not `stateless`: apply asks before it deletes one. `defineResource` refuses a `database` that breaks any of that; `resolveConfig` refuses one whose `storeUrl` is not among the config's operations, or does not take a binding id and an export. Its conformance kit is [`sanoma/testing/database`](../testing/README.md#a-databases-conformance). After retiring a database, a workflow can remove its exported URL with `sanoma.secret.delete` under the [runtime operation contract](#the-runtimes-own-operations).
768
+
769
+ `databaseUrlSecret` converts camel-case exports to uppercase words (`mainStore` → `SANOMA_DATABASE_URL_MAIN_STORE`) and preserves exports that are already uppercase, including digits and underscores (`CLOUD_ACME_97F9` → `SANOMA_DATABASE_URL_CLOUD_ACME_97F9`). Use the same export when storing, binding and retiring its URL.
770
+
771
+ ### Sandboxes
772
+
773
+ A sandbox is a resource type whose boxes a coding agent works in (an Agent37 instance): `defineResource({ …, writable: true, sandbox })`, where `sandbox` (`SandboxSpec`) says what its boxes can do (`capabilities: { snapshot, pause, port }`: their files survive a stop; a stopped box keeps its memory; a port is reachable from outside), where it takes a box's image and its size in vCPUs, by dotted path into its fields (`inputs: { image, size }`), and how its state reads (`outputs(state) → { id, healthy }`). The vendor's own facts (region, machine type) are fields of the resource, never the environment. Its connector attaches the backend (`withSetup(connector, { sandbox: ({ secrets, declared }) => backend })`, `declared` the declared resource's fields, where the vendor's facts are): `open({ name, image, size })` gives the box `name`, made, woken or started as it needs, and `discard({ name })` deletes it and all the vendor kept. A `Box` runs `bash -c` (`run(command, { cwd, env, stdin, signal })` → a `Process` of web streams, `wait()` and `kill()`), reads and writes files (a relative path is under its home), exposes a port (`expose(port)` → `{ url, headers? }`) and stops. `localBackend(dir, env?)` is the backend on this machine: a box is the directory `<dir>/<name>`, its commands children in process groups of their own (`LOCAL_SANDBOX`: it snapshots and exposes ports on loopback). A remote box is driven through the runner, a small server of Sanoma's that its backend starts inside it: `runnerScript()` is the runner as one file (Node 22 or later, nothing to install), which listens on `RUNNER_PORT` (7700), answers `GET /runner/health` (`RUNNER_HEALTH`) with its protocol and pid (`RunnerHealth`, `{ protocol, pid }`, `RUNNER_PROTOCOL`; `runnerHealth(url, headers?)` asks it) and asks no credential, since the vendor's edge authenticates every request to the port; `runnerBox({ url, headers, id })` is the box's `run`, `read`, `write` and `stop` over one WebSocket to it, the upgrade sent with `headers`, its commands streaming both ways, which a vendor's buffered exec cannot. `ResolvedConfig.sandboxes()` gives the declared one, read at each call (an instance opens its coding agents' boxes in one sandbox: several are each a problem of the data files, and left out), and `sandboxBackends` the makers of the backends the connectors attach, by vendor: the app (`personBox`) makes the declared one's vendor's with its fields and opens a person's box in it, falls back to `localBackend` on this computer, and refuses its coding agents on a live instance that declares none. `open`'s `image` and `size`, left out, are the backend's own. `defineResource` refuses a `sandbox` that breaks any of that. Its conformance kit is [`sanoma/testing/sandbox`](../testing/README.md#a-sandboxs-conformance).
774
+
775
+ ### Secrets
776
+
777
+ Never put a secret in a workflow's input or an operation's input or output. They are persisted verbatim: DBOS keeps every step's input and output in Postgres, the ledger records each call's input and output, an approval a policy asks for carries the held call's input, and the app shows all of it to anyone who can reach it. A driver reads its credentials when it is called (from the environment or a secret store), and an operation that creates a secret (an API key, a password reset link) returns a reference to where it is stored, not the secret.
778
+
779
+ A secret a resource needs is named, never written. A data file gives `secret("NAME")` (from `sanoma/resources`; `NAME` upper case, as a variable's; sanoma's own, `SANOMA_…`, only in a host's `secrets`) at a write-only field (or an entry of a write-only map), and `secret("NAME", { generate: true })` for one apply makes when none is stored: `database_password: secret("SUPABASE_DB_PASSWORD", { generate: true })`. Declarations, checkpoints and the ledger hold its marker, `{ "$secret": "NAME", "generate": true }`; the resource type refuses one at any other field, and its schema does not judge it. The driver resolves the markers just before the vendor call, `await resolveSecrets(input, call.secrets)`: each is replaced by the stored value, a `generate` one with none stored first made (32 random bytes, base64url) and stored, and one with nothing stored fails the call for good, before the vendor call, with the `vendorCode` `secret_not_set` (the run's ledger then says nothing changed at the vendor). `call.secrets` is `{ get(name), ensure(name, make), delete?(name) }`, resolved through the configured store and explicit bindings (see [Credentials](#credentials)); a fake's and a sandbox run's are in memory (`memorySecrets()`, which a driver's tests use too).
780
+
781
+ ### Versions
782
+
783
+ Every run is stamped with the application version of the worker that runs it, `<appName>@<version>`, and only a worker on that version recovers it after a restart. Versioning is automatic: the version is a hash of each workflow's name, the source of its `run` function, its operations and its input schema, which is DBOS's own scheme applied to the workflow code rather than to the runtime's registration wrapper (DBOS would otherwise see one identical function for every workflow and never change). The hash cannot see functions `run` calls that live elsewhere, op schemas, drivers or the policy: edit those with no run in flight, or restart on the old code first. To name a version instead (a git commit, say), set DBOS's `DBOS__APPVERSION` environment variable; it is prefixed with the app name the same way. A new version becomes the app's latest when it first starts, and runs queued without a version go to the latest; a worker started on an older version (a rollback) warns instead, unless started with `{ promote: true }`. The hash is of the code as it runs, so TypeScript source and the compiled JavaScript of the same workflow have different versions.
784
+
785
+ Built-in runs are the exception: a deploy restarts the worker on the merged code, a new version, and the `apply` or `change` run that made the deploy has to outlive its version. Each run of a built-in workflow (`apply`, `change`, `drift`, `call`, `login-code`, `import`) carries a hash of that workflow's own code (its `builtInCode` attribute: what the version hashes of the workflow, with the runtime's and DBOS's versions, never the company's workflows), and a worker that starts as the app's latest version takes over the unfinished built-in runs of other versions whose hash is its own, keeping each run's id, its completed steps and the messages it has not read yet (an approval decided, an event told while no worker ran). It says so in one line at `info`. Runs of the company's workflows stay on their version; so does a built-in run whose hash differs, after an upgrade of the runtime (or, for `apply`, a change of the resource types it may call).
786
+
787
+ When a worker starts, it warns about unfinished runs it will not pick up, naming them: runs started on another version, and runs queued on another queue. Run the version that started them, or fork each onto the current version with `DBOSClient.forkWorkflow(id, step, { applicationVersion, queueName })` and cancel the original.
788
+
789
+ Queues used to be one `sanoma` queue for every app and are now `sanoma:<appName>`, so runs queued before the change are never started. Sandbox runs had their own queue, `sanoma:<appName>:sandbox`, until they went on the app's; the warning names the runs left on it, and a sandbox run forked or resumed past its seed step fails at once, so start its scenario again or cancel it. On a local database, `pnpm db:down && pnpm db:up` resets it.
790
+
791
+ ## Keeping workflows replay-safe
792
+
793
+ A run is replayed after a restart by calling the function again and reading each step's result back, so workflows must do the same thing every time, and must reach vendors only through `ctx` so the policy sees every call. Two checks guard against getting that wrong by accident, on files under `workflows/`. They are not a sandbox: they read the source, and code written to get around them can.
794
+
795
+ oxlint, with the rules this package ships in `oxlint.json`, refuses the clock (`Date.now()`, `new Date()` and `Date()`, through the plugin's rule `sanoma/date`, which allows `new Date(await ctx.now())`; `performance`), randomness (`Math.random`, `crypto`), the network (`fetch`, `WebSocket`), timers, `process`, `globalThis`, `Promise.all` and its kin (use `ctx.all`; nothing races), and imports of `sanoma/testing`, `sanoma/app`, `sanoma/workflows/describe`, `sanoma/workflows/fake`, `sanoma/workflows/plugin`, `sanoma/workflows/scenario`, `sanoma/workflows/scenarios`, `sanoma/workflows/wakeup-service`, `@sanoma-ai/connector-*/fake` and `@sanoma-ai/connector-*/driver`. From `sanoma/workflows` it allows only `defineWorkflow`, `mayDecide`, `errorCode`, `z`, `sanoma` ([the runtime's own operations](#the-runtimes-own-operations)) (which `sanoma` re-exports) and types (the list is `allowImportNames` in `oxlint.json`; the `sanoma` package's own `oxlint.json` allows the same names from `sanoma` and refuses its subpaths): the rest could start runs or approve the run's own approvals (`SanomaClient`, `startWorker`), forge the audit record (`jsonlLedger`, `memoryLedger`: a store keeps the first record per id) or read credentials. Each message names the `ctx` replacement. `sanoma check` runs it, through `sanoma/oxlint.json`, which carries these rules.
796
+
797
+ `describeConfig` (`sanoma/workflows/describe`) reads each workflow's file once, the one way the worker does, and lists on the workflow's entry, in `problems`, what oxlint can't express: imports come only from `sanoma/workflows` or `sanoma`, a `@sanoma-ai/connector-<vendor>` package, zod, or a relative file that stays inside the file's `workflows/` directory (so not `../sanoma.config.ts`, which holds the config); no namespace import of either package; no dynamic `import()`; and no `instanceof` against `DriverError`, `SanomaError`, `PolicyDeniedError` or `RejectedError`. On a replay DBOS rethrows a serialized copy of an error, which is no instance of its class, so a branch on `instanceof` would go another way than the first time and the run's steps would fall out of step. Read `errorCode(err)` instead.
798
+
799
+ In each workflow's `run` it also lists what the run's graph could not show, the same problems that make the outline `{ error }` and `startWorker` refuse (see [Outline](#outline)): `ctx` used other than called directly or read for `ctx.runId` or `ctx.startedBy` (passed to a helper, aliased, destructured, or `run` taking it destructured); a call on `ctx` that is no operation or built-in (`ctx.ghost.post()`); `ctx.all` over members made elsewhere (write the list, or `items.map(…)`, in the call); a `ctx` call inside a function the outline does not read (one defined inside `run`, or a callback not passed to `ctx.all`, `.map`, `.forEach` or `.reduce`) or in a `finally`; and, in `run`, in a `finally` and in the callbacks that make `ctx` calls, a `return` before the end, a `throw` outside a `catch`, a `break` out of a loop or to a label, and `continue`; and a [step name](#step-names) that is not a literal or reads as an operation's id or `Sleep`, and two steps given one name. A function without `ctx` calls computes, and may do as it likes. Each message says what to write instead: inline the helper, use `if`/`else` around the rest, name the call. Each problem has its `line` and `column` in the entry's `file` (an unreadable file, or one that holds no workflow of the entry's name, is the outline's error at 1:1); `sanoma check` prints them, as `problemLine` does, and the app's startup warns of them. A test holds a repo to the same:
800
+
801
+ ```ts
802
+ import { describeConfig } from "sanoma/workflows/describe";
803
+ import { expect, it } from "vitest";
804
+ import config from "../sanoma.config.ts";
805
+
806
+ it("has no problems", () => {
807
+ const { problems, workflows } = describeConfig(config);
808
+ expect([...problems, ...workflows.flatMap((wf) => wf.problems)]).toEqual([]);
809
+ });
810
+ ```
811
+
812
+ ## Fakes for tests
813
+
814
+ `sanoma/workflows/fake` exports `defineFake(connector, { initial, ops }, { calls? })`, the fake a connector package attaches the maker of (`withSetup`), which builds an in-memory vendor for a connector: `ops` implements every operation against the fake's state, typed by the connector as `defineDriver` is, and the fake adds what a real vendor does around them (a repeated idempotency key gets the first reply and changes nothing) and faults a test can inject (`failNext`, `loseReply`, `rateLimit`, `hold`). `update(change)` changes the state as someone at the vendor would, so the next call sees it. `calls` logs into a list given, so several fakes share one ordered log. The connectors' own fakes (`@sanoma-ai/connector-ghost/fake` and the others) are built with it. The entry also declares `ResourceFake`, the contract of a fake that holds its vendor's objects by resource type and import id (`put`, `override`, `remove`, with fields in the resource's shape), which `sanoma/internal/bridge`'s `tfFake` meets and a scenario's [resource steps](#scenarios-and-sandbox-runs) seed through. It is a separate entry so the runtime carries no test tooling, and the lint refuses it in workflow files.
815
+
816
+ ## Scenarios and sandbox runs
817
+
818
+ A scenario is a Gherkin feature file that says what a sandbox run starts from, how its approvals are decided and what it should do. A sandbox run is a real run of a workflow, under the same policy and approvals, that calls fake vendors instead of the drivers, so a workflow can be tried before it touches anything. The fakes are the ones the connectors carry, and the scenarios are the `.feature` files in `scenarios/` in the config's root: nothing to add to the config.
819
+
820
+ [Cucumber](https://github.com/cucumber/cucumber-js) (`@cucumber/cucumber`, pinned) runs the feature files, in this process, in two ways, and never drives a run itself. Compiling a file, its steps only record what they say (the seeds, the faults, the workflow and its input, the decisions, what each `Then` is about), which gives the scenarios the worker seeds from, `drive` decides by and the app lists. Checking a run, the scenario's `Then` steps run against the run's ledger as assertions, and the rest do nothing. Steps come from three places: the generic steps below, the steps each connector ships (`withSetup`'s `steps`, see [Steps a connector ships](#steps-a-connector-ships)), and the company's own (the config's `steps`), so one scenario can combine steps from several connectors. Sanoma registers them all with Cucumber from the config; a connector never imports Cucumber.
821
+
822
+ The fakes are made per run: a connector attaches the maker of its fake (one per vendor; `resolveConfig` refuses two different ones for one), and each sandbox run calls it once for a fake of its own, so it starts from the fake's initial state plus its scenario's `Given` seeds. A root without `scenarios/` has no scenarios. Every `.feature` file under it is read; each must hold at least one scenario, and each scenario's name must be unique across them. Each row of a `Scenario Outline`'s examples is a scenario of its own, named from the outline's title; rows whose names come out the same get their line appended, such as `Launch (line 12)`.
823
+
824
+ ```gherkin
825
+ Feature: Announce a launch
826
+
827
+ Scenario: Launch on time
828
+ Given a post titled "Old news" exists
829
+ And bluesky.post.create fails once
830
+ When announce runs with
831
+ """
832
+ { "title": "Acme Pro", "launchAt": "2030-01-01T09:00:00Z" }
833
+ """
834
+ And "Review launch copy" is approved by marketing-lead with note "ship it"
835
+ Then a post titled "Acme Pro" is created
836
+ And post "post_0002" is published
837
+ And "Acme Pro https://blog.example.test/acme-pro/" is posted to Bluesky
838
+ And resend.broadcast.send was called with
839
+ """
840
+ { "id": "bc_0001" }
841
+ """
842
+ And the run succeeds
843
+ ```
844
+
845
+ The steps, as [Cucumber expressions](https://github.com/cucumber/cucumber-expressions) (`{op}` is an operation id, `{workflow}` a workflow name, `{who}` a person's id or a group's name, `{string}` a quoted string, `{resource}` a resource type such as `github.repository`, `{declared}` a declared resource as a drift report names it, `resources/identity/github.ts#website`, and `{field}` a field's dotted path; `And` and `But` take the keyword before them):
846
+
847
+ | Keyword | Step | What it does |
848
+ | ------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
849
+ | Given | `{op} was called with` and a JSON doc string or a two-column table (`name \| value`) | Seeds the fake: calls the operation through it before the run |
850
+ | Given | `{op} fails once`, `{op} is rate limited once`, `{op} loses its reply once` | Injects the fault into the operation's next call (`failNext`, `rateLimit`, `loseReply`); its step has `fault: true` |
851
+ | Given | `{resource} {string} has` and a two-column table (`field \| value`) or a JSON doc string | The vendor's fake holds the object with these fields: `Given github.repository "website" has` then `\| has_wiki \| true \|` |
852
+ | Given | `{resource} {string} is gone` | The vendor's fake no longer holds the object: `Given github.repository "docs" is gone` |
853
+ | Given | `{who} is acting` | Starts the run as that declared person or agent, or `anonymous`: `Given refund-bot is acting` (else `runScenario`'s `startedBy`, `scenarios` by default) |
854
+ | Given | `a visitor is acting` | Starts the run as a visitor of a public site signed in (`visitor:scenario:visitor`, in `visitors`), which only a `permit` lets start one |
855
+ | Given | `a visitor {string} is acting` | The same visitor with the email its login verified: `Given a visitor "hopper@example.com" is acting` (`ctx.startedBy.email`) |
856
+ | Given | `a visitor {string} with GitHub {string} is acting` | The same, with the GitHub login it signed in with or linked too: `Given a visitor "hopper@example.com" with GitHub "hopper" is acting` (`ctx.startedBy.github`) |
857
+ | When | `{workflow} runs with` and a JSON doc string or a two-column table (`name \| value`) | The workflow the scenario runs, and its input |
858
+ | When | `{workflow} runs with exactly` and a JSON doc string or a two-column table | Uses only the supplied input, parsed by the workflow schema; omitted optional fields stay absent and schema defaults apply |
859
+ | When | `{workflow} runs` | The same, with the input made up |
860
+ | Any | `{string} is approved by {who}`, `… with note {string}`, and the `rejected` forms | How the approval with that title (or id, such as `approval-2`) is decided |
861
+ | Then | `{op} was called with` and a JSON doc string or a two-column table | Expects a call whose input has at least these fields, at any depth: an object may give some of its fields |
862
+ | Then | `{op} was called`, `{op} was not called` | Expects a call to the operation, or none |
863
+ | Then | `step {string} was called with` and a JSON doc string or a two-column table | Expects a call by the [step](#step-names) of that name whose input has at least these fields, at any depth: `Then step "Draft the post" was called with` |
864
+ | Then | `step {string} was called`, `step {string} was not called` | Expects the named step to have run, or not |
865
+ | Then | `step {string} ran {int} time(s)` | Expects the named step to have run that often: `Then step "Draft the post" ran 2 times` |
866
+ | Then | `{op} was denied` | Expects the policy to have denied a call to it: `Then github.repository.import was denied` |
867
+ | Then | `{op} was denied with {string}` | The same, with that reason (a Cedar policy's `@reason`): `Then shop.refunds.create was denied with "Agents do not refund"` |
868
+ | Then | `{op} was held for {who}` | Expects an approval for that approver to have held it: `Then stripe.product.import was held for finance` |
869
+ | Then | `{op} was held for group {string}` | The same, for the group alone, never a person of that id: `Then shop.refunds.create was held for group "finance"` |
870
+ | Then | `{declared} is drifted in {field}` | For a drift run: `Then resources/identity/github.ts#website is drifted in has_wiki` |
871
+ | Then | `{declared} is clean`, `{declared} is gone`, `{declared} is absent` | For a drift run: `Then resources/identity/github.ts#docs is clean` |
872
+ | Then | `apply creates {declared}` | For an apply run: it created the resource (or made a gone one again): `Then apply creates resources/identity/github.ts#docs` |
873
+ | Then | `{declared} is bound to {string}` | For an apply run: the lockfile it ended with binds it so: `Then resources/identity/rules.ts#docsMain is bound to "BPR_docs:main"` |
874
+ | Then | `the run succeeds`, `the run fails`, `the run fails with {string}` | Expects the run to finish, or to fail (with that error code, such as `"approval_rejected"`) |
875
+
876
+ A resource step names an object a vendor's fake holds, by resource type and import id (a binding id, or the provider's import id: a GitHub repository's name without its owner, a branch protection rule's `repository:pattern`; a fake also finds an object by its binding id, such as a repository's `node_id`), for a fake that holds objects (`sanoma/internal/bridge`'s `tfFake`, as the GitHub and Stripe fakes are; a sandbox run whose scenario seeds a resource of another vendor's fake fails with `invalid_input`). `has` puts the fields on the object (`put`: over the one the vendor has, keeping its other fields, or a new one), each read as a table cell is for an operation's input and checked against the type's schema; `is gone` removes it (`remove`), and is nothing when there is none. The run's own fake is what is seeded. A fake starts a sandbox run with what its replies were recorded with, so a declared resource the recording lacks is `gone` to a drift run until a scenario puts it.
877
+
878
+ The policy steps read the run's ledger: `was denied` holds when the policy's decision on some call to the operation is `deny`, and `was held for {who}` when an approval addressed to that person (by id) or group (by name) holds it, whether the policy asked for it on that call or the workflow asked for one that `covers` it. A failed step says what happened instead: `github.repository.import was allowed, not denied`, `stripe.product.import was held for finance, not marketing-lead`, `shop.refunds.create was denied with "Agents do not refund", not "No"`. When the data files declare people, `is acting` names a declared person or agent (one of the runtime's own too, or `anonymous`) and `held for group` a declared group, `agents` or `visitors`, else the scenario does not load, naming those declared; while they declare no one, any id and any group go, as a run's start admits anyone then. A scenario has one actor. The drift steps read the report a finished [drift](#drift) run returned, so their scenario must run `drift` (a parse error otherwise), as the apply steps read an apply run's report, and an apply run's input is only what `runs with` gives, never made up; a failed one says how the report found the resource: `resources/identity/github.ts#website is drifted in has_wiki, not clean`, `… is gone, not drifted in has_wiki`, or that the report has no such resource.
879
+
880
+ The `step` steps name a [step](#step-names) of the scenario's workflow, after its `When`: one whose name is no step's, or several's (a default an operation called twice shares), is an error listing the names it has, so a test names one call (an unnamed call with a computed segment, `ctx.ghost.post[action](…)`, is named in a run by the operation it calls, so it shares that operation's id; an approval whose title is no literal is named by its title in a run, which the outline cannot tell apart), and `was called with` checks its operation's input fields. They read the ledger by the `name` its records carry: a step ran when a call by it was made (not denied, rejected or failed for good), a sleep by it started, or the workflow asked for an approval of that title; a policy's hold on a call is that call's, not a run of its own. A call in a loop runs once per pass: `ran 3 times` for three items. A failed one says what happened: `step "Draft the post" ran twice, not 3 times`.
881
+
882
+ Cucumber matches a step by its text alone, whatever its keyword; Sanoma then picks the step of that keyword, so `{op} was called with` seeds after `Given` and expects after `Then`. Two different expressions matching one step's text is ambiguous whatever their keywords.
883
+
884
+ Each scenario has exactly one `When … runs`. An operation can add its own steps with `phrases` in its spec: `{ given: "a post titled {title} exists", expect: "a post titled {title} is created" }`. Each `{name}` is a field of the operation's input (a phrase naming another is a configuration error); it matches what `{string}` does (a quoted string) or one word, and is read as a table cell is. A field may have any name, even one a parameter type has (`op`, `string`, `int`): the phrase reads it as the field. A `given` phrase seeds the fake as `was called with` does, and an `expect` phrase (for `Then` steps) expects a call with those fields. `describeConfig` lists them as an operation's `phrases`.
885
+
886
+ A doc string is a JSON object. A table cell, and a phrase's field, is read as text when its field takes text, else as JSON (a number, `true`, a list): `| title | 123 |` is the text `"123"` for a string field, and `| count | 5 |` the number 5 for a number field. Every field a doc string or a table names must be one the input has (the error lists those it has), and its value one the field takes; a value it takes neither as text nor as JSON, such as `yes` for a boolean, is an error. A `Then` checks each field it names this way, not the whole input, and at any depth: an object it gives (in an object field, optional or nullable too) may name some of its fields (`{ "record": { "stage": "won" } }`), each checked against its own schema (`stage in record in data.outbound.save's input cannot be …`), where a `Given`, which seeds a call, needs the whole object; a list, and an object in a list or a union, is given whole. So does an `expect` phrase's field.
887
+
888
+ `runs with` and `runs` make up omitted workflow input from the schema with [zod-schema-faker](https://github.com/soc221b/zod-schema-faker), seeded from the scenario's name, so one scenario always makes up the same values; it is then parsed by the schema. Use `runs with exactly` to test omitted optional inputs or schema defaults: it parses only the supplied JSON object or table, without generating values. A missing required field is a scenario compilation error. For example, `When cloud-signup runs with exactly` can omit an optional `installation` to exercise the workflow's missing-installation path. A step no rule matches, or more than one, an unknown operation, workflow or field, a value its field does not take, a missing or second `When`, a doc string that is not JSON, and a file Gherkin cannot parse are errors naming the file and line; the first lists every step there is, each operation's phrases under its id and each connector's steps under its vendor. A file with an error has none of its scenarios; the other files still load.
889
+
890
+ Checking a run, every `Then` step runs and judges the run on its own: one that does not hold says why, and the steps after it are still checked.
891
+
892
+ ### Steps a connector ships
893
+
894
+ A connector's package declares steps with `defineSteps(vendor, ({ given, then }) => …)` (from the main entry) and attaches them with `withSetup(ops, { driver, fake, steps })`; a company passes its own as the config's `steps`. A step is a Cucumber expression (with the built-in parameter types, `{string}`, `{int}`, `{word}` and the rest) and a pure function of its parameters' values: compiling calls it, the app too, whenever a feature file changes.
895
+
896
+ ```ts
897
+ import { defineSteps } from "sanoma/workflows";
898
+
899
+ export const blueskySteps = defineSteps("bluesky", ({ given, then }) => {
900
+ given("Bluesky fails to post once", () => ({ op: blueskyOps.post.create, fault: "failNext" }));
901
+ then("Bluesky has a post with {string}", (text: string) => ({
902
+ op: blueskyOps.post.create, // what the step is about, for the graph
903
+ called: true,
904
+ check: (run) =>
905
+ run.calls(blueskyOps.post.create).some((c) => c.input.text.includes(text))
906
+ ? undefined
907
+ : `no Bluesky post has "${text}"`,
908
+ }));
909
+ });
910
+ ```
911
+
912
+ A `given` returns a `Seed`: `{ op, input, as? }` calls the operation through the run's fake before it starts, `{ op, fault }` injects `failNext`, `rateLimit` or `loseReply` into its next call. A `then` returns an `Expect`: `op` and `called` say what it is about (the graph marks the operation), and `check(run)` reads the run (`RunView`: its `records`; `calls(op)`, the calls made without an error; `seeded(op)`, what the `Given` steps seeded through it; and `made(op)`, both: each `{ input, output }`, typed by the operation) and returns why it does not hold, or throws; returning nothing passes. In `scenario.expect` such a step is `{ step, custom: true, op?, called? }`.
913
+
914
+ The same steps test the connector's own operations, in its `features/`: there the generic steps below call an operation directly (no worker, no policy) on a fake or on the driver over recorded replies, and `$name.field` in a table cell is a field of what a `Given` named `as` returned (`| id | $draft.id |`). A `Given` that calls a resource type's `create` seeds the object as apply makes it: the type's `afterCreate` calls follow, each polled as apply polls it (a Neon project's compute has started), the seed's name (else the type's) as the export a `storeUrl` stores under. [`describeFeatures`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/testing/README.md#a-connectors-own-features) runs them.
915
+
916
+ | Keyword | Step | What it does |
917
+ | ------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
918
+ | When | `{op} is called with` and a JSON doc string or a two-column table | Calls the operation with that input, the rest made up; the call and its output or error are kept |
919
+ | Then | `it returns` and a two-column table of fields of its output | Expects the last call to have returned at least these fields, at any depth |
920
+ | Then | `it fails with status {int}` | Expects the last call to have failed with that vendor status |
921
+
922
+ A workflow's scenario refuses `{op} is called with`, and an operation's own test refuses a step that runs a workflow, decides an approval or seeds a resource; a fault needs the fake.
923
+
924
+ `sanoma/workflows/scenario` (server-side only; the lint refuses it in workflow files) compiles and checks them:
925
+
926
+ - `loadScenarios(resolveConfig(config))` resolves to `{ scenarios, errors }`: every scenario, compiled by Cucumber, and an error for each file that does not compile or name used twice. It reads the resolved config's `ops`, `workflows`, `types`, `steps` and `scenarios` (the directory). A scenario's `line` is its keyword's, or its examples row's. A scenario's `text` is its own lines of its file, for display: from its keyword line to the end of its last step (doc strings, tables and an outline's examples included), less that line's indent; its `steps` are each `{ text, kind, op?, name?, called?, decision?, fault? }`, in order: `op` names the operation a step is about, `name` the step a `step "…"` Then is about, `called` says whether a `Then` about either expects a call (or a run) or none (`ran 0 times` too), `decision` that it expects the policy to have denied it (`denied`) or held it (`held`), and `fault` marks a `Given` that injects a fault rather than seeding. It compiles the files again only when one has been added, removed or written since its last call with that config (a file's name, `mtimeMs` or size changed); until then it resolves to the same object, so the worker and the app can call it on every run and every request. Compiling builds Cucumber's support library from the config (once per resolved config) and runs the files: a few milliseconds.
927
+ - `check(scope, scenario, records)` runs the scenario's `Then` steps, as its feature file reads now, against a run's ledger records, and resolves to `{ step, ok, detail? }` for each expectation, in order; it rejects when the file no longer has the scenario as it was compiled (load the scenarios again first). Each `Then` is judged on its own, so one that does not hold leaves the rest checked. For the generic steps: a call matches when its parsed input contains the expected input (every field, at every depth); a call is an `op.called` record without an `error`, so one the policy denied, an approver rejected or the vendor failed for good was attempted, not made (`was not called` passes, and a failed `was called` lists the attempts in its `detail`); a denial is read from the `op.called` records' `decision`, a hold from `approval.requested` (its `op`, or its `covers`); a named step's runs from the `name` on the `op.called` (made), `sleep.started` and workflow-asked `approval.requested` records; an outcome is read from `run.finished` or `run.failed` (`ok: false`, "run not ended", before either); and a drift result from the `DriftReport` a `run.finished` holds as its `output`. A connector's or the company's `Then` whose `check` throws fails with the error's message.
928
+ - `testFeature(scope, file, line, { driver, fake? })` runs one scenario of a connector's own feature file as an operation's test, rejecting with its first step that did not pass at its `file:line`, and `featureScenarios(scope, dir)` lists a directory's scenarios from a dry run: what `describeFeatures` is built on.
929
+ - `drive(client, runId, scenario, { timeoutMs? })` decides the run's approvals as the scenario says until the run ends, and returns its `RunSummary`. Each pending approval takes the decision naming its title or id, else the next decision left that names no approval of the run: none it has asked for, and none in `scenario.approvals`, the titles its workflow's code asks for where they are string literals (read from its [outline](#outline)). So `"the first one"` is decided in order, but a decision for `"Final check"` is never spent on the approval before it. An approval with no such decision throws, naming the decisions left. Each decision waits for the run to read it until the timeout; a worker that has not read it by then throws `run_running`, as does a run still going. `by` is a person's id, so a scenario cannot decide an approval addressed to a group.
930
+
931
+ Start a sandbox run with `client.start(workflow, input, { startedBy, sandbox: "<scenario name>" })`. `sandbox` must be a non-empty string, else `start` throws `invalid_input`; the worker looks the scenario up. The input is the caller's (a scenario's own is `scenario.input`). The worker then:
932
+
933
+ - parses the input, then seeds its own fakes from the scenario, once, in a step named `sandbox:seed`: it reads the scenario, makes a fake of every vendor for the run (each maker, called once), checks the scenario against them, calls each `Given` operation through its fake, puts or removes each `Given` resource in its fake, and injects the faults into them. It records `scenario.seeded` (the scenario, and each seed: an operation's with its input and output, a resource's with its type's id, its import id and its fields, or `gone: true`) right after `run.started`. A scenario that does not exist or runs another workflow, a workflow using (or a scenario seeding) an operation with no fake, a scenario seeding a resource of a vendor whose fake holds none, and a resource seed the fake refuses (a field its provider's shape lacks), fail the run with `invalid_input`, the last naming the step.
934
+ - calls its own fakes, never a driver, under the same policy and approvals as a live run.
935
+ - does not wait on `ctx.sleep`: it still records `sleep.started` with the real `until`, and goes straight on.
936
+ - runs it on the app's queue, as any run: sandbox runs share no fakes, so several run at once, and one waiting on an approval holds up no other.
937
+ - checks it against its scenario as it starts to wait on an approval and once it ends (its outcome recorded, before DBOS records it): Cucumber runs the scenario's `Then` steps over the feature file as it reads then, against the ledger so far, and the answers (`RunChecks`: each `Check` with whether it is `settled`, or why there are none) go to the runtime's table, which `client.runChecks(runId)` reads. No step and no ledger record: what the run does never depends on them.
938
+ - prints nothing of it through DBOS's log: none of DBOS's warnings from inside it (a step's failed try among them: a fake's `fails once` is on purpose), nor the error the run fails with. Its ledger and its status say what happened; a live run's tries and failures print as ever.
939
+
940
+ A sandbox run does not survive a worker restart: its fakes keep their state in the worker's memory, so a run whose seeding DBOS replays from its checkpoint (after a restart, or in a fork) fails with `invalid_input`, "Sandbox run … was interrupted by a worker restart and the fakes' state is gone; start the scenario again", rather than going on against fakes in some other state.
941
+
942
+ `RunSummary.sandbox` names the scenario a sandbox run was seeded from (kept in DBOS's `attributes` for the run). Reusing a run id with another `sandbox`, or none, is `invalid_input`, as with another input.
943
+
944
+ `runScenarios(config, { databaseUrl, startedBy?, timeoutMs?, log? })` from `sanoma/workflows/scenarios` (server-side only, like `/scenario`) runs every scenario of the config as a sandbox run, on a worker it starts on `databaseUrl` with an in-memory ledger and stops after, and returns `{ passed, failed }`: the names of the scenarios whose every check held, and one `{ scenario, step, message }` per step that did not (with `check`'s detail), per run that could not be driven to its end (at its `When` step), and per feature file that did not load (`step: "did not load"`); a config whose root has no `scenarios/` passes and fails nothing. `sanoma check` runs it. `startedBy` (an id or a principal) starts each run whose scenario does not say who `is acting`. `runScenario(scenario, { client, scope, startedBy?, timeoutMs? })` runs one against a worker you started, `scope` being what it was loaded from (the resolved config). To run them as tests, a vitest test each, use `describeScenarios` from [`sanoma/testing/scenarios`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/testing/README.md#scenarios), which wraps the same `runScenario`.
945
+
946
+ ## Building your own UI
947
+
948
+ `sanoma/app` is one UI over a config; another (a Slack bot, an internal tool) can be built on the same pieces, which the package exports for that:
949
+
950
+ - `describeConfig(config)` and its types (`ConfigDescription`, `WorkflowEntry`, `OpEntry`, `VendorEntry`, `ResourceTypeEntry`, `DeclaredResource`, `ResourceProblem`), and `loadDataFiles(root, connectors)` and `readResources(config)`, from `sanoma/workflows/describe`: what to render, as plain JSON, with each workflow's outline. Its shape is `ConfigDescriptionSchema`, from `sanoma/workflows/description` (zod and nothing of Node, so a browser may import it): each entry type is inferred from its schema, and the schema refuses a key it does not name. Beside what the sections above say, a resource type carries its `capabilities` (`host`, `database` and `wakeup` from its spec, `source` for a type a host type's `source` field names, such as `github.repository`), a vendor its `credentials` (each variable its driver's `env` declares: its name, description and whether it is optional, never a value or a status), and the policy its `files` (each `.cedar` file's path and text, the root's then each app's). It is a separate entry so the worker never loads the parser the outline uses, and the lint refuses it in workflow files. `resolveConfig(config)` returns the checked config as a `ResolvedConfig`, with the operations and drivers by id, the resource types by `<vendor>.<type>` (`types`), the workflows by name (the built-ins `drift`, `apply` and `call` among them), its `root` and each vendor's `credentials` (`CredentialStatus`); `isOp(x)` tells an operation from a built-in in a workflow's `uses`.
951
+ - `readSites(root, description, connectors, policies?)`, from `sanoma/workflows/describe`, which `describeConfig` returns as `sites`: what each site calls, read from its source with oxc and never run (its pages are browser code: what they call is the site's outline), for a workflow's **Used by**; its `site.ts` is loaded. A site is a folder of `sites/` with a `routes/`, named as a URL segment; its `routes/**` and `components/**` (`.ts`, `.tsx`, less tests) are read for each `<RunForm workflow="…" />` and each use of `api`, both imported from `sanoma/site`, called or passed on (`queryFn: api.data.leads.list`): `api.<name>` and `api.<name>.<method>` are the workflow whose `apiNameOf` is `<name>`, `api.data.<collection>.<op>` a collection, `api.<vendor>.<resource>.<op>` the operation of that id. Each is a `SiteCall` (`kind`, `target`, `method`, what it calls of a workflow or collection as written (`start`, `latest`, `list`), `via`, `file`, `line`, `column`, and `page`, the page's path from its `createFileRoute` or `createLazyFileRoute` id, in a page's file); a `SiteEntry` holds a site's `name`, its `title` (`defineSite({ title })` in `site.ts`, the file's default export, which a zod schema checks: a key it does not name or a field of the wrong type (a number for `icon`) is a problem and that field is left out, the rest still read, so a bad `icon` keeps a site public, though a wrong `public`, `login` or `locales` leaves out all three; a `login` naming no login half, or `locales` that are no language tags or not on a public site without a login, is a problem too), its `pages` (each `SitePage` a `path` from a route file's id, one per path, a layout and its index being one; and on a path with one parameter, such as `/sites/www/blog/$slug`, `content`, the one kind its file reads an entry of by that parameter, `content.<kind>.get(params.slug)` (or `slug`, destructured) with `content` from `sanoma/site`, for the app's sitemap and its pages' languages, which `siteContentPages(root)` gives the app's build alone, path to kind), its `calls`, its `warnings` (on a public site, each page with one parameter whose file reads content but not by that parameter, so the sitemap lists none of its pages: a warning `sanoma check` prints and does not fail on) and its `problems`: each call to a workflow, collection or operation the config does not have (`calls workflow "<name>", which does not exist`), or to an operation a page may not call directly, and, given the policies (`describeConfig` passes them unless they have problems), on a public site each start (`api.<name>(…)`, `.start(…)`, a `RunForm`) and direct call that no company `permit` could let a visitor make, its `when` and `unless` aside (one naming `anonymous`; on a site with a `login`, `anonymous` or the group `visitors`), whose message ends with the permit to add, and, whatever the policies, its call of a built-in workflow or read of a workflow's runs but `.result` (`.latest`, `.runs`, `.approvals`, `.ledger`), which the app refuses a visitor; which `sanoma check` fails on. A name not written out (a variable, a template with holes, a computed member) is skipped, as is a call through a namespace import or a destructured `api`.
952
+ - `generateApi(description)` and `writeApi(root, description)`, from `sanoma/workflows/describe`: a site's typed `api`, `.sanoma/api.ts` (`API_FILE`), from a `ConfigDescription`, types and JSDoc only and the same text for the same description. It holds a record type per collection and `CompanyApi`: `<apiNameOf(workflow)>: WorkflowFn<input>` per workflow, built-ins too; `<vendor>: { <resource>: { <op>: OpFn<input> } }` for the operations `direct` marks; `data: { <collection>: CollectionApi<record> }`; each member documented from its title or description. Then it augments `sanoma/site`'s `Register`. Inputs are typed from their JSON Schema for the kinds a start form draws, constants, and unions of them (`null` among them); anything else, and every output, is `unknown`. A workflow with `describeConfig`'s api-name problem is left out (`problems`). `writeApi` writes only when the text differs (`wrote`).
953
+ - `SanomaClient`: call an operation directly (`call`, see [Direct calls](#direct-calls)), start runs, list them (`runs({ limit, status, workflow })`) or read a workflow's last result (`latest`), read a run's ledger and approvals, decide approvals, with the checks described above, and start a drift check or an apply and read its report (`drift`, `driftReport`, `apply`, `applyReport`, see [Drift](#drift) and [Apply](#apply)). `client.chats` keeps the operator agent's chats in the config's database: `open({ id, person, engine, title })` (the id the browser gave the new chat), `attach(id, draftId)`, `upsert(id, messages)` (the AI SDK's UI messages, each by its id, a new one after the last), `load(id)`, `get(id)` and `list(person)` (the newest first, `Chat`).
954
+ - `APPROVALS_EVENT` and `decisionEventOf(approvalId)`: the DBOS events a run publishes its approvals and each decision on, for a UI that reads DBOS directly. `ApprovalMessage` is the zod schema of a decision as a run reads it. `RunArgs` is what a run receives: its input, `startedBy` and, for a sandbox run, its scenario as `sandbox`.
955
+ - `mayDecide(approval, principal, run, people)` and `approverLabel(approver)`: who may decide, and how to name them, the same way the run does. `isEnded(status)` and `ENDED_STATUSES`: the run statuses that read no more decisions; `RUN_STATUSES`: every run status, in the order a run may pass through them.
956
+ - Errors: `errorCode(err)` for the code to branch on, `errorMessage(err)` for the text of anything thrown, `invalidInput(what, issues)` to build an `invalid_input` error from zod issues (`InputIssue` is one issue, without symbols in its path), and the classes `SanomaError`, `PolicyDeniedError`, `RejectedError`, `WithdrawnError`, `ApprovalPendingError` and `DriverError`. Read codes with `errorCode`, never `instanceof`.
957
+ - `sanoma/workflows/shared` exports `mayDecide`, `approverLabel`, `errorMessage`, `isEnded`, `ENDED_STATUSES`, `RUN_STATUSES`, `DRIFT_WORKFLOW`, `CALL_WORKFLOW`, `isLoopback` (whether a host is this machine: `localhost`, `127.x.x.x`, `::1`), `problemAt` (a problem's place: `file:line:column`, else `file#export`, else `file`), `problemLine` (a problem as one line: its place, then `: message`, or the message), `exportSpan` (where `export const <name>` or `export default` is in a file's text, for marking a declaration), `credentialReady` (a variable is set, or optional and unset) and the `RunStatus` and `CredentialStatus` types, the resource types' types (`Resource`, `ResourceSpec`, `ResourceFields`, `References`, `FieldReference`, `Declared`, `Declaring`, `DeclaredResource`, `ResourceProblem`) and the drift report's (`DriftReport`, `DriftResult`, `DriftField`, `DriftStatus`), with nothing else: no DBOS or Node imports, so a browser bundle can use them. The main entry exports them too.
958
+ - `LedgerRecord` and `LedgerStore` for the audit record (`LedgerBody` is a record without the fields every record carries, and `LedgerGroup` a record's `ctx.all` tag), `postgresLedger(databaseUrl)` (the default), `jsonlLedger(dir)` and `memoryLedger()` to keep it, and `RUNTIME_VERSION`, this package's version as the runtime reports it.
959
+
960
+ ### Outline
961
+
962
+ `outlineWorkflow(wf)`, from `sanoma/workflows/describe`, reads a workflow's shape from the file that defined it, for drawing it before it runs, and the worker holds every run to it, so the drawing is what a run can do and nothing else. `describeConfig` returns it as each workflow's `outline`:
963
+
964
+ ```ts
965
+ import { outlineWorkflow } from "sanoma/workflows/describe";
966
+
967
+ outlineWorkflow(announce);
968
+ // { nodes: [{ kind: "op", path: "0", id: "ghost.post.create", span: [913, 974] }, …, { kind: "approval", path: "2", title: "Review launch copy", span: […] }, …], file: "/…/workflows/announce.ts" }
969
+ ```
970
+
971
+ It parses the file with oxc-parser (TypeScript in a repo, `.tsx` included, JavaScript once built) and lists, in the order they run, the calls `run` makes on its first parameter, whatever it is named: operations (`op`, with a `*` for a computed segment such as `ctx[vendor].comments.list`, as the built-in `drift` imports each resource by its type, with the step's `name`), approvals (with the title, when it is a string literal or a top-level `const` holding one), sleeps (with their `name`), and `ctx.all`: `all` with one branch per member of an array literal, or for anything else, such as `ids.map(…)`, `each` with the callback's calls as its `body`. Around them it shows loops and `.map`, `.forEach` and `.reduce` callbacks as `repeat`, `if`, `switch`, `?:`, `&&`, `||` and `??` as `branch` (one case per arm that makes calls, plus one empty case for the way past them when there is one: an arm without calls, an `if` without `else`, a `switch` without `default`, the right side of `&&` not run), and `try` / `catch` as `try`, with the handler's calls as `handler`; a `finally` is not read. It does not read the functions `run` calls, whether defined outside `run` (a helper that takes `ctx`) or inside it, only callbacks passed to `ctx.all`, `.map`, `.forEach` and `.reduce`, and it cannot see how many times a loop runs or which arm is taken: the ledger says that, per run. Each loop, and each `each`, has a `label` read from its code: `for each of subscribers` for `for (const s of subscribers)` or `subscribers.map(…)`, `for each key of` for `for…in`, `repeat while queue.length` for a `while`, `do` or `for` with a test, and `repeat` for one without (the code on one line, cut at 40 characters). A loop's label is no step's name, and need not be unique.
972
+
973
+ Each node's `path` is its place in the outline: its index among its siblings, under its parent's path and the index of the branch, case or body it is in (`"2"`, `"2.1.0"`), the same for the same tree however the code is laid out. Each node's `span` is where its code is in the file, as UTF-16 offsets (a string index, and what CodeMirror counts): the call, the `ctx.all(…)`, the loop or `.map(…)` call, the whole `if` / `else` chain, `switch`, `?:` or `&&`, or the `try` statement. `describeConfig` puts the file's text beside the outline, as the workflow's `source`, with `\n` line endings; a server can keep that from its clients, since it is a whole file.
974
+
975
+ `defineWorkflow` records the file it is called from as the workflow's `file`, by itself; nothing passes it, and a definition made from code with no file (an eval, a bundle without one) is refused. The outline is read from that file, which must hold the workflow as an object literal with its `name` (a string literal, or a top-level `const` of the file holding one) and a `run` function taking `ctx` by name; otherwise it is `{ error }`, saying why (the file could not be read or parsed, holds no workflow of that name, or `run` destructures `ctx`). It is `{ error }` too, one line per problem at `file:line:column`, when `run` holds what the graph cannot draw: the control flow and uses of `ctx` that `lintWorkflow` refuses (see [Keeping workflows replay-safe](#keeping-workflows-replay-safe)). Either way `startWorker` refuses the config, since nothing could say where the workflow's calls are.
976
+
977
+ The worker reads each workflow's outline when it starts and holds every run to it. Each `ctx` call captures where the workflow made it, from the stack, and the worker finds the call node whose code holds that position; a call from anywhere else fails the run with `call_not_in_outline`, naming the file, line and column and what to do (inline the helper): from a function the outline does not read, from another file, from a `finally`, or through an alias (`const create = ctx.ghost.post.create`). `ctx.now()`, `ctx.runId` and `ctx.startedBy` are exempt: a read of the clock, and values. The records a call writes name its node as `node` (its `path`): `op.called`, `sleep.started`, `approval.requested` (a policy hold's approval names the held call's node) and each `group` of a `ctx.all`, so a UI places a run's steps in the code exactly, a loop's every pass on its one node. Records written by a worker from before calls were placed have no `node`.
978
+
979
+ Status: early (0.x). The API may change between minor versions.
980
+
981
+ TODO: redact fields a schema marks `.meta({ sensitive: true })` from the ledger, the approvals event and DBOS's step records, so a secret passed by mistake is not kept.
982
+
983
+ ## Changes
984
+
985
+ - 0.11.25: the `workload-identity` authentication kind is removed, with the `WorkloadAuthentication` and `AuthenticationContext` types; no connector used it. Every method now keeps a bundle in the store: `defineConnection` requires `credentials`, and `verifyAuthentication(method, credentials)` takes no third argument. A federated identity stores its bootstrap secret as an `api-key` bundle, as [GCP provisioning](../../../connectors/gcp/README.md#deployment-identity) does.
986
+ - 0.11.0: the config's `login` takes `from`, the address sign-in codes are sent from, and requires it: a config with `login` and no `from` (or one that is no email address, or a sender that does not keep it) is refused when it loads, so the worker, the app and `sanoma check` do not start until it is set ([Signing in on a host](#signing-in-on-a-host)). It replaces the Resend connector's retired `RESEND_FROM`.
987
+
988
+ License: FSL-1.1-ALv2.
989
+
990
+ The server-only [GCP KMS credential store](KMS-SECRETS.md) is a managed-backend option with explicit company-scoped bootstrap. It requires reviewed IAM/database isolation and does not provision Cloud infrastructure.