zitejs 0.9.152 → 0.9.154

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 (395) 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.d.ts +1 -0
  36. package/dist/cjs/integrations/rules.js +44 -41
  37. package/dist/cjs/integrations/rules.test.js +60 -54
  38. package/dist/cjs/internal/appMode.d.ts +14 -0
  39. package/dist/cjs/internal/appMode.js +19 -0
  40. package/dist/cjs/internal/env.js +3 -2
  41. package/dist/cjs/internal/platformFetch.d.ts +2 -0
  42. package/dist/cjs/internal/platformFetch.js +14 -0
  43. package/dist/cjs/internal/reservedIds.d.ts +8 -0
  44. package/dist/cjs/internal/reservedIds.js +14 -0
  45. package/dist/cjs/internal/serviceUrls.d.ts +5 -0
  46. package/dist/cjs/internal/serviceUrls.js +14 -0
  47. package/dist/cjs/pdf/index.js +2 -1
  48. package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
  49. package/dist/cjs/runtime/index.d.ts +69 -21
  50. package/dist/cjs/runtime/index.js +32 -26
  51. package/dist/cjs/runtime/index.test.js +34 -34
  52. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +35 -18
  53. package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
  54. package/dist/cjs/sourceRoots.js +15 -15
  55. package/dist/cjs/sourceRoots.test.js +29 -27
  56. package/dist/cjs/start/build/entries.d.ts +25 -0
  57. package/dist/cjs/start/build/entries.js +121 -0
  58. package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
  59. package/dist/cjs/start/build/placeholders/devApp.js +6 -0
  60. package/dist/cjs/start/describe/describeBuilt.d.ts +5 -0
  61. package/dist/cjs/start/describe/describeBuilt.js +144 -0
  62. package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
  63. package/dist/cjs/start/platform/aiUsage.js +215 -0
  64. package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
  65. package/dist/cjs/start/platform/airtable/cache.js +93 -0
  66. package/dist/cjs/start/protocol.d.ts +19 -0
  67. package/dist/cjs/start/protocol.js +33 -0
  68. package/dist/cjs/start/serve/local/provider.d.ts +25 -0
  69. package/dist/cjs/start/serve/local/provider.js +196 -0
  70. package/dist/cjs/start/serve/provider.d.ts +19 -0
  71. package/dist/cjs/start/serve/provider.js +86 -0
  72. package/dist/cjs/start/types.d.ts +373 -0
  73. package/dist/cjs/start/types.js +2 -0
  74. package/dist/cjs/steps/index.d.ts +8 -8
  75. package/dist/cjs/steps/index.js +53 -53
  76. package/dist/cjs/steps/index.test.js +218 -218
  77. package/dist/cjs/sync/index.d.ts +1 -1
  78. package/dist/cjs/sync/index.js +28 -27
  79. package/dist/cjs/sync/lib.d.ts +15 -8
  80. package/dist/cjs/sync/lib.js +652 -661
  81. package/dist/cjs/sync/lib.test.js +81 -14
  82. package/dist/cjs/sync/sdkNames.d.ts +67 -9
  83. package/dist/cjs/sync/sdkNames.js +97 -31
  84. package/dist/cjs/sync/sdkNames.test.js +189 -113
  85. package/dist/cjs/types/fields.d.ts +1 -1
  86. package/dist/cjs/types/fields.js +105 -97
  87. package/dist/cjs/types/index.d.ts +2 -2
  88. package/dist/cjs/types/tables.d.ts +1 -1
  89. package/dist/cjs/upload/index.js +89 -24
  90. package/dist/cjs/upload/index.test.js +104 -1
  91. package/dist/cjs/vite/domTagNames.js +252 -252
  92. package/dist/cjs/vite/index.d.ts +1 -1
  93. package/dist/cjs/vite/index.js +51 -42
  94. package/dist/cjs/vite/index.test.js +10 -2
  95. package/dist/esm/auth/actions.d.ts +28 -0
  96. package/dist/esm/auth/actions.js +55 -0
  97. package/dist/esm/auth/client.d.ts +357 -0
  98. package/dist/esm/auth/client.js +62 -0
  99. package/dist/esm/auth/config.js +9 -3
  100. package/dist/esm/auth/index.d.ts +2 -249
  101. package/dist/esm/auth/index.js +2 -103
  102. package/dist/esm/auth/index.test.js +60 -0
  103. package/dist/esm/auth/previewClaim.d.ts +7 -0
  104. package/dist/esm/auth/previewClaim.js +12 -0
  105. package/dist/esm/auth/profileUpdates.d.ts +9 -0
  106. package/dist/esm/auth/profileUpdates.js +6 -0
  107. package/dist/esm/backend/index.d.ts +6 -6
  108. package/dist/esm/backend/index.js +13 -13
  109. package/dist/esm/backend/index.test.js +106 -106
  110. package/dist/esm/bundle/index.js +29 -16
  111. package/dist/esm/caller/index.js +44 -44
  112. package/dist/esm/check/index.d.ts +44 -1
  113. package/dist/esm/check/index.js +194 -61
  114. package/dist/esm/check/start/routeTree.d.ts +8 -0
  115. package/dist/esm/check/start/routeTree.js +77 -0
  116. package/dist/esm/check/start/tsgo.d.ts +2 -0
  117. package/dist/esm/check/start/tsgo.js +29 -0
  118. package/dist/esm/cli.js +19 -6
  119. package/dist/esm/client/index.d.ts +2 -2
  120. package/dist/esm/client/index.js +25 -25
  121. package/dist/esm/dev/index.js +88 -60
  122. package/dist/esm/dev/signin.d.ts +16 -0
  123. package/dist/esm/dev/signin.js +80 -0
  124. package/dist/esm/index.d.ts +5 -5
  125. package/dist/esm/index.js +3 -3
  126. package/dist/esm/integrations/client.d.ts +3 -3
  127. package/dist/esm/integrations/client.js +6 -5
  128. package/dist/esm/integrations/client.test-d.js +19 -19
  129. package/dist/esm/integrations/index.d.ts +2 -2
  130. package/dist/esm/integrations/index.js +1 -1
  131. package/dist/esm/integrations/rules.d.ts +1 -0
  132. package/dist/esm/integrations/rules.js +44 -41
  133. package/dist/esm/integrations/rules.test.js +62 -56
  134. package/dist/esm/internal/appMode.d.ts +14 -0
  135. package/dist/esm/internal/appMode.js +13 -0
  136. package/dist/esm/internal/env.js +3 -2
  137. package/dist/esm/internal/platformFetch.d.ts +2 -0
  138. package/dist/esm/internal/platformFetch.js +9 -0
  139. package/dist/esm/internal/reservedIds.d.ts +8 -0
  140. package/dist/esm/internal/reservedIds.js +10 -0
  141. package/dist/esm/internal/serviceUrls.d.ts +5 -0
  142. package/dist/esm/internal/serviceUrls.js +10 -0
  143. package/dist/esm/pdf/index.js +2 -1
  144. package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
  145. package/dist/esm/runtime/index.d.ts +69 -21
  146. package/dist/esm/runtime/index.js +35 -29
  147. package/dist/esm/runtime/index.test.js +36 -36
  148. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +36 -19
  149. package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
  150. package/dist/esm/signin/conformance.d.ts +100 -0
  151. package/dist/esm/signin/conformance.js +616 -0
  152. package/dist/esm/signin/cookies.d.ts +28 -0
  153. package/dist/esm/signin/cookies.js +67 -0
  154. package/dist/esm/signin/encoding.d.ts +1 -0
  155. package/dist/esm/signin/encoding.js +12 -0
  156. package/dist/esm/signin/endpoints.d.ts +12 -0
  157. package/dist/esm/signin/endpoints.js +32 -0
  158. package/dist/esm/signin/http.d.ts +25 -0
  159. package/dist/esm/signin/http.js +106 -0
  160. package/dist/esm/signin/index.d.ts +8 -0
  161. package/dist/esm/signin/index.js +9 -0
  162. package/dist/esm/signin/keys.d.ts +35 -0
  163. package/dist/esm/signin/keys.js +230 -0
  164. package/dist/esm/signin/paths.d.ts +2 -0
  165. package/dist/esm/signin/paths.js +5 -0
  166. package/dist/esm/signin/seal.d.ts +19 -0
  167. package/dist/esm/signin/seal.js +47 -0
  168. package/dist/esm/signin/signin.d.ts +60 -0
  169. package/dist/esm/signin/signin.js +447 -0
  170. package/dist/esm/signin/transport.d.ts +112 -0
  171. package/dist/esm/signin/transport.js +1 -0
  172. package/dist/esm/signin/verifier.d.ts +2 -0
  173. package/dist/esm/signin/verifier.js +4 -0
  174. package/dist/esm/signin/verify.d.ts +83 -0
  175. package/dist/esm/signin/verify.js +142 -0
  176. package/dist/esm/sourceRoots.js +17 -17
  177. package/dist/esm/sourceRoots.test.js +34 -32
  178. package/dist/esm/start/access.d.ts +19 -0
  179. package/dist/esm/start/access.js +43 -0
  180. package/dist/esm/start/auth.d.ts +28 -0
  181. package/dist/esm/start/auth.js +33 -0
  182. package/dist/esm/start/automations/quiet.d.ts +2 -0
  183. package/dist/esm/start/automations/quiet.js +36 -0
  184. package/dist/esm/start/automations/registration.d.ts +13 -0
  185. package/dist/esm/start/automations/registration.js +25 -0
  186. package/dist/esm/start/automations/steps.d.ts +29 -0
  187. package/dist/esm/start/automations/steps.js +95 -0
  188. package/dist/esm/start/automations/workflow.d.ts +83 -0
  189. package/dist/esm/start/automations/workflow.js +36 -0
  190. package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
  191. package/dist/esm/start/automations/workflow.test-d.js +130 -0
  192. package/dist/esm/start/automations/workflowRun.d.ts +130 -0
  193. package/dist/esm/start/automations/workflowRun.js +185 -0
  194. package/dist/esm/start/barrel.test-d.d.ts +10 -0
  195. package/dist/esm/start/barrel.test-d.js +6 -0
  196. package/dist/esm/start/build/entries.d.ts +25 -0
  197. package/dist/esm/start/build/entries.js +109 -0
  198. package/dist/esm/start/build/placeholders/authHooksModule.d.ts +1 -0
  199. package/dist/esm/start/build/placeholders/authHooksModule.js +3 -0
  200. package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
  201. package/dist/esm/start/build/placeholders/devApp.js +3 -0
  202. package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
  203. package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
  204. package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
  205. package/dist/esm/start/build/placeholders/siteHead.js +3 -0
  206. package/dist/esm/start/build/placeholders/workflowModules.d.ts +1 -0
  207. package/dist/esm/start/build/placeholders/workflowModules.js +3 -0
  208. package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
  209. package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
  210. package/dist/esm/start/build/registrationHash.d.ts +11 -0
  211. package/dist/esm/start/build/registrationHash.js +88 -0
  212. package/dist/esm/start/build/sdk/axios.d.ts +76 -0
  213. package/dist/esm/start/build/sdk/axios.js +253 -0
  214. package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
  215. package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
  216. package/dist/esm/start/build/sdk/undici.d.ts +34 -0
  217. package/dist/esm/start/build/sdk/undici.js +18 -0
  218. package/dist/esm/start/build/sdkPatches.d.ts +22 -0
  219. package/dist/esm/start/build/sdkPatches.js +430 -0
  220. package/dist/esm/start/build/siteHead.d.ts +26 -0
  221. package/dist/esm/start/build/siteHead.js +88 -0
  222. package/dist/esm/start/build/vite.d.ts +50 -0
  223. package/dist/esm/start/build/vite.js +487 -0
  224. package/dist/esm/start/classicOnly.d.ts +1 -0
  225. package/dist/esm/start/classicOnly.js +4 -0
  226. package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
  227. package/dist/esm/start/clientErrorMessage.test.js +105 -0
  228. package/dist/esm/start/describe/describe.d.ts +120 -0
  229. package/dist/esm/start/describe/describe.js +372 -0
  230. package/dist/esm/start/describe/describeBuilt.d.ts +5 -0
  231. package/dist/esm/start/describe/describeBuilt.js +102 -0
  232. package/dist/esm/start/describe/descriptions.d.ts +4 -0
  233. package/dist/esm/start/describe/descriptions.js +54 -0
  234. package/dist/esm/start/errors.d.ts +62 -0
  235. package/dist/esm/start/errors.js +163 -0
  236. package/dist/esm/start/errors.test.d.ts +1 -0
  237. package/dist/esm/start/errors.test.js +54 -0
  238. package/dist/esm/start/factories.d.ts +14 -0
  239. package/dist/esm/start/factories.js +23 -0
  240. package/dist/esm/start/factories.test-d.d.ts +2 -0
  241. package/dist/esm/start/factories.test-d.js +60 -0
  242. package/dist/esm/start/failures.d.ts +7 -0
  243. package/dist/esm/start/failures.js +62 -0
  244. package/dist/esm/start/fnFactory.d.ts +16 -0
  245. package/dist/esm/start/fnFactory.js +1 -0
  246. package/dist/esm/start/host.d.ts +3 -0
  247. package/dist/esm/start/host.js +4 -0
  248. package/dist/esm/start/index.d.ts +10 -0
  249. package/dist/esm/start/index.js +7 -0
  250. package/dist/esm/start/login.d.ts +5 -0
  251. package/dist/esm/start/login.js +29 -0
  252. package/dist/esm/start/middlewareKind.d.ts +13 -0
  253. package/dist/esm/start/middlewareKind.js +9 -0
  254. package/dist/esm/start/platform/aiUsage.d.ts +29 -0
  255. package/dist/esm/start/platform/aiUsage.js +210 -0
  256. package/dist/esm/start/platform/airtable/arrayFields.d.ts +10 -0
  257. package/dist/esm/start/platform/airtable/arrayFields.js +30 -0
  258. package/dist/esm/start/platform/airtable/built.d.ts +2 -0
  259. package/dist/esm/start/platform/airtable/built.js +3 -0
  260. package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
  261. package/dist/esm/start/platform/airtable/cache.js +89 -0
  262. package/dist/esm/start/platform/airtable/dispatch.d.ts +57 -0
  263. package/dist/esm/start/platform/airtable/dispatch.js +541 -0
  264. package/dist/esm/start/platform/airtable/formulas.d.ts +70 -0
  265. package/dist/esm/start/platform/airtable/formulas.js +261 -0
  266. package/dist/esm/start/platform/airtable/index.d.ts +6 -0
  267. package/dist/esm/start/platform/airtable/index.js +51 -0
  268. package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
  269. package/dist/esm/start/platform/airtable/settings.js +138 -0
  270. package/dist/esm/start/platform/analytics.d.ts +3 -0
  271. package/dist/esm/start/platform/analytics.js +59 -0
  272. package/dist/esm/start/platform/calls.d.ts +5 -0
  273. package/dist/esm/start/platform/calls.js +104 -0
  274. package/dist/esm/start/platform/caps.d.ts +9 -0
  275. package/dist/esm/start/platform/caps.js +35 -0
  276. package/dist/esm/start/platform/connections.d.ts +25 -0
  277. package/dist/esm/start/platform/connections.js +198 -0
  278. package/dist/esm/start/platform/data/baseRunner.d.ts +97 -0
  279. package/dist/esm/start/platform/data/baseRunner.js +117 -0
  280. package/dist/esm/start/platform/data/dispatch.d.ts +17 -0
  281. package/dist/esm/start/platform/data/dispatch.js +216 -0
  282. package/dist/esm/start/platform/data/fetch.d.ts +7 -0
  283. package/dist/esm/start/platform/data/fetch.js +9 -0
  284. package/dist/esm/start/platform/data/index.d.ts +27 -0
  285. package/dist/esm/start/platform/data/index.js +75 -0
  286. package/dist/esm/start/platform/data/names.d.ts +7 -0
  287. package/dist/esm/start/platform/data/names.js +18 -0
  288. package/dist/esm/start/platform/data/sqlNameMappings.d.ts +58 -0
  289. package/dist/esm/start/platform/data/sqlNameMappings.js +92 -0
  290. package/dist/esm/start/platform/data/transformations.d.ts +97 -0
  291. package/dist/esm/start/platform/data/transformations.js +262 -0
  292. package/dist/esm/start/platform/data/types.d.ts +94 -0
  293. package/dist/esm/start/platform/data/types.js +14 -0
  294. package/dist/esm/start/platform/local.d.ts +6 -0
  295. package/dist/esm/start/platform/local.js +18 -0
  296. package/dist/esm/start/platform/meta.d.ts +3 -0
  297. package/dist/esm/start/platform/meta.js +33 -0
  298. package/dist/esm/start/platform/outbound.d.ts +17 -0
  299. package/dist/esm/start/platform/outbound.js +510 -0
  300. package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
  301. package/dist/esm/start/platform/redactSecrets.js +156 -0
  302. package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
  303. package/dist/esm/start/platform/redactSecrets.test.js +151 -0
  304. package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
  305. package/dist/esm/start/platform/requestSecrets.js +41 -0
  306. package/dist/esm/start/platform/runLog.d.ts +40 -0
  307. package/dist/esm/start/platform/runLog.js +149 -0
  308. package/dist/esm/start/platform/services.d.ts +7 -0
  309. package/dist/esm/start/platform/services.js +46 -0
  310. package/dist/esm/start/platform/steps.d.ts +9 -0
  311. package/dist/esm/start/platform/steps.js +60 -0
  312. package/dist/esm/start/platform/telemetry.d.ts +13 -0
  313. package/dist/esm/start/platform/telemetry.js +71 -0
  314. package/dist/esm/start/platform/transport.d.ts +28 -0
  315. package/dist/esm/start/platform/transport.js +59 -0
  316. package/dist/esm/start/platformHead.d.ts +23 -0
  317. package/dist/esm/start/platformHead.js +133 -0
  318. package/dist/esm/start/previewClaim.d.ts +6 -0
  319. package/dist/esm/start/previewClaim.js +24 -0
  320. package/dist/esm/start/protocol.d.ts +19 -0
  321. package/dist/esm/start/protocol.js +27 -0
  322. package/dist/esm/start/roles.d.ts +12 -0
  323. package/dist/esm/start/roles.js +27 -0
  324. package/dist/esm/start/router.d.ts +44 -0
  325. package/dist/esm/start/router.js +280 -0
  326. package/dist/esm/start/serve/authHooks.d.ts +7 -0
  327. package/dist/esm/start/serve/authHooks.js +18 -0
  328. package/dist/esm/start/serve/demo.d.ts +9 -0
  329. package/dist/esm/start/serve/demo.js +24 -0
  330. package/dist/esm/start/serve/fetch.d.ts +1 -0
  331. package/dist/esm/start/serve/fetch.js +6 -0
  332. package/dist/esm/start/serve/instance.d.ts +12 -0
  333. package/dist/esm/start/serve/instance.js +134 -0
  334. package/dist/esm/start/serve/invoke.d.ts +13 -0
  335. package/dist/esm/start/serve/invoke.js +126 -0
  336. package/dist/esm/start/serve/local/load.d.ts +8 -0
  337. package/dist/esm/start/serve/local/load.js +44 -0
  338. package/dist/esm/start/serve/local/provider.d.ts +25 -0
  339. package/dist/esm/start/serve/local/provider.js +188 -0
  340. package/dist/esm/start/serve/local/signIn.d.ts +28 -0
  341. package/dist/esm/start/serve/local/signIn.js +123 -0
  342. package/dist/esm/start/serve/pageHead.d.ts +20 -0
  343. package/dist/esm/start/serve/pageHead.js +34 -0
  344. package/dist/esm/start/serve/provider.d.ts +19 -0
  345. package/dist/esm/start/serve/provider.js +78 -0
  346. package/dist/esm/start/serve/requestEnv.d.ts +2 -0
  347. package/dist/esm/start/serve/requestEnv.js +84 -0
  348. package/dist/esm/start/serve/scope.d.ts +18 -0
  349. package/dist/esm/start/serve/scope.js +67 -0
  350. package/dist/esm/start/serve/server.d.ts +56 -0
  351. package/dist/esm/start/serve/server.js +297 -0
  352. package/dist/esm/start/serve/uploads.d.ts +2 -0
  353. package/dist/esm/start/serve/uploads.js +49 -0
  354. package/dist/esm/start/serve/worker.d.ts +6 -0
  355. package/dist/esm/start/serve/worker.js +12 -0
  356. package/dist/esm/start/types.d.ts +373 -0
  357. package/dist/esm/start/types.js +1 -0
  358. package/dist/esm/start/version.d.ts +1 -0
  359. package/dist/esm/start/version.js +2 -0
  360. package/dist/esm/steps/index.d.ts +8 -8
  361. package/dist/esm/steps/index.js +54 -54
  362. package/dist/esm/steps/index.test.js +220 -220
  363. package/dist/esm/sync/index.d.ts +1 -1
  364. package/dist/esm/sync/index.js +32 -31
  365. package/dist/esm/sync/lib.d.ts +15 -8
  366. package/dist/esm/sync/lib.js +656 -665
  367. package/dist/esm/sync/lib.test.js +81 -14
  368. package/dist/esm/sync/sdkNames.d.ts +67 -9
  369. package/dist/esm/sync/sdkNames.js +94 -30
  370. package/dist/esm/sync/sdkNames.test.js +192 -116
  371. package/dist/esm/types/fields.d.ts +1 -1
  372. package/dist/esm/types/fields.js +106 -98
  373. package/dist/esm/types/index.d.ts +2 -2
  374. package/dist/esm/types/index.js +2 -2
  375. package/dist/esm/types/tables.d.ts +1 -1
  376. package/dist/esm/types/tables.js +2 -2
  377. package/dist/esm/upload/index.js +89 -24
  378. package/dist/esm/upload/index.test.js +104 -1
  379. package/dist/esm/vite/domTagNames.js +252 -252
  380. package/dist/esm/vite/index.d.ts +1 -1
  381. package/dist/esm/vite/index.js +56 -47
  382. package/dist/esm/vite/index.test.js +10 -2
  383. package/package.json +129 -16
  384. package/dist/cjs/auth-server/index.d.ts +0 -369
  385. package/dist/cjs/auth-server/index.js +0 -119
  386. package/dist/cjs/meta/index.d.ts +0 -14
  387. package/dist/cjs/meta/index.js +0 -12
  388. package/dist/cjs/notifications/index.d.ts +0 -25
  389. package/dist/cjs/notifications/index.js +0 -12
  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/meta/index.d.ts +0 -14
  393. package/dist/esm/meta/index.js +0 -8
  394. package/dist/esm/notifications/index.d.ts +0 -25
  395. package/dist/esm/notifications/index.js +0 -8
@@ -0,0 +1,59 @@
1
+ // The platform's own requests on the request's app token. A request with no token or platform URLs reaches nothing: the
2
+ // host dispatches every request with both, and `local` mints its own.
3
+ import { platformFetch } from '../../internal/platformFetch.js';
4
+ import { DEMO_UNAVAILABLE_MESSAGE } from './data/dispatch.js';
5
+ const BACKEND_TIMEOUT_MS = 5_000;
6
+ export class PlatformError extends Error {
7
+ route;
8
+ status;
9
+ constructor(route, status) {
10
+ super(`${route} answered ${status}`);
11
+ this.route = route;
12
+ this.status = status;
13
+ }
14
+ }
15
+ /** Thrown for a platform call on a request that has no token or no platform URLs. */
16
+ export class NoPlatformError extends Error {
17
+ constructor() {
18
+ super("This request has no app token or platform URLs: Zite didn't dispatch it");
19
+ this.name = 'NoPlatformError';
20
+ }
21
+ }
22
+ /** What a demo's call is refused with when it would act on the author's live app. */
23
+ export const DEMO_REFUSED = {
24
+ error: { code: 'FORBIDDEN', message: DEMO_UNAVAILABLE_MESSAGE },
25
+ };
26
+ /** The request's token and where to send it, renewed first if it's about to expire; undefined without either. */
27
+ export const directAccess = async (host) => {
28
+ const urls = host.provider?.urls;
29
+ const token = urls ? await host.provider?.token() : undefined;
30
+ return urls && token ? { token, urls } : undefined;
31
+ };
32
+ /** As `directAccess`, failing loudly without a token or URLs. */
33
+ export const requireAccess = async (host) => {
34
+ const access = await directAccess(host);
35
+ if (!access)
36
+ throw new NoPlatformError();
37
+ return access;
38
+ };
39
+ /** One request to the platform as JSON, on the token. */
40
+ export const sendOnToken = (token, url, init) => platformFetch(new Request(url, {
41
+ method: init.method,
42
+ headers: {
43
+ authorization: `Bearer ${token}`,
44
+ 'content-type': 'application/json',
45
+ },
46
+ body: init.body,
47
+ ...(init.timeoutMs && { signal: AbortSignal.timeout(init.timeoutMs) }),
48
+ }));
49
+ export const platformJson = async (access, method, url, route, body) => {
50
+ const response = await sendOnToken(access.token, url, {
51
+ method,
52
+ body: body === undefined ? undefined : JSON.stringify(body),
53
+ timeoutMs: BACKEND_TIMEOUT_MS,
54
+ });
55
+ if (!response.ok)
56
+ throw new PlatformError(route, response.status);
57
+ return (await response.json());
58
+ };
59
+ export const backendJson = (access, method, path, body) => platformJson(access, method, `${access.urls.backend}/v1/start/app${path}`, path, body);
@@ -0,0 +1,23 @@
1
+ import type { JSX } from 'react';
2
+ import type { PlatformHead } from './types.js';
3
+ type Meta = JSX.IntrinsicElements['meta'];
4
+ type Link = JSX.IntrinsicElements['link'];
5
+ type Script = JSX.IntrinsicElements['script'];
6
+ /** What a route's `head()` answers, as TanStack's React router types it. */
7
+ export type RouteHead = {
8
+ meta?: Array<Meta | undefined>;
9
+ links?: Array<Link | undefined>;
10
+ scripts?: Array<Script | undefined>;
11
+ styles?: Array<JSX.IntrinsicElements['style'] | undefined>;
12
+ };
13
+ /** Where an installable app's web manifest is served. */
14
+ export declare const MANIFEST_PATH = "/manifest.webmanifest";
15
+ /** @internal Takes in what the page carried. */
16
+ export declare const keepHydratedHead: (head: PlatformHead | undefined) => void;
17
+ /**
18
+ * @internal The root route's head: the app's Settings first, as the site-wide default for its title, description and
19
+ * share tags, which `own` (the root's own entries) and any page's head() can set their own of. The platform's favicon,
20
+ * manifest and installable-app tags and its scripts come with them, and nothing of the app's replaces those.
21
+ */
22
+ export declare const withPlatformHead: (own?: RouteHead) => RouteHead;
23
+ export {};
@@ -0,0 +1,133 @@
1
+ import { currentHost } from './host.js';
2
+ /** Where an installable app's web manifest is served. */
3
+ export const MANIFEST_PATH = '/manifest.webmanifest';
4
+ // The browser's, from the page it hydrated; the server's is the request's own.
5
+ let hydrated;
6
+ /** @internal Takes in what the page carried. */
7
+ export const keepHydratedHead = (head) => {
8
+ hydrated = head;
9
+ };
10
+ const PWA_METAS = new Set([
11
+ 'theme-color',
12
+ 'mobile-web-app-capable',
13
+ 'apple-mobile-web-app-capable',
14
+ 'apple-mobile-web-app-title',
15
+ ]);
16
+ const PLATFORM_SCRIPTS = [
17
+ 'data-zite-branding',
18
+ 'data-zite-analytics',
19
+ 'data-zite-demo',
20
+ ];
21
+ // Safe inside a <script>: nothing in it can close the tag.
22
+ const scriptJson = (value) => JSON.stringify(value).replace(/</g, '\\u003c');
23
+ const metaKey = (meta) => meta?.name ?? meta?.property;
24
+ const rels = (link) => (link?.rel ?? '').toLowerCase().split(/\s+/);
25
+ // Only the platform writes these, each marked so a copy in the app's own head can be told apart.
26
+ const platformScript = (marker, children) => ({
27
+ ...{ [marker]: 'true' },
28
+ children,
29
+ });
30
+ /**
31
+ * @internal The root route's head: the app's Settings first, as the site-wide default for its title, description and
32
+ * share tags, which `own` (the root's own entries) and any page's head() can set their own of. The platform's favicon,
33
+ * manifest and installable-app tags and its scripts come with them, and nothing of the app's replaces those.
34
+ */
35
+ export const withPlatformHead = (own = {}) => {
36
+ const head = typeof window === 'undefined' ? currentHost()?.head : hydrated;
37
+ if (!head)
38
+ return own;
39
+ const { site, platform } = head;
40
+ const appleTouchIcon = site.appleTouchIcon ?? site.icon;
41
+ const shared = site.title !== undefined ||
42
+ site.description !== undefined ||
43
+ site.image !== undefined;
44
+ const meta = [
45
+ { name: 'viewport', content: 'width=device-width, initial-scale=1' },
46
+ ...(site.title !== undefined
47
+ ? [
48
+ { title: site.title },
49
+ { property: 'og:title', content: site.title },
50
+ { property: 'og:site_name', content: site.title || 'Zite' },
51
+ { name: 'twitter:title', content: site.title },
52
+ ]
53
+ : []),
54
+ ...(site.description !== undefined
55
+ ? [
56
+ { name: 'description', content: site.description },
57
+ { property: 'og:description', content: site.description },
58
+ { name: 'twitter:description', content: site.description },
59
+ ]
60
+ : []),
61
+ ...(shared
62
+ ? [
63
+ { property: 'og:type', content: 'website' },
64
+ { name: 'twitter:card', content: 'summary_large_image' },
65
+ ]
66
+ : []),
67
+ ...(site.image
68
+ ? [
69
+ { property: 'og:image', content: site.image },
70
+ { name: 'twitter:image', content: site.image },
71
+ ]
72
+ : []),
73
+ ...(site.manifest
74
+ ? [
75
+ { name: 'theme-color', content: site.manifest.theme_color },
76
+ { name: 'mobile-web-app-capable', content: 'yes' },
77
+ { name: 'apple-mobile-web-app-capable', content: 'yes' },
78
+ {
79
+ name: 'apple-mobile-web-app-title',
80
+ content: site.manifest.short_name,
81
+ },
82
+ ]
83
+ : []),
84
+ ];
85
+ const links = [
86
+ ...(site.icon
87
+ ? [{ rel: 'icon', type: 'image/x-icon', href: site.icon }]
88
+ : []),
89
+ ...(appleTouchIcon
90
+ ? [{ rel: 'apple-touch-icon', href: appleTouchIcon }]
91
+ : []),
92
+ ...(site.manifest
93
+ ? [
94
+ {
95
+ rel: 'manifest',
96
+ href: MANIFEST_PATH,
97
+ crossOrigin: 'use-credentials',
98
+ },
99
+ ]
100
+ : []),
101
+ ];
102
+ // The demo's listing before the runtime, whose demo bridge reads it as it starts.
103
+ const scripts = platform
104
+ ? [
105
+ ...(platform.demo
106
+ ? [
107
+ platformScript('data-zite-demo', `window.__ziteDemo = ${scriptJson(platform.demo)};`),
108
+ ]
109
+ : []),
110
+ ...(platform.runtimeUrl ? [{ src: platform.runtimeUrl }] : []),
111
+ platformScript('data-zite-branding', `window.__ziteBranding = ${platform.branding};`),
112
+ platformScript('data-zite-analytics', `window.__ziteAnalytics = ${scriptJson(platform.analytics)};`),
113
+ ]
114
+ : [];
115
+ const kept = (rel) => (rel === 'icon' && !!site.icon) ||
116
+ (rel === 'apple-touch-icon' && !!appleTouchIcon) ||
117
+ (rel === 'manifest' && !!site.manifest);
118
+ return {
119
+ ...own,
120
+ meta: [
121
+ ...meta,
122
+ ...(own.meta ?? []).filter(entry => !(site.manifest && PWA_METAS.has(metaKey(entry) ?? ''))),
123
+ ],
124
+ links: [
125
+ ...links,
126
+ ...(own.links ?? []).filter(link => !rels(link).some(kept)),
127
+ ],
128
+ scripts: [
129
+ ...scripts,
130
+ ...(own.scripts ?? []).filter(script => !PLATFORM_SCRIPTS.some(marker => script && marker in script)),
131
+ ],
132
+ };
133
+ };
@@ -0,0 +1,6 @@
1
+ import { PREVIEW_CLAIM_PARAM } from '../auth/previewClaim.js';
2
+ export { PREVIEW_CLAIM_PARAM };
3
+ /** An editor preview's access: on the server the host hands it over, in the browser it's on the URL. */
4
+ export declare const previewClaim: () => string | undefined;
5
+ /** Every same-origin fetch from the page carries the claim: server functions and the app's own routes alike. */
6
+ export declare const carryPreviewClaim: (claim: string) => void;
@@ -0,0 +1,24 @@
1
+ import { browserPreviewClaim, PREVIEW_CLAIM_PARAM, } from '../auth/previewClaim.js';
2
+ import { currentHost } from './host.js';
3
+ import { PREVIEW_CLAIM_HEADER } from './protocol.js';
4
+ export { PREVIEW_CLAIM_PARAM };
5
+ /** An editor preview's access: on the server the host hands it over, in the browser it's on the URL. */
6
+ export const previewClaim = () => typeof window === 'undefined'
7
+ ? currentHost()?.previewClaim
8
+ : browserPreviewClaim();
9
+ let carrying = false;
10
+ /** Every same-origin fetch from the page carries the claim: server functions and the app's own routes alike. */
11
+ export const carryPreviewClaim = (claim) => {
12
+ if (carrying || typeof window === 'undefined')
13
+ return;
14
+ carrying = true;
15
+ const original = window.fetch.bind(window);
16
+ window.fetch = (input, init) => {
17
+ const target = new URL(input instanceof Request ? input.url : String(input), window.location.href);
18
+ if (target.origin !== window.location.origin)
19
+ return original(input, init);
20
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
21
+ headers.set(PREVIEW_CLAIM_HEADER, claim);
22
+ return original(input, { ...init, headers });
23
+ };
24
+ };
@@ -0,0 +1,19 @@
1
+ export { isReservedIntegrationId, RESERVED_INTEGRATION_IDS, } from '../internal/reservedIds.js';
2
+ export type { AppContext, ExpiringToken, HostConnection, HostMode, HostPage, HostProps, PlatformBinding, SiteHead, WebManifest, } from './types.js';
3
+ /** What the host dispatches a request to do beside serving it; without props, only `warm` and `describe`. */
4
+ export declare const INVOKE_KINDS: readonly ["webhook", "describe", "workflow", "register", "warm", "authHook", "function"];
5
+ export type InvokeKind = (typeof INVOKE_KINDS)[number];
6
+ export declare const isInvokeKind: (kind: unknown) => kind is InvokeKind;
7
+ /** `warm` or `describe`, on a request the host sends without props. */
8
+ export declare const INVOKE_HEADER = "x-zite-invoke";
9
+ /** Where the host POSTs a workflow, registration, auth hook or test run, with `{ input }`. */
10
+ export declare const INVOKE_PATH = "/_zite/invoke";
11
+ /** On describe's answer: the zitejs the build's server code was bundled from. */
12
+ export declare const RUNTIME_VERSION_HEADER = "x-zitejs-version";
13
+ /** An editor preview's access, on every same-origin fetch its pages make. */
14
+ export declare const PREVIEW_CLAIM_HEADER = "x-zite-preview";
15
+ /** At the gateway, the connection a call on Zite's AI key bills to. */
16
+ export declare const GATEWAY_CONNECTION_HEADER = "x-zite-gateway-connection";
17
+ /** On a demo's refused answer, beside its 403, so the platform's runtime shows the demo notice. */
18
+ export declare const ERROR_CODE_HEADER = "x-zite-error-code";
19
+ export declare const DEMO_READ_ONLY_CODE = "DEMO_READ_ONLY";
@@ -0,0 +1,27 @@
1
+ // What a Start build and the platform's host say to each other on the wire. Import-free but for the reserved ids,
2
+ // themselves import-free, so the host takes these without loading anything of zitejs.
3
+ export { isReservedIntegrationId, RESERVED_INTEGRATION_IDS, } from '../internal/reservedIds.js';
4
+ /** What the host dispatches a request to do beside serving it; without props, only `warm` and `describe`. */
5
+ export const INVOKE_KINDS = [
6
+ 'webhook',
7
+ 'describe',
8
+ 'workflow',
9
+ 'register',
10
+ 'warm',
11
+ 'authHook',
12
+ 'function',
13
+ ];
14
+ export const isInvokeKind = (kind) => INVOKE_KINDS.includes(kind);
15
+ /** `warm` or `describe`, on a request the host sends without props. */
16
+ export const INVOKE_HEADER = 'x-zite-invoke';
17
+ /** Where the host POSTs a workflow, registration, auth hook or test run, with `{ input }`. */
18
+ export const INVOKE_PATH = '/_zite/invoke';
19
+ /** On describe's answer: the zitejs the build's server code was bundled from. */
20
+ export const RUNTIME_VERSION_HEADER = 'x-zitejs-version';
21
+ /** An editor preview's access, on every same-origin fetch its pages make. */
22
+ export const PREVIEW_CLAIM_HEADER = 'x-zite-preview';
23
+ /** At the gateway, the connection a call on Zite's AI key bills to. */
24
+ export const GATEWAY_CONNECTION_HEADER = 'x-zite-gateway-connection';
25
+ /** On a demo's refused answer, beside its 403, so the platform's runtime shows the demo notice. */
26
+ export const ERROR_CODE_HEADER = 'x-zite-error-code';
27
+ export const DEMO_READ_ONLY_CODE = 'DEMO_READ_ONLY';
@@ -0,0 +1,12 @@
1
+ import type { User } from './types.js';
2
+ /**
3
+ * By the role's id, as classic's does: a role's name can change. Takes the user, or a context carrying one as
4
+ * classic's `hasRole(context, id)` does; signed out, no one has a role.
5
+ */
6
+ export declare const hasRole: (who: User | {
7
+ user: User | null;
8
+ } | null | undefined, roleId: string) => boolean;
9
+ /** Signed-in users with this role, by its id. */
10
+ export declare const role: (id: string) => import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, readonly [import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, {
11
+ user: User;
12
+ }>], undefined>;
@@ -0,0 +1,27 @@
1
+ import { createMiddleware } from '@tanstack/react-start';
2
+ import { signedIn } from './access.js';
3
+ import { ZiteError } from './errors.js';
4
+ import { withStatus } from './failures.js';
5
+ import { tag } from './middlewareKind.js';
6
+ /**
7
+ * By the role's id, as classic's does: a role's name can change. Takes the user, or a context carrying one as
8
+ * classic's `hasRole(context, id)` does; signed out, no one has a role.
9
+ */
10
+ export const hasRole = (who, roleId) => {
11
+ const user = who && 'user' in who ? who.user : who;
12
+ return user?.roles.some(({ id }) => id === roleId) ?? false;
13
+ };
14
+ /** Signed-in users with this role, by its id. */
15
+ export const role = (id) => tag(createMiddleware()
16
+ .middleware([signedIn])
17
+ .server(({ next, context, serverFnMeta }) => withStatus(!!serverFnMeta, async () => {
18
+ if (!hasRole(context.user, id)) {
19
+ // A role's id means nothing to the app's users; the editor still reads which one.
20
+ throw new ZiteError({
21
+ code: 'FORBIDDEN',
22
+ message: `Requires the ${id} role`,
23
+ userFacingMessage: "You don't have access to this.",
24
+ });
25
+ }
26
+ return next();
27
+ })), { kind: 'role', role: id });
@@ -0,0 +1,44 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ import { type AnyRoute, type RouterConstructorOptions, type RouterHistory } from '@tanstack/react-router';
3
+ import { type ProfileChanges } from '../auth/profileUpdates.js';
4
+ import type { HostMode, PlatformHead, User } from './types.js';
5
+ export declare const QUERY_STALE_TIME_MS = 30000;
6
+ /** The router context every Zite app's root route declares: `createRootRouteWithContext<ZiteRouterContext>()`. */
7
+ export type ZiteRouterContext = {
8
+ user: User | null;
9
+ queryClient: QueryClient;
10
+ };
11
+ type Dehydrated = {
12
+ user: User | null;
13
+ mode?: HostMode;
14
+ head?: PlatformHead;
15
+ };
16
+ /**
17
+ * @internal What a page carries to the browser beside its queries: the signed-in user, the mode it was served in, and
18
+ * the platform's head entries, which the browser renders again as it navigates.
19
+ */
20
+ export declare const dehydrateZite: (context: ZiteRouterContext) => Dehydrated;
21
+ /** @internal The user after a profile edit, named as the host names them: first and last name, else the email. */
22
+ export declare const withProfile: (user: User, changes: ProfileChanges) => User;
23
+ /** @internal In the browser: `updateProfile` from zitejs/auth updates the router's user and reruns its guards and loaders. */
24
+ export declare const refreshOnProfileUpdate: (router: {
25
+ invalidate: () => Promise<void>;
26
+ }, context: ZiteRouterContext) => void;
27
+ /** @internal Takes in what the page carried. */
28
+ export declare const hydrateZite: (context: ZiteRouterContext, dehydrated: Dehydrated) => void;
29
+ type ZiteRouterOptions<TRouteTree extends AnyRoute> = Omit<RouterConstructorOptions<TRouteTree, 'never', false, RouterHistory, Dehydrated>, 'context' | 'dehydrate' | 'hydrate'>;
30
+ /**
31
+ * @internal Tells the editor's preview the page crashed, as classic's runtime reports an emptied #root: a Start page
32
+ * has none, and an error a route's boundary catches is the crash. Being signed out isn't one.
33
+ */
34
+ export declare const reportCrash: (error: unknown) => void;
35
+ /**
36
+ * The router for `src/router.tsx`. The signed-in user is in `context.user`: on the server from the platform, in the
37
+ * browser from the page it rendered, so no request asks for it again. `context.queryClient` is new for each request
38
+ * on the server, so a page never renders with another visitor's cached queries, and its queries reach the browser
39
+ * with the page.
40
+ */
41
+ export declare function createZiteRouter<TRouteTree extends AnyRoute>(options: ZiteRouterOptions<TRouteTree>): import("@tanstack/router-core").RouterCore<TRouteTree, "never", false, RouterHistory, Dehydrated>;
42
+ /** @internal Whether createZiteRouter built it: describe refuses a router file whose router it didn't. */
43
+ export declare const isZiteRouter: (router: unknown) => boolean;
44
+ export {};
@@ -0,0 +1,280 @@
1
+ import { createElement as h, useEffect, useState } from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { createRouter, Link, useRouter, } from '@tanstack/react-router';
4
+ import { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query';
5
+ import { createMiddleware } from '@tanstack/react-start';
6
+ import { asCrossed, errorFromThrown, isSignInError, withThrownRejections, } from './errors.js';
7
+ import { carryPreviewClaim, PREVIEW_CLAIM_PARAM, previewClaim, } from './previewClaim.js';
8
+ import { currentHost } from './host.js';
9
+ import { INVOKE_PATH } from './protocol.js';
10
+ import { keepRenderedMode } from '../internal/appMode.js';
11
+ import { onProfileUpdated, } from '../auth/profileUpdates.js';
12
+ import { keepHydratedHead, withPlatformHead, } from './platformHead.js';
13
+ // Long enough that a page's queries don't refetch as the browser picks it up, short enough to stay fresh.
14
+ export const QUERY_STALE_TIME_MS = 30_000;
15
+ /**
16
+ * @internal What a page carries to the browser beside its queries: the signed-in user, the mode it was served in, and
17
+ * the platform's head entries, which the browser renders again as it navigates.
18
+ */
19
+ export const dehydrateZite = (context) => {
20
+ const host = currentHost();
21
+ return {
22
+ user: context.user,
23
+ mode: host?.mode,
24
+ ...(host?.head && { head: host.head }),
25
+ };
26
+ };
27
+ /** @internal The user after a profile edit, named as the host names them: first and last name, else the email. */
28
+ export const withProfile = (user, changes) => {
29
+ const { firstName: _firstName, lastName: _lastName, ...rest } = user;
30
+ const firstName = changes.firstName !== undefined ? changes.firstName : user.firstName;
31
+ const lastName = changes.lastName !== undefined ? changes.lastName : user.lastName;
32
+ return {
33
+ ...rest,
34
+ name: [firstName, lastName].filter(Boolean).join(' ') || user.email,
35
+ ...(firstName && { firstName }),
36
+ ...(lastName && { lastName }),
37
+ };
38
+ };
39
+ /** @internal In the browser: `updateProfile` from zitejs/auth updates the router's user and reruns its guards and loaders. */
40
+ export const refreshOnProfileUpdate = (router, context) => onProfileUpdated(changes => {
41
+ if (!context.user)
42
+ return;
43
+ context.user = withProfile(context.user, changes);
44
+ void router.invalidate();
45
+ });
46
+ /** @internal Takes in what the page carried. */
47
+ export const hydrateZite = (context, dehydrated) => {
48
+ context.user = dehydrated.user;
49
+ keepRenderedMode(dehydrated.mode);
50
+ keepHydratedHead(dehydrated.head);
51
+ };
52
+ const ziteWindow = () => typeof window === 'undefined' ? undefined : window;
53
+ const box = {
54
+ maxWidth: 480,
55
+ margin: '15vh auto',
56
+ padding: 24,
57
+ fontFamily: 'system-ui, sans-serif',
58
+ textAlign: 'center',
59
+ };
60
+ /**
61
+ * @internal Tells the editor's preview the page crashed, as classic's runtime reports an emptied #root: a Start page
62
+ * has none, and an error a route's boundary catches is the crash. Being signed out isn't one.
63
+ */
64
+ export const reportCrash = (error) => {
65
+ if (!isSignInError(error))
66
+ ziteWindow()?._ziteOnCrash?.(error);
67
+ };
68
+ // As classic's crash screen: the message, "Fix it for me" in the editor, and a reload. The server renders from the
69
+ // error the router already mapped and the browser from the one that crossed, so both show the same text.
70
+ function ZiteErrorComponent({ error }) {
71
+ const router = useRouter();
72
+ const [allowAiFix, setAllowAiFix] = useState(false);
73
+ useEffect(() => setAllowAiFix(ziteWindow()?.__ziteAllowAiFix === true), []);
74
+ useEffect(() => markReady('error'), []);
75
+ const message = error instanceof Error ? error.message : String(error);
76
+ const reload = () => {
77
+ const onReload = ziteWindow()?._ziteOnReload;
78
+ if (onReload)
79
+ onReload();
80
+ else
81
+ router.invalidate();
82
+ };
83
+ return h('div', { role: 'alert', style: box }, h('p', { style: { fontWeight: 600 } }, 'Something went wrong'), h('pre', { style: { whiteSpace: 'pre-wrap', textAlign: 'left' } }, message), allowAiFix &&
84
+ !isSignInError(error) &&
85
+ h('button', {
86
+ type: 'button',
87
+ onClick: () => ziteWindow()?._ziteOnFixError?.(error),
88
+ }, 'Fix it for me'), h('button', { type: 'button', onClick: reload }, 'Try again'));
89
+ }
90
+ /**
91
+ * `<html data-zite-ready>`: what the platform's screenshots wait for. `1` once
92
+ * the page has rendered with nothing loading, `error` when the error screen did.
93
+ */
94
+ const markReady = (state) => {
95
+ if (typeof document !== 'undefined')
96
+ document.documentElement.dataset.ziteReady = state;
97
+ };
98
+ const watchReady = (router) => () => {
99
+ const { status, isLoading, matches } = router.state;
100
+ if (status !== 'idle' ||
101
+ isLoading ||
102
+ matches.some(match => match.status === 'pending'))
103
+ return;
104
+ markReady(matches.some(match => match.status === 'error') ? 'error' : '1');
105
+ };
106
+ function ZiteNotFound() {
107
+ return h('div', { style: box }, h('p', { style: { fontWeight: 600 } }, 'Page not found'), h(Link, { to: '/' }, 'Go home'));
108
+ }
109
+ function ZitePending() {
110
+ return h('div', { 'aria-busy': true, style: { ...box, color: '#888' } }, 'Loading…');
111
+ }
112
+ const rejectingWithErrors = (load) => (...args) => {
113
+ const out = load(...args);
114
+ return out instanceof Promise
115
+ ? out.then(withThrownRejections)
116
+ : withThrownRejections(out);
117
+ };
118
+ // A loader's error crosses to the browser as thrown, and so does a deferred value's rejection; only an Error goes
119
+ // through the zite-error adapter. A route's onError may replace its error; routes outlive a request's router, so each
120
+ // is wrapped once.
121
+ const wrapped = new WeakSet();
122
+ const failWithErrors = (routes) => {
123
+ for (const route of routes) {
124
+ if (wrapped.has(route))
125
+ continue;
126
+ wrapped.add(route);
127
+ const own = route.options.onError;
128
+ const loader = route.options.loader;
129
+ route.update({
130
+ onError: (error) => {
131
+ let failure = error;
132
+ try {
133
+ own?.(error);
134
+ }
135
+ catch (replaced) {
136
+ failure = replaced;
137
+ }
138
+ const normalized = errorFromThrown(failure);
139
+ // The server renders a failed route's error component in-process.
140
+ if (typeof window === 'undefined' && normalized instanceof Error)
141
+ throw asCrossed(normalized);
142
+ if (normalized !== error)
143
+ throw normalized;
144
+ },
145
+ ...(loader && {
146
+ loader: typeof loader === 'function'
147
+ ? rejectingWithErrors(loader)
148
+ : { ...loader, handler: rejectingWithErrors(loader.handler) },
149
+ }),
150
+ });
151
+ }
152
+ };
153
+ // The host's test run of a server function, answered at the invoke path in TanStack's own request, so the function runs
154
+ // as a page's call does. Root middleware, so it stands before any route of the app's and describe lists no route.
155
+ const invokeRoute = createMiddleware().server(({ next, pathname }) => {
156
+ const run = pathname === INVOKE_PATH ? currentHost()?.functionRun : undefined;
157
+ return run ? run() : next();
158
+ });
159
+ const invoking = new WeakSet();
160
+ const withInvokeRoute = (root) => {
161
+ if (invoking.has(root))
162
+ return;
163
+ invoking.add(root);
164
+ const { server } = root.options;
165
+ root.options.server = {
166
+ ...server,
167
+ middleware: [invokeRoute, ...(server?.middleware ?? [])],
168
+ };
169
+ };
170
+ // The platform's head goes on every page whatever the app's root asks for, as the page's defaults and the platform's
171
+ // own tags. On the server and in the browser, where it's the one the page carried; once per root, as routes outlive
172
+ // a request's router.
173
+ const headed = new WeakSet();
174
+ const withRootHead = (root) => {
175
+ if (headed.has(root))
176
+ return;
177
+ headed.add(root);
178
+ const own = root.options.head;
179
+ const head = ctx => {
180
+ const asked = own?.(ctx);
181
+ return asked instanceof Promise
182
+ ? asked.then(withPlatformHead)
183
+ : withPlatformHead(asked);
184
+ };
185
+ root.options.head = head;
186
+ };
187
+ // The claim stays on every URL the router writes, and the app's own routes never see it.
188
+ const keepPreviewClaim = (claim, own) => ({
189
+ input: ({ url }) => {
190
+ url.searchParams.delete(PREVIEW_CLAIM_PARAM);
191
+ return own?.input?.({ url }) ?? url;
192
+ },
193
+ output: ({ url }) => {
194
+ const rewritten = own?.output?.({ url }) ?? url;
195
+ const out = new URL(rewritten.toString(), url);
196
+ out.searchParams.set(PREVIEW_CLAIM_PARAM, claim);
197
+ return out;
198
+ },
199
+ });
200
+ /**
201
+ * The router for `src/router.tsx`. The signed-in user is in `context.user`: on the server from the platform, in the
202
+ * browser from the page it rendered, so no request asks for it again. `context.queryClient` is new for each request
203
+ * on the server, so a page never renders with another visitor's cached queries, and its queries reach the browser
204
+ * with the page.
205
+ */
206
+ export function createZiteRouter(options) {
207
+ const queryClient = new QueryClient({
208
+ defaultOptions: { queries: { staleTime: QUERY_STALE_TIME_MS } },
209
+ });
210
+ const claim = previewClaim();
211
+ if (claim)
212
+ carryPreviewClaim(claim);
213
+ const context = {
214
+ user: currentHost()?.user ?? null,
215
+ queryClient,
216
+ };
217
+ const router = createRouter({
218
+ defaultPreload: 'intent',
219
+ defaultPreloadStaleTime: 0,
220
+ scrollRestoration: true,
221
+ defaultErrorComponent: ZiteErrorComponent,
222
+ defaultNotFoundComponent: ZiteNotFound,
223
+ defaultPendingComponent: ZitePending,
224
+ ...options,
225
+ ...(claim && { rewrite: keepPreviewClaim(claim, options.rewrite) }),
226
+ // Whichever screen shows it: a route may have its own.
227
+ defaultOnCatch: (error, info) => {
228
+ markReady('error');
229
+ reportCrash(error);
230
+ options.defaultOnCatch?.(error, info);
231
+ },
232
+ context,
233
+ dehydrate: () => dehydrateZite(context),
234
+ hydrate: (dehydrated) => hydrateZite(context, dehydrated),
235
+ });
236
+ if (typeof window === 'undefined')
237
+ withInvokeRoute(router.routeTree);
238
+ withRootHead(router.routeTree);
239
+ failWithErrors(Object.values(router.routesById));
240
+ setupRouterSsrQueryIntegration({ router, queryClient });
241
+ const mark = watchReady(router);
242
+ router.subscribe('onResolved', mark);
243
+ router.subscribe('onRendered', mark);
244
+ const host = currentHost();
245
+ if (host)
246
+ host.router = router;
247
+ if (typeof window === 'undefined')
248
+ refuseOtherRequests(router, host);
249
+ else
250
+ refreshOnProfileUpdate(router, context);
251
+ loadPlatformPagesAsDocuments(router);
252
+ Object.defineProperty(router, ZITE_ROUTER, { value: true });
253
+ return router;
254
+ }
255
+ // Shared across copies of zitejs in one bundle, like an automation's tag.
256
+ const ZITE_ROUTER = Symbol.for('zitejs:router');
257
+ /** @internal Whether createZiteRouter built it: describe refuses a router file whose router it didn't. */
258
+ export const isZiteRouter = (router) => typeof router === 'object' &&
259
+ router !== null &&
260
+ router[ZITE_ROUTER] === true;
261
+ // The platform serves these, so no route of the app's matches them: going there, by a link or a guard's redirect,
262
+ // loads the document instead.
263
+ const PLATFORM_PAGES = /^\/auth(\/|$)/;
264
+ const loadPlatformPagesAsDocuments = (router) => {
265
+ const commit = router.commitLocation;
266
+ router.commitLocation = next => commit(PLATFORM_PAGES.test(next.pathname)
267
+ ? { ...next, maskedLocation: undefined, external: true }
268
+ : next);
269
+ };
270
+ // A router built once for the isolate would render the first visitor's user and cached queries into every
271
+ // later visitor's page, and its guards would treat everyone as that visitor.
272
+ const refuseOtherRequests = (router, builtFor) => {
273
+ const load = router.load.bind(router);
274
+ router.load = async (...args) => {
275
+ if (currentHost() !== builtFor) {
276
+ throw new Error('This router was built for another request. Call createZiteRouter inside getRouter, so each request gets its own.');
277
+ }
278
+ return load(...args);
279
+ };
280
+ };