zitejs 0.10.0-start.3 → 0.10.0-start.30

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 (414) 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 +123 -5
  14. package/dist/cjs/backend/index.js +13 -13
  15. package/dist/cjs/backend/index.test.js +144 -86
  16. package/dist/cjs/bundle/index.d.ts +8 -0
  17. package/dist/cjs/bundle/index.js +38 -24
  18. package/dist/cjs/caller/index.js +43 -43
  19. package/dist/cjs/check/index.d.ts +44 -1
  20. package/dist/cjs/check/index.js +188 -113
  21. package/dist/cjs/check/start/routeTree.d.ts +8 -0
  22. package/dist/cjs/check/start/routeTree.js +118 -0
  23. package/dist/cjs/check/start/tsgo.d.ts +2 -0
  24. package/dist/cjs/check/start/tsgo.js +35 -0
  25. package/dist/cjs/cli.js +10 -4
  26. package/dist/cjs/client/index.d.ts +26 -2
  27. package/dist/cjs/client/index.js +25 -25
  28. package/dist/cjs/dev/index.js +79 -54
  29. package/dist/cjs/dev/signin.d.ts +16 -0
  30. package/dist/cjs/dev/signin.js +84 -0
  31. package/dist/cjs/index.d.ts +5 -5
  32. package/dist/cjs/integrations/client.d.ts +3 -3
  33. package/dist/cjs/integrations/client.js +5 -4
  34. package/dist/cjs/integrations/client.test-d.js +15 -15
  35. package/dist/cjs/integrations/index.d.ts +2 -2
  36. package/dist/cjs/integrations/rules.d.ts +14 -0
  37. package/dist/cjs/integrations/rules.js +67 -33
  38. package/dist/cjs/integrations/rules.test.js +60 -53
  39. package/dist/cjs/internal/appMode.d.ts +14 -0
  40. package/dist/cjs/internal/appMode.js +19 -0
  41. package/dist/cjs/internal/env.js +3 -2
  42. package/dist/cjs/internal/platformFetch.d.ts +2 -0
  43. package/dist/cjs/internal/platformFetch.js +14 -0
  44. package/dist/cjs/internal/reservedIds.d.ts +8 -0
  45. package/dist/cjs/internal/reservedIds.js +14 -0
  46. package/dist/cjs/internal/serviceUrls.d.ts +5 -0
  47. package/dist/cjs/internal/serviceUrls.js +14 -0
  48. package/dist/cjs/pdf/index.js +2 -1
  49. package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
  50. package/dist/cjs/runtime/index.d.ts +126 -39
  51. package/dist/cjs/runtime/index.js +32 -26
  52. package/dist/cjs/runtime/index.test.js +34 -34
  53. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +50 -0
  54. package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
  55. package/dist/cjs/sourceRoots.js +15 -15
  56. package/dist/cjs/sourceRoots.test.js +29 -27
  57. package/dist/cjs/start/{entries.d.ts → build/entries.d.ts} +13 -4
  58. package/dist/cjs/start/{entries.js → build/entries.js} +49 -21
  59. package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
  60. package/dist/cjs/start/build/placeholders/devApp.js +6 -0
  61. package/dist/{esm/start → cjs/start/describe}/describeBuilt.d.ts +2 -0
  62. package/dist/cjs/start/{describeBuilt.js → describe/describeBuilt.js} +55 -17
  63. package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
  64. package/dist/cjs/start/platform/aiUsage.js +215 -0
  65. package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
  66. package/dist/cjs/start/platform/airtable/cache.js +93 -0
  67. package/dist/cjs/start/protocol.d.ts +19 -0
  68. package/dist/cjs/start/protocol.js +33 -0
  69. package/dist/cjs/start/serve/local/provider.d.ts +25 -0
  70. package/dist/cjs/start/serve/local/provider.js +196 -0
  71. package/dist/cjs/start/serve/provider.d.ts +19 -0
  72. package/dist/cjs/start/serve/provider.js +86 -0
  73. package/dist/cjs/start/types.d.ts +373 -0
  74. package/dist/cjs/start/types.js +2 -0
  75. package/dist/cjs/steps/index.d.ts +78 -0
  76. package/dist/cjs/steps/index.js +507 -0
  77. package/dist/cjs/steps/index.test.d.ts +1 -0
  78. package/dist/cjs/steps/index.test.js +635 -0
  79. package/dist/cjs/sync/index.d.ts +1 -1
  80. package/dist/cjs/sync/index.js +28 -27
  81. package/dist/cjs/sync/lib.d.ts +15 -8
  82. package/dist/cjs/sync/lib.js +660 -663
  83. package/dist/cjs/sync/lib.test.js +177 -46
  84. package/dist/cjs/sync/sdkNames.d.ts +67 -9
  85. package/dist/cjs/sync/sdkNames.js +97 -31
  86. package/dist/cjs/sync/sdkNames.test.js +189 -113
  87. package/dist/cjs/types/fields.d.ts +9 -2
  88. package/dist/cjs/types/fields.js +110 -96
  89. package/dist/cjs/types/index.d.ts +2 -2
  90. package/dist/cjs/types/tables.d.ts +17 -1
  91. package/dist/cjs/upload/index.js +89 -24
  92. package/dist/cjs/upload/index.test.js +104 -1
  93. package/dist/cjs/vite/domTagNames.js +252 -252
  94. package/dist/cjs/vite/index.d.ts +1 -1
  95. package/dist/cjs/vite/index.js +51 -42
  96. package/dist/cjs/vite/index.test.js +10 -2
  97. package/dist/esm/auth/actions.d.ts +28 -0
  98. package/dist/esm/auth/actions.js +55 -0
  99. package/dist/esm/auth/client.d.ts +357 -0
  100. package/dist/esm/auth/client.js +62 -0
  101. package/dist/esm/auth/config.js +9 -3
  102. package/dist/esm/auth/index.d.ts +2 -249
  103. package/dist/esm/auth/index.js +2 -103
  104. package/dist/esm/auth/index.test.js +60 -0
  105. package/dist/esm/auth/previewClaim.d.ts +7 -0
  106. package/dist/esm/auth/previewClaim.js +12 -0
  107. package/dist/esm/auth/profileUpdates.d.ts +9 -0
  108. package/dist/esm/auth/profileUpdates.js +6 -0
  109. package/dist/esm/backend/index.d.ts +123 -5
  110. package/dist/esm/backend/index.js +13 -13
  111. package/dist/esm/backend/index.test.js +148 -90
  112. package/dist/esm/bundle/index.d.ts +8 -0
  113. package/dist/esm/bundle/index.js +37 -24
  114. package/dist/esm/caller/index.js +44 -44
  115. package/dist/esm/check/index.d.ts +44 -1
  116. package/dist/esm/check/index.js +187 -116
  117. package/dist/esm/check/start/routeTree.d.ts +8 -0
  118. package/dist/esm/check/start/routeTree.js +77 -0
  119. package/dist/esm/check/start/tsgo.d.ts +2 -0
  120. package/dist/esm/check/start/tsgo.js +29 -0
  121. package/dist/esm/cli.js +10 -4
  122. package/dist/esm/client/index.d.ts +26 -2
  123. package/dist/esm/client/index.js +25 -25
  124. package/dist/esm/dev/index.js +86 -61
  125. package/dist/esm/dev/signin.d.ts +16 -0
  126. package/dist/esm/dev/signin.js +80 -0
  127. package/dist/esm/index.d.ts +5 -5
  128. package/dist/esm/index.js +3 -3
  129. package/dist/esm/integrations/client.d.ts +3 -3
  130. package/dist/esm/integrations/client.js +6 -5
  131. package/dist/esm/integrations/client.test-d.js +19 -19
  132. package/dist/esm/integrations/index.d.ts +2 -2
  133. package/dist/esm/integrations/index.js +1 -1
  134. package/dist/esm/integrations/rules.d.ts +14 -0
  135. package/dist/esm/integrations/rules.js +67 -33
  136. package/dist/esm/integrations/rules.test.js +62 -55
  137. package/dist/esm/internal/appMode.d.ts +14 -0
  138. package/dist/esm/internal/appMode.js +13 -0
  139. package/dist/esm/internal/env.js +3 -2
  140. package/dist/esm/internal/platformFetch.d.ts +2 -0
  141. package/dist/esm/internal/platformFetch.js +9 -0
  142. package/dist/esm/internal/reservedIds.d.ts +8 -0
  143. package/dist/esm/internal/reservedIds.js +10 -0
  144. package/dist/esm/internal/serviceUrls.d.ts +5 -0
  145. package/dist/esm/internal/serviceUrls.js +10 -0
  146. package/dist/esm/pdf/index.js +2 -1
  147. package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
  148. package/dist/esm/runtime/index.d.ts +126 -39
  149. package/dist/esm/runtime/index.js +35 -29
  150. package/dist/esm/runtime/index.test.js +36 -36
  151. package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  152. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +48 -0
  153. package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
  154. package/dist/esm/signin/conformance.d.ts +100 -0
  155. package/dist/esm/signin/conformance.js +616 -0
  156. package/dist/esm/signin/cookies.d.ts +28 -0
  157. package/dist/esm/signin/cookies.js +67 -0
  158. package/dist/esm/signin/encoding.d.ts +1 -0
  159. package/dist/esm/signin/encoding.js +12 -0
  160. package/dist/esm/signin/endpoints.d.ts +12 -0
  161. package/dist/esm/signin/endpoints.js +32 -0
  162. package/dist/esm/signin/http.d.ts +25 -0
  163. package/dist/esm/signin/http.js +106 -0
  164. package/dist/esm/signin/index.d.ts +8 -0
  165. package/dist/esm/signin/index.js +9 -0
  166. package/dist/esm/signin/keys.d.ts +35 -0
  167. package/dist/esm/signin/keys.js +230 -0
  168. package/dist/esm/signin/paths.d.ts +2 -0
  169. package/dist/esm/signin/paths.js +5 -0
  170. package/dist/esm/signin/seal.d.ts +19 -0
  171. package/dist/esm/signin/seal.js +47 -0
  172. package/dist/esm/signin/signin.d.ts +60 -0
  173. package/dist/esm/signin/signin.js +447 -0
  174. package/dist/esm/signin/transport.d.ts +112 -0
  175. package/dist/esm/signin/transport.js +1 -0
  176. package/dist/esm/signin/verifier.d.ts +2 -0
  177. package/dist/esm/signin/verifier.js +4 -0
  178. package/dist/esm/signin/verify.d.ts +83 -0
  179. package/dist/esm/signin/verify.js +142 -0
  180. package/dist/esm/sourceRoots.js +17 -17
  181. package/dist/esm/sourceRoots.test.js +34 -32
  182. package/dist/esm/start/access.d.ts +19 -0
  183. package/dist/esm/start/access.js +43 -0
  184. package/dist/esm/start/auth.d.ts +28 -0
  185. package/dist/esm/start/auth.js +33 -0
  186. package/dist/esm/start/automations/quiet.d.ts +2 -0
  187. package/dist/esm/start/automations/quiet.js +36 -0
  188. package/dist/esm/start/automations/registration.d.ts +13 -0
  189. package/dist/esm/start/automations/registration.js +25 -0
  190. package/dist/esm/start/automations/steps.d.ts +29 -0
  191. package/dist/esm/start/automations/steps.js +95 -0
  192. package/dist/esm/start/automations/workflow.d.ts +83 -0
  193. package/dist/esm/start/automations/workflow.js +36 -0
  194. package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
  195. package/dist/esm/start/automations/workflow.test-d.js +130 -0
  196. package/dist/esm/start/automations/workflowRun.d.ts +130 -0
  197. package/dist/esm/start/automations/workflowRun.js +185 -0
  198. package/dist/esm/start/barrel.test-d.d.ts +10 -0
  199. package/dist/esm/start/barrel.test-d.js +6 -0
  200. package/dist/esm/start/{entries.d.ts → build/entries.d.ts} +13 -4
  201. package/dist/esm/start/build/entries.js +109 -0
  202. package/dist/esm/start/build/placeholders/authHooksModule.d.ts +1 -0
  203. package/dist/esm/start/build/placeholders/authHooksModule.js +3 -0
  204. package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
  205. package/dist/esm/start/build/placeholders/devApp.js +3 -0
  206. package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
  207. package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
  208. package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
  209. package/dist/esm/start/build/placeholders/siteHead.js +3 -0
  210. package/dist/esm/start/{workflowModules.js → build/placeholders/workflowModules.js} +1 -1
  211. package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
  212. package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
  213. package/dist/esm/start/build/registrationHash.d.ts +11 -0
  214. package/dist/esm/start/build/registrationHash.js +88 -0
  215. package/dist/esm/start/build/sdk/axios.d.ts +76 -0
  216. package/dist/esm/start/build/sdk/axios.js +253 -0
  217. package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
  218. package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
  219. package/dist/esm/start/build/sdk/undici.d.ts +34 -0
  220. package/dist/esm/start/build/sdk/undici.js +18 -0
  221. package/dist/esm/start/build/sdkPatches.d.ts +22 -0
  222. package/dist/esm/start/build/sdkPatches.js +430 -0
  223. package/dist/esm/start/build/siteHead.d.ts +26 -0
  224. package/dist/esm/start/build/siteHead.js +88 -0
  225. package/dist/esm/start/build/vite.d.ts +50 -0
  226. package/dist/esm/start/build/vite.js +487 -0
  227. package/dist/esm/start/classicOnly.d.ts +1 -0
  228. package/dist/esm/start/classicOnly.js +4 -0
  229. package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
  230. package/dist/esm/start/clientErrorMessage.test.js +105 -0
  231. package/dist/esm/start/describe/describe.d.ts +120 -0
  232. package/dist/esm/start/describe/describe.js +372 -0
  233. package/dist/{cjs/start → esm/start/describe}/describeBuilt.d.ts +2 -0
  234. package/dist/esm/start/describe/describeBuilt.js +102 -0
  235. package/dist/esm/start/{descriptions.js → describe/descriptions.js} +17 -10
  236. package/dist/esm/start/errors.d.ts +62 -0
  237. package/dist/esm/start/errors.js +163 -0
  238. package/dist/esm/start/errors.test.d.ts +1 -0
  239. package/dist/esm/start/errors.test.js +54 -0
  240. package/dist/esm/start/factories.d.ts +14 -0
  241. package/dist/esm/start/factories.js +23 -0
  242. package/dist/esm/start/factories.test-d.d.ts +2 -0
  243. package/dist/esm/start/factories.test-d.js +60 -0
  244. package/dist/esm/start/failures.d.ts +7 -0
  245. package/dist/esm/start/failures.js +62 -0
  246. package/dist/esm/start/fnFactory.d.ts +16 -0
  247. package/dist/esm/start/fnFactory.js +1 -0
  248. package/dist/esm/start/host.d.ts +2 -2
  249. package/dist/esm/start/host.js +3 -3
  250. package/dist/esm/start/index.d.ts +10 -70
  251. package/dist/esm/start/index.js +7 -152
  252. package/dist/esm/start/login.d.ts +5 -0
  253. package/dist/esm/start/login.js +29 -0
  254. package/dist/esm/start/middlewareKind.d.ts +13 -0
  255. package/dist/esm/start/middlewareKind.js +9 -0
  256. package/dist/esm/start/platform/aiUsage.d.ts +29 -0
  257. package/dist/esm/start/platform/aiUsage.js +210 -0
  258. package/dist/esm/start/platform/airtable/arrayFields.d.ts +10 -0
  259. package/dist/esm/start/platform/airtable/arrayFields.js +30 -0
  260. package/dist/esm/start/platform/airtable/built.d.ts +2 -0
  261. package/dist/esm/start/platform/airtable/built.js +3 -0
  262. package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
  263. package/dist/esm/start/platform/airtable/cache.js +89 -0
  264. package/dist/esm/start/platform/airtable/dispatch.d.ts +57 -0
  265. package/dist/esm/start/platform/airtable/dispatch.js +541 -0
  266. package/dist/esm/start/platform/airtable/formulas.d.ts +70 -0
  267. package/dist/esm/start/platform/airtable/formulas.js +261 -0
  268. package/dist/esm/start/platform/airtable/index.d.ts +6 -0
  269. package/dist/esm/start/platform/airtable/index.js +51 -0
  270. package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
  271. package/dist/esm/start/platform/airtable/settings.js +138 -0
  272. package/dist/esm/start/platform/analytics.d.ts +3 -0
  273. package/dist/esm/start/platform/analytics.js +59 -0
  274. package/dist/esm/start/platform/calls.d.ts +5 -0
  275. package/dist/esm/start/platform/calls.js +104 -0
  276. package/dist/esm/start/platform/caps.d.ts +9 -0
  277. package/dist/esm/start/platform/caps.js +35 -0
  278. package/dist/esm/start/platform/connections.d.ts +25 -0
  279. package/dist/esm/start/platform/connections.js +198 -0
  280. package/dist/esm/start/platform/data/baseRunner.d.ts +97 -0
  281. package/dist/esm/start/platform/data/baseRunner.js +117 -0
  282. package/dist/esm/start/platform/data/dispatch.d.ts +17 -0
  283. package/dist/esm/start/platform/data/dispatch.js +216 -0
  284. package/dist/esm/start/platform/data/fetch.d.ts +7 -0
  285. package/dist/esm/start/platform/data/fetch.js +9 -0
  286. package/dist/esm/start/platform/data/index.d.ts +27 -0
  287. package/dist/esm/start/platform/data/index.js +75 -0
  288. package/dist/esm/start/platform/data/names.d.ts +7 -0
  289. package/dist/esm/start/platform/data/names.js +18 -0
  290. package/dist/esm/start/platform/data/sqlNameMappings.d.ts +58 -0
  291. package/dist/esm/start/platform/data/sqlNameMappings.js +92 -0
  292. package/dist/esm/start/platform/data/transformations.d.ts +97 -0
  293. package/dist/esm/start/platform/data/transformations.js +262 -0
  294. package/dist/esm/start/platform/data/types.d.ts +94 -0
  295. package/dist/esm/start/platform/data/types.js +14 -0
  296. package/dist/esm/start/platform/local.d.ts +6 -0
  297. package/dist/esm/start/platform/local.js +18 -0
  298. package/dist/esm/start/platform/meta.d.ts +3 -0
  299. package/dist/esm/start/platform/meta.js +33 -0
  300. package/dist/esm/start/platform/outbound.d.ts +17 -0
  301. package/dist/esm/start/platform/outbound.js +510 -0
  302. package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
  303. package/dist/esm/start/platform/redactSecrets.js +156 -0
  304. package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
  305. package/dist/esm/start/platform/redactSecrets.test.js +151 -0
  306. package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
  307. package/dist/esm/start/platform/requestSecrets.js +41 -0
  308. package/dist/esm/start/platform/runLog.d.ts +40 -0
  309. package/dist/esm/start/platform/runLog.js +149 -0
  310. package/dist/esm/start/platform/services.d.ts +7 -0
  311. package/dist/esm/start/platform/services.js +46 -0
  312. package/dist/esm/start/platform/steps.d.ts +9 -0
  313. package/dist/esm/start/platform/steps.js +60 -0
  314. package/dist/esm/start/platform/telemetry.d.ts +13 -0
  315. package/dist/esm/start/platform/telemetry.js +71 -0
  316. package/dist/esm/start/platform/transport.d.ts +28 -0
  317. package/dist/esm/start/platform/transport.js +59 -0
  318. package/dist/esm/start/platformHead.d.ts +23 -0
  319. package/dist/esm/start/platformHead.js +133 -0
  320. package/dist/esm/start/previewClaim.d.ts +6 -0
  321. package/dist/esm/start/previewClaim.js +24 -0
  322. package/dist/esm/start/protocol.d.ts +19 -0
  323. package/dist/esm/start/protocol.js +27 -0
  324. package/dist/esm/start/roles.d.ts +12 -0
  325. package/dist/esm/start/roles.js +27 -0
  326. package/dist/esm/start/router.d.ts +33 -6
  327. package/dist/esm/start/router.js +259 -16
  328. package/dist/esm/start/serve/authHooks.d.ts +7 -0
  329. package/dist/esm/start/serve/authHooks.js +18 -0
  330. package/dist/esm/start/serve/demo.d.ts +9 -0
  331. package/dist/esm/start/serve/demo.js +24 -0
  332. package/dist/esm/start/serve/fetch.d.ts +1 -0
  333. package/dist/esm/start/serve/fetch.js +6 -0
  334. package/dist/esm/start/{instance.d.ts → serve/instance.d.ts} +7 -7
  335. package/dist/esm/start/serve/instance.js +134 -0
  336. package/dist/esm/start/serve/invoke.d.ts +13 -0
  337. package/dist/esm/start/serve/invoke.js +126 -0
  338. package/dist/esm/start/serve/local/load.d.ts +8 -0
  339. package/dist/esm/start/serve/local/load.js +44 -0
  340. package/dist/esm/start/serve/local/provider.d.ts +25 -0
  341. package/dist/esm/start/serve/local/provider.js +188 -0
  342. package/dist/esm/start/serve/local/signIn.d.ts +28 -0
  343. package/dist/esm/start/serve/local/signIn.js +123 -0
  344. package/dist/esm/start/serve/pageHead.d.ts +20 -0
  345. package/dist/esm/start/serve/pageHead.js +34 -0
  346. package/dist/esm/start/serve/provider.d.ts +19 -0
  347. package/dist/esm/start/serve/provider.js +78 -0
  348. package/dist/esm/start/serve/requestEnv.d.ts +2 -0
  349. package/dist/esm/start/serve/requestEnv.js +84 -0
  350. package/dist/esm/start/serve/scope.d.ts +18 -0
  351. package/dist/esm/start/serve/scope.js +67 -0
  352. package/dist/esm/start/serve/server.d.ts +56 -0
  353. package/dist/esm/start/serve/server.js +297 -0
  354. package/dist/esm/start/serve/uploads.d.ts +2 -0
  355. package/dist/esm/start/serve/uploads.js +49 -0
  356. package/dist/esm/start/serve/worker.d.ts +6 -0
  357. package/dist/esm/start/serve/worker.js +12 -0
  358. package/dist/esm/start/types.d.ts +316 -24
  359. package/dist/esm/start/version.d.ts +1 -0
  360. package/dist/esm/start/version.js +2 -0
  361. package/dist/esm/steps/index.d.ts +78 -0
  362. package/dist/esm/steps/index.js +502 -0
  363. package/dist/esm/steps/index.test.d.ts +1 -0
  364. package/dist/esm/steps/index.test.js +633 -0
  365. package/dist/esm/sync/index.d.ts +1 -1
  366. package/dist/esm/sync/index.js +32 -31
  367. package/dist/esm/sync/lib.d.ts +15 -8
  368. package/dist/esm/sync/lib.js +664 -667
  369. package/dist/esm/sync/lib.test.js +177 -46
  370. package/dist/esm/sync/sdkNames.d.ts +67 -9
  371. package/dist/esm/sync/sdkNames.js +94 -30
  372. package/dist/esm/sync/sdkNames.test.js +192 -116
  373. package/dist/esm/types/fields.d.ts +9 -2
  374. package/dist/esm/types/fields.js +110 -96
  375. package/dist/esm/types/index.d.ts +2 -2
  376. package/dist/esm/types/index.js +2 -2
  377. package/dist/esm/types/tables.d.ts +17 -1
  378. package/dist/esm/types/tables.js +2 -2
  379. package/dist/esm/upload/index.js +89 -24
  380. package/dist/esm/upload/index.test.js +104 -1
  381. package/dist/esm/vite/domTagNames.js +252 -252
  382. package/dist/esm/vite/index.d.ts +1 -1
  383. package/dist/esm/vite/index.js +56 -47
  384. package/dist/esm/vite/index.test.js +10 -2
  385. package/package.json +111 -40
  386. package/dist/cjs/auth-server/index.d.ts +0 -369
  387. package/dist/cjs/auth-server/index.js +0 -119
  388. package/dist/cjs/start/problems.d.ts +0 -19
  389. package/dist/cjs/start/problems.js +0 -11
  390. package/dist/esm/auth-server/index.d.ts +0 -369
  391. package/dist/esm/auth-server/index.js +0 -116
  392. package/dist/esm/start/describe.d.ts +0 -56
  393. package/dist/esm/start/describe.js +0 -147
  394. package/dist/esm/start/describeBuilt.js +0 -66
  395. package/dist/esm/start/entries.js +0 -82
  396. package/dist/esm/start/instance.js +0 -73
  397. package/dist/esm/start/problems.d.ts +0 -19
  398. package/dist/esm/start/problems.js +0 -8
  399. package/dist/esm/start/runLog.d.ts +0 -5
  400. package/dist/esm/start/runLog.js +0 -18
  401. package/dist/esm/start/scope.d.ts +0 -15
  402. package/dist/esm/start/scope.js +0 -58
  403. package/dist/esm/start/server.d.ts +0 -37
  404. package/dist/esm/start/server.js +0 -159
  405. package/dist/esm/start/vite.d.ts +0 -9
  406. package/dist/esm/start/vite.js +0 -143
  407. package/dist/esm/start/workflow.d.ts +0 -36
  408. package/dist/esm/start/workflow.js +0 -13
  409. package/dist/esm/start/workflow.test-d.js +0 -24
  410. package/dist/esm/start/workflowRun.d.ts +0 -80
  411. package/dist/esm/start/workflowRun.js +0 -107
  412. /package/dist/{esm/start/workflow.test-d.d.ts → cjs/runtime/sendEmailParamsTypes.test-d.d.ts} +0 -0
  413. /package/dist/esm/start/{workflowModules.d.ts → build/placeholders/workflowModules.d.ts} +0 -0
  414. /package/dist/esm/start/{descriptions.d.ts → describe/descriptions.d.ts} +0 -0
@@ -0,0 +1,78 @@
1
+ // A streamed answer can outlive the request's deadline, which the token's expiry follows.
2
+ const RENEW_WITHIN_MS = 30_000;
3
+ const expiresWithin = (expiresAt, ms) => expiresAt !== undefined && expiresAt - Date.now() < ms;
4
+ export const isExpiringToken = (value) => {
5
+ const given = value;
6
+ return (typeof given?.token === 'string' &&
7
+ given.token !== '' &&
8
+ typeof given.expiresAt === 'number' &&
9
+ Number.isFinite(given.expiresAt));
10
+ };
11
+ /**
12
+ * The token to send: the one held until its expiry is near, then a renewed one. Callers at once share one renewal,
13
+ * and one that fails keeps the held token while it still serves.
14
+ */
15
+ export const renewedToken = ({ held, keep, renew, withinMs, }) => {
16
+ let renewing;
17
+ return async () => {
18
+ const current = held();
19
+ if (current && !expiresWithin(current.expiresAt, withinMs))
20
+ return current.token;
21
+ renewing ??= renew()
22
+ .then(fresh => {
23
+ if (fresh)
24
+ keep(fresh);
25
+ }, (error) => {
26
+ if (!current || expiresWithin(current.expiresAt, 0))
27
+ throw error;
28
+ console.error("[zite] couldn't renew the token; using the one held until it expires", error);
29
+ })
30
+ .finally(() => (renewing = undefined));
31
+ await renewing;
32
+ return held()?.token;
33
+ };
34
+ };
35
+ export const contextOf = ({ appId, buildId, baseId, mode, orgSettingsVersion, showZiteBadge, appUrl, }) => ({
36
+ appId,
37
+ buildId,
38
+ baseId,
39
+ mode,
40
+ orgSettingsVersion,
41
+ showZiteBadge,
42
+ appUrl,
43
+ });
44
+ export const URL_NAMES = [
45
+ 'baseRunner',
46
+ 'backend',
47
+ 'gateway',
48
+ 'runs',
49
+ 'email',
50
+ 'pdf',
51
+ 'uploads',
52
+ 'steps',
53
+ 'schedules',
54
+ ];
55
+ export const trimmed = (urls) => Object.fromEntries(URL_NAMES.flatMap(name => urls[name] ? [[name, urls[name].replace(/\/+$/, '')]] : []));
56
+ export const ziteProvider = (props) => {
57
+ let current = props.appToken
58
+ ? { token: props.appToken, expiresAt: props.appTokenExpiresAt }
59
+ : undefined;
60
+ const renewed = renewedToken({
61
+ held: () => current,
62
+ keep: fresh => (current = fresh),
63
+ renew: async () => {
64
+ const fresh = await props.platform.appToken();
65
+ return isExpiringToken(fresh) ? fresh : null;
66
+ },
67
+ withinMs: RENEW_WITHIN_MS,
68
+ });
69
+ const context = contextOf(props);
70
+ return {
71
+ kind: 'zite',
72
+ urls: props.urls && trimmed(props.urls),
73
+ user: () => props.user,
74
+ context: async () => context,
75
+ // A dispatch with no token has nothing to renew.
76
+ token: async () => (current ? renewed() : undefined),
77
+ };
78
+ };
@@ -0,0 +1,2 @@
1
+ /** Puts the overlay in front of `process.env`, once per isolate, before the app's modules read it. */
2
+ export declare const installRequestEnv: () => void;
@@ -0,0 +1,84 @@
1
+ // process.env as each request reads it: the isolate's own vars under the request's overlay, which holds the vars classic
2
+ // sets per run and whatever the request's code set or deleted. No request writes the isolate's vars, so none reads
3
+ // another's: a demo, which shares the build's isolates with live, reads no live request's tokens or secrets.
4
+ import { getHost } from './scope.js';
5
+ /** The vars classic sets per run, from what the host sent the request. */
6
+ const requestVars = (host) => new Map(Object.entries({
7
+ ...(host.appUrl && { ZITE_APP_URL: host.appUrl }),
8
+ ...(host.baseId && { ZITE_BASE_ID: host.baseId }),
9
+ ...Object.fromEntries(Object.entries(host.env ?? {}).filter(([key]) => key.startsWith('ZITE_'))),
10
+ }));
11
+ // Outside a request (a module loading) the isolate's own vars are read and written.
12
+ const requestOverlay = () => {
13
+ const host = getHost();
14
+ return host && (host.processEnv ??= requestVars(host));
15
+ };
16
+ const overlay = (key) => typeof key === 'string' ? requestOverlay() : undefined;
17
+ /** The request's own answer for `key`, set or deleted; undefined when the isolate's stands. */
18
+ const own = (key) => {
19
+ const view = overlay(key);
20
+ return view?.has(key)
21
+ ? { value: view.get(key) }
22
+ : undefined;
23
+ };
24
+ let installed;
25
+ /** Puts the overlay in front of `process.env`, once per isolate, before the app's modules read it. */
26
+ export const installRequestEnv = () => {
27
+ const proc = globalThis.process;
28
+ if (!proc?.env || proc.env === installed)
29
+ return;
30
+ installed = proc.env = new Proxy(proc.env, {
31
+ get: (target, key) => {
32
+ const answer = own(key);
33
+ return answer ? answer.value : Reflect.get(target, key);
34
+ },
35
+ has: (target, key) => {
36
+ const answer = own(key);
37
+ return answer ? answer.value !== undefined : Reflect.has(target, key);
38
+ },
39
+ set: (target, key, value) => {
40
+ const view = overlay(key);
41
+ if (!view)
42
+ return Reflect.set(target, key, value);
43
+ view.set(key, String(value));
44
+ return true;
45
+ },
46
+ defineProperty: (target, key, attributes) => {
47
+ const view = overlay(key);
48
+ if (!view)
49
+ return Reflect.defineProperty(target, key, attributes);
50
+ view.set(key, String(attributes.value));
51
+ return true;
52
+ },
53
+ deleteProperty: (target, key) => {
54
+ const view = overlay(key);
55
+ if (!view)
56
+ return Reflect.deleteProperty(target, key);
57
+ view.set(key, undefined);
58
+ return true;
59
+ },
60
+ ownKeys: target => {
61
+ const view = requestOverlay();
62
+ if (!view)
63
+ return Reflect.ownKeys(target);
64
+ const kept = Reflect.ownKeys(target).filter(key => !(typeof key === 'string' && view.has(key)));
65
+ return [
66
+ ...kept,
67
+ ...[...view].flatMap(([key, value]) => value === undefined ? [] : [key]),
68
+ ];
69
+ },
70
+ getOwnPropertyDescriptor: (target, key) => {
71
+ const answer = own(key);
72
+ if (!answer)
73
+ return Reflect.getOwnPropertyDescriptor(target, key);
74
+ return answer.value === undefined
75
+ ? undefined
76
+ : {
77
+ value: answer.value,
78
+ writable: true,
79
+ enumerable: true,
80
+ configurable: true,
81
+ };
82
+ },
83
+ });
84
+ };
@@ -0,0 +1,18 @@
1
+ import type { AccessScope, HostRequestState } from '../types.js';
2
+ export type { AccessKind, AccessScope } from '../types.js';
3
+ /** A request's one async-local frame: what the host resolved for it, and the access decision a call runs under. */
4
+ type RequestFrame = {
5
+ host: HostRequestState;
6
+ scope?: AccessScope;
7
+ };
8
+ /** Runs `fn` under an access decision, in the request it was made in. */
9
+ export declare const runInScope: <T>(scope: AccessScope, fn: () => T) => T;
10
+ /** True inside another server function's scope, i.e. a nested server-side call. */
11
+ export declare const inScope: () => boolean;
12
+ export declare class NoAccessDecisionError extends Error {
13
+ constructor(what: string);
14
+ }
15
+ /** The request a platform call was made in, and the access decision it was made under. */
16
+ export declare const requireRequest: (what: string) => Required<RequestFrame>;
17
+ export declare const runWithHost: <T>(host: HostRequestState, fn: () => T) => T;
18
+ export declare const getHost: () => HostRequestState | undefined;
@@ -0,0 +1,67 @@
1
+ // Server-only. Only zitejs's access middleware opens an access scope, and the
2
+ // platform transport refuses calls outside one, so code with no access decision
3
+ // can't reach data, integrations or email however it was written.
4
+ import { AsyncLocalStorage } from 'node:async_hooks';
5
+ import { HOST_STORE_KEY } from '../host.js';
6
+ // Keyed on globalThis so two copies of zitejs in one bundle share the store.
7
+ const stores = globalThis;
8
+ const storage = (stores[Symbol.for('zitejs:request-frame')] ??=
9
+ new AsyncLocalStorage());
10
+ // What isomorphic code reads, ../host.ts and classic's upload client among it: only the frame's host.
11
+ stores[HOST_STORE_KEY] ??= { getStore: () => storage.getStore()?.host };
12
+ const isAsyncIterable = (value) => typeof value === 'object' &&
13
+ value !== null &&
14
+ Symbol.asyncIterator in value &&
15
+ !(value instanceof ReadableStream);
16
+ // TanStack resumes a streamed async generator from its serializer, outside the
17
+ // middleware's async context, so each step re-enters the frame it started in.
18
+ const rescope = (frame, source) => (async function* () {
19
+ const iterator = source[Symbol.asyncIterator]();
20
+ try {
21
+ while (true) {
22
+ const step = await storage.run(frame, () => iterator.next());
23
+ if (step.done)
24
+ return step.value;
25
+ yield step.value;
26
+ }
27
+ }
28
+ finally {
29
+ await storage.run(frame, async () => iterator.return?.());
30
+ }
31
+ })();
32
+ const rescopeResult = (frame, out) => {
33
+ const result = out?.result;
34
+ return isAsyncIterable(result)
35
+ ? { ...out, result: rescope(frame, result) }
36
+ : out;
37
+ };
38
+ /** Runs `fn` under an access decision, in the request it was made in. */
39
+ export const runInScope = (scope, fn) => {
40
+ const host = storage.getStore()?.host;
41
+ if (!host)
42
+ throw new Error('An access decision is made only inside a request the platform is serving');
43
+ const frame = { host, scope };
44
+ const out = storage.run(frame, fn);
45
+ return (out instanceof Promise
46
+ ? out.then(value => rescopeResult(frame, value))
47
+ : rescopeResult(frame, out));
48
+ };
49
+ /** True inside another server function's scope, i.e. a nested server-side call. */
50
+ export const inScope = () => storage.getStore()?.scope !== undefined;
51
+ export class NoAccessDecisionError extends Error {
52
+ constructor(what) {
53
+ super(`${what} ran outside an access decision. Define server functions with signedInFn or publicFn, ` +
54
+ 'and give server routes signedIn, anyone or webhook middleware. Loaders get data by calling a server function. ' +
55
+ "If this runs at a module's top level, move it into the handler.");
56
+ this.name = 'NoAccessDecisionError';
57
+ }
58
+ }
59
+ /** The request a platform call was made in, and the access decision it was made under. */
60
+ export const requireRequest = (what) => {
61
+ const frame = storage.getStore();
62
+ if (!frame?.scope)
63
+ throw new NoAccessDecisionError(what);
64
+ return { host: frame.host, scope: frame.scope };
65
+ };
66
+ export const runWithHost = (host, fn) => storage.run({ host }, fn);
67
+ export const getHost = () => storage.getStore()?.host;
@@ -0,0 +1,56 @@
1
+ import type { HostProps, PlatformProvider, HostRequestState } from '../types.js';
2
+ export { runWithHost } from './scope.js';
3
+ export { describeApp } from '../describe/describe.js';
4
+ export type { WorkflowRunResult, WorkflowStop, } from '../automations/workflowRun.js';
5
+ export type { AppContext, DurableCall, HostProps, PlatformBinding, PlatformCallInput, PlatformCallResult, PlatformProvider, PlatformUrls, RunRecord, } from '../types.js';
6
+ /**
7
+ * Routes every zitejs data, integration and email call to this request's
8
+ * platform on its app token, and only inside an access scope. The access kind
9
+ * travels with the call so the platform can record what a page read and
10
+ * narrow anonymous reads. A request with no token or URLs fails each call
11
+ * that would leave the app loudly: there is nowhere else for it to go. What
12
+ * props already answer, integrations.get and ZiteMeta.getWorkspace, needs none.
13
+ */
14
+ export declare function installPlatformTransport(): void;
15
+ /** What the host dispatched this request with. Headers are ignored: props are the only thing it alone can set. */
16
+ export declare function hostContextFromProps(request: Request, props: HostProps): HostRequestState;
17
+ /**
18
+ * A request the host didn't dispatch: the host's warm-up, `zitejs describe` under `vite preview`, a server off Zite,
19
+ * and tests. Only the host can set props, so without them a build answers warm and describe, nobody is signed in, only
20
+ * an entry that passes its own provider (a test's) reaches a platform, and pages show the Settings the build baked.
21
+ */
22
+ export declare function hostContextFromRequest(request: Request, provider?: PlatformProvider): HostRequestState;
23
+ /** Every server function TanStack compiled, written in by `zite()` at build. Empty in dev, where TanStack doesn't call its id hook. */
24
+ export declare const builtFunctionIds: () => string[];
25
+ /** Each server function's `description` option, written in by `zite()` at build. */
26
+ export declare const builtFunctionDescriptions: () => Record<string, string>;
27
+ /** Each route's file, by route id, written in by `zite()` at build. */
28
+ export declare const builtRouteFiles: () => Record<string, string>;
29
+ /** Each registry module's registration hash, by its path, written in by `zite()` at build from the module graph. */
30
+ export declare const builtRegistrationHashes: () => Record<string, string>;
31
+ export type ZiteServerOptions = {
32
+ handler: {
33
+ fetch(request: Request, ...rest: unknown[]): Promise<Response> | Response;
34
+ };
35
+ getRouter: () => unknown;
36
+ /** A test entry's own platform, for the requests no host dispatched; see `hostContextFromRequest`. */
37
+ provider?: PlatformProvider;
38
+ };
39
+ /** What a Worker's fetch is handed beside its request: the host's props, when the host dispatched it. */
40
+ export type HostedContext = {
41
+ waitUntil(promise: Promise<unknown>): void;
42
+ props?: Partial<HostProps>;
43
+ };
44
+ export type ZiteFetch = (request: Request, env?: unknown, ctx?: HostedContext) => Promise<Response>;
45
+ export type ZiteHandlers = {
46
+ fetch: ZiteFetch;
47
+ };
48
+ /**
49
+ * The handlers of a Start app's server entry. A request the host dispatched
50
+ * carries its identity, app token and platform URLs in props. Without props, a
51
+ * developer's dev token or API key in env selects the `local` provider;
52
+ * anything else (describe under `vite preview`, tests) uses `provider` if one is given.
53
+ */
54
+ export declare function createZiteHandlers(options: ZiteServerOptions): ZiteHandlers;
55
+ /** The fetch handler alone, for the Node entry. */
56
+ export declare function createZiteFetch(options: ZiteServerOptions): ZiteFetch;
@@ -0,0 +1,297 @@
1
+ import { asZiteError, SIGN_IN_REQUIRED, ZITE_ERROR_STATUS } from '../errors.js';
2
+ import { describeApp } from '../describe/describe.js';
3
+ import { asDemoRefusal, failedOnDemo, noteDemoRefusal } from './demo.js';
4
+ import { watchOutboundFetches } from '../platform/outbound.js';
5
+ import { callPlatform } from '../platform/calls.js';
6
+ import { takeAnalytics } from '../platform/analytics.js';
7
+ import { takeUploadSession } from './uploads.js';
8
+ import { UPLOAD_SESSION_PATH } from '../../internal/serviceUrls.js';
9
+ import { sendRunReport } from '../platform/telemetry.js';
10
+ import { ANALYTICS_PATH, MANIFEST_PATH, manifestAnswer, opensPage, platformHeadOf, } from './pageHead.js';
11
+ import { builtSiteHead } from '../build/placeholders/siteHead.js';
12
+ import { ziteProvider } from './provider.js';
13
+ import { localPlatform } from './local/provider.js';
14
+ import { signInLocally, userOfIdentity, withSetCookies, } from './local/signIn.js';
15
+ import { hostContextFromLocal, loadLocal } from './local/load.js';
16
+ import { createInvoker, headerInvoke } from './invoke.js';
17
+ import { getHost, requireRequest, runWithHost } from './scope.js';
18
+ import { installRequestEnv } from './requestEnv.js';
19
+ import { RUNTIME_VERSION_HEADER } from '../protocol.js';
20
+ import { ZITEJS_VERSION } from '../version.js';
21
+ import { loadUnfinishedWorkflows, loadWorkflows, } from '../automations/workflowRun.js';
22
+ export { runWithHost } from './scope.js';
23
+ export { describeApp } from '../describe/describe.js';
24
+ /**
25
+ * Routes every zitejs data, integration and email call to this request's
26
+ * platform on its app token, and only inside an access scope. The access kind
27
+ * travels with the call so the platform can record what a page read and
28
+ * narrow anonymous reads. A request with no token or URLs fails each call
29
+ * that would leave the app loudly: there is nowhere else for it to go. What
30
+ * props already answer, integrations.get and ZiteMeta.getWorkspace, needs none.
31
+ */
32
+ export function installPlatformTransport() {
33
+ const platformCall = async (integrationId, className, methodName, params) => {
34
+ const { host, scope } = requireRequest(`${className}.${methodName}`);
35
+ return callPlatform(host, {
36
+ integrationId,
37
+ className,
38
+ methodName,
39
+ params,
40
+ access: scope.kind,
41
+ });
42
+ };
43
+ const sdkCall = async (...call) => {
44
+ try {
45
+ return await platformCall(...call);
46
+ }
47
+ catch (error) {
48
+ noteDemoRefusal(getHost(), error);
49
+ throw error;
50
+ }
51
+ };
52
+ globalThis.__wrapSdkCall = sdkCall;
53
+ watchOutboundFetches();
54
+ }
55
+ /** What the host dispatched this request with. Headers are ignored: props are the only thing it alone can set. */
56
+ export function hostContextFromProps(request, props) {
57
+ const host = {
58
+ requestId: props.requestId,
59
+ url: request.url,
60
+ user: props.user,
61
+ mode: props.mode,
62
+ invoke: props.invoke,
63
+ appUrl: props.appUrl ?? undefined,
64
+ baseId: props.baseId ?? undefined,
65
+ previewClaim: props.previewClaim,
66
+ env: props.env,
67
+ envConnections: props.envConnections,
68
+ connectionServices: props.connectionServices,
69
+ runRoot: props.runRoot,
70
+ durable: props.durable,
71
+ runs: [],
72
+ workspace: props.workspace,
73
+ connections: props.connections,
74
+ provider: ziteProvider(props),
75
+ };
76
+ if (props.page) {
77
+ const { runtimeUrl, demo, ...site } = props.page;
78
+ host.head = platformHeadOf(site, { url: request.url, mode: props.mode }, { context: props, runtimeUrl, demo });
79
+ }
80
+ return host;
81
+ }
82
+ /**
83
+ * A request the host didn't dispatch: the host's warm-up, `zitejs describe` under `vite preview`, a server off Zite,
84
+ * and tests. Only the host can set props, so without them a build answers warm and describe, nobody is signed in, only
85
+ * an entry that passes its own provider (a test's) reaches a platform, and pages show the Settings the build baked.
86
+ */
87
+ export function hostContextFromRequest(request, provider) {
88
+ return {
89
+ requestId: crypto.randomUUID(),
90
+ url: request.url,
91
+ user: null,
92
+ mode: 'live',
93
+ invoke: headerInvoke(request.headers),
94
+ runs: [],
95
+ provider,
96
+ ...(builtSiteHead && {
97
+ head: platformHeadOf(builtSiteHead, { url: request.url, mode: 'live' }),
98
+ }),
99
+ };
100
+ }
101
+ /** As the dispatcher answers a caller an internal app turns away: a server function, a page, or a call. */
102
+ const signInRequired = (request) => {
103
+ const url = new URL(request.url);
104
+ if (url.pathname.startsWith('/_serverFn/') ||
105
+ request.headers.has('x-tsr-serverfn')) {
106
+ return new Response(SIGN_IN_REQUIRED, {
107
+ status: 401,
108
+ headers: { 'content-type': 'text/plain; charset=utf-8' },
109
+ });
110
+ }
111
+ if (!opensPage(request))
112
+ return Response.json({ error: 'SIGN_IN_REQUIRED' }, { status: 401 });
113
+ const login = new URL('/auth/login', url);
114
+ login.searchParams.set('redirectUrl', url.href);
115
+ return new Response(null, {
116
+ status: 302,
117
+ headers: { location: login.pathname + login.search },
118
+ });
119
+ };
120
+ // The platform's own paths on the app's origin, which no app route answers and no sign-in stands before.
121
+ const isPlatformPath = (pathname) => pathname === ANALYTICS_PATH || pathname === UPLOAD_SESSION_PATH;
122
+ /** Every server function TanStack compiled, written in by `zite()` at build. Empty in dev, where TanStack doesn't call its id hook. */
123
+ export const builtFunctionIds = () => '__ZITE_FN_IDS__'.split(',').filter(id => id && !id.startsWith('__ZITE'));
124
+ const parseBuiltJson = (json) => {
125
+ try {
126
+ return JSON.parse(json);
127
+ }
128
+ catch {
129
+ return {};
130
+ }
131
+ };
132
+ /** Each server function's `description` option, written in by `zite()` at build. */
133
+ export const builtFunctionDescriptions = () => parseBuiltJson('__ZITE_FN_DESCRIPTIONS__');
134
+ /** Each route's file, by route id, written in by `zite()` at build. */
135
+ export const builtRouteFiles = () => parseBuiltJson('__ZITE_ROUTE_FILES__');
136
+ /** Each registry module's registration hash, by its path, written in by `zite()` at build from the module graph. */
137
+ export const builtRegistrationHashes = () => parseBuiltJson('__ZITE_REGISTRATION_HASHES__');
138
+ // Server functions also run while a streamed page renders, so the run log is
139
+ // complete only once the body ends: read to the end, cancelled by the reader or
140
+ // failed. A TransformStream's flush hears only the first.
141
+ const onBodyEnd = (response, done) => {
142
+ if (!response.body) {
143
+ done();
144
+ return response;
145
+ }
146
+ const reader = response.body.getReader();
147
+ let ended = false;
148
+ const end = () => {
149
+ if (ended)
150
+ return;
151
+ ended = true;
152
+ done();
153
+ };
154
+ const body = new ReadableStream({
155
+ async pull(controller) {
156
+ try {
157
+ const { done: finished, value } = await reader.read();
158
+ if (finished) {
159
+ end();
160
+ controller.close();
161
+ }
162
+ else {
163
+ controller.enqueue(value);
164
+ }
165
+ }
166
+ catch (error) {
167
+ end();
168
+ controller.error(error);
169
+ }
170
+ },
171
+ cancel(reason) {
172
+ end();
173
+ return reader.cancel(reason);
174
+ },
175
+ });
176
+ return new Response(body, response);
177
+ };
178
+ // TanStack renders any loader error as a 500. A page refused with a ZiteError
179
+ // (a missing role, a record that isn't there) answers with that error's status.
180
+ const pageStatus = (host) => {
181
+ const matches = host.router?.state?.matches;
182
+ const failed = asZiteError(matches?.find(match => match.status === 'error')?.error);
183
+ return failed ? ZITE_ERROR_STATUS[failed.code] : undefined;
184
+ };
185
+ // The platform binding is what only the host's dispatch carries.
186
+ const isDispatched = (props) => !!props?.platform;
187
+ /**
188
+ * The handlers of a Start app's server entry. A request the host dispatched
189
+ * carries its identity, app token and platform URLs in props. Without props, a
190
+ * developer's dev token or API key in env selects the `local` provider;
191
+ * anything else (describe under `vite preview`, tests) uses `provider` if one is given.
192
+ */
193
+ export function createZiteHandlers(options) {
194
+ installPlatformTransport();
195
+ installRequestEnv();
196
+ // Loaded on first use, so a page request never pays for importing workflow modules.
197
+ let workflows;
198
+ const loadedWorkflows = () => (workflows ??= loadWorkflows());
199
+ const invoke = createInvoker({
200
+ workflows: loadedWorkflows,
201
+ functionIds: builtFunctionIds,
202
+ handler: options.handler,
203
+ });
204
+ const fetch = async (incoming, _env, ctx) => {
205
+ const given = ctx?.props;
206
+ const props = isDispatched(given) ? given : undefined;
207
+ const local = props ? undefined : localPlatform();
208
+ const { pathname } = new URL(incoming.url);
209
+ const mounted = local && !headerInvoke(incoming.headers) && !isPlatformPath(pathname)
210
+ ? await signInLocally(incoming)
211
+ : undefined;
212
+ if (mounted && 'answered' in mounted)
213
+ return mounted.answered;
214
+ const request = mounted?.request ?? incoming;
215
+ const host = props
216
+ ? hostContextFromProps(request, props)
217
+ : local
218
+ ? hostContextFromLocal(request, local)
219
+ : hostContextFromRequest(request, options.provider);
220
+ if (mounted)
221
+ host.user = userOfIdentity(mounted.signedIn.user);
222
+ // A browser asks for an installable app's manifest before anyone signs in.
223
+ const manifest = host.invoke === null &&
224
+ request.method === 'GET' &&
225
+ pathname === MANIFEST_PATH
226
+ ? host.head?.site.manifest
227
+ : undefined;
228
+ if (manifest)
229
+ return manifestAnswer(manifest);
230
+ // The platform walls internal apps before dispatch; this is the same wall again, before any app code.
231
+ if (props?.accessMode === 'internal' && host.invoke === null && !host.user)
232
+ return signInRequired(request);
233
+ if (ctx?.waitUntil)
234
+ host.waitUntil = promise => ctx.waitUntil(promise);
235
+ // The platform's, before any app route could answer them.
236
+ if (host.invoke === null && pathname === ANALYTICS_PATH)
237
+ return takeAnalytics(request, host);
238
+ if (host.invoke === null && pathname === UPLOAD_SESSION_PATH)
239
+ return takeUploadSession(request, host);
240
+ if (local && host.invoke === null)
241
+ await loadLocal(host);
242
+ // Starting this isolate was the point: the platform warms a build before its
243
+ // first visitors, and no app code runs.
244
+ if (host.invoke?.kind === 'warm')
245
+ return new Response(null, { status: 204 });
246
+ if (host.invoke?.kind === 'describe') {
247
+ return Response.json(await describeApp({
248
+ fnIds: builtFunctionIds(),
249
+ descriptions: builtFunctionDescriptions(),
250
+ routeFiles: builtRouteFiles(),
251
+ registrationHashes: builtRegistrationHashes(),
252
+ getRouter: options.getRouter,
253
+ request,
254
+ workflows: await loadedWorkflows(),
255
+ unfinishedWorkflows: await loadUnfinishedWorkflows(),
256
+ }), { headers: { [RUNTIME_VERSION_HEADER]: ZITEJS_VERSION } });
257
+ }
258
+ let response = await runWithHost(host, () => invoke(host, request) ?? options.handler.fetch(request));
259
+ const status = response.status === 500 ? pageStatus(host) : undefined;
260
+ if (status)
261
+ response = new Response(response.body, {
262
+ status,
263
+ headers: response.headers,
264
+ });
265
+ if (host.invoke === null &&
266
+ !opensPage(request) &&
267
+ failedOnDemo(host, response))
268
+ response = asDemoRefusal(response);
269
+ if (mounted)
270
+ response = withSetCookies(response, mounted.signedIn.setCookies);
271
+ return onBodyEnd(response, () => {
272
+ if (!host.runs.length &&
273
+ !host.calls?.length &&
274
+ !host.fetches?.length &&
275
+ !host.pending?.length)
276
+ return;
277
+ const flushed = (async () => {
278
+ await Promise.all(host.pending ?? []);
279
+ if (!host.runs.length && !host.calls?.length && !host.fetches?.length)
280
+ return;
281
+ await sendRunReport(host, {
282
+ runs: host.runs,
283
+ ...(host.calls?.length && { calls: host.calls }),
284
+ ...(host.fetches?.length && { fetches: host.fetches }),
285
+ });
286
+ })().catch((error) => {
287
+ console.error("[zite] couldn't record runs", error);
288
+ });
289
+ ctx?.waitUntil(flushed);
290
+ });
291
+ };
292
+ return { fetch };
293
+ }
294
+ /** The fetch handler alone, for the Node entry. */
295
+ export function createZiteFetch(options) {
296
+ return createZiteHandlers(options).fetch;
297
+ }
@@ -0,0 +1,2 @@
1
+ import type { HostRequestState } from '../types.js';
2
+ export declare const takeUploadSession: (request: Request, host: HostRequestState) => Promise<Response>;
@@ -0,0 +1,49 @@
1
+ // A Start page's upload session, asked of the app's own origin: the app's server asks the platform's uploads service on
2
+ // the request's token, which says the app and the mode, so neither the token nor a platform host reaches the browser.
3
+ import { serviceUrl } from '../../internal/serviceUrls.js';
4
+ import { textUpTo } from '../platform/caps.js';
5
+ import { directAccess, sendOnToken } from '../platform/transport.js';
6
+ const MAX_SESSION_BYTES = 16 * 1024;
7
+ const UPLOADS_TIMEOUT_MS = 15_000;
8
+ const refused = (status, message) => Response.json({ success: false, message }, { status });
9
+ // As the app's own routes are checked (serve/instance.ts): a cookie rides only on a request from the app's own pages.
10
+ const crossSite = (request) => {
11
+ if (!request.headers.has('cookie'))
12
+ return false;
13
+ const site = request.headers.get('sec-fetch-site');
14
+ if (site !== null)
15
+ return site !== 'same-origin';
16
+ return request.headers.get('origin') !== new URL(request.url).origin;
17
+ };
18
+ const sessionBody = (raw) => {
19
+ try {
20
+ const { filename, uploadLength, contentType } = JSON.parse(raw ?? '');
21
+ return JSON.stringify({ filename, uploadLength, contentType });
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ };
27
+ export const takeUploadSession = async (request, host) => {
28
+ if (request.method !== 'POST')
29
+ return new Response('Method not allowed', { status: 405 });
30
+ if (crossSite(request))
31
+ return refused(403, 'Forbidden');
32
+ const access = await directAccess(host);
33
+ if (!access)
34
+ return refused(503, "Uploads need the platform's app token, and this request has none");
35
+ const body = sessionBody(await textUpTo(request, MAX_SESSION_BYTES));
36
+ if (body === undefined)
37
+ return refused(400, 'Invalid upload session request');
38
+ try {
39
+ const answer = await sendOnToken(access.token, serviceUrl(access.urls, 'uploads'), { method: 'POST', body, timeoutMs: UPLOADS_TIMEOUT_MS });
40
+ return new Response(answer.body, {
41
+ status: answer.status,
42
+ headers: { 'content-type': 'application/json' },
43
+ });
44
+ }
45
+ catch (error) {
46
+ console.error('[zite] the upload session failed', error);
47
+ return refused(502, 'Upload failed');
48
+ }
49
+ };
@@ -0,0 +1,6 @@
1
+ import { type ZiteServerOptions } from './server.js';
2
+ export type ZiteWorker = new (ctx: unknown, env: unknown) => {
3
+ fetch(request: Request): Promise<Response>;
4
+ };
5
+ /** A Start app's Worker. The host sends it every request, with that request's props. */
6
+ export declare function createZiteWorker(options: ZiteServerOptions): ZiteWorker;