zitejs 0.9.153 → 0.9.155

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 (393) hide show
  1. package/dist/cjs/auth/actions.d.ts +28 -0
  2. package/dist/cjs/auth/actions.js +93 -0
  3. package/dist/cjs/auth/client.d.ts +357 -0
  4. package/dist/cjs/auth/client.js +66 -0
  5. package/dist/cjs/auth/config.js +9 -3
  6. package/dist/cjs/auth/index.d.ts +2 -249
  7. package/dist/cjs/auth/index.js +11 -108
  8. package/dist/cjs/auth/index.test.js +60 -0
  9. package/dist/cjs/auth/previewClaim.d.ts +7 -0
  10. package/dist/cjs/auth/previewClaim.js +16 -0
  11. package/dist/cjs/auth/profileUpdates.d.ts +9 -0
  12. package/dist/cjs/auth/profileUpdates.js +11 -0
  13. package/dist/cjs/backend/index.d.ts +6 -6
  14. package/dist/cjs/backend/index.js +13 -13
  15. package/dist/cjs/backend/index.test.js +102 -102
  16. package/dist/cjs/bundle/index.js +29 -16
  17. package/dist/cjs/caller/index.js +43 -43
  18. package/dist/cjs/check/index.d.ts +44 -1
  19. package/dist/cjs/check/index.js +198 -61
  20. package/dist/cjs/check/start/routeTree.d.ts +8 -0
  21. package/dist/cjs/check/start/routeTree.js +118 -0
  22. package/dist/cjs/check/start/tsgo.d.ts +2 -0
  23. package/dist/cjs/check/start/tsgo.js +35 -0
  24. package/dist/cjs/cli.js +19 -6
  25. package/dist/cjs/client/index.d.ts +2 -2
  26. package/dist/cjs/client/index.js +25 -25
  27. package/dist/cjs/dev/index.js +81 -53
  28. package/dist/cjs/dev/signin.d.ts +16 -0
  29. package/dist/cjs/dev/signin.js +84 -0
  30. package/dist/cjs/index.d.ts +5 -5
  31. package/dist/cjs/integrations/client.d.ts +3 -3
  32. package/dist/cjs/integrations/client.js +5 -4
  33. package/dist/cjs/integrations/client.test-d.js +15 -15
  34. package/dist/cjs/integrations/index.d.ts +2 -2
  35. package/dist/cjs/integrations/rules.js +42 -42
  36. package/dist/cjs/integrations/rules.test.js +60 -55
  37. package/dist/cjs/internal/appMode.d.ts +14 -0
  38. package/dist/cjs/internal/appMode.js +19 -0
  39. package/dist/cjs/internal/env.js +3 -2
  40. package/dist/cjs/internal/platformFetch.d.ts +2 -0
  41. package/dist/cjs/internal/platformFetch.js +14 -0
  42. package/dist/cjs/internal/reservedIds.d.ts +8 -0
  43. package/dist/cjs/internal/reservedIds.js +14 -0
  44. package/dist/cjs/internal/serviceUrls.d.ts +5 -0
  45. package/dist/cjs/internal/serviceUrls.js +14 -0
  46. package/dist/cjs/pdf/index.js +2 -1
  47. package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
  48. package/dist/cjs/runtime/index.d.ts +22 -22
  49. package/dist/cjs/runtime/index.js +28 -28
  50. package/dist/cjs/runtime/index.test.js +34 -34
  51. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +29 -29
  52. package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
  53. package/dist/cjs/sourceRoots.js +15 -15
  54. package/dist/cjs/sourceRoots.test.js +29 -27
  55. package/dist/cjs/start/build/entries.d.ts +25 -0
  56. package/dist/cjs/start/build/entries.js +121 -0
  57. package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
  58. package/dist/cjs/start/build/placeholders/devApp.js +6 -0
  59. package/dist/cjs/start/describe/describeBuilt.d.ts +5 -0
  60. package/dist/cjs/start/describe/describeBuilt.js +144 -0
  61. package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
  62. package/dist/cjs/start/platform/aiUsage.js +215 -0
  63. package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
  64. package/dist/cjs/start/platform/airtable/cache.js +93 -0
  65. package/dist/cjs/start/protocol.d.ts +19 -0
  66. package/dist/cjs/start/protocol.js +33 -0
  67. package/dist/cjs/start/serve/local/provider.d.ts +25 -0
  68. package/dist/cjs/start/serve/local/provider.js +196 -0
  69. package/dist/cjs/start/serve/provider.d.ts +19 -0
  70. package/dist/cjs/start/serve/provider.js +86 -0
  71. package/dist/cjs/start/types.d.ts +373 -0
  72. package/dist/cjs/start/types.js +2 -0
  73. package/dist/cjs/steps/index.d.ts +8 -8
  74. package/dist/cjs/steps/index.js +53 -53
  75. package/dist/cjs/steps/index.test.js +218 -218
  76. package/dist/cjs/sync/index.d.ts +1 -1
  77. package/dist/cjs/sync/index.js +28 -27
  78. package/dist/cjs/sync/lib.d.ts +15 -8
  79. package/dist/cjs/sync/lib.js +651 -665
  80. package/dist/cjs/sync/lib.test.js +81 -14
  81. package/dist/cjs/sync/sdkNames.d.ts +67 -9
  82. package/dist/cjs/sync/sdkNames.js +97 -31
  83. package/dist/cjs/sync/sdkNames.test.js +189 -113
  84. package/dist/cjs/types/fields.d.ts +1 -1
  85. package/dist/cjs/types/fields.js +105 -97
  86. package/dist/cjs/types/index.d.ts +2 -2
  87. package/dist/cjs/types/tables.d.ts +1 -1
  88. package/dist/cjs/upload/index.js +89 -24
  89. package/dist/cjs/upload/index.test.js +104 -1
  90. package/dist/cjs/vite/domTagNames.js +252 -252
  91. package/dist/cjs/vite/index.d.ts +1 -1
  92. package/dist/cjs/vite/index.js +51 -42
  93. package/dist/cjs/vite/index.test.js +10 -2
  94. package/dist/esm/auth/actions.d.ts +28 -0
  95. package/dist/esm/auth/actions.js +55 -0
  96. package/dist/esm/auth/client.d.ts +357 -0
  97. package/dist/esm/auth/client.js +62 -0
  98. package/dist/esm/auth/config.js +9 -3
  99. package/dist/esm/auth/index.d.ts +2 -249
  100. package/dist/esm/auth/index.js +2 -103
  101. package/dist/esm/auth/index.test.js +60 -0
  102. package/dist/esm/auth/previewClaim.d.ts +7 -0
  103. package/dist/esm/auth/previewClaim.js +12 -0
  104. package/dist/esm/auth/profileUpdates.d.ts +9 -0
  105. package/dist/esm/auth/profileUpdates.js +6 -0
  106. package/dist/esm/backend/index.d.ts +6 -6
  107. package/dist/esm/backend/index.js +13 -13
  108. package/dist/esm/backend/index.test.js +106 -106
  109. package/dist/esm/bundle/index.js +29 -16
  110. package/dist/esm/caller/index.js +44 -44
  111. package/dist/esm/check/index.d.ts +44 -1
  112. package/dist/esm/check/index.js +194 -61
  113. package/dist/esm/check/start/routeTree.d.ts +8 -0
  114. package/dist/esm/check/start/routeTree.js +77 -0
  115. package/dist/esm/check/start/tsgo.d.ts +2 -0
  116. package/dist/esm/check/start/tsgo.js +29 -0
  117. package/dist/esm/cli.js +19 -6
  118. package/dist/esm/client/index.d.ts +2 -2
  119. package/dist/esm/client/index.js +25 -25
  120. package/dist/esm/dev/index.js +88 -60
  121. package/dist/esm/dev/signin.d.ts +16 -0
  122. package/dist/esm/dev/signin.js +80 -0
  123. package/dist/esm/index.d.ts +5 -5
  124. package/dist/esm/index.js +3 -3
  125. package/dist/esm/integrations/client.d.ts +3 -3
  126. package/dist/esm/integrations/client.js +6 -5
  127. package/dist/esm/integrations/client.test-d.js +19 -19
  128. package/dist/esm/integrations/index.d.ts +2 -2
  129. package/dist/esm/integrations/index.js +1 -1
  130. package/dist/esm/integrations/rules.js +42 -42
  131. package/dist/esm/integrations/rules.test.js +62 -57
  132. package/dist/esm/internal/appMode.d.ts +14 -0
  133. package/dist/esm/internal/appMode.js +13 -0
  134. package/dist/esm/internal/env.js +3 -2
  135. package/dist/esm/internal/platformFetch.d.ts +2 -0
  136. package/dist/esm/internal/platformFetch.js +9 -0
  137. package/dist/esm/internal/reservedIds.d.ts +8 -0
  138. package/dist/esm/internal/reservedIds.js +10 -0
  139. package/dist/esm/internal/serviceUrls.d.ts +5 -0
  140. package/dist/esm/internal/serviceUrls.js +10 -0
  141. package/dist/esm/pdf/index.js +2 -1
  142. package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
  143. package/dist/esm/runtime/index.d.ts +22 -22
  144. package/dist/esm/runtime/index.js +31 -31
  145. package/dist/esm/runtime/index.test.js +36 -36
  146. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +30 -30
  147. package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
  148. package/dist/esm/signin/conformance.d.ts +100 -0
  149. package/dist/esm/signin/conformance.js +616 -0
  150. package/dist/esm/signin/cookies.d.ts +28 -0
  151. package/dist/esm/signin/cookies.js +67 -0
  152. package/dist/esm/signin/encoding.d.ts +1 -0
  153. package/dist/esm/signin/encoding.js +12 -0
  154. package/dist/esm/signin/endpoints.d.ts +12 -0
  155. package/dist/esm/signin/endpoints.js +32 -0
  156. package/dist/esm/signin/http.d.ts +25 -0
  157. package/dist/esm/signin/http.js +106 -0
  158. package/dist/esm/signin/index.d.ts +8 -0
  159. package/dist/esm/signin/index.js +9 -0
  160. package/dist/esm/signin/keys.d.ts +35 -0
  161. package/dist/esm/signin/keys.js +230 -0
  162. package/dist/esm/signin/paths.d.ts +2 -0
  163. package/dist/esm/signin/paths.js +5 -0
  164. package/dist/esm/signin/seal.d.ts +19 -0
  165. package/dist/esm/signin/seal.js +47 -0
  166. package/dist/esm/signin/signin.d.ts +60 -0
  167. package/dist/esm/signin/signin.js +447 -0
  168. package/dist/esm/signin/transport.d.ts +112 -0
  169. package/dist/esm/signin/transport.js +1 -0
  170. package/dist/esm/signin/verifier.d.ts +2 -0
  171. package/dist/esm/signin/verifier.js +4 -0
  172. package/dist/esm/signin/verify.d.ts +83 -0
  173. package/dist/esm/signin/verify.js +142 -0
  174. package/dist/esm/sourceRoots.js +17 -17
  175. package/dist/esm/sourceRoots.test.js +34 -32
  176. package/dist/esm/start/access.d.ts +19 -0
  177. package/dist/esm/start/access.js +43 -0
  178. package/dist/esm/start/auth.d.ts +28 -0
  179. package/dist/esm/start/auth.js +33 -0
  180. package/dist/esm/start/automations/quiet.d.ts +2 -0
  181. package/dist/esm/start/automations/quiet.js +36 -0
  182. package/dist/esm/start/automations/registration.d.ts +13 -0
  183. package/dist/esm/start/automations/registration.js +25 -0
  184. package/dist/esm/start/automations/steps.d.ts +29 -0
  185. package/dist/esm/start/automations/steps.js +95 -0
  186. package/dist/esm/start/automations/workflow.d.ts +83 -0
  187. package/dist/esm/start/automations/workflow.js +36 -0
  188. package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
  189. package/dist/esm/start/automations/workflow.test-d.js +130 -0
  190. package/dist/esm/start/automations/workflowRun.d.ts +130 -0
  191. package/dist/esm/start/automations/workflowRun.js +185 -0
  192. package/dist/esm/start/barrel.test-d.d.ts +10 -0
  193. package/dist/esm/start/barrel.test-d.js +6 -0
  194. package/dist/esm/start/build/entries.d.ts +25 -0
  195. package/dist/esm/start/build/entries.js +109 -0
  196. package/dist/esm/start/build/placeholders/authHooksModule.d.ts +1 -0
  197. package/dist/esm/start/build/placeholders/authHooksModule.js +3 -0
  198. package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
  199. package/dist/esm/start/build/placeholders/devApp.js +3 -0
  200. package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
  201. package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
  202. package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
  203. package/dist/esm/start/build/placeholders/siteHead.js +3 -0
  204. package/dist/esm/start/build/placeholders/workflowModules.d.ts +1 -0
  205. package/dist/esm/start/build/placeholders/workflowModules.js +3 -0
  206. package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
  207. package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
  208. package/dist/esm/start/build/registrationHash.d.ts +11 -0
  209. package/dist/esm/start/build/registrationHash.js +88 -0
  210. package/dist/esm/start/build/sdk/axios.d.ts +76 -0
  211. package/dist/esm/start/build/sdk/axios.js +253 -0
  212. package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
  213. package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
  214. package/dist/esm/start/build/sdk/undici.d.ts +34 -0
  215. package/dist/esm/start/build/sdk/undici.js +18 -0
  216. package/dist/esm/start/build/sdkPatches.d.ts +22 -0
  217. package/dist/esm/start/build/sdkPatches.js +430 -0
  218. package/dist/esm/start/build/siteHead.d.ts +26 -0
  219. package/dist/esm/start/build/siteHead.js +88 -0
  220. package/dist/esm/start/build/vite.d.ts +50 -0
  221. package/dist/esm/start/build/vite.js +487 -0
  222. package/dist/esm/start/classicOnly.d.ts +1 -0
  223. package/dist/esm/start/classicOnly.js +4 -0
  224. package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
  225. package/dist/esm/start/clientErrorMessage.test.js +105 -0
  226. package/dist/esm/start/describe/describe.d.ts +120 -0
  227. package/dist/esm/start/describe/describe.js +372 -0
  228. package/dist/esm/start/describe/describeBuilt.d.ts +5 -0
  229. package/dist/esm/start/describe/describeBuilt.js +102 -0
  230. package/dist/esm/start/describe/descriptions.d.ts +4 -0
  231. package/dist/esm/start/describe/descriptions.js +54 -0
  232. package/dist/esm/start/errors.d.ts +62 -0
  233. package/dist/esm/start/errors.js +163 -0
  234. package/dist/esm/start/errors.test.d.ts +1 -0
  235. package/dist/esm/start/errors.test.js +54 -0
  236. package/dist/esm/start/factories.d.ts +14 -0
  237. package/dist/esm/start/factories.js +23 -0
  238. package/dist/esm/start/factories.test-d.d.ts +2 -0
  239. package/dist/esm/start/factories.test-d.js +60 -0
  240. package/dist/esm/start/failures.d.ts +7 -0
  241. package/dist/esm/start/failures.js +62 -0
  242. package/dist/esm/start/fnFactory.d.ts +16 -0
  243. package/dist/esm/start/fnFactory.js +1 -0
  244. package/dist/esm/start/host.d.ts +3 -0
  245. package/dist/esm/start/host.js +4 -0
  246. package/dist/esm/start/index.d.ts +10 -0
  247. package/dist/esm/start/index.js +7 -0
  248. package/dist/esm/start/login.d.ts +5 -0
  249. package/dist/esm/start/login.js +29 -0
  250. package/dist/esm/start/middlewareKind.d.ts +13 -0
  251. package/dist/esm/start/middlewareKind.js +9 -0
  252. package/dist/esm/start/platform/aiUsage.d.ts +29 -0
  253. package/dist/esm/start/platform/aiUsage.js +210 -0
  254. package/dist/esm/start/platform/airtable/arrayFields.d.ts +10 -0
  255. package/dist/esm/start/platform/airtable/arrayFields.js +30 -0
  256. package/dist/esm/start/platform/airtable/built.d.ts +2 -0
  257. package/dist/esm/start/platform/airtable/built.js +3 -0
  258. package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
  259. package/dist/esm/start/platform/airtable/cache.js +89 -0
  260. package/dist/esm/start/platform/airtable/dispatch.d.ts +57 -0
  261. package/dist/esm/start/platform/airtable/dispatch.js +541 -0
  262. package/dist/esm/start/platform/airtable/formulas.d.ts +70 -0
  263. package/dist/esm/start/platform/airtable/formulas.js +261 -0
  264. package/dist/esm/start/platform/airtable/index.d.ts +6 -0
  265. package/dist/esm/start/platform/airtable/index.js +51 -0
  266. package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
  267. package/dist/esm/start/platform/airtable/settings.js +138 -0
  268. package/dist/esm/start/platform/analytics.d.ts +3 -0
  269. package/dist/esm/start/platform/analytics.js +59 -0
  270. package/dist/esm/start/platform/calls.d.ts +5 -0
  271. package/dist/esm/start/platform/calls.js +104 -0
  272. package/dist/esm/start/platform/caps.d.ts +9 -0
  273. package/dist/esm/start/platform/caps.js +35 -0
  274. package/dist/esm/start/platform/connections.d.ts +25 -0
  275. package/dist/esm/start/platform/connections.js +198 -0
  276. package/dist/esm/start/platform/data/baseRunner.d.ts +97 -0
  277. package/dist/esm/start/platform/data/baseRunner.js +117 -0
  278. package/dist/esm/start/platform/data/dispatch.d.ts +17 -0
  279. package/dist/esm/start/platform/data/dispatch.js +216 -0
  280. package/dist/esm/start/platform/data/fetch.d.ts +7 -0
  281. package/dist/esm/start/platform/data/fetch.js +9 -0
  282. package/dist/esm/start/platform/data/index.d.ts +27 -0
  283. package/dist/esm/start/platform/data/index.js +75 -0
  284. package/dist/esm/start/platform/data/names.d.ts +7 -0
  285. package/dist/esm/start/platform/data/names.js +18 -0
  286. package/dist/esm/start/platform/data/sqlNameMappings.d.ts +58 -0
  287. package/dist/esm/start/platform/data/sqlNameMappings.js +92 -0
  288. package/dist/esm/start/platform/data/transformations.d.ts +97 -0
  289. package/dist/esm/start/platform/data/transformations.js +262 -0
  290. package/dist/esm/start/platform/data/types.d.ts +94 -0
  291. package/dist/esm/start/platform/data/types.js +14 -0
  292. package/dist/esm/start/platform/local.d.ts +6 -0
  293. package/dist/esm/start/platform/local.js +18 -0
  294. package/dist/esm/start/platform/meta.d.ts +3 -0
  295. package/dist/esm/start/platform/meta.js +33 -0
  296. package/dist/esm/start/platform/outbound.d.ts +17 -0
  297. package/dist/esm/start/platform/outbound.js +510 -0
  298. package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
  299. package/dist/esm/start/platform/redactSecrets.js +156 -0
  300. package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
  301. package/dist/esm/start/platform/redactSecrets.test.js +151 -0
  302. package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
  303. package/dist/esm/start/platform/requestSecrets.js +41 -0
  304. package/dist/esm/start/platform/runLog.d.ts +40 -0
  305. package/dist/esm/start/platform/runLog.js +149 -0
  306. package/dist/esm/start/platform/services.d.ts +7 -0
  307. package/dist/esm/start/platform/services.js +46 -0
  308. package/dist/esm/start/platform/steps.d.ts +9 -0
  309. package/dist/esm/start/platform/steps.js +60 -0
  310. package/dist/esm/start/platform/telemetry.d.ts +13 -0
  311. package/dist/esm/start/platform/telemetry.js +71 -0
  312. package/dist/esm/start/platform/transport.d.ts +28 -0
  313. package/dist/esm/start/platform/transport.js +59 -0
  314. package/dist/esm/start/platformHead.d.ts +23 -0
  315. package/dist/esm/start/platformHead.js +133 -0
  316. package/dist/esm/start/previewClaim.d.ts +6 -0
  317. package/dist/esm/start/previewClaim.js +24 -0
  318. package/dist/esm/start/protocol.d.ts +19 -0
  319. package/dist/esm/start/protocol.js +27 -0
  320. package/dist/esm/start/roles.d.ts +12 -0
  321. package/dist/esm/start/roles.js +27 -0
  322. package/dist/esm/start/router.d.ts +44 -0
  323. package/dist/esm/start/router.js +280 -0
  324. package/dist/esm/start/serve/authHooks.d.ts +7 -0
  325. package/dist/esm/start/serve/authHooks.js +18 -0
  326. package/dist/esm/start/serve/demo.d.ts +9 -0
  327. package/dist/esm/start/serve/demo.js +24 -0
  328. package/dist/esm/start/serve/fetch.d.ts +1 -0
  329. package/dist/esm/start/serve/fetch.js +6 -0
  330. package/dist/esm/start/serve/instance.d.ts +12 -0
  331. package/dist/esm/start/serve/instance.js +134 -0
  332. package/dist/esm/start/serve/invoke.d.ts +13 -0
  333. package/dist/esm/start/serve/invoke.js +126 -0
  334. package/dist/esm/start/serve/local/load.d.ts +8 -0
  335. package/dist/esm/start/serve/local/load.js +44 -0
  336. package/dist/esm/start/serve/local/provider.d.ts +25 -0
  337. package/dist/esm/start/serve/local/provider.js +188 -0
  338. package/dist/esm/start/serve/local/signIn.d.ts +28 -0
  339. package/dist/esm/start/serve/local/signIn.js +123 -0
  340. package/dist/esm/start/serve/pageHead.d.ts +20 -0
  341. package/dist/esm/start/serve/pageHead.js +34 -0
  342. package/dist/esm/start/serve/provider.d.ts +19 -0
  343. package/dist/esm/start/serve/provider.js +78 -0
  344. package/dist/esm/start/serve/requestEnv.d.ts +2 -0
  345. package/dist/esm/start/serve/requestEnv.js +84 -0
  346. package/dist/esm/start/serve/scope.d.ts +18 -0
  347. package/dist/esm/start/serve/scope.js +67 -0
  348. package/dist/esm/start/serve/server.d.ts +56 -0
  349. package/dist/esm/start/serve/server.js +297 -0
  350. package/dist/esm/start/serve/uploads.d.ts +2 -0
  351. package/dist/esm/start/serve/uploads.js +49 -0
  352. package/dist/esm/start/serve/worker.d.ts +6 -0
  353. package/dist/esm/start/serve/worker.js +12 -0
  354. package/dist/esm/start/types.d.ts +373 -0
  355. package/dist/esm/start/types.js +1 -0
  356. package/dist/esm/start/version.d.ts +1 -0
  357. package/dist/esm/start/version.js +2 -0
  358. package/dist/esm/steps/index.d.ts +8 -8
  359. package/dist/esm/steps/index.js +54 -54
  360. package/dist/esm/steps/index.test.js +220 -220
  361. package/dist/esm/sync/index.d.ts +1 -1
  362. package/dist/esm/sync/index.js +32 -31
  363. package/dist/esm/sync/lib.d.ts +15 -8
  364. package/dist/esm/sync/lib.js +655 -669
  365. package/dist/esm/sync/lib.test.js +81 -14
  366. package/dist/esm/sync/sdkNames.d.ts +67 -9
  367. package/dist/esm/sync/sdkNames.js +94 -30
  368. package/dist/esm/sync/sdkNames.test.js +192 -116
  369. package/dist/esm/types/fields.d.ts +1 -1
  370. package/dist/esm/types/fields.js +106 -98
  371. package/dist/esm/types/index.d.ts +2 -2
  372. package/dist/esm/types/index.js +2 -2
  373. package/dist/esm/types/tables.d.ts +1 -1
  374. package/dist/esm/types/tables.js +2 -2
  375. package/dist/esm/upload/index.js +89 -24
  376. package/dist/esm/upload/index.test.js +104 -1
  377. package/dist/esm/vite/domTagNames.js +252 -252
  378. package/dist/esm/vite/index.d.ts +1 -1
  379. package/dist/esm/vite/index.js +56 -47
  380. package/dist/esm/vite/index.test.js +10 -2
  381. package/package.json +129 -16
  382. package/dist/cjs/auth-server/index.d.ts +0 -369
  383. package/dist/cjs/auth-server/index.js +0 -119
  384. package/dist/cjs/meta/index.d.ts +0 -14
  385. package/dist/cjs/meta/index.js +0 -12
  386. package/dist/cjs/notifications/index.d.ts +0 -25
  387. package/dist/cjs/notifications/index.js +0 -12
  388. package/dist/esm/auth-server/index.d.ts +0 -369
  389. package/dist/esm/auth-server/index.js +0 -116
  390. package/dist/esm/meta/index.d.ts +0 -14
  391. package/dist/esm/meta/index.js +0 -8
  392. package/dist/esm/notifications/index.d.ts +0 -25
  393. package/dist/esm/notifications/index.js +0 -8
@@ -0,0 +1,95 @@
1
+ import { createStepRuntime, isStepFailureMemo } from '../../steps/index.js';
2
+ import { ZITE_PLATFORM_FAULT_FLAG } from '../platform/data/types.js';
3
+ import { ZiteError } from '../errors.js';
4
+ // TanStack's words when a server function, or anything else reading the request, runs without one.
5
+ const NO_START_CONTEXT = 'No Start context found in AsyncLocalStorage';
6
+ /** @internal An automation runs outside any request: TanStack's error for that, as one naming the fix. */
7
+ export const asAutomationError = (error) => {
8
+ if (!(error instanceof Error) || !error.message.startsWith(NO_START_CONTEXT))
9
+ return error;
10
+ const explained = new ZiteError('INTERNAL_ERROR', "An automation can't call a server function: it runs outside any request. Move the shared logic into a *.server.ts helper and call that from both.");
11
+ // The frames say which call it was.
12
+ if (error.stack)
13
+ explained.stack = error.stack.replace(/^Error: .*/, `ZiteError: ${explained.message}`);
14
+ return explained;
15
+ };
16
+ const explainingErrors = async (run) => {
17
+ try {
18
+ return await run();
19
+ }
20
+ catch (error) {
21
+ throw asAutomationError(error);
22
+ }
23
+ };
24
+ // Inside the host's 300-second wait on the app, so a call whose step is stuck behind a stop still answers.
25
+ const SETTLE_DEADLINE_MS = 280_000;
26
+ /**
27
+ * Each completed step's result is saved before the code after it runs, so a resumed run gets it back instead of
28
+ * running the step's side effects again. Only a resumed run reads saved results, once, at its first step. Without
29
+ * `durable` a step's error reaches the code at once, as in classic's one-call runs.
30
+ */
31
+ export function createSteps({ store, resuming, durable, now = Date.now, }) {
32
+ // No prototype: a step named `__proto__` would otherwise set it.
33
+ const memos = Object.create(null);
34
+ const log = [];
35
+ let failedStep;
36
+ const runtime = createStepRuntime({
37
+ memos,
38
+ durable: durable !== undefined,
39
+ budgetMs: durable?.budgetMs,
40
+ attempts: durable?.attempts,
41
+ deadlineMs: SETTLE_DEADLINE_MS,
42
+ save: (name, value, durationMs) => store.persist(name, value, durationMs),
43
+ onEvent: (name, status, durationMs, extra) => {
44
+ const replayedFailure = extra?.failed === true;
45
+ if (status === 'failed' || replayedFailure)
46
+ failedStep ??= name;
47
+ log.push({
48
+ name,
49
+ status,
50
+ ...(durationMs !== undefined && { durationMs }),
51
+ at: now(),
52
+ ...(replayedFailure && { failed: true }),
53
+ ...(typeof extra?.wakeAt === 'string' && { wakeAt: extra.wakeAt }),
54
+ });
55
+ },
56
+ onPlatformFault: error => {
57
+ Object.assign(error, { [ZITE_PLATFORM_FAULT_FLAG]: true });
58
+ },
59
+ now,
60
+ });
61
+ // A resume tries a failed step again, as classic's does; only a durable run's later calls throw its saved failure.
62
+ const keepsFailures = (durable?.invocation ?? 1) > 1;
63
+ let readying;
64
+ let loading;
65
+ const loaded = () => (loading ??= resuming
66
+ ? store.load().then(saved => {
67
+ for (const [name, memo] of Object.entries(saved ?? {})) {
68
+ if (keepsFailures || !isStepFailureMemo(memo))
69
+ memos[name] = memo;
70
+ }
71
+ }, (err) => {
72
+ throw new Error(`Could not read this run's saved steps (${err instanceof Error ? err.message : String(err)}); nothing ran again. Resume it once more.`);
73
+ })
74
+ : Promise.resolve());
75
+ const step = {
76
+ run: async (name, fn, options) => {
77
+ await (readying ??= store.ready());
78
+ await loaded();
79
+ // Anything but a function goes as it is, for the runtime to refuse.
80
+ const run = typeof fn === 'function' ? () => explainingErrors(fn) : fn;
81
+ return runtime.step.run(name, run, options);
82
+ },
83
+ };
84
+ return {
85
+ step,
86
+ log,
87
+ failedStep: () => failedStep,
88
+ stopped: runtime.stopped,
89
+ stop: runtime.stop,
90
+ retry: runtime.retry,
91
+ suspension: runtime.suspension,
92
+ saved: runtime.saved,
93
+ settle: runtime.settle,
94
+ };
95
+ }
@@ -0,0 +1,83 @@
1
+ import type { ZiteTrigger, ZiteTriggerContext, ZiteTriggerSubscribe, ZiteTriggerUnsubscribe } from '../../backend/index.js';
2
+ import type { ZiteSchedule } from '../../schedules/index.js';
3
+ import type { StartStep } from './steps.js';
4
+ declare const WORKFLOW: unique symbol;
5
+ declare const UNFINISHED: unique symbol;
6
+ declare const PROVIDER_TRIGGER: unique symbol;
7
+ type ProviderTriggerBase = Extract<ZiteTrigger, {
8
+ every?: never;
9
+ events?: never;
10
+ table?: never;
11
+ form?: never;
12
+ }>;
13
+ /** What `createProviderTrigger` takes. */
14
+ export type ProviderTriggerConfig = ProviderTriggerBase & {
15
+ subscribe: ZiteTriggerSubscribe;
16
+ unsubscribe: ZiteTriggerUnsubscribe;
17
+ };
18
+ /**
19
+ * A provider trigger, registered with the provider by its `subscribe` when the
20
+ * app is published and taken down by its `unsubscribe` when it no longer is.
21
+ * Both run on the platform with only the trigger's own connection.
22
+ */
23
+ export type StartProviderTrigger = ProviderTriggerConfig & {
24
+ readonly [PROVIDER_TRIGGER]: true;
25
+ };
26
+ /**
27
+ * A provider trigger, in a module of its own that exports nothing else:
28
+ * `export const taskCompleted = createProviderTrigger({ integration, subscribe, unsubscribe })`, then
29
+ * `createAutomation({ description, trigger: taskCompleted })` in another. Publish registers it again whenever that module, or
30
+ * anything it imports, changes, and an edit to the automation alone leaves it registered.
31
+ */
32
+ export declare function createProviderTrigger(trigger: ProviderTriggerConfig): StartProviderTrigger;
33
+ /** Database and form triggers aren't supported in a Start automation yet. */
34
+ export type StartTrigger = Exclude<ZiteTrigger, ProviderTriggerBase | {
35
+ table: string;
36
+ } | {
37
+ form: string;
38
+ }> | StartProviderTrigger;
39
+ export type AutomationConfig = {
40
+ /** What this automation does, in a sentence. Shown in the editor. */
41
+ description: string;
42
+ } & ({
43
+ schedule: ZiteSchedule;
44
+ trigger?: never;
45
+ } | {
46
+ trigger: StartTrigger;
47
+ schedule?: never;
48
+ } | {
49
+ schedule?: never;
50
+ trigger?: never;
51
+ });
52
+ /**
53
+ * What an automation's handler gets. A trigger adds `trigger`, typed by the kind it declares.
54
+ * `step.run(name, fn)` runs `fn` once per run: its result is saved before the code after it,
55
+ * and a failed run resumed from run history replays completed steps from their saved results.
56
+ */
57
+ export type AutomationArgs<TConfig extends AutomationConfig> = {
58
+ input: unknown;
59
+ step: StartStep;
60
+ } & (TConfig extends {
61
+ trigger: infer T;
62
+ } ? {
63
+ trigger: ZiteTriggerContext<T>;
64
+ } : unknown);
65
+ export type Automation<TConfig extends AutomationConfig = AutomationConfig> = {
66
+ readonly [WORKFLOW]: true;
67
+ readonly config: TConfig;
68
+ readonly handler: (args: AutomationArgs<TConfig>) => unknown;
69
+ };
70
+ /**
71
+ * Scheduled or triggered work, in a `*.server.ts` file:
72
+ * `export const nightly = createAutomation({ description, schedule }).handler(async () => { ... })`.
73
+ * Only the platform runs it. It has no user and no URL, and reads data like a server function does.
74
+ */
75
+ export declare function createAutomation<const TConfig extends AutomationConfig>(config: TConfig & Record<Exclude<keyof TConfig, 'description' | 'schedule' | 'trigger'>, never>): {
76
+ [UNFINISHED]: boolean;
77
+ handler: (fn: (args: AutomationArgs<TConfig>) => unknown) => Automation<TConfig>;
78
+ };
79
+ export declare const isAutomation: (value: unknown) => value is Automation;
80
+ export declare const isProviderTrigger: (value: unknown) => value is StartProviderTrigger;
81
+ /** `createAutomation(...)` exported without its `.handler()`, which nothing would ever run. */
82
+ export declare const isUnfinishedAutomation: (value: unknown) => boolean;
83
+ export {};
@@ -0,0 +1,36 @@
1
+ // Shared across copies of zitejs in one bundle, like the access scope.
2
+ const WORKFLOW = Symbol.for('zitejs:workflow');
3
+ const UNFINISHED = Symbol.for('zitejs:automation-without-handler');
4
+ const PROVIDER_TRIGGER = Symbol.for('zitejs:provider-trigger');
5
+ /**
6
+ * A provider trigger, in a module of its own that exports nothing else:
7
+ * `export const taskCompleted = createProviderTrigger({ integration, subscribe, unsubscribe })`, then
8
+ * `createAutomation({ description, trigger: taskCompleted })` in another. Publish registers it again whenever that module, or
9
+ * anything it imports, changes, and an edit to the automation alone leaves it registered.
10
+ */
11
+ export function createProviderTrigger(trigger) {
12
+ // Not enumerable, so a copy made with a spread isn't one, and the description leaves it out.
13
+ return Object.defineProperty({ ...trigger }, PROVIDER_TRIGGER, {
14
+ value: true,
15
+ });
16
+ }
17
+ /**
18
+ * Scheduled or triggered work, in a `*.server.ts` file:
19
+ * `export const nightly = createAutomation({ description, schedule }).handler(async () => { ... })`.
20
+ * Only the platform runs it. It has no user and no URL, and reads data like a server function does.
21
+ */
22
+ export function createAutomation(
23
+ // Inferring TConfig skips the excess-key check, so a classic `{ handler }` in the config would typecheck.
24
+ config) {
25
+ return {
26
+ [UNFINISHED]: true,
27
+ handler: (fn) => ({ [WORKFLOW]: true, config, handler: fn }),
28
+ };
29
+ }
30
+ const tagged = (value, tag) => typeof value === 'object' &&
31
+ value !== null &&
32
+ value[tag] === true;
33
+ export const isAutomation = (value) => tagged(value, WORKFLOW);
34
+ export const isProviderTrigger = (value) => tagged(value, PROVIDER_TRIGGER);
35
+ /** `createAutomation(...)` exported without its `.handler()`, which nothing would ever run. */
36
+ export const isUnfinishedAutomation = (value) => tagged(value, UNFINISHED);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,130 @@
1
+ import { describe, expectTypeOf, it } from 'vitest';
2
+ import { createAutomation, createProviderTrigger } from './workflow.js';
3
+ describe('createAutomation handler args', () => {
4
+ it('gives a schedule no trigger', () => {
5
+ createAutomation({
6
+ description: 'Runs for this test',
7
+ schedule: {
8
+ scheduleType: 'oneTime',
9
+ fireAt: '2026-10-10T03:00:00Z',
10
+ timezone: 'UTC',
11
+ },
12
+ }).handler(args => {
13
+ expectTypeOf(args).toEqualTypeOf();
14
+ });
15
+ });
16
+ it('types the trigger by the kind it declares', () => {
17
+ createAutomation({
18
+ description: 'Runs for this test',
19
+ trigger: { every: '5m' },
20
+ }).handler(({ trigger }) => {
21
+ expectTypeOf(trigger).toEqualTypeOf();
22
+ });
23
+ createAutomation({
24
+ description: 'Runs for this test',
25
+ trigger: { integration: 'slack', events: ['message.channels'] },
26
+ }).handler(({ trigger }) => {
27
+ expectTypeOf(trigger).toEqualTypeOf();
28
+ });
29
+ const taskCompleted = createProviderTrigger({
30
+ integration: 'asana',
31
+ subscribe: async () => ({ externalId: 'w1' }),
32
+ unsubscribe: async () => { },
33
+ });
34
+ createAutomation({
35
+ description: 'Runs for this test',
36
+ trigger: taskCompleted,
37
+ }).handler(({ trigger }) => {
38
+ expectTypeOf(trigger).toEqualTypeOf();
39
+ });
40
+ });
41
+ it('registers a provider trigger with subscribe, and takes it down with unsubscribe', () => {
42
+ // @ts-expect-error nothing would register it with the provider
43
+ createProviderTrigger({ integration: 'asana' });
44
+ // @ts-expect-error its registration would outlive it
45
+ createProviderTrigger({
46
+ integration: 'asana',
47
+ subscribe: async () => ({ externalId: 'w1' }),
48
+ });
49
+ createProviderTrigger({
50
+ integration: 'github',
51
+ subscribe: input => {
52
+ expectTypeOf(input.notificationUrl).toEqualTypeOf();
53
+ return { externalId: '1', secret: input.secret };
54
+ },
55
+ unsubscribe: async () => { },
56
+ });
57
+ createProviderTrigger({
58
+ integration: 'asana',
59
+ subscribe: async () => ({ externalId: 'w1' }),
60
+ unsubscribe: async () => { },
61
+ // @ts-expect-error nor any key it doesn't know
62
+ retries: 3,
63
+ });
64
+ });
65
+ it('takes a provider trigger only from createProviderTrigger, never written inline', () => {
66
+ const subscribe = async () => ({ externalId: 'w1' });
67
+ const unsubscribe = async () => { };
68
+ createAutomation({
69
+ description: 'Runs for this test',
70
+ // @ts-expect-error a trigger's own module decides when it registers again
71
+ trigger: { integration: 'asana', subscribe, unsubscribe },
72
+ });
73
+ createAutomation({
74
+ description: 'Runs for this test',
75
+ // @ts-expect-error nothing would register it with the provider
76
+ trigger: { integration: 'asana' },
77
+ });
78
+ });
79
+ it('takes no database or form trigger yet, with or without subscribe', () => {
80
+ const subscribe = async () => ({ externalId: 'w1' });
81
+ createAutomation({
82
+ description: 'Runs for this test',
83
+ // @ts-expect-error a Start automation can't take a database trigger yet
84
+ trigger: { table: 'orders', on: ['created'], subscribe },
85
+ });
86
+ createAutomation({
87
+ description: 'Runs for this test',
88
+ // @ts-expect-error nor a form trigger
89
+ trigger: { form: 'Intake', on: ['submitted'], subscribe },
90
+ });
91
+ });
92
+ it('needs neither when only schedules added at runtime run it', () => {
93
+ createAutomation({ description: 'Sends one reminder' }).handler(args => {
94
+ expectTypeOf(args).toEqualTypeOf();
95
+ });
96
+ });
97
+ it('gives every workflow step.run, typed by what its function returns', () => {
98
+ createAutomation({
99
+ description: 'Runs for this test',
100
+ trigger: { every: '5m' },
101
+ }).handler(async ({ step }) => {
102
+ expectTypeOf(await step.run('load', async () => ({ id: 7 }))).toEqualTypeOf();
103
+ expectTypeOf(await step.run('count', () => 3)).toEqualTypeOf();
104
+ });
105
+ });
106
+ it("takes its function in .handler(), not in its config as classic's does", () => {
107
+ createAutomation({
108
+ description: 'Runs for this test',
109
+ trigger: { every: '5m' },
110
+ // @ts-expect-error nothing would run it
111
+ handler: async () => { },
112
+ });
113
+ // @ts-expect-error nor any other key it doesn't know
114
+ createAutomation({ description: 'Nightly', retries: 3 });
115
+ });
116
+ it('takes a description, as server functions and API routes do', () => {
117
+ // @ts-expect-error the editor shows what each automation does
118
+ createAutomation({ trigger: { every: '5m' } });
119
+ // @ts-expect-error even one only runtime schedules run
120
+ createAutomation({});
121
+ });
122
+ it('takes a schedule or a trigger, not both', () => {
123
+ // @ts-expect-error an automation runs on one or the other
124
+ createAutomation({
125
+ description: 'Runs for this test',
126
+ schedule: { scheduleType: 'oneTime', fireAt: 'x', timezone: 'UTC' },
127
+ trigger: { every: '5m' },
128
+ });
129
+ });
130
+ });
@@ -0,0 +1,130 @@
1
+ import type { StepRetry, StepSuspension } from '../../steps/index.js';
2
+ import { type StepStore } from '../platform/steps.js';
3
+ import { type StepLog } from './steps.js';
4
+ import type { DurableCall } from '../types.js';
5
+ import { type Automation, type StartProviderTrigger } from './workflow.js';
6
+ export type TriggerReport = {
7
+ handled: string[];
8
+ cursor?: string;
9
+ };
10
+ /**
11
+ * How the call ended. `finished` and `failed` end the run. Only a durable call stops short: `retry` when a step threw
12
+ * with tries left, `suspended` when it ran out of time (`suspension.kind` is `step`).
13
+ */
14
+ export type WorkflowStop = 'finished' | 'failed' | 'retry' | 'suspended';
15
+ /** `stepsSaved`: the steps this call saved, which the run's next call or a resume replays. */
16
+ type StepsRan = {
17
+ steps?: StepLog[];
18
+ stepsSaved: number;
19
+ };
20
+ type RunError = {
21
+ code: string;
22
+ message: string;
23
+ };
24
+ export type WorkflowRunResult = ({
25
+ ok: true;
26
+ stop: 'finished';
27
+ output: unknown;
28
+ trigger?: TriggerReport;
29
+ } & StepsRan) | ({
30
+ ok: true;
31
+ stop: 'suspended';
32
+ suspension: StepSuspension;
33
+ trigger?: TriggerReport;
34
+ } & StepsRan) | ({
35
+ ok: false;
36
+ stop: 'failed';
37
+ error: RunError;
38
+ trigger?: TriggerReport;
39
+ failedStep?: string;
40
+ } & StepsRan) | ({
41
+ ok: false;
42
+ stop: 'retry';
43
+ error: RunError;
44
+ retry: StepRetry;
45
+ failedStep: string;
46
+ trigger?: TriggerReport;
47
+ } & StepsRan);
48
+ /**
49
+ * Splits the platform's state out of the input. A poll or a provider delivery
50
+ * with a cursor gets `seen`, `handled` and `advance`. Handled ids are reported
51
+ * whether or not the run throws, so an item acted on is never acted on again;
52
+ * the staged cursor only on success. Only ids the incoming `seen` lacked are
53
+ * reported: billing reads an empty list as a run that found nothing new.
54
+ */
55
+ export declare function triggerContext(workflow: Automation, rawInput: unknown): {
56
+ input: unknown;
57
+ trigger?: undefined;
58
+ report?: undefined;
59
+ } | {
60
+ input: {
61
+ [x: string]: unknown;
62
+ };
63
+ trigger: {
64
+ provider: string;
65
+ deliveryId?: string | undefined;
66
+ headers: Record<string, unknown>;
67
+ } | {
68
+ headers?: undefined;
69
+ } | {
70
+ headers: {};
71
+ };
72
+ report?: undefined;
73
+ } | {
74
+ input: {
75
+ [x: string]: unknown;
76
+ };
77
+ trigger: {
78
+ provider: string;
79
+ deliveryId?: string | undefined;
80
+ headers: Record<string, unknown>;
81
+ cursor: string | null;
82
+ seen: (id: string) => boolean;
83
+ handled: (id: string) => void;
84
+ advance: (cursor: string) => void;
85
+ } | {
86
+ headers?: undefined;
87
+ cursor: string | null;
88
+ seen: (id: string) => boolean;
89
+ handled: (id: string) => void;
90
+ advance: (cursor: string) => void;
91
+ } | {
92
+ headers: {};
93
+ cursor: string | null;
94
+ seen: (id: string) => boolean;
95
+ handled: (id: string) => void;
96
+ advance: (cursor: string) => void;
97
+ };
98
+ report: (succeeded: boolean) => TriggerReport;
99
+ };
100
+ /**
101
+ * Runs the handler in a workflow access scope: no user, and data calls allowed.
102
+ * A resumed run replays the steps its first attempt saved.
103
+ */
104
+ export declare function runWorkflow(workflow: Automation, rawInput: unknown, { resuming, durable, store, }?: {
105
+ resuming?: boolean;
106
+ durable?: DurableCall;
107
+ store?: StepStore;
108
+ }): Promise<WorkflowRunResult>;
109
+ export type LoadedWorkflow = {
110
+ id: string;
111
+ file: string;
112
+ workflow: Automation;
113
+ };
114
+ /** Every exported workflow in the app, by export name. */
115
+ export declare function loadWorkflows(modules?: Record<string, () => Promise<Record<string, unknown>>>): Promise<LoadedWorkflow[]>;
116
+ /** Each `createAutomation(...)` exported without its `.handler()`, by export name: describe refuses them. */
117
+ export declare function loadUnfinishedWorkflows(modules?: Record<string, () => Promise<Record<string, unknown>>>): Promise<Array<{
118
+ id: string;
119
+ file: string;
120
+ }>>;
121
+ export type LoadedTrigger = {
122
+ id: string;
123
+ file: string;
124
+ trigger: StartProviderTrigger;
125
+ };
126
+ /** Every provider trigger an app module exports, by export name: describe finds each automation's trigger module. */
127
+ export declare function loadProviderTriggers(modules?: Record<string, () => Promise<Record<string, unknown>>>): Promise<LoadedTrigger[]>;
128
+ /** The input as the run log keeps it: a trigger's `seen` list can hold thousands of ids. */
129
+ export declare const loggedInput: (rawInput: unknown) => unknown;
130
+ export {};
@@ -0,0 +1,185 @@
1
+ import { errorOf } from '../platform/runLog.js';
2
+ import { platformSteps } from '../platform/steps.js';
3
+ import { getHost, runInScope } from '../serve/scope.js';
4
+ import { asAutomationError, createSteps } from './steps.js';
5
+ import { isAutomation, isProviderTrigger, isUnfinishedAutomation, } from './workflow.js';
6
+ import { workflowModules } from '../build/placeholders/workflowModules.js';
7
+ const asRecord = (value) => value && typeof value === 'object' && !Array.isArray(value)
8
+ ? value
9
+ : null;
10
+ const idOf = (id) => {
11
+ if (typeof id !== 'string' && typeof id !== 'number')
12
+ throw new TypeError(`trigger ids must be strings, got ${typeof id}`);
13
+ const value = String(id);
14
+ if (value.length === 0 || value.length > 512)
15
+ throw new TypeError('trigger ids must be 1 to 512 characters');
16
+ return value;
17
+ };
18
+ /**
19
+ * Splits the platform's state out of the input. A poll or a provider delivery
20
+ * with a cursor gets `seen`, `handled` and `advance`. Handled ids are reported
21
+ * whether or not the run throws, so an item acted on is never acted on again;
22
+ * the staged cursor only on success. Only ids the incoming `seen` lacked are
23
+ * reported: billing reads an empty list as a run that found nothing new.
24
+ */
25
+ export function triggerContext(workflow, rawInput) {
26
+ const raw = asRecord(rawInput);
27
+ // `__cron` stays in the input, as on classic: scheduled code reads its scheduleId and scheduledAt there.
28
+ const { __poll, __webhook, ...input } = raw ?? {};
29
+ const declared = workflow.config.trigger;
30
+ if (!declared)
31
+ return { input: raw ? input : rawInput };
32
+ const poll = asRecord(__poll);
33
+ const webhook = asRecord(__webhook);
34
+ const delivery = typeof webhook?.provider === 'string' ? webhook : null;
35
+ // A run with no trigger state, such as a manual one, still gets a trigger: an empty one.
36
+ const info = delivery
37
+ ? {
38
+ headers: asRecord(delivery.headers) ?? {},
39
+ ...(typeof delivery.deliveryId === 'string'
40
+ ? { deliveryId: delivery.deliveryId }
41
+ : {}),
42
+ provider: delivery.provider,
43
+ }
44
+ : declared.every
45
+ ? {}
46
+ : { headers: {} };
47
+ if (!poll && declared.events)
48
+ return { input, trigger: info };
49
+ const state = poll ?? delivery ?? {};
50
+ const known = new Set(Array.isArray(state.seen) ? state.seen.map(String) : []);
51
+ const handled = [];
52
+ let staged;
53
+ const trigger = {
54
+ cursor: typeof state.cursor === 'string' ? state.cursor : null,
55
+ seen: (id) => known.has(String(id)),
56
+ handled: (id) => {
57
+ const value = idOf(id);
58
+ if (known.has(value))
59
+ return;
60
+ known.add(value);
61
+ handled.push(value);
62
+ },
63
+ advance: (cursor) => {
64
+ if (typeof cursor !== 'string' || cursor.length > 4096) {
65
+ throw new TypeError('trigger.advance takes a string of at most 4096 characters');
66
+ }
67
+ staged = cursor;
68
+ },
69
+ ...info,
70
+ };
71
+ const report = (succeeded) => ({
72
+ handled: handled.slice(-2000),
73
+ ...(succeeded && staged !== undefined ? { cursor: staged } : {}),
74
+ });
75
+ return { input, trigger, report };
76
+ }
77
+ /**
78
+ * Runs the handler in a workflow access scope: no user, and data calls allowed.
79
+ * A resumed run replays the steps its first attempt saved.
80
+ */
81
+ export async function runWorkflow(workflow, rawInput, { resuming = false, durable, store = platformSteps(getHost()), } = {}) {
82
+ const { input, trigger, report } = triggerContext(workflow, rawInput);
83
+ const steps = createSteps({ store, resuming, durable });
84
+ const args = {
85
+ input,
86
+ step: steps.step,
87
+ ...(trigger ? { trigger } : {}),
88
+ };
89
+ const handled = (async () => runInScope({ kind: 'workflow', user: null }, () => workflow.handler(args)))().then((output) => ({ output }), (error) => ({ error: asAutomationError(error) }));
90
+ // A stopped step never settles, so the code awaiting it never returns: the stop ends the call instead.
91
+ const ended = await Promise.race([
92
+ handled,
93
+ steps.stopped.then(() => undefined),
94
+ ]);
95
+ // A step still working when a sibling threw or the call stopped saves before the answer.
96
+ await steps.settle();
97
+ const ran = {
98
+ ...(steps.log.length > 0 ? { steps: steps.log } : {}),
99
+ stepsSaved: steps.saved(),
100
+ };
101
+ const reported = (succeeded) => report ? { trigger: report(succeeded) } : {};
102
+ // A stop decides how the call ends, whatever the code did after it.
103
+ const stop = steps.stop();
104
+ const retry = steps.retry();
105
+ if (stop?.kind === 'retry' && retry) {
106
+ return {
107
+ ok: false,
108
+ stop: 'retry',
109
+ error: errorOf(stop.error),
110
+ retry,
111
+ failedStep: retry.step,
112
+ ...reported(false),
113
+ ...ran,
114
+ };
115
+ }
116
+ const suspension = steps.suspension();
117
+ if (suspension)
118
+ return {
119
+ ok: true,
120
+ stop: 'suspended',
121
+ suspension,
122
+ ...reported(false),
123
+ ...ran,
124
+ };
125
+ if (ended && 'output' in ended)
126
+ return {
127
+ ok: true,
128
+ stop: 'finished',
129
+ output: ended.output,
130
+ ...reported(true),
131
+ ...ran,
132
+ };
133
+ const failedStep = steps.failedStep();
134
+ return {
135
+ ok: false,
136
+ stop: 'failed',
137
+ error: errorOf(ended?.error),
138
+ ...reported(false),
139
+ ...(failedStep !== undefined ? { failedStep } : {}),
140
+ ...ran,
141
+ };
142
+ }
143
+ /** Every exported workflow in the app, by export name. */
144
+ export async function loadWorkflows(modules = workflowModules) {
145
+ const found = [];
146
+ for (const [file, load] of Object.entries(modules)) {
147
+ for (const [id, value] of Object.entries(await load()))
148
+ if (isAutomation(value))
149
+ found.push({ id, file, workflow: value });
150
+ }
151
+ return found;
152
+ }
153
+ /** Each `createAutomation(...)` exported without its `.handler()`, by export name: describe refuses them. */
154
+ export async function loadUnfinishedWorkflows(modules = workflowModules) {
155
+ const found = [];
156
+ for (const [file, load] of Object.entries(modules)) {
157
+ for (const [id, value] of Object.entries(await load()))
158
+ if (isUnfinishedAutomation(value))
159
+ found.push({ id, file });
160
+ }
161
+ return found;
162
+ }
163
+ /** Every provider trigger an app module exports, by export name: describe finds each automation's trigger module. */
164
+ export async function loadProviderTriggers(modules = workflowModules) {
165
+ const found = [];
166
+ for (const [file, load] of Object.entries(modules)) {
167
+ for (const [id, value] of Object.entries(await load()))
168
+ if (isProviderTrigger(value))
169
+ found.push({ id, file, trigger: value });
170
+ }
171
+ return found;
172
+ }
173
+ /** The input as the run log keeps it: a trigger's `seen` list can hold thousands of ids. */
174
+ export const loggedInput = (rawInput) => {
175
+ const raw = asRecord(rawInput);
176
+ if (!raw)
177
+ return rawInput;
178
+ const out = { ...raw };
179
+ for (const key of ['__poll', '__webhook']) {
180
+ const state = asRecord(raw[key]);
181
+ if (state && Array.isArray(state.seen))
182
+ out[key] = { ...state, seen: `[${state.seen.length} ids]` };
183
+ }
184
+ return out;
185
+ };
@@ -0,0 +1,10 @@
1
+ import type { HostProps as FromBarrel } from './index.js';
2
+ import { setFailedStatus } from './index.js';
3
+ import { ziteMiddlewareKind } from './index.js';
4
+ import { ZITE_ERROR_STATUS } from './index.js';
5
+ export type Unexported = [
6
+ FromBarrel,
7
+ typeof setFailedStatus,
8
+ typeof ziteMiddlewareKind,
9
+ typeof ZITE_ERROR_STATUS
10
+ ];
@@ -0,0 +1,6 @@
1
+ import { describe, expectTypeOf, it } from 'vitest';
2
+ describe('zitejs/start/protocol', () => {
3
+ it("carries the host's types", () => {
4
+ expectTypeOf().toEqualTypeOf();
5
+ });
6
+ });