jazz-tools 2.0.0-alpha.60 → 2.0.0-alpha.61

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 (544) hide show
  1. package/README.md +1 -1
  2. package/bin/jazz-tools.js +3 -0
  3. package/dist/_dev/native-account-session.d.ts +8 -1
  4. package/dist/_dev/native-account-session.d.ts.map +1 -1
  5. package/dist/_dev/native-account-session.js +10 -0
  6. package/dist/_dev/native-account-session.js.map +1 -1
  7. package/dist/accounts/account-manager-core.d.ts +6 -0
  8. package/dist/accounts/account-manager-core.d.ts.map +1 -1
  9. package/dist/accounts/account-manager-core.js +26 -2
  10. package/dist/accounts/account-manager-core.js.map +1 -1
  11. package/dist/accounts/enrollment.d.ts.map +1 -1
  12. package/dist/accounts/enrollment.js +11 -4
  13. package/dist/accounts/enrollment.js.map +1 -1
  14. package/dist/accounts/exports.d.ts +1 -2
  15. package/dist/accounts/exports.d.ts.map +1 -1
  16. package/dist/accounts/exports.js +4 -1
  17. package/dist/accounts/exports.js.map +1 -1
  18. package/dist/accounts/persistence.d.ts +8 -0
  19. package/dist/accounts/persistence.d.ts.map +1 -1
  20. package/dist/accounts/persistence.js +12 -0
  21. package/dist/accounts/persistence.js.map +1 -1
  22. package/dist/accounts/registry-client.d.ts +20 -0
  23. package/dist/accounts/registry-client.d.ts.map +1 -1
  24. package/dist/accounts/registry-client.js +34 -0
  25. package/dist/accounts/registry-client.js.map +1 -1
  26. package/dist/accounts/state.d.ts.map +1 -1
  27. package/dist/accounts/state.js +2 -1
  28. package/dist/accounts/state.js.map +1 -1
  29. package/dist/backend/create-jazz-session.d.ts +9 -7
  30. package/dist/backend/create-jazz-session.d.ts.map +1 -1
  31. package/dist/backend/create-jazz-session.js +55 -17
  32. package/dist/backend/create-jazz-session.js.map +1 -1
  33. package/dist/backend/create-jazz.d.ts +122 -34
  34. package/dist/backend/create-jazz.d.ts.map +1 -1
  35. package/dist/backend/create-jazz.js +396 -101
  36. package/dist/backend/create-jazz.js.map +1 -1
  37. package/dist/backend/early-db.d.ts.map +1 -1
  38. package/dist/backend/early-db.js +1 -0
  39. package/dist/backend/early-db.js.map +1 -1
  40. package/dist/backend/from-jwt.d.ts +2 -2
  41. package/dist/backend/from-jwt.d.ts.map +1 -1
  42. package/dist/backend/from-jwt.js +7 -1
  43. package/dist/backend/from-jwt.js.map +1 -1
  44. package/dist/backend/index.d.ts +2 -1
  45. package/dist/backend/index.d.ts.map +1 -1
  46. package/dist/backend/index.js +3 -1
  47. package/dist/backend/index.js.map +1 -1
  48. package/dist/backend/inspect-ui.d.ts +14 -0
  49. package/dist/backend/inspect-ui.d.ts.map +1 -0
  50. package/dist/backend/inspect-ui.js +156 -0
  51. package/dist/backend/inspect-ui.js.map +1 -0
  52. package/dist/backend/inspect.d.ts +129 -0
  53. package/dist/backend/inspect.d.ts.map +1 -0
  54. package/dist/backend/inspect.js +763 -0
  55. package/dist/backend/inspect.js.map +1 -0
  56. package/dist/backend/inspector-ui/0.js +2 -0
  57. package/dist/backend/inspector-ui/1.js +2 -0
  58. package/dist/backend/inspector-ui/10.js +2 -0
  59. package/dist/backend/inspector-ui/11.js +2 -0
  60. package/dist/backend/inspector-ui/12.js +2 -0
  61. package/dist/backend/inspector-ui/13.js +2 -0
  62. package/dist/backend/inspector-ui/14.js +2 -0
  63. package/dist/backend/inspector-ui/15.js +2 -0
  64. package/dist/backend/inspector-ui/16.js +2 -0
  65. package/dist/backend/inspector-ui/17.js +2 -0
  66. package/dist/backend/inspector-ui/18.js +2 -0
  67. package/dist/backend/inspector-ui/19.js +2 -0
  68. package/dist/backend/inspector-ui/2.js +2 -0
  69. package/dist/backend/inspector-ui/20.js +2 -0
  70. package/dist/backend/inspector-ui/3.js +2 -0
  71. package/dist/backend/inspector-ui/4.js +2 -0
  72. package/dist/backend/inspector-ui/5.js +2 -0
  73. package/dist/backend/inspector-ui/6.js +2 -0
  74. package/dist/backend/inspector-ui/7.js +2 -0
  75. package/dist/backend/inspector-ui/8.js +2 -0
  76. package/dist/backend/inspector-ui/9.js +2 -0
  77. package/dist/backend/inspector-ui-files.d.ts +4 -0
  78. package/dist/backend/inspector-ui-files.d.ts.map +1 -0
  79. package/dist/backend/inspector-ui-files.js +25 -0
  80. package/dist/backend/session-expiry.d.ts +61 -0
  81. package/dist/backend/session-expiry.d.ts.map +1 -0
  82. package/dist/backend/session-expiry.js +102 -0
  83. package/dist/backend/session-expiry.js.map +1 -0
  84. package/dist/backend/upgrade-status.d.ts +19 -0
  85. package/dist/backend/upgrade-status.d.ts.map +1 -0
  86. package/dist/backend/upgrade-status.js +55 -0
  87. package/dist/backend/upgrade-status.js.map +1 -0
  88. package/dist/backend/vercel-sockets.d.ts +16 -0
  89. package/dist/backend/vercel-sockets.d.ts.map +1 -0
  90. package/dist/backend/vercel-sockets.js +24 -0
  91. package/dist/backend/vercel-sockets.js.map +1 -0
  92. package/dist/backend/vercel-store.d.ts.map +1 -1
  93. package/dist/backend/vercel-store.js +77 -10
  94. package/dist/backend/vercel-store.js.map +1 -1
  95. package/dist/classic-api.d.ts.map +1 -1
  96. package/dist/classic-api.js +36 -0
  97. package/dist/classic-api.js.map +1 -1
  98. package/dist/cli.d.ts.map +1 -1
  99. package/dist/cli.js +30 -2
  100. package/dist/cli.js.map +1 -1
  101. package/dist/client/index.d.ts +2 -6
  102. package/dist/client/index.d.ts.map +1 -1
  103. package/dist/client/index.js +2 -3
  104. package/dist/client/index.js.map +1 -1
  105. package/dist/cloud/credentials.d.ts +1 -1
  106. package/dist/cloud/credentials.d.ts.map +1 -1
  107. package/dist/cloud/credentials.js.map +1 -1
  108. package/dist/dev/catalogue.d.ts +12 -0
  109. package/dist/dev/catalogue.d.ts.map +1 -1
  110. package/dist/dev/catalogue.js +31 -0
  111. package/dist/dev/catalogue.js.map +1 -1
  112. package/dist/dev/inspector-overlay/embedded/assets/backend-DHeT1LCS.css +1 -0
  113. package/dist/dev/inspector-overlay/embedded/assets/backend-Dt5FYVfX.js +1 -0
  114. package/dist/dev/inspector-overlay/embedded/assets/{create-legacy-browser-delegate-X_T_QKCN.js → create-legacy-browser-delegate-Bf58kV5i.js} +1 -1
  115. package/dist/dev/inspector-overlay/embedded/assets/esm-BQhYkCKN.js +1 -0
  116. package/dist/dev/inspector-overlay/embedded/assets/{esm-aRzpnC3u.js → esm-CI6IodCN.js} +1 -1
  117. package/dist/dev/inspector-overlay/embedded/assets/{esm-ezD5H765.js → esm-D5aLlEYl.js} +1 -1
  118. package/dist/dev/inspector-overlay/embedded/assets/{esm-7mP3GQX4.js → esm-D_R-EGgt.js} +1 -1
  119. package/dist/dev/inspector-overlay/embedded/assets/{esm-BX6IY2Mv.js → esm-WihpI9g6.js} +1 -1
  120. package/dist/dev/inspector-overlay/embedded/assets/index-CjhxdwQ7.js +1 -0
  121. package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CaVlHITU.js +3 -0
  122. package/dist/dev/inspector-overlay/embedded/assets/{jazz-broker-worker-XRRxJUcx.js → jazz-broker-worker-D-HQuhdu.js} +160 -557
  123. package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-t1Mm3faf.js +1 -0
  124. package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm_bg-KR7h3v27.wasm → jazz_wasm_bg-BazWJnU4.wasm} +0 -0
  125. package/dist/dev/inspector-overlay/embedded/assets/{index-C78Pprka.css → src-Cq8gSOLx.css} +1 -1
  126. package/dist/dev/inspector-overlay/embedded/assets/src-Dg6641Mj.js +22 -0
  127. package/dist/dev/inspector-overlay/embedded/assets/{trace-api-B5CaetI0.js → trace-api-BctnwbUf.js} +1 -1
  128. package/dist/dev/inspector-overlay/embedded/backend.html +16 -0
  129. package/dist/dev/inspector-overlay/embedded/embedded.html +3 -2
  130. package/dist/dev/inspector-overlay/host-bridge.d.ts.map +1 -1
  131. package/dist/dev/inspector-overlay/host-bridge.js +4 -1
  132. package/dist/dev/inspector-overlay/host-bridge.js.map +1 -1
  133. package/dist/dev/inspector-overlay/loader.d.ts +12 -1
  134. package/dist/dev/inspector-overlay/loader.d.ts.map +1 -1
  135. package/dist/dev/inspector-overlay/loader.js +31 -4
  136. package/dist/dev/inspector-overlay/loader.js.map +1 -1
  137. package/dist/drivers/schema-wire.d.ts +6 -2
  138. package/dist/drivers/schema-wire.d.ts.map +1 -1
  139. package/dist/drivers/schema-wire.js +6 -2
  140. package/dist/drivers/schema-wire.js.map +1 -1
  141. package/dist/effect/jazz.d.ts +12 -5
  142. package/dist/effect/jazz.d.ts.map +1 -1
  143. package/dist/effect/jazz.js +28 -5
  144. package/dist/effect/jazz.js.map +1 -1
  145. package/dist/expo/create-account-manager.d.ts +1 -1
  146. package/dist/expo/create-account-manager.d.ts.map +1 -1
  147. package/dist/expo/create-jazz-session.d.ts +37 -17
  148. package/dist/expo/create-jazz-session.d.ts.map +1 -1
  149. package/dist/expo/create-jazz-session.js +49 -10
  150. package/dist/expo/create-jazz-session.js.map +1 -1
  151. package/dist/expo/index.d.ts +5 -8
  152. package/dist/expo/index.d.ts.map +1 -1
  153. package/dist/expo/index.js +5 -7
  154. package/dist/expo/index.js.map +1 -1
  155. package/dist/expo/provider.d.ts +6 -3
  156. package/dist/expo/provider.d.ts.map +1 -1
  157. package/dist/expo/provider.js +7 -6
  158. package/dist/expo/provider.js.map +1 -1
  159. package/dist/index.d.ts +2 -2
  160. package/dist/index.d.ts.map +1 -1
  161. package/dist/index.js +2 -1
  162. package/dist/index.js.map +1 -1
  163. package/dist/inspect/cli.d.ts +12 -0
  164. package/dist/inspect/cli.d.ts.map +1 -0
  165. package/dist/inspect/cli.js +292 -0
  166. package/dist/inspect/cli.js.map +1 -0
  167. package/dist/inspect/client.d.ts +60 -0
  168. package/dist/inspect/client.d.ts.map +1 -0
  169. package/dist/inspect/client.js +241 -0
  170. package/dist/inspect/client.js.map +1 -0
  171. package/dist/inspect/mcp.d.ts +17 -0
  172. package/dist/inspect/mcp.d.ts.map +1 -0
  173. package/dist/inspect/mcp.js +308 -0
  174. package/dist/inspect/mcp.js.map +1 -0
  175. package/dist/inspect/protocol.d.ts +218 -0
  176. package/dist/inspect/protocol.d.ts.map +1 -0
  177. package/dist/inspect/protocol.js +357 -0
  178. package/dist/inspect/protocol.js.map +1 -0
  179. package/dist/inspector/index.d.ts +10 -0
  180. package/dist/inspector/index.d.ts.map +1 -0
  181. package/dist/inspector/index.js +27 -0
  182. package/dist/inspector/index.js.map +1 -0
  183. package/dist/migrations.d.ts +1 -1
  184. package/dist/migrations.js +1 -1
  185. package/dist/migrations.js.map +1 -1
  186. package/dist/react/index.d.ts +4 -9
  187. package/dist/react/index.d.ts.map +1 -1
  188. package/dist/react/index.js +4 -6
  189. package/dist/react/index.js.map +1 -1
  190. package/dist/react/provider-props.d.ts +7 -0
  191. package/dist/react/provider-props.d.ts.map +1 -0
  192. package/dist/react/provider-props.js +15 -0
  193. package/dist/react/provider-props.js.map +1 -0
  194. package/dist/react/provider.d.ts +9 -15
  195. package/dist/react/provider.d.ts.map +1 -1
  196. package/dist/react/provider.js +19 -38
  197. package/dist/react/provider.js.map +1 -1
  198. package/dist/react-core/index.d.ts +3 -4
  199. package/dist/react-core/index.d.ts.map +1 -1
  200. package/dist/react-core/index.js +8 -4
  201. package/dist/react-core/index.js.map +1 -1
  202. package/dist/react-core/provider.d.ts +6 -6
  203. package/dist/react-core/provider.d.ts.map +1 -1
  204. package/dist/react-core/provider.js +5 -6
  205. package/dist/react-core/provider.js.map +1 -1
  206. package/dist/react-core/session.d.ts +41 -33
  207. package/dist/react-core/session.d.ts.map +1 -1
  208. package/dist/react-core/session.js +41 -89
  209. package/dist/react-core/session.js.map +1 -1
  210. package/dist/react-native/account-session.js +1 -1
  211. package/dist/react-native/account-session.js.map +1 -1
  212. package/dist/react-native/create-account-manager.d.ts +1 -1
  213. package/dist/react-native/create-account-manager.d.ts.map +1 -1
  214. package/dist/react-native/create-jazz-session.d.ts +37 -17
  215. package/dist/react-native/create-jazz-session.d.ts.map +1 -1
  216. package/dist/react-native/create-jazz-session.js +49 -10
  217. package/dist/react-native/create-jazz-session.js.map +1 -1
  218. package/dist/react-native/index.d.ts +5 -10
  219. package/dist/react-native/index.d.ts.map +1 -1
  220. package/dist/react-native/index.js +5 -7
  221. package/dist/react-native/index.js.map +1 -1
  222. package/dist/react-native/native-foreground-db.d.ts +7 -0
  223. package/dist/react-native/native-foreground-db.d.ts.map +1 -1
  224. package/dist/react-native/native-foreground-db.js +29 -0
  225. package/dist/react-native/native-foreground-db.js.map +1 -1
  226. package/dist/react-native/provider.d.ts +14 -19
  227. package/dist/react-native/provider.d.ts.map +1 -1
  228. package/dist/react-native/provider.js +19 -18
  229. package/dist/react-native/provider.js.map +1 -1
  230. package/dist/react-native/runtime-source.js +1 -1
  231. package/dist/react-native/runtime-source.js.map +1 -1
  232. package/dist/removed-api.d.ts +87 -0
  233. package/dist/removed-api.d.ts.map +1 -0
  234. package/dist/removed-api.js +95 -0
  235. package/dist/removed-api.js.map +1 -0
  236. package/dist/runtime/auth-secret-store.d.ts +0 -44
  237. package/dist/runtime/auth-secret-store.d.ts.map +1 -1
  238. package/dist/runtime/auth-secret-store.js +1 -103
  239. package/dist/runtime/auth-secret-store.js.map +1 -1
  240. package/dist/runtime/client.d.ts +10 -4
  241. package/dist/runtime/client.d.ts.map +1 -1
  242. package/dist/runtime/client.js.map +1 -1
  243. package/dist/runtime/connection-manager/browser-connection-manager.d.ts +4 -1
  244. package/dist/runtime/connection-manager/browser-connection-manager.d.ts.map +1 -1
  245. package/dist/runtime/connection-manager/browser-connection-manager.js +33 -2
  246. package/dist/runtime/connection-manager/browser-connection-manager.js.map +1 -1
  247. package/dist/runtime/connection-manager/types.d.ts +17 -2
  248. package/dist/runtime/connection-manager/types.d.ts.map +1 -1
  249. package/dist/runtime/connection-manager/types.js +19 -5
  250. package/dist/runtime/connection-manager/types.js.map +1 -1
  251. package/dist/runtime/credentialed-transport.d.ts +5 -2
  252. package/dist/runtime/credentialed-transport.d.ts.map +1 -1
  253. package/dist/runtime/credentialed-transport.js +12 -3
  254. package/dist/runtime/credentialed-transport.js.map +1 -1
  255. package/dist/runtime/db-replaced-error.d.ts +3 -1
  256. package/dist/runtime/db-replaced-error.d.ts.map +1 -1
  257. package/dist/runtime/db-replaced-error.js +4 -2
  258. package/dist/runtime/db-replaced-error.js.map +1 -1
  259. package/dist/runtime/db.d.ts +35 -7
  260. package/dist/runtime/db.d.ts.map +1 -1
  261. package/dist/runtime/db.js +65 -9
  262. package/dist/runtime/db.js.map +1 -1
  263. package/dist/runtime/index.d.ts +3 -4
  264. package/dist/runtime/index.d.ts.map +1 -1
  265. package/dist/runtime/index.js +1 -2
  266. package/dist/runtime/index.js.map +1 -1
  267. package/dist/runtime/native-artifact-fingerprint-napi.d.ts +1 -1
  268. package/dist/runtime/native-artifact-fingerprint-napi.js +1 -1
  269. package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -1
  270. package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +1 -1
  271. package/dist/runtime/native-artifact-fingerprint-wasm.js +1 -1
  272. package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -1
  273. package/dist/runtime/native-artifact-fingerprints.d.ts +2 -2
  274. package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts +3 -1
  275. package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts.map +1 -1
  276. package/dist/runtime/native-runtime/attached-browser-worker-connection.js.map +1 -1
  277. package/dist/runtime/native-runtime/broker-worker-load-failure.d.ts +31 -0
  278. package/dist/runtime/native-runtime/broker-worker-load-failure.d.ts.map +1 -0
  279. package/dist/runtime/native-runtime/broker-worker-load-failure.js +66 -0
  280. package/dist/runtime/native-runtime/broker-worker-load-failure.js.map +1 -0
  281. package/dist/runtime/native-runtime/browser-follower-connection.d.ts +5 -1
  282. package/dist/runtime/native-runtime/browser-follower-connection.d.ts.map +1 -1
  283. package/dist/runtime/native-runtime/browser-follower-connection.js +4 -3
  284. package/dist/runtime/native-runtime/browser-follower-connection.js.map +1 -1
  285. package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts +3 -1
  286. package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts.map +1 -1
  287. package/dist/runtime/native-runtime/browser-shared-worker-connection.js +55 -4
  288. package/dist/runtime/native-runtime/browser-shared-worker-connection.js.map +1 -1
  289. package/dist/runtime/native-runtime/browser-worker-protocol.d.ts +5 -0
  290. package/dist/runtime/native-runtime/browser-worker-protocol.d.ts.map +1 -1
  291. package/dist/runtime/native-runtime/browser-worker-protocol.js.map +1 -1
  292. package/dist/runtime/native-runtime/http-stream-socket.d.ts +25 -7
  293. package/dist/runtime/native-runtime/http-stream-socket.d.ts.map +1 -1
  294. package/dist/runtime/native-runtime/http-stream-socket.js +56 -29
  295. package/dist/runtime/native-runtime/http-stream-socket.js.map +1 -1
  296. package/dist/runtime/native-runtime/native-runtime-adapter.d.ts +13 -5
  297. package/dist/runtime/native-runtime/native-runtime-adapter.d.ts.map +1 -1
  298. package/dist/runtime/native-runtime/native-runtime-adapter.js +38 -10
  299. package/dist/runtime/native-runtime/native-runtime-adapter.js.map +1 -1
  300. package/dist/runtime/native-runtime/websocket.d.ts +13 -0
  301. package/dist/runtime/native-runtime/websocket.d.ts.map +1 -1
  302. package/dist/runtime/native-runtime/websocket.js +23 -4
  303. package/dist/runtime/native-runtime/websocket.js.map +1 -1
  304. package/dist/runtime/page-handle.d.ts +87 -0
  305. package/dist/runtime/page-handle.d.ts.map +1 -0
  306. package/dist/runtime/page-handle.js +144 -0
  307. package/dist/runtime/page-handle.js.map +1 -0
  308. package/dist/runtime/removed-provider-props.d.ts +17 -0
  309. package/dist/runtime/removed-provider-props.d.ts.map +1 -0
  310. package/dist/runtime/removed-provider-props.js +16 -0
  311. package/dist/runtime/removed-provider-props.js.map +1 -0
  312. package/dist/runtime/runtime-source.d.ts +4 -1
  313. package/dist/runtime/runtime-source.d.ts.map +1 -1
  314. package/dist/runtime/runtime-source.js.map +1 -1
  315. package/dist/runtime/store-held-by-another-tab-error.d.ts +11 -0
  316. package/dist/runtime/store-held-by-another-tab-error.d.ts.map +1 -1
  317. package/dist/runtime/store-held-by-another-tab-error.js +11 -0
  318. package/dist/runtime/store-held-by-another-tab-error.js.map +1 -1
  319. package/dist/runtime/sync-status.d.ts +60 -1
  320. package/dist/runtime/sync-status.d.ts.map +1 -1
  321. package/dist/runtime/sync-status.js +64 -4
  322. package/dist/runtime/sync-status.js.map +1 -1
  323. package/dist/session/backend-watch.d.ts +53 -14
  324. package/dist/session/backend-watch.d.ts.map +1 -1
  325. package/dist/session/backend-watch.js +99 -22
  326. package/dist/session/backend-watch.js.map +1 -1
  327. package/dist/session/config-options.d.ts +15 -0
  328. package/dist/session/config-options.d.ts.map +1 -0
  329. package/dist/session/config-options.js +55 -0
  330. package/dist/session/config-options.js.map +1 -0
  331. package/dist/session/consumer.d.ts +1 -1
  332. package/dist/session/consumer.js +1 -1
  333. package/dist/session/consumer.js.map +1 -1
  334. package/dist/session/create-jazz-session.d.ts +57 -21
  335. package/dist/session/create-jazz-session.d.ts.map +1 -1
  336. package/dist/session/create-jazz-session.js +257 -58
  337. package/dist/session/create-jazz-session.js.map +1 -1
  338. package/dist/session/follow-user.d.ts +17 -7
  339. package/dist/session/follow-user.d.ts.map +1 -1
  340. package/dist/session/follow-user.js +23 -2
  341. package/dist/session/follow-user.js.map +1 -1
  342. package/dist/session/jazz-session.d.ts +164 -0
  343. package/dist/session/jazz-session.d.ts.map +1 -0
  344. package/dist/session/jazz-session.js +432 -0
  345. package/dist/session/jazz-session.js.map +1 -0
  346. package/dist/session/left-behind-replicas.d.ts +8 -1
  347. package/dist/session/left-behind-replicas.d.ts.map +1 -1
  348. package/dist/session/left-behind-replicas.js +21 -4
  349. package/dist/session/left-behind-replicas.js.map +1 -1
  350. package/dist/session/state.d.ts +20 -13
  351. package/dist/session/state.d.ts.map +1 -1
  352. package/dist/session/state.js +68 -23
  353. package/dist/session/state.js.map +1 -1
  354. package/dist/solid/index.d.ts +3 -9
  355. package/dist/solid/index.d.ts.map +1 -1
  356. package/dist/solid/index.js +8 -11
  357. package/dist/solid/index.ssr.js +3 -6
  358. package/dist/solid/provider.d.ts +3 -3
  359. package/dist/solid/provider.d.ts.map +1 -1
  360. package/dist/solid/provider.js +23 -39
  361. package/dist/solid/provider.js.map +1 -1
  362. package/dist/solid/provider.ssr.js +6 -23
  363. package/dist/solid/provider.ssr.js.map +1 -1
  364. package/dist/solid/session.d.ts +42 -12
  365. package/dist/solid/session.d.ts.map +1 -1
  366. package/dist/solid/session.js +82 -35
  367. package/dist/solid/session.js.map +1 -1
  368. package/dist/solid/session.ssr.js +85 -22
  369. package/dist/solid/session.ssr.js.map +1 -1
  370. package/dist/svelte/JazzProvider.svelte +54 -20
  371. package/dist/svelte/JazzProvider.svelte.d.ts +14 -4
  372. package/dist/svelte/JazzProvider.svelte.d.ts.map +1 -1
  373. package/dist/svelte/JazzSvelteClientProvider.svelte +1 -7
  374. package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts +0 -1
  375. package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts.map +1 -1
  376. package/dist/svelte/JazzSvelteProvider.svelte +5 -4
  377. package/dist/svelte/JazzSvelteProvider.svelte.d.ts +2 -2
  378. package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +1 -1
  379. package/dist/svelte/index.d.ts +4 -12
  380. package/dist/svelte/index.d.ts.map +1 -1
  381. package/dist/svelte/index.js +4 -8
  382. package/dist/svelte/session-state.d.ts +14 -4
  383. package/dist/svelte/session-state.d.ts.map +1 -1
  384. package/dist/svelte/session-state.js +10 -4
  385. package/dist/testing/policy-test-app.d.ts.map +1 -1
  386. package/dist/testing/policy-test-app.js +5 -4
  387. package/dist/testing/policy-test-app.js.map +1 -1
  388. package/dist/testing/test-jazz.d.ts +2 -2
  389. package/dist/testing/test-jazz.d.ts.map +1 -1
  390. package/dist/testing/test-jazz.js +5 -2
  391. package/dist/testing/test-jazz.js.map +1 -1
  392. package/dist/thin/index.d.ts +7 -10
  393. package/dist/thin/index.d.ts.map +1 -1
  394. package/dist/thin/index.js +28 -11
  395. package/dist/thin/index.js.map +1 -1
  396. package/dist/thin/thin-runtime.d.ts +22 -2
  397. package/dist/thin/thin-runtime.d.ts.map +1 -1
  398. package/dist/thin/thin-runtime.js +157 -24
  399. package/dist/thin/thin-runtime.js.map +1 -1
  400. package/dist/vue/index.d.ts +3 -8
  401. package/dist/vue/index.d.ts.map +1 -1
  402. package/dist/vue/index.js +3 -5
  403. package/dist/vue/index.js.map +1 -1
  404. package/dist/vue/provider.d.ts +6 -27
  405. package/dist/vue/provider.d.ts.map +1 -1
  406. package/dist/vue/provider.js +10 -19
  407. package/dist/vue/provider.js.map +1 -1
  408. package/dist/vue/session.d.ts +29 -28
  409. package/dist/vue/session.d.ts.map +1 -1
  410. package/dist/vue/session.js +79 -22
  411. package/dist/vue/session.js.map +1 -1
  412. package/dist/window-client-storage.d.ts +4 -30
  413. package/dist/window-client-storage.d.ts.map +1 -1
  414. package/dist/window-client-storage.js +2 -63
  415. package/dist/window-client-storage.js.map +1 -1
  416. package/dist/worker/jazz-broker-worker-core.d.ts.map +1 -1
  417. package/dist/worker/jazz-broker-worker-core.js +16 -19
  418. package/dist/worker/jazz-broker-worker-core.js.map +1 -1
  419. package/dist/worker/jazz-broker-worker.js +160 -557
  420. package/dist/worker/jazz_wasm_bg.wasm +0 -0
  421. package/dist/worker/runtime-admission.d.ts +19 -0
  422. package/dist/worker/runtime-admission.d.ts.map +1 -0
  423. package/dist/worker/runtime-admission.js +34 -0
  424. package/dist/worker/runtime-admission.js.map +1 -0
  425. package/package.json +18 -5
  426. package/dist/backend/session-recheck.d.ts +0 -18
  427. package/dist/backend/session-recheck.d.ts.map +0 -1
  428. package/dist/backend/session-recheck.js +0 -57
  429. package/dist/backend/session-recheck.js.map +0 -1
  430. package/dist/dev/inspector-overlay/embedded/assets/esm-k3rsq4Gn.js +0 -1
  431. package/dist/dev/inspector-overlay/embedded/assets/index-C-btvLcw.js +0 -20
  432. package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CAMcDeUa.js +0 -3
  433. package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-Cc71x_6y.js +0 -1
  434. package/dist/dev/inspector-overlay/serve.d.ts +0 -46
  435. package/dist/dev/inspector-overlay/serve.d.ts.map +0 -1
  436. package/dist/dev/inspector-overlay/serve.js +0 -131
  437. package/dist/dev/inspector-overlay/serve.js.map +0 -1
  438. package/dist/dev-tools/auto-attach.d.ts +0 -11
  439. package/dist/dev-tools/auto-attach.d.ts.map +0 -1
  440. package/dist/dev-tools/auto-attach.js +0 -26
  441. package/dist/dev-tools/auto-attach.js.map +0 -1
  442. package/dist/expo/auth-secret-store.d.ts +0 -37
  443. package/dist/expo/auth-secret-store.d.ts.map +0 -1
  444. package/dist/expo/auth-secret-store.js +0 -139
  445. package/dist/expo/auth-secret-store.js.map +0 -1
  446. package/dist/expo/session.d.ts +0 -10
  447. package/dist/expo/session.d.ts.map +0 -1
  448. package/dist/expo/session.js +0 -5
  449. package/dist/expo/session.js.map +0 -1
  450. package/dist/expo/use-local-first-auth.d.ts +0 -12
  451. package/dist/expo/use-local-first-auth.d.ts.map +0 -1
  452. package/dist/expo/use-local-first-auth.js +0 -13
  453. package/dist/expo/use-local-first-auth.js.map +0 -1
  454. package/dist/react/devtools-auto-attach.d.ts +0 -2
  455. package/dist/react/devtools-auto-attach.d.ts.map +0 -1
  456. package/dist/react/devtools-auto-attach.js +0 -11
  457. package/dist/react/devtools-auto-attach.js.map +0 -1
  458. package/dist/react/session.d.ts +0 -18
  459. package/dist/react/session.d.ts.map +0 -1
  460. package/dist/react/session.js +0 -28
  461. package/dist/react/session.js.map +0 -1
  462. package/dist/react/use-local-first-auth.d.ts +0 -11
  463. package/dist/react/use-local-first-auth.d.ts.map +0 -1
  464. package/dist/react/use-local-first-auth.js +0 -13
  465. package/dist/react/use-local-first-auth.js.map +0 -1
  466. package/dist/react-core/app.d.ts +0 -31
  467. package/dist/react-core/app.d.ts.map +0 -1
  468. package/dist/react-core/app.js +0 -65
  469. package/dist/react-core/app.js.map +0 -1
  470. package/dist/react-core/use-account-state.d.ts +0 -4
  471. package/dist/react-core/use-account-state.d.ts.map +0 -1
  472. package/dist/react-core/use-account-state.js +0 -6
  473. package/dist/react-core/use-account-state.js.map +0 -1
  474. package/dist/react-core/use-local-first-auth.d.ts +0 -12
  475. package/dist/react-core/use-local-first-auth.d.ts.map +0 -1
  476. package/dist/react-core/use-local-first-auth.js +0 -14
  477. package/dist/react-core/use-local-first-auth.js.map +0 -1
  478. package/dist/react-native/session.d.ts +0 -10
  479. package/dist/react-native/session.d.ts.map +0 -1
  480. package/dist/react-native/session.js +0 -5
  481. package/dist/react-native/session.js.map +0 -1
  482. package/dist/react-native/use-local-first-auth.d.ts +0 -15
  483. package/dist/react-native/use-local-first-auth.d.ts.map +0 -1
  484. package/dist/react-native/use-local-first-auth.js +0 -14
  485. package/dist/react-native/use-local-first-auth.js.map +0 -1
  486. package/dist/runtime/local-first-auth-controller.d.ts +0 -29
  487. package/dist/runtime/local-first-auth-controller.d.ts.map +0 -1
  488. package/dist/runtime/local-first-auth-controller.js +0 -101
  489. package/dist/runtime/local-first-auth-controller.js.map +0 -1
  490. package/dist/session/app.d.ts +0 -58
  491. package/dist/session/app.d.ts.map +0 -1
  492. package/dist/session/app.js +0 -325
  493. package/dist/session/app.js.map +0 -1
  494. package/dist/session/create-jazz-app.d.ts +0 -11
  495. package/dist/session/create-jazz-app.d.ts.map +0 -1
  496. package/dist/session/create-jazz-app.js +0 -11
  497. package/dist/session/create-jazz-app.js.map +0 -1
  498. package/dist/solid/app.d.ts +0 -30
  499. package/dist/solid/app.d.ts.map +0 -1
  500. package/dist/solid/app.js +0 -95
  501. package/dist/solid/app.js.map +0 -1
  502. package/dist/solid/app.ssr.js +0 -109
  503. package/dist/solid/app.ssr.js.map +0 -1
  504. package/dist/solid/create-account-state.d.ts +0 -4
  505. package/dist/solid/create-account-state.d.ts.map +0 -1
  506. package/dist/solid/create-account-state.js +0 -10
  507. package/dist/solid/create-account-state.js.map +0 -1
  508. package/dist/solid/create-account-state.ssr.js +0 -12
  509. package/dist/solid/create-account-state.ssr.js.map +0 -1
  510. package/dist/solid/use-local-first-auth.d.ts +0 -11
  511. package/dist/solid/use-local-first-auth.d.ts.map +0 -1
  512. package/dist/solid/use-local-first-auth.js +0 -30
  513. package/dist/solid/use-local-first-auth.js.map +0 -1
  514. package/dist/solid/use-local-first-auth.ssr.js +0 -31
  515. package/dist/solid/use-local-first-auth.ssr.js.map +0 -1
  516. package/dist/svelte/JazzSessionClientProvider.svelte +0 -42
  517. package/dist/svelte/JazzSessionClientProvider.svelte.d.ts +0 -13
  518. package/dist/svelte/JazzSessionClientProvider.svelte.d.ts.map +0 -1
  519. package/dist/svelte/JazzSessionProvider.svelte +0 -68
  520. package/dist/svelte/JazzSessionProvider.svelte.d.ts +0 -19
  521. package/dist/svelte/JazzSessionProvider.svelte.d.ts.map +0 -1
  522. package/dist/svelte/account-state.d.ts +0 -5
  523. package/dist/svelte/account-state.d.ts.map +0 -1
  524. package/dist/svelte/account-state.js +0 -9
  525. package/dist/svelte/auth-state.d.ts +0 -23
  526. package/dist/svelte/auth-state.d.ts.map +0 -1
  527. package/dist/svelte/auth-state.js +0 -16
  528. package/dist/svelte/local-first-auth.svelte.d.ts +0 -50
  529. package/dist/svelte/local-first-auth.svelte.d.ts.map +0 -1
  530. package/dist/svelte/local-first-auth.svelte.js +0 -58
  531. package/dist/vue/app.d.ts +0 -76
  532. package/dist/vue/app.d.ts.map +0 -1
  533. package/dist/vue/app.js +0 -100
  534. package/dist/vue/app.js.map +0 -1
  535. package/dist/vue/use-account-state.d.ts +0 -5
  536. package/dist/vue/use-account-state.d.ts.map +0 -1
  537. package/dist/vue/use-account-state.js +0 -10
  538. package/dist/vue/use-account-state.js.map +0 -1
  539. package/dist/vue/use-local-first-auth.d.ts +0 -53
  540. package/dist/vue/use-local-first-auth.d.ts.map +0 -1
  541. package/dist/vue/use-local-first-auth.js +0 -67
  542. package/dist/vue/use-local-first-auth.js.map +0 -1
  543. /package/dist/dev/inspector-overlay/embedded/assets/{esm-CH5eVyQQ.js → esm-xNe3wI_B.js} +0 -0
  544. /package/dist/dev/inspector-overlay/embedded/assets/{node-foreground-node-lease.browser-Bm3gYjlT.js → node-foreground-node-lease.browser-CH8w-D6S.js} +0 -0
@@ -5,19 +5,15 @@ import { join, resolve } from "node:path";
5
5
  import { JazzCore } from "jazz-napi";
6
6
  import { registerInProcessTransport } from "../runtime/in-process-transport.js";
7
7
  import { accountAppId, localFirstAccountId } from "../accounts/local-first.js";
8
+ import { AUTHENTICATE_EXPIRES_AT_MISSING } from "../accounts/registry-client.js";
8
9
  import { LOCAL_FIRST_JWT_ISSUER, parseJwtPayload } from "../runtime/client-session.js";
9
10
  import { verifyLocalFirstToken } from "../runtime/local-first-token.js";
10
11
  import { endpointScope } from "../runtime/client-scope.js";
11
12
  import { PostcardWriter } from "../runtime/native-runtime/native-codec.js";
12
- import { encodeWebSocketFrameBatch } from "../runtime/native-runtime/websocket.js";
13
+ import { encodeWebSocketFrameBatch, REAUTHENTICATE_WIRE_MESSAGE_PREFIX, } from "../runtime/native-runtime/websocket.js";
13
14
  import { STREAM_RECORD_MESSAGE, STREAM_RECORD_SESSION, StreamRecordReader, encodeStreamClose, encodeStreamRecord, } from "../runtime/native-runtime/http-stream-socket.js";
14
15
  import { resolveSchemaSource } from "../schema-source.js";
15
- import { mergePermissionsIntoWasmSchema, } from "../schema-permissions.js";
16
- import { shippedMigrations } from "../runtime/client-migrations.js";
17
- import { computeSchemaHash } from "../schema-hash.js";
18
- import { validateSchemaAndPermissions } from "../dev/schema-validation.js";
19
- import { deployArtifacts } from "../dev/catalogue.js";
20
- import { fetchMigrationGraph } from "../dev/migration-graph.js";
16
+ import { deployApp } from "../dev/catalogue.js";
21
17
  import { DeploymentError } from "../dev/catalogue-api.js";
22
18
  import { backendDbAttributedTo, backendDbForSession, openJazzSession, } from "./create-jazz-session.js";
23
19
  import { BackendClientsUnavailable, backendClientVerifier, } from "./backend-clients.js";
@@ -25,12 +21,15 @@ import { BACKEND_USER_ISSUER } from "./backend-issuer.js";
25
21
  import { earlyDb } from "./early-db.js";
26
22
  import { defaultCoreName, onVercelDeployment, onVercelHost, openVercelCore, refuseVercelAppId, } from "./vercel-store.js";
27
23
  import { files } from "./blobs.js";
24
+ import { createInspector, inspectorSettings, newTokenSecret, } from "./inspect.js";
25
+ import { createInspectorUi } from "./inspect-ui.js";
28
26
  export { files, s3, vercelBlob, } from "./blobs.js";
29
- import { isSameAdmission, recheckEvery } from "./session-recheck.js";
27
+ import { AuthenticateExpiresAtError, reauthenticateAt, sessionDeadline, startTimer, withCheckedExpiry, } from "./session-expiry.js";
30
28
  import { NoJazzAccountError } from "./no-account-error.js";
31
29
  import { RequestAuthenticationError } from "./request-auth.js";
32
30
  import { optionalPeerImportError } from "./optional-peer.js";
33
31
  import { closingBeforeDeadline } from "./socket-deadline.js";
32
+ import { vercelUpgradesSockets } from "./vercel-sockets.js";
34
33
  /**
35
34
  * A SQLite core in this process, kept in the directory `path`. It generates
36
35
  * its app id on first start and keeps it beside its data, in `<path>/app-id`
@@ -78,20 +77,28 @@ export function remote(options) {
78
77
  throw new Error("remote(): appId must name the app the core serves (it is empty)");
79
78
  }
80
79
  let backendCredential;
80
+ let secret;
81
81
  if ("backendCredential" in options) {
82
82
  backendCredential = options.backendCredential;
83
83
  }
84
84
  else {
85
- const secret = options.secret;
85
+ secret = options.secret;
86
86
  if (secret === undefined && "adminSecret" in options) {
87
87
  throw new Error("remote(): `adminSecret` and `backendSecret` were replaced by one `secret`, the app's admin secret");
88
88
  }
89
89
  if (typeof secret !== "string" || !secret.trim()) {
90
90
  throw new Error("remote(): secret must be the app's admin secret (it is empty)");
91
91
  }
92
- backendCredential = () => secret;
92
+ const given = secret;
93
+ backendCredential = () => given;
93
94
  }
94
- return { kind: "remote", url: options.url.replace(/\/+$/, ""), appId, backendCredential };
95
+ return {
96
+ kind: "remote",
97
+ url: options.url.replace(/\/+$/, ""),
98
+ appId,
99
+ backendCredential,
100
+ ...(secret === undefined ? {} : { secret }),
101
+ };
95
102
  }
96
103
  /**
97
104
  * The store for apps deployed on Vercel. Use it in dev too: outside a
@@ -141,9 +148,41 @@ function blobOptions(blobs) {
141
148
  }
142
149
  return { blobs: "files", ...(blobs.dir === undefined ? {} : { blobsDir: blobs.dir }) };
143
150
  }
151
+ /**
152
+ * The marker's brand, registered globally like `createJazz`'s store registry:
153
+ * a bundler may load this module more than once (Next dev evaluates it per
154
+ * route), and a shared Jazz must still recognise a marker made by another copy.
155
+ */
156
+ const LOCAL_FIRST_GUEST_BRAND = Symbol.for("jazz-tools.acceptDeviceAccounts.guest");
144
157
  const LOCAL_FIRST_GUEST = Object.freeze({
158
+ [LOCAL_FIRST_GUEST_BRAND]: true,
145
159
  kind: "jazz:local-first-guest",
146
160
  });
161
+ /** Whether `answer` is {@link acceptDeviceAccounts}'s marker, from any copy of this module. */
162
+ function isLocalFirstGuest(answer) {
163
+ return (typeof answer === "object" &&
164
+ answer !== null &&
165
+ answer[LOCAL_FIRST_GUEST_BRAND] === true);
166
+ }
167
+ /**
168
+ * `authenticate`'s answer, checked: a user must have a string `userId`. Any
169
+ * other answer is a bug in the app's `authenticate`, said so here rather than
170
+ * as a failure from the core about a missing identity.
171
+ */
172
+ function checkedUser(answer) {
173
+ const userId = answer?.userId;
174
+ if (typeof answer === "object" && answer !== null && typeof userId === "string" && userId !== "")
175
+ return answer;
176
+ throw new TypeError(`createJazz: authenticate must return { userId: string, expiresAt: number }, acceptDeviceAccounts(request) or null; it returned ${describeAnswer(answer)}`);
177
+ }
178
+ function describeAnswer(answer) {
179
+ if (typeof answer !== "object" || answer === null)
180
+ return String(answer);
181
+ const keys = Reflect.ownKeys(answer).map(String);
182
+ const userId = answer.userId;
183
+ const detail = "userId" in answer ? `, userId: ${JSON.stringify(userId) ?? String(userId)}` : "";
184
+ return `an object with keys [${keys.join(", ")}]${detail}`;
185
+ }
147
186
  /** `request` without the credentials a browser sends with it (its cookies, an `Authorization` header). */
148
187
  function withoutCredentials(request) {
149
188
  const headers = new Headers(request.headers);
@@ -152,30 +191,37 @@ function withoutCredentials(request) {
152
191
  return new Request(request.url, { method: request.method, headers });
153
192
  }
154
193
  /**
155
- * Let this request through as a local-first guest, when it comes from one.
156
- * Guests are refused unless `authenticate` returns this: a guest has no user
157
- * in your auth, so only your permissions stand between it and your data.
194
+ * Let this request through as a device account, when it comes from one: an
195
+ * account whose key lives on the user's device, with no user in your auth.
196
+ * It's how your app lets people in as guests, and a local-first friendly way
197
+ * to sign in at all. Device accounts are refused unless `authenticate`
198
+ * returns this, since only your permissions stand between them and your
199
+ * data.
158
200
  *
159
201
  * ```ts
160
202
  * authenticate: async (request) => {
161
203
  * const session = await auth.api.getSession({ headers: request.headers });
162
- * return session ? { userId: session.user.id } : acceptLocalFirstAuth(request);
204
+ * if (!session) return acceptDeviceAccounts(request);
205
+ * return {
206
+ * userId: session.user.id,
207
+ * expiresAt: Math.floor(session.session.expiresAt.getTime() / 1000),
208
+ * };
163
209
  * },
164
210
  * ```
165
211
  *
166
- * An app with no sign-in of its own, where every browser is a guest, passes
167
- * it as is: `authenticate: acceptLocalFirstAuth`.
212
+ * An app with no sign-in of its own, where every browser has a device
213
+ * account, passes it as is: `authenticate: acceptDeviceAccounts`.
168
214
  *
169
- * For a request that is not a guest's, it means the same as `null`: no one
170
- * is signed in.
215
+ * For a request that is not a device account's, it means the same as `null`:
216
+ * no one is signed in.
171
217
  *
172
- * A guest's request may also carry a user's cookie: someone signed in (or
173
- * up) on that browser, and the guest still uploads its writes before it
174
- * links to them. Jazz then asks `authenticate` about the request without its
175
- * cookies and `Authorization` header, so the guest is let in as it would be
176
- * on its own.
218
+ * A device account's request may also carry a user's cookie: someone signed
219
+ * in (or up) on that browser, and the device account still uploads its
220
+ * writes before it links to them. Jazz then asks `authenticate` about the
221
+ * request without its cookies and `Authorization` header, so the device
222
+ * account is let in as it would be on its own.
177
223
  */
178
- export function acceptLocalFirstAuth(_request) {
224
+ export function acceptDeviceAccounts(_request) {
179
225
  return LOCAL_FIRST_GUEST;
180
226
  }
181
227
  const DEFAULT_BASE_PATH = "/jazz";
@@ -185,6 +231,11 @@ const DEFAULT_BASE_PATH = "/jazz";
185
231
  const PRELUDE_DEADLINE_MS = 30_000;
186
232
  /** On createJazz's 426 for a socket path: this endpoint serves the HTTP stream. */
187
233
  const STREAM_AVAILABLE_HEADER = "x-jazz-stream";
234
+ /** The answer for a socket path where this host can't upgrade sockets. */
235
+ const useHttpStream = () => new Response("WebSocket upgrade not available here; use the HTTP stream", {
236
+ status: 426,
237
+ headers: { [STREAM_AVAILABLE_HEADER]: "1" },
238
+ });
188
239
  /** The stream session's key, on each send and close (see `openStream`). */
189
240
  const STREAM_KEY_HEADER = "x-jazz-stream-key";
190
241
  const PUBLIC_APP_ROUTES = /^\/apps\/[^/]+\/(schemas|schema\/[^/]+)$/;
@@ -206,6 +257,14 @@ const ACCESS_HEADER = "x-jazz-backend-access";
206
257
  // What the secret slots carry to a remote core: the access stated next to
207
258
  // the backend credential decides what a request gets, not these.
208
259
  const STAND_IN_SECRET = "stated-by-backend-credential";
260
+ /** The core's refusal of every local-first identity: it admits none. */
261
+ const LOCAL_FIRST_AUTH_DISABLED = "local_first_auth_disabled";
262
+ /**
263
+ * What a core that admits no local-first identity tells a guest's session
264
+ * (`LOCAL_FIRST_AUTH_DISABLED_MESSAGE` in jazz-server's middleware/auth.rs;
265
+ * vercel-guest.integration.test.ts pins it against a real core).
266
+ */
267
+ const CORE_REFUSES_GUESTS = "Local-first auth is not enabled";
209
268
  // What a browser's request to a public route carries on to a remote core:
210
269
  // never its cookies or its app session.
211
270
  const REMOTE_FORWARDED_HEADERS = ["accept", "content-type", "if-none-match"];
@@ -216,6 +275,10 @@ const MAX_STREAM_MESSAGE_BYTES = 2 * 1024 * 1024;
216
275
  * client ignored flow control and its session ends.
217
276
  */
218
277
  const MAX_WAITING_SESSION_BYTES = 32 * 1024 * 1024;
278
+ /** What `inspector` is when createJazz isn't given one: one object, so the Inspector reads it once. */
279
+ const NO_INSPECTOR_OPTIONS = Object.freeze({});
280
+ /** The peer address of requests that came through a Node handler, where Jazz can know it. */
281
+ const remoteAddresses = new WeakMap();
219
282
  function headerPairs(headers) {
220
283
  const pairs = [];
221
284
  headers.forEach((value, name) => {
@@ -340,31 +403,16 @@ function inProcessWebSocket(open) {
340
403
  }
341
404
  /** The app's schema versions, migrations and permissions, as its code declares them. */
342
405
  async function applyBundle(origin, options) {
343
- const declared = resolveSchemaSource(options.app);
344
- const schema = mergePermissionsIntoWasmSchema(declared, {});
345
- await validateSchemaAndPermissions(schema, options.permissions);
346
- const targetSchemaHash = await computeSchemaHash(schema);
347
- const shipped = shippedMigrations(declared);
348
- const schemas = new Map();
349
- for (const version of shipped?.schemas ?? []) {
350
- schemas.set(version.hash, version.schema.tables);
351
- }
352
- schemas.set(targetSchemaHash, schema);
353
- const server = { appId: options.appId, serverUrl: origin, adminSecret: options.adminSecret };
354
- const graph = await fetchMigrationGraph(server);
355
- const confirm = { ...server, allowDroppingHistory: options.allowDroppingHistory };
356
406
  // Published, never activated: this backend's sessions are pinned to its
357
407
  // bundle, so deployments of the app serve side by side and a rollback is
358
408
  // publishing the older bundle again.
359
- const deployed = await deployArtifacts(confirm, graph, {
360
- targetSchemaHash,
361
- schemas: [...schemas].map(([hash, schema]) => ({ hash, schema })),
362
- migrations: (shipped?.migrations ?? []).map((edge) => ({
363
- fromHash: edge.fromHash,
364
- toHash: edge.toHash,
365
- forward: edge.forward,
366
- })),
409
+ const deployed = await deployApp({
410
+ appId: options.appId,
411
+ serverUrl: origin,
412
+ adminSecret: options.adminSecret,
413
+ app: options.app,
367
414
  permissions: options.permissions,
415
+ allowDroppingHistory: options.allowDroppingHistory,
368
416
  }).catch((error) => {
369
417
  // A core without `/bundles` predates per-deployment permissions; it
370
418
  // must not be handed a deployment it would activate for every backend.
@@ -504,6 +552,33 @@ async function keptAppId(dir) {
504
552
  }
505
553
  return appId;
506
554
  }
555
+ /**
556
+ * The secret an in-process SQLite core's agent tokens are signed with, kept
557
+ * beside its data in `<path>/inspect-token-secret` (mode 0600) so tokens
558
+ * survive restarts. Deleting the file revokes every token.
559
+ */
560
+ async function keptTokenSecret(dir) {
561
+ const file = join(dir, "inspect-token-secret");
562
+ try {
563
+ const kept = (await readFile(file, "utf8")).trim();
564
+ if (kept)
565
+ return kept;
566
+ }
567
+ catch (error) {
568
+ if (error.code !== "ENOENT")
569
+ throw error;
570
+ }
571
+ const secret = newTokenSecret();
572
+ try {
573
+ await writeFile(file, `${secret}\n`, { flag: "wx", mode: 0o600 });
574
+ return secret;
575
+ }
576
+ catch (error) {
577
+ if (error.code !== "EEXIST")
578
+ throw error;
579
+ return (await readFile(file, "utf8")).trim();
580
+ }
581
+ }
507
582
  /**
508
583
  * Serverless functions have no disk that outlives an instance (or none
509
584
  * writable at all), so a sqlite store there loses data silently.
@@ -677,6 +752,8 @@ function signedOut(operation) {
677
752
  /** How long `close()` waits for pending writes to reach the core. */
678
753
  const CLOSE_SYNC_TIMEOUT_MS = 10_000;
679
754
  function jazzSettings(options) {
755
+ if (options.recheckSeconds !== undefined)
756
+ throw new Error("createJazz: recheckSeconds was removed. A sync session now lasts until the expiresAt your authenticate returns, and then authenticates again on its client's new connection; to end a user's sessions at once, call jazz.revokeUser(userId).");
680
757
  const basePath = (options.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
681
758
  const publicUrls = [options.publicUrl ?? []].flat().map((value) => {
682
759
  try {
@@ -735,6 +812,8 @@ async function openJazz(initial, store) {
735
812
  : await openInProcessCore(store, bundle);
736
813
  const appId = core.appId;
737
814
  const issuer = BACKEND_USER_ISSUER;
815
+ // An in-memory store's agent tokens last as long as its data: this process.
816
+ const memoryTokenSecret = newTokenSecret();
738
817
  /** Publish `next`'s bundle: what it is pinned by. Publishing one already published changes nothing. */
739
818
  const publish = (next) => applyBundle(core.serverUrl, { ...next, appId, adminSecret: core.adminSecret });
740
819
  /** Publish `next`'s bundle and open the backend's own session on it. */
@@ -773,6 +852,7 @@ async function openJazz(initial, store) {
773
852
  */
774
853
  async function reload(next) {
775
854
  const settings = jazzSettings(next);
855
+ inspectorSettings(next.inspector ?? NO_INSPECTOR_OPTIONS);
776
856
  // The same app and permissions (a reload of a module that imports them
777
857
  // unchanged, or a hot reload that rebuilt equal ones): the bundle, and
778
858
  // the backend's session with its writes and `forReqUser` dbs, stay.
@@ -817,6 +897,22 @@ async function openJazz(initial, store) {
817
897
  timer.unref?.();
818
898
  retiring.add(closeOld);
819
899
  }
900
+ // An `authenticate` that returns expired answers, or none at all, is a
901
+ // bug in the app: said once per process.
902
+ let warnedExpiredAnswer = false;
903
+ function warnExpiredAnswer() {
904
+ if (warnedExpiredAnswer)
905
+ return;
906
+ warnedExpiredAnswer = true;
907
+ console.error("createJazz: authenticate named a user with an expiresAt in the past, so Jazz treats them as signed out. Return the expiry of the session the user is signed in with (the one a sign-out ends), in Unix seconds, not of a short-lived access token.");
908
+ }
909
+ let warnedMissingExpiry = false;
910
+ function warnMissingExpiry(error) {
911
+ if (warnedMissingExpiry)
912
+ return;
913
+ warnedMissingExpiry = true;
914
+ console.error(error.message);
915
+ }
820
916
  /**
821
917
  * Who sent `request`: a scoped backend client's user, or the user the
822
918
  * app's own `authenticate` names. A trusted backend client has no user.
@@ -824,34 +920,54 @@ async function openJazz(initial, store) {
824
920
  async function authenticate(request) {
825
921
  const client = await backendClients.resolve(request);
826
922
  if (client !== null)
827
- return client !== "refused" && client.kind === "user" ? client.user : null;
923
+ return client !== "refused" && client.kind === "user"
924
+ ? { ...client.user, expiresAt: client.expiresAt }
925
+ : null;
828
926
  const answer = await askAuthenticate(request);
829
- return answer === LOCAL_FIRST_GUEST ? null : answer;
927
+ if (answer === null || isLocalFirstGuest(answer))
928
+ return null;
929
+ const user = withCheckedExpiry(checkedUser(answer));
930
+ // An answer that has already expired names no one, here and in every
931
+ // other place that asks (who is signed in, sign-in, forReqUser), so a
932
+ // client can't be told it is signed in while its sync is refused.
933
+ if (user.expiresAt * 1000 <= Date.now()) {
934
+ warnExpiredAnswer();
935
+ return null;
936
+ }
937
+ return user;
830
938
  }
831
939
  async function askAuthenticate(request) {
832
940
  if (!options.authenticate)
833
941
  return null;
834
942
  return (await options.authenticate(request)) ?? null;
835
943
  }
836
- /** Whether the app lets `request` in as a local-first guest (`acceptLocalFirstAuth`). */
944
+ /** Whether the app lets `request` in as a device account (`acceptDeviceAccounts`). */
837
945
  let warnedGuestsOff = false;
838
946
  async function acceptsGuest(request) {
839
947
  const answer = await askAuthenticate(request);
840
- if (answer === LOCAL_FIRST_GUEST)
948
+ if (isLocalFirstGuest(answer))
841
949
  return true;
842
950
  // A user is signed in on this browser too: one who just signed up, whose
843
951
  // guest still uploads its writes before it links to them. A guest is
844
952
  // bound to its own key, never to that user, and whether the app lets
845
953
  // guests in doesn't depend on who else is signed in: ask as the request
846
954
  // would be without the user's credentials.
847
- if (answer && (await askAuthenticate(withoutCredentials(request))) === LOCAL_FIRST_GUEST)
955
+ if (answer && isLocalFirstGuest(await askAuthenticate(withoutCredentials(request))))
848
956
  return true;
849
957
  if (!warnedGuestsOff) {
850
958
  warnedGuestsOff = true;
851
- console.warn("createJazz: refused a local-first guest. To let guests sync, return acceptLocalFirstAuth(request) from authenticate for them.");
959
+ console.warn("createJazz: refused a local-first guest. To let guests sync, return acceptDeviceAccounts(request) from authenticate for them.");
852
960
  }
853
961
  return false;
854
962
  }
963
+ /** Say once that the core turns every local-first guest away, whatever `authenticate` says. */
964
+ let warnedGuestsOffOnCore = false;
965
+ function warnGuestsOffOnCore() {
966
+ if (warnedGuestsOffOnCore)
967
+ return;
968
+ warnedGuestsOffOnCore = true;
969
+ console.error("createJazz: the core refuses local-first guests (local_first_auth_disabled), so device accounts can't sync or link. Start the core with allowLocalFirstAuth: true. A vercel() core started by an older jazz-tools keeps refusing them until a deployment of a newer one restarts it.");
970
+ }
855
971
  /** One admin account request to the core: this backend vouches for the identities. */
856
972
  async function adminAccounts(operation, body) {
857
973
  const response = await core.handle("POST", `/apps/${encodeURIComponent(accountAppId(appId))}/admin/accounts/${operation}`, [
@@ -1085,7 +1201,9 @@ async function openJazz(initial, store) {
1085
1201
  catch (error) {
1086
1202
  // A guest key an earlier link retired: only that link's own user
1087
1203
  // gets an answer (the retry of a link whose response was lost).
1088
- if (error.status !== 403 || !(await userIs(account)))
1204
+ if (error.status !== 403 ||
1205
+ error.code === LOCAL_FIRST_AUTH_DISABLED ||
1206
+ !(await userIs(account)))
1089
1207
  throw error;
1090
1208
  guestRevoked = true;
1091
1209
  }
@@ -1111,6 +1229,14 @@ async function openJazz(initial, store) {
1111
1229
  }
1112
1230
  catch (error) {
1113
1231
  const status = error.status;
1232
+ // A core that admits no local-first accounts refuses every guest, not
1233
+ // this user's link: say that, not that the user has another account.
1234
+ if (error.code === LOCAL_FIRST_AUTH_DISABLED) {
1235
+ warnGuestsOffOnCore();
1236
+ // A setup problem on the backend's side, not a refusal of this link:
1237
+ // 503, so the client tries again later.
1238
+ return new Response(LOCAL_FIRST_AUTH_DISABLED, { status: 503 });
1239
+ }
1114
1240
  // Only the core's own refusals refuse the link for good: an invalid
1115
1241
  // link intent (400), a retired or foreign identity (403), a user with
1116
1242
  // no account to check (404), an identity of another account (409).
@@ -1139,7 +1265,9 @@ async function openJazz(initial, store) {
1139
1265
  const expiresAt = Math.floor(Date.now() / 1000) + (options.sessionTtlSeconds ?? 3600);
1140
1266
  return Response.json({ account, identity: identity(user.userId), claims: user.claims ?? {}, expiresAt }, { headers: { "Cache-Control": "no-store" } });
1141
1267
  }
1142
- function openClientSession(request, onEvent) {
1268
+ /** The sessions this instance serves, for the Inspector's `sessions`. */
1269
+ const liveSessions = new Set();
1270
+ function openClientSession(request, onEvent, transport) {
1143
1271
  // The core socket opens once the prelude is admitted, with the access
1144
1272
  // that admission needs: a vouched user's session is the backend's, and
1145
1273
  // so is the endpoint it vouches for on a guest's behalf; a guest signed
@@ -1148,22 +1276,28 @@ async function openJazz(initial, store) {
1148
1276
  let ended = false;
1149
1277
  let userId;
1150
1278
  let trusted = false;
1151
- let recheck;
1152
1279
  // A session that never sends its prelude ends too.
1153
- let expiry = setTimeout(() => {
1280
+ let stopExpiry = startTimer(() => {
1154
1281
  onEvent(null, { kind: "close", code: 1008, reason: "no sign-in in time" });
1155
1282
  end();
1156
1283
  }, PRELUDE_DEADLINE_MS);
1157
- expiry.unref?.();
1158
1284
  const end = () => {
1159
1285
  if (ended)
1160
1286
  return;
1161
1287
  ended = true;
1162
- if (expiry)
1163
- clearTimeout(expiry);
1164
- recheck?.();
1288
+ liveSessions.delete(live);
1289
+ stopExpiry?.();
1165
1290
  socket?.close();
1166
1291
  };
1292
+ // Ask the client to connect again, so the app's auth decides on a new
1293
+ // request: a planned reconnect the client doesn't show as an outage.
1294
+ const reauthenticate = () => {
1295
+ if (ended)
1296
+ return;
1297
+ onEvent(null, { kind: "message", data: reauthenticateBatch() });
1298
+ onEvent(null, { kind: "close", code: 1008, reason: "reauthenticate" });
1299
+ end();
1300
+ };
1167
1301
  const admit = async (prelude) => {
1168
1302
  const admitted = await admitPrelude(request, prelude);
1169
1303
  if (!admitted || ended) {
@@ -1181,34 +1315,53 @@ async function openJazz(initial, store) {
1181
1315
  }
1182
1316
  userId = admitted.userId;
1183
1317
  trusted = admitted.trusted;
1184
- if (expiry)
1185
- clearTimeout(expiry);
1186
- // A backend client's session ends with its token, so it reconnects
1187
- // with a fresh one.
1188
- const ttl = Math.min((options.sessionTtlSeconds ?? 3600) * 1000, admitted.expiresAt === undefined ? Infinity : admitted.expiresAt * 1000 - Date.now());
1189
- expiry = setTimeout(end, Math.max(ttl, 0));
1190
- expiry.unref?.();
1191
- const every = (options.recheckSeconds ?? 60) * 1000;
1192
- // The socket's request carries the cookies it opened with, so a
1193
- // refusal may only mean they expired. The client reconnects with fresh
1194
- // ones; if no one is signed in, that admission fails as an auth
1195
- // failure (above), and otherwise it carries the user's claims now.
1196
- const authenticateAgain = () => {
1197
- if (ended)
1198
- return;
1199
- onEvent(null, { kind: "close", code: 1008, reason: "authenticate again" });
1200
- end();
1201
- };
1202
- const admittedUser = admitted.user;
1203
- if (admittedUser && every > 0) {
1204
- // Signed out, someone else, or the same user with other claims.
1205
- recheck = recheckEvery(every, async () => isSameAdmission(admittedUser, await authenticate(request)), authenticateAgain);
1318
+ stopExpiry?.();
1319
+ const admittedAt = Date.now();
1320
+ if (admitted.user) {
1321
+ // A signed-in user's session holds until the expiry `authenticate`
1322
+ // gave it, and at most `sessionTtlSeconds`. Shortly before, the
1323
+ // client is asked to connect again, so `authenticate` decides on its
1324
+ // new request with current cookies.
1325
+ const at = reauthenticateAt(admittedAt, sessionDeadline(admittedAt, admitted.user.expiresAt, options.sessionTtlSeconds));
1326
+ if (at === null) {
1327
+ // `authenticate` named the user with an answer already expired.
1328
+ warnExpiredAnswer();
1329
+ onEvent(null, {
1330
+ kind: "message",
1331
+ data: authFailedBatch("session expired: authenticate returned an expiresAt in the past"),
1332
+ });
1333
+ onEvent(null, { kind: "close", code: 1008, reason: "session expired" });
1334
+ end();
1335
+ return false;
1336
+ }
1337
+ stopExpiry = startTimer(reauthenticate, at - admittedAt);
1338
+ }
1339
+ else if (admitted.guest) {
1340
+ // A guest's key is its credential; the app lets it in anew each
1341
+ // `sessionTtlSeconds`, the same way.
1342
+ const ttl = (options.sessionTtlSeconds ?? 3600) * 1000;
1343
+ stopExpiry = startTimer(reauthenticate, ttl);
1206
1344
  }
1207
- else if (admitted.guest && every > 0) {
1208
- // The app may stop letting guests in (or this one): ask again, as for users.
1209
- recheck = recheckEvery(every, () => acceptsGuest(request), authenticateAgain);
1345
+ else {
1346
+ // A backend client's session ends with its token, so it reconnects
1347
+ // with a fresh one.
1348
+ const ttl = Math.min((options.sessionTtlSeconds ?? 3600) * 1000, admitted.expiresAt === undefined ? Infinity : admitted.expiresAt * 1000 - admittedAt);
1349
+ stopExpiry = startTimer(end, ttl);
1210
1350
  }
1211
- socket = core.openSocket(headerPairs(request.headers), onEvent, admitted.access);
1351
+ // A guest's session the core refuses because it admits no device
1352
+ // accounts at all: the client only goes offline, so say why here.
1353
+ // The core refuses in its first message, so only that one is looked at.
1354
+ let firstFromCore = admitted.guest === true;
1355
+ const relay = (error, event) => {
1356
+ if (firstFromCore && event.kind === "message" && event.data) {
1357
+ firstFromCore = false;
1358
+ const { buffer, byteOffset, byteLength } = event.data;
1359
+ if (Buffer.from(buffer, byteOffset, byteLength).includes(CORE_REFUSES_GUESTS))
1360
+ warnGuestsOffOnCore();
1361
+ }
1362
+ onEvent(error, event);
1363
+ };
1364
+ socket = core.openSocket(headerPairs(request.headers), relay, admitted.access);
1212
1365
  return socket.send(admitted.prelude);
1213
1366
  };
1214
1367
  // Messages after the prelude wait for its admission, in order.
@@ -1264,7 +1417,11 @@ async function openJazz(initial, store) {
1264
1417
  }
1265
1418
  else {
1266
1419
  // The core is unreachable or failed (5xx), or the app's own
1267
- // `authenticate` threw: the client tries again later.
1420
+ // `authenticate` threw: the client tries again later. An
1421
+ // `authenticate` without `expiresAt` fails the same way every
1422
+ // time: say why, once.
1423
+ if (error instanceof AuthenticateExpiresAtError)
1424
+ warnMissingExpiry(error);
1268
1425
  onEvent(null, { kind: "close", code: 1011, reason: "admission failed" });
1269
1426
  }
1270
1427
  end();
@@ -1273,7 +1430,7 @@ async function openJazz(initial, store) {
1273
1430
  .then(taken);
1274
1431
  return chain;
1275
1432
  };
1276
- return {
1433
+ const clientSession = {
1277
1434
  send(data) {
1278
1435
  if (ended)
1279
1436
  return false;
@@ -1282,6 +1439,15 @@ async function openJazz(initial, store) {
1282
1439
  },
1283
1440
  deliver,
1284
1441
  close: end,
1442
+ revoke(reason) {
1443
+ if (ended)
1444
+ return;
1445
+ // A refusal the client doesn't retry: its session asks the backend
1446
+ // who is signed in, and signs out if no one is.
1447
+ onEvent(null, { kind: "message", data: authFailedBatch(`session revoked: ${reason}`) });
1448
+ onEvent(null, { kind: "close", code: 1008, reason: "session revoked" });
1449
+ end();
1450
+ },
1285
1451
  get userId() {
1286
1452
  return userId;
1287
1453
  },
@@ -1289,6 +1455,9 @@ async function openJazz(initial, store) {
1289
1455
  return trusted;
1290
1456
  },
1291
1457
  };
1458
+ const live = { session: clientSession, transport, openedAt: Date.now() };
1459
+ liveSessions.add(live);
1460
+ return clientSession;
1292
1461
  }
1293
1462
  /**
1294
1463
  * Turn a browser prelude into one the core admits on this backend's word:
@@ -1414,6 +1583,11 @@ async function openJazz(initial, store) {
1414
1583
  const streams = new Map();
1415
1584
  // Sockets accepted for clients, so close() can end them.
1416
1585
  const clientSockets = new Set();
1586
+ // Why stream sessions this process served lately ended, by id: a send that
1587
+ // arrives after its session ended (refused at sign-in, say) is told that,
1588
+ // not that it reached the wrong instance.
1589
+ const endedStreams = new Map();
1590
+ const ENDED_STREAMS_KEPT = 1000;
1417
1591
  function openStream(request) {
1418
1592
  const id = randomUUID();
1419
1593
  // The id goes in URLs (and so in logs); the key only in a header.
@@ -1425,6 +1599,10 @@ async function openJazz(initial, store) {
1425
1599
  return;
1426
1600
  closed = true;
1427
1601
  streams.delete(id);
1602
+ endedStreams.set(id, { key, reason: reason || `closed (${code})` });
1603
+ if (endedStreams.size > ENDED_STREAMS_KEPT) {
1604
+ endedStreams.delete(endedStreams.keys().next().value);
1605
+ }
1428
1606
  try {
1429
1607
  controller.enqueue(encodeStreamClose(code, reason));
1430
1608
  controller.close();
@@ -1454,7 +1632,7 @@ async function openJazz(initial, store) {
1454
1632
  else if (event.kind === "close") {
1455
1633
  end(event.code ?? 1000, event.reason ?? "");
1456
1634
  }
1457
- });
1635
+ }, "stream");
1458
1636
  }
1459
1637
  catch (error) {
1460
1638
  return new Response(error instanceof Error ? error.message : String(error), { status: 503 });
@@ -1469,6 +1647,10 @@ async function openJazz(initial, store) {
1469
1647
  },
1470
1648
  });
1471
1649
  }
1650
+ function holdsKey(request, key) {
1651
+ const given = Buffer.from(request.headers.get(STREAM_KEY_HEADER) ?? "", "base64url");
1652
+ return given.length === key.length && timingSafeEqual(given, key);
1653
+ }
1472
1654
  /**
1473
1655
  * The stream session `id`, when `request` comes from the client that
1474
1656
  * opened it (it carries the session's key) and, once the session is
@@ -1479,11 +1661,16 @@ async function openJazz(initial, store) {
1479
1661
  async function ownStream(id, request) {
1480
1662
  const entry = streams.get(id);
1481
1663
  if (!entry) {
1664
+ const ended = endedStreams.get(id);
1665
+ if (ended !== undefined) {
1666
+ if (!holdsKey(request, ended.key))
1667
+ return new Response("not this stream's client", { status: 403 });
1668
+ return new Response(`stream session ended: ${ended.reason}`, { status: 410 });
1669
+ }
1482
1670
  // Sessions live in the process that opened them.
1483
1671
  return new Response("unknown stream session: HTTP stream sessions need a single backend instance or sticky routing", { status: 404 });
1484
1672
  }
1485
- const given = Buffer.from(request.headers.get(STREAM_KEY_HEADER) ?? "", "base64url");
1486
- if (given.length !== entry.key.length || !timingSafeEqual(given, entry.key)) {
1673
+ if (!holdsKey(request, entry.key)) {
1487
1674
  return new Response("not this stream's client", { status: 403 });
1488
1675
  }
1489
1676
  const socket = entry.session;
@@ -1583,7 +1770,7 @@ async function openJazz(initial, store) {
1583
1770
  else if (event.kind === "close") {
1584
1771
  close(sendableCloseCode(event.code), event.reason ?? "");
1585
1772
  }
1586
- });
1773
+ }, "socket");
1587
1774
  }
1588
1775
  catch (error) {
1589
1776
  close(1013, error instanceof Error ? error.message : String(error));
@@ -1825,6 +2012,17 @@ async function openJazz(initial, store) {
1825
2012
  return await route(request, upgrades);
1826
2013
  }
1827
2014
  catch (error) {
2015
+ if (error instanceof AuthenticateExpiresAtError) {
2016
+ // The app's own setup is wrong, the same way on every request: tell
2017
+ // the client by a stable code it explains (naming the fix), and log
2018
+ // the detail (what `authenticate` returned) here once. The response
2019
+ // carries nothing of the app's answer.
2020
+ warnMissingExpiry(error);
2021
+ return new Response(AUTHENTICATE_EXPIRES_AT_MISSING, {
2022
+ status: 500,
2023
+ headers: { "Cache-Control": "no-store" },
2024
+ });
2025
+ }
1828
2026
  if (!(error instanceof BackendClientsUnavailable))
1829
2027
  throw error;
1830
2028
  // The reason stays in the backend's logs.
@@ -1842,6 +2040,9 @@ async function openJazz(initial, store) {
1842
2040
  if (request.method !== "GET" && request.method !== "HEAD" && !originAllowed(request)) {
1843
2041
  return new Response("origin not allowed", { status: 403 });
1844
2042
  }
2043
+ if (path === "/inspect" || path.startsWith("/inspect/")) {
2044
+ return inspector.handle(request, path);
2045
+ }
1845
2046
  if (/^\/apps\/[^/]+\/accounts\/backend-sign-in$/.test(path)) {
1846
2047
  return backendSignIn(request);
1847
2048
  }
@@ -1889,10 +2090,7 @@ async function openJazz(initial, store) {
1889
2090
  if (upgrades) {
1890
2091
  return new Response("Upgrade to a WebSocket", { status: 426 });
1891
2092
  }
1892
- return new Response("WebSocket upgrade not available here; use the HTTP stream", {
1893
- status: 426,
1894
- headers: { [STREAM_AVAILABLE_HEADER]: "1" },
1895
- });
2093
+ return useHttpStream();
1896
2094
  }
1897
2095
  if (!PUBLIC_APP_ROUTES.test(path))
1898
2096
  return new Response("Not found", { status: 404 });
@@ -1909,12 +2107,20 @@ async function openJazz(initial, store) {
1909
2107
  }
1910
2108
  async function nextHandler(request) {
1911
2109
  const path = innerPath(request);
2110
+ // On Vercel this handler upgrades sockets (below), once `ws` is
2111
+ // installed; elsewhere (next dev) only if attach() runs on the same
2112
+ // server. Where it can't, a socket gets the HTTP stream marker, as a
2113
+ // plain request for the socket path does.
2114
+ const onVercel = onVercelHost();
2115
+ const vercelUpgrades = onVercel && (await vercelUpgradesSockets());
1912
2116
  if (request.method === "GET" &&
1913
2117
  path?.endsWith("/ws") &&
1914
2118
  request.headers.get("upgrade")?.toLowerCase() === "websocket" &&
1915
- onVercelHost()) {
2119
+ onVercel) {
1916
2120
  if (!originAllowed(request))
1917
2121
  return new Response("origin not allowed", { status: 403 });
2122
+ if (!vercelUpgrades)
2123
+ return useHttpStream();
1918
2124
  // An optional peer: a literal import inside `try`, so bundlers report
1919
2125
  // a missing one at runtime, not on every route (see importSandboxSdk).
1920
2126
  let vercelFunctions;
@@ -1931,9 +2137,7 @@ async function openJazz(initial, store) {
1931
2137
  const deadline = vercelFunctions.getDeadline?.()?.getTime();
1932
2138
  return upgradeWebSocket((ws) => acceptSocket(request, deadline === undefined ? ws : closingBeforeDeadline(ws, deadline)), { maxPayload: MAX_STREAM_MESSAGE_BYTES });
1933
2139
  }
1934
- // On Vercel this handler upgrades sockets (above); elsewhere (next dev)
1935
- // only if attach() runs on the same server.
1936
- return handle(request, upgradesSockets || onVercelHost());
2140
+ return handle(request, upgradesSockets || vercelUpgrades);
1937
2141
  }
1938
2142
  function nodeRequest(req) {
1939
2143
  const host = req.headers.host ?? "localhost";
@@ -1974,11 +2178,15 @@ async function openJazz(initial, store) {
1974
2178
  else if (hasBody) {
1975
2179
  body = req;
1976
2180
  }
1977
- return new Request(`http://${host}${req.url ?? "/"}`, {
2181
+ const request = new Request(`http://${host}${req.url ?? "/"}`, {
1978
2182
  method: req.method,
1979
2183
  headers,
1980
2184
  ...(body === undefined ? {} : { body, duplex: "half" }),
1981
2185
  });
2186
+ const address = req.socket?.remoteAddress;
2187
+ if (address)
2188
+ remoteAddresses.set(request, address);
2189
+ return request;
1982
2190
  }
1983
2191
  function nodeHandler(req, res, next) {
1984
2192
  // Only Jazz's own paths: a request for the app passes on untouched, its
@@ -2047,6 +2255,63 @@ async function openJazz(initial, store) {
2047
2255
  upgradesSockets = true;
2048
2256
  attached = true;
2049
2257
  }
2258
+ // The Inspector follows `reload`: it reads the current options each time.
2259
+ let keptSecret;
2260
+ let schemaOf = null;
2261
+ const inspector = createInspector({
2262
+ appId,
2263
+ get basePath() {
2264
+ return basePath;
2265
+ },
2266
+ get publicUrls() {
2267
+ return publicUrls;
2268
+ },
2269
+ schema: () => {
2270
+ if (schemaOf?.app !== options.app) {
2271
+ schemaOf = { app: options.app, schema: resolveSchemaSource(options.app) };
2272
+ }
2273
+ return schemaOf.schema;
2274
+ },
2275
+ get permissions() {
2276
+ return options.permissions;
2277
+ },
2278
+ db: () => backend.db,
2279
+ dbAs: async (user) => backendDbForSession(backend, await sessionFor(user, "inspect `as`")),
2280
+ sessions: () => [...liveSessions].map(({ session: live, transport, openedAt }) => ({
2281
+ userId: live.userId ?? null,
2282
+ kind: live.trusted ? "backend-client" : live.userId === undefined ? "guest" : "user",
2283
+ transport,
2284
+ openedAt,
2285
+ })),
2286
+ get hook() {
2287
+ return options.inspect;
2288
+ },
2289
+ get options() {
2290
+ return options.inspector ?? NO_INSPECTOR_OPTIONS;
2291
+ },
2292
+ tokenSecret: async () => {
2293
+ const configured = options.inspector?.tokenSecret;
2294
+ if (configured !== undefined)
2295
+ return configured;
2296
+ if (store.kind === "remote")
2297
+ return store.secret ?? null;
2298
+ if (store.kind === "sqlite") {
2299
+ // Read once; a failed read is tried again on the next call.
2300
+ keptSecret ??= keptTokenSecret(store.path).catch((error) => {
2301
+ keptSecret = undefined;
2302
+ throw error;
2303
+ });
2304
+ return keptSecret;
2305
+ }
2306
+ if (store.kind === "memory")
2307
+ return memoryTokenSecret;
2308
+ // A Vercel core's only credential is the function's OIDC token: there
2309
+ // is no shared secret to sign with.
2310
+ return null;
2311
+ },
2312
+ remoteAddress: (request) => remoteAddresses.get(request),
2313
+ serveUi: createInspectorUi(),
2314
+ });
2050
2315
  let closing;
2051
2316
  return {
2052
2317
  appId,
@@ -2085,6 +2350,18 @@ async function openJazz(initial, store) {
2085
2350
  throw new Error("createAccountFor: pass the user's id, as your authenticate names it");
2086
2351
  return accountOf(userId);
2087
2352
  },
2353
+ async revokeUser(userId) {
2354
+ if (typeof userId !== "string" || userId === "")
2355
+ throw new Error("revokeUser: pass the user's id, as your authenticate names it");
2356
+ let ended = 0;
2357
+ for (const { session } of [...liveSessions]) {
2358
+ if (session.trusted || session.userId !== userId)
2359
+ continue;
2360
+ session.revoke("revokeUser");
2361
+ ended += 1;
2362
+ }
2363
+ return ended;
2364
+ },
2088
2365
  close() {
2089
2366
  closing ??= (async () => {
2090
2367
  // Every client connection ends, so the host's own shutdown (which
@@ -2135,6 +2412,9 @@ async function openJazz(initial, store) {
2135
2412
  */
2136
2413
  export function createJazz(options) {
2137
2414
  jazzSettings(options);
2415
+ // Checked at startup, so a missing `ws` is in the logs before the first socket.
2416
+ if (onVercelHost())
2417
+ void vercelUpgradesSockets();
2138
2418
  const store = runningStore(options.store);
2139
2419
  const key = storeKey(store);
2140
2420
  const entries = registry();
@@ -2672,6 +2952,7 @@ function facade(entry) {
2672
2952
  withAttribution: async (request) => (await use()).withAttribution(request),
2673
2953
  accountFor: async (request) => (await use()).accountFor(request),
2674
2954
  createAccountFor: async (userId) => (await use()).createAccountFor(userId),
2955
+ revokeUser: async (userId) => (await use()).revokeUser(userId),
2675
2956
  linkIdentity: async (link) => (await use()).linkIdentity(link),
2676
2957
  async ready() {
2677
2958
  await use();
@@ -2707,6 +2988,20 @@ function refusalCode(error) {
2707
2988
  return code ?? "refused";
2708
2989
  }
2709
2990
  /** A WireFrame::Error batch with code AuthFailed and retry Never. */
2991
+ /**
2992
+ * The error a session sends its client when the expiry its app's auth gave
2993
+ * it is near: `auth_failed` with `after_resume` retry, which a client takes
2994
+ * as "connect again now" (`isReauthenticateWireError`). A client that
2995
+ * doesn't know it takes it as a refused credential and asks its backend.
2996
+ */
2997
+ function reauthenticateBatch() {
2998
+ const frame = new PostcardWriter();
2999
+ frame.u64(1); // WireFrame::Error
3000
+ frame.u64(3); // WireErrorCode::AuthFailed
3001
+ frame.u64(2); // WireRetry::AfterResume
3002
+ frame.string(`${REAUTHENTICATE_WIRE_MESSAGE_PREFIX} the session reached the expiry authenticate gave it`);
3003
+ return Buffer.from(encodeWebSocketFrameBatch([frame.finish()]));
3004
+ }
2710
3005
  function authFailedBatch(message) {
2711
3006
  const frame = new PostcardWriter();
2712
3007
  frame.u64(1); // WireFrame::Error