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

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 (719) 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 +13 -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 +38 -2
  19. package/dist/accounts/persistence.d.ts.map +1 -1
  20. package/dist/accounts/persistence.js +123 -6
  21. package/dist/accounts/persistence.js.map +1 -1
  22. package/dist/accounts/registry-client.d.ts +29 -0
  23. package/dist/accounts/registry-client.d.ts.map +1 -1
  24. package/dist/accounts/registry-client.js +45 -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-context.d.ts +7 -0
  30. package/dist/backend/create-jazz-context.d.ts.map +1 -1
  31. package/dist/backend/create-jazz-context.js +115 -18
  32. package/dist/backend/create-jazz-context.js.map +1 -1
  33. package/dist/backend/create-jazz-session.d.ts +9 -7
  34. package/dist/backend/create-jazz-session.d.ts.map +1 -1
  35. package/dist/backend/create-jazz-session.js +55 -17
  36. package/dist/backend/create-jazz-session.js.map +1 -1
  37. package/dist/backend/create-jazz.d.ts +196 -38
  38. package/dist/backend/create-jazz.d.ts.map +1 -1
  39. package/dist/backend/create-jazz.js +935 -147
  40. package/dist/backend/create-jazz.js.map +1 -1
  41. package/dist/backend/early-db.d.ts.map +1 -1
  42. package/dist/backend/early-db.js +1 -0
  43. package/dist/backend/early-db.js.map +1 -1
  44. package/dist/backend/external-jwt.d.ts.map +1 -1
  45. package/dist/backend/external-jwt.js +34 -10
  46. package/dist/backend/external-jwt.js.map +1 -1
  47. package/dist/backend/from-jwt.d.ts +6 -4
  48. package/dist/backend/from-jwt.d.ts.map +1 -1
  49. package/dist/backend/from-jwt.js +11 -3
  50. package/dist/backend/from-jwt.js.map +1 -1
  51. package/dist/backend/index.d.ts +2 -1
  52. package/dist/backend/index.d.ts.map +1 -1
  53. package/dist/backend/index.js +3 -1
  54. package/dist/backend/index.js.map +1 -1
  55. package/dist/backend/inspect-ui.d.ts +14 -0
  56. package/dist/backend/inspect-ui.d.ts.map +1 -0
  57. package/dist/backend/inspect-ui.js +156 -0
  58. package/dist/backend/inspect-ui.js.map +1 -0
  59. package/dist/backend/inspect.d.ts +133 -0
  60. package/dist/backend/inspect.d.ts.map +1 -0
  61. package/dist/backend/inspect.js +983 -0
  62. package/dist/backend/inspect.js.map +1 -0
  63. package/dist/backend/inspector-ui/0.js +2 -0
  64. package/dist/backend/inspector-ui/1.js +2 -0
  65. package/dist/backend/inspector-ui/10.js +2 -0
  66. package/dist/backend/inspector-ui/11.js +2 -0
  67. package/dist/backend/inspector-ui/12.js +2 -0
  68. package/dist/backend/inspector-ui/13.js +2 -0
  69. package/dist/backend/inspector-ui/14.js +2 -0
  70. package/dist/backend/inspector-ui/15.js +2 -0
  71. package/dist/backend/inspector-ui/16.js +2 -0
  72. package/dist/backend/inspector-ui/17.js +2 -0
  73. package/dist/backend/inspector-ui/18.js +2 -0
  74. package/dist/backend/inspector-ui/19.js +2 -0
  75. package/dist/backend/inspector-ui/2.js +2 -0
  76. package/dist/backend/inspector-ui/20.js +2 -0
  77. package/dist/backend/inspector-ui/3.js +2 -0
  78. package/dist/backend/inspector-ui/4.js +2 -0
  79. package/dist/backend/inspector-ui/5.js +2 -0
  80. package/dist/backend/inspector-ui/6.js +2 -0
  81. package/dist/backend/inspector-ui/7.js +2 -0
  82. package/dist/backend/inspector-ui/8.js +2 -0
  83. package/dist/backend/inspector-ui/9.js +2 -0
  84. package/dist/backend/inspector-ui-files.d.ts +4 -0
  85. package/dist/backend/inspector-ui-files.d.ts.map +1 -0
  86. package/dist/backend/inspector-ui-files.js +25 -0
  87. package/dist/backend/request-auth.d.ts +11 -0
  88. package/dist/backend/request-auth.d.ts.map +1 -1
  89. package/dist/backend/request-auth.js +14 -0
  90. package/dist/backend/request-auth.js.map +1 -1
  91. package/dist/backend/session-expiry.d.ts +61 -0
  92. package/dist/backend/session-expiry.d.ts.map +1 -0
  93. package/dist/backend/session-expiry.js +102 -0
  94. package/dist/backend/session-expiry.js.map +1 -0
  95. package/dist/backend/signing-key.d.ts +10 -0
  96. package/dist/backend/signing-key.d.ts.map +1 -0
  97. package/dist/backend/signing-key.js +15 -0
  98. package/dist/backend/signing-key.js.map +1 -0
  99. package/dist/backend/store-log.d.ts +3 -0
  100. package/dist/backend/store-log.d.ts.map +1 -0
  101. package/dist/backend/store-log.js +16 -0
  102. package/dist/backend/store-log.js.map +1 -0
  103. package/dist/backend/upgrade-status.d.ts +19 -0
  104. package/dist/backend/upgrade-status.d.ts.map +1 -0
  105. package/dist/backend/upgrade-status.js +55 -0
  106. package/dist/backend/upgrade-status.js.map +1 -0
  107. package/dist/backend/vercel-store.d.ts +88 -12
  108. package/dist/backend/vercel-store.d.ts.map +1 -1
  109. package/dist/backend/vercel-store.js +303 -44
  110. package/dist/backend/vercel-store.js.map +1 -1
  111. package/dist/backend/ws-peer.d.ts +32 -0
  112. package/dist/backend/ws-peer.d.ts.map +1 -0
  113. package/dist/backend/ws-peer.js +40 -0
  114. package/dist/backend/ws-peer.js.map +1 -0
  115. package/dist/better-auth-adapter/fixtures/issuer-upgrade-schema.d.ts +134 -0
  116. package/dist/better-auth-adapter/fixtures/issuer-upgrade-schema.d.ts.map +1 -0
  117. package/dist/better-auth-adapter/fixtures/issuer-upgrade-schema.js +121 -0
  118. package/dist/better-auth-adapter/fixtures/issuer-upgrade-schema.js.map +1 -0
  119. package/dist/better-auth-adapter/fixtures/schema.d.ts +2 -1
  120. package/dist/better-auth-adapter/fixtures/schema.d.ts.map +1 -1
  121. package/dist/better-auth-adapter/fixtures/schema.js +2 -1
  122. package/dist/better-auth-adapter/fixtures/schema.js.map +1 -1
  123. package/dist/better-auth-adapter/index.d.ts.map +1 -1
  124. package/dist/better-auth-adapter/index.js +47 -0
  125. package/dist/better-auth-adapter/index.js.map +1 -1
  126. package/dist/classic-api.d.ts.map +1 -1
  127. package/dist/classic-api.js +36 -0
  128. package/dist/classic-api.js.map +1 -1
  129. package/dist/cli.d.ts.map +1 -1
  130. package/dist/cli.js +54 -11
  131. package/dist/cli.js.map +1 -1
  132. package/dist/client/index.d.ts +2 -6
  133. package/dist/client/index.d.ts.map +1 -1
  134. package/dist/client/index.js +2 -3
  135. package/dist/client/index.js.map +1 -1
  136. package/dist/cloud/credentials.d.ts +1 -1
  137. package/dist/cloud/credentials.d.ts.map +1 -1
  138. package/dist/cloud/credentials.js.map +1 -1
  139. package/dist/dev/catalogue-project.d.ts +12 -3
  140. package/dist/dev/catalogue-project.d.ts.map +1 -1
  141. package/dist/dev/catalogue-project.js +29 -4
  142. package/dist/dev/catalogue-project.js.map +1 -1
  143. package/dist/dev/catalogue.d.ts +12 -0
  144. package/dist/dev/catalogue.d.ts.map +1 -1
  145. package/dist/dev/catalogue.js +94 -15
  146. package/dist/dev/catalogue.js.map +1 -1
  147. package/dist/dev/dev-server.d.ts +4 -1
  148. package/dist/dev/dev-server.d.ts.map +1 -1
  149. package/dist/dev/dev-server.js +41 -3
  150. package/dist/dev/dev-server.js.map +1 -1
  151. package/dist/dev/inspector-overlay/embedded/assets/backend-C6JfNAB2.js +1 -0
  152. package/dist/dev/inspector-overlay/embedded/assets/backend-DHeT1LCS.css +1 -0
  153. package/dist/dev/inspector-overlay/embedded/assets/{create-legacy-browser-delegate-X_T_QKCN.js → create-legacy-browser-delegate-Bf58kV5i.js} +1 -1
  154. package/dist/dev/inspector-overlay/embedded/assets/{esm-aRzpnC3u.js → esm-B8Fn7-qJ.js} +1 -1
  155. package/dist/dev/inspector-overlay/embedded/assets/{esm-ezD5H765.js → esm-C3BWHq-S.js} +1 -1
  156. package/dist/dev/inspector-overlay/embedded/assets/esm-DC_mAoiW.js +1 -0
  157. package/dist/dev/inspector-overlay/embedded/assets/{esm-7mP3GQX4.js → esm-D_R-EGgt.js} +1 -1
  158. package/dist/dev/inspector-overlay/embedded/assets/{esm-BX6IY2Mv.js → esm-WihpI9g6.js} +1 -1
  159. package/dist/dev/inspector-overlay/embedded/assets/index-C_pcvEcg.js +1 -0
  160. package/dist/dev/inspector-overlay/embedded/assets/{jazz-broker-worker-XRRxJUcx.js → jazz-broker-worker-Cv6-V0tc.js} +787 -608
  161. package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-Db-pNME-.js +5 -0
  162. package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-CTwPHZcZ.js +1 -0
  163. package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm_bg-KR7h3v27.wasm → jazz_wasm_bg-HpkRDlj-.wasm} +0 -0
  164. package/dist/dev/inspector-overlay/embedded/assets/src-B5UtjtXQ.js +22 -0
  165. package/dist/dev/inspector-overlay/embedded/assets/{index-C78Pprka.css → src-Cq8gSOLx.css} +1 -1
  166. package/dist/dev/inspector-overlay/embedded/assets/{trace-api-B5CaetI0.js → trace-api-BctnwbUf.js} +1 -1
  167. package/dist/dev/inspector-overlay/embedded/backend.html +16 -0
  168. package/dist/dev/inspector-overlay/embedded/embedded.html +3 -2
  169. package/dist/dev/inspector-overlay/host-bridge.d.ts.map +1 -1
  170. package/dist/dev/inspector-overlay/host-bridge.js +4 -1
  171. package/dist/dev/inspector-overlay/host-bridge.js.map +1 -1
  172. package/dist/dev/inspector-overlay/loader.d.ts +12 -1
  173. package/dist/dev/inspector-overlay/loader.d.ts.map +1 -1
  174. package/dist/dev/inspector-overlay/loader.js +31 -4
  175. package/dist/dev/inspector-overlay/loader.js.map +1 -1
  176. package/dist/dev/migrations.d.ts.map +1 -1
  177. package/dist/dev/migrations.js +53 -7
  178. package/dist/dev/migrations.js.map +1 -1
  179. package/dist/drivers/schema-wire.d.ts +6 -2
  180. package/dist/drivers/schema-wire.d.ts.map +1 -1
  181. package/dist/drivers/schema-wire.js +6 -2
  182. package/dist/drivers/schema-wire.js.map +1 -1
  183. package/dist/effect/jazz.d.ts +12 -5
  184. package/dist/effect/jazz.d.ts.map +1 -1
  185. package/dist/effect/jazz.js +28 -5
  186. package/dist/effect/jazz.js.map +1 -1
  187. package/dist/expo/create-account-manager.d.ts +1 -1
  188. package/dist/expo/create-account-manager.d.ts.map +1 -1
  189. package/dist/expo/create-jazz-session.d.ts +37 -17
  190. package/dist/expo/create-jazz-session.d.ts.map +1 -1
  191. package/dist/expo/create-jazz-session.js +53 -10
  192. package/dist/expo/create-jazz-session.js.map +1 -1
  193. package/dist/expo/index.d.ts +5 -8
  194. package/dist/expo/index.d.ts.map +1 -1
  195. package/dist/expo/index.js +5 -7
  196. package/dist/expo/index.js.map +1 -1
  197. package/dist/expo/metro.d.ts +20 -0
  198. package/dist/expo/metro.d.ts.map +1 -0
  199. package/dist/expo/metro.js +58 -0
  200. package/dist/expo/metro.js.map +1 -0
  201. package/dist/expo/provider.d.ts +6 -3
  202. package/dist/expo/provider.d.ts.map +1 -1
  203. package/dist/expo/provider.js +7 -6
  204. package/dist/expo/provider.js.map +1 -1
  205. package/dist/index.d.ts +3 -2
  206. package/dist/index.d.ts.map +1 -1
  207. package/dist/index.js +3 -1
  208. package/dist/index.js.map +1 -1
  209. package/dist/inspect/cli.d.ts +12 -0
  210. package/dist/inspect/cli.d.ts.map +1 -0
  211. package/dist/inspect/cli.js +320 -0
  212. package/dist/inspect/cli.js.map +1 -0
  213. package/dist/inspect/client.d.ts +67 -0
  214. package/dist/inspect/client.d.ts.map +1 -0
  215. package/dist/inspect/client.js +254 -0
  216. package/dist/inspect/client.js.map +1 -0
  217. package/dist/inspect/mcp.d.ts +28 -0
  218. package/dist/inspect/mcp.d.ts.map +1 -0
  219. package/dist/inspect/mcp.js +441 -0
  220. package/dist/inspect/mcp.js.map +1 -0
  221. package/dist/inspect/protocol.d.ts +317 -0
  222. package/dist/inspect/protocol.d.ts.map +1 -0
  223. package/dist/inspect/protocol.js +544 -0
  224. package/dist/inspect/protocol.js.map +1 -0
  225. package/dist/inspector/index.d.ts +10 -0
  226. package/dist/inspector/index.d.ts.map +1 -0
  227. package/dist/inspector/index.js +27 -0
  228. package/dist/inspector/index.js.map +1 -0
  229. package/dist/local-first/index.d.ts +2 -0
  230. package/dist/local-first/index.d.ts.map +1 -1
  231. package/dist/local-first/index.js +2 -0
  232. package/dist/local-first/index.js.map +1 -1
  233. package/dist/migrations.d.ts +23 -3
  234. package/dist/migrations.d.ts.map +1 -1
  235. package/dist/migrations.js +28 -6
  236. package/dist/migrations.js.map +1 -1
  237. package/dist/module-interop.d.ts +17 -0
  238. package/dist/module-interop.d.ts.map +1 -0
  239. package/dist/module-interop.js +32 -0
  240. package/dist/module-interop.js.map +1 -0
  241. package/dist/permissions/index.d.ts +1 -1
  242. package/dist/permissions/index.d.ts.map +1 -1
  243. package/dist/permissions/index.js +31 -10
  244. package/dist/permissions/index.js.map +1 -1
  245. package/dist/prosemirror/sync.d.ts.map +1 -1
  246. package/dist/prosemirror/sync.js +43 -21
  247. package/dist/prosemirror/sync.js.map +1 -1
  248. package/dist/react/index.d.ts +4 -9
  249. package/dist/react/index.d.ts.map +1 -1
  250. package/dist/react/index.js +4 -6
  251. package/dist/react/index.js.map +1 -1
  252. package/dist/react/provider-props.d.ts +7 -0
  253. package/dist/react/provider-props.d.ts.map +1 -0
  254. package/dist/react/provider-props.js +15 -0
  255. package/dist/react/provider-props.js.map +1 -0
  256. package/dist/react/provider.d.ts +9 -15
  257. package/dist/react/provider.d.ts.map +1 -1
  258. package/dist/react/provider.js +19 -38
  259. package/dist/react/provider.js.map +1 -1
  260. package/dist/react-core/index.d.ts +3 -4
  261. package/dist/react-core/index.d.ts.map +1 -1
  262. package/dist/react-core/index.js +8 -4
  263. package/dist/react-core/index.js.map +1 -1
  264. package/dist/react-core/provider.d.ts +6 -6
  265. package/dist/react-core/provider.d.ts.map +1 -1
  266. package/dist/react-core/provider.js +5 -6
  267. package/dist/react-core/provider.js.map +1 -1
  268. package/dist/react-core/session.d.ts +41 -33
  269. package/dist/react-core/session.d.ts.map +1 -1
  270. package/dist/react-core/session.js +42 -90
  271. package/dist/react-core/session.js.map +1 -1
  272. package/dist/react-native/account-session.js +1 -1
  273. package/dist/react-native/account-session.js.map +1 -1
  274. package/dist/react-native/create-account-manager.d.ts +1 -1
  275. package/dist/react-native/create-account-manager.d.ts.map +1 -1
  276. package/dist/react-native/create-jazz-session.d.ts +37 -17
  277. package/dist/react-native/create-jazz-session.d.ts.map +1 -1
  278. package/dist/react-native/create-jazz-session.js +53 -10
  279. package/dist/react-native/create-jazz-session.js.map +1 -1
  280. package/dist/react-native/index.d.ts +5 -10
  281. package/dist/react-native/index.d.ts.map +1 -1
  282. package/dist/react-native/index.js +5 -7
  283. package/dist/react-native/index.js.map +1 -1
  284. package/dist/react-native/native-foreground-db.d.ts +21 -0
  285. package/dist/react-native/native-foreground-db.d.ts.map +1 -1
  286. package/dist/react-native/native-foreground-db.js +47 -1
  287. package/dist/react-native/native-foreground-db.js.map +1 -1
  288. package/dist/react-native/provider.d.ts +14 -19
  289. package/dist/react-native/provider.d.ts.map +1 -1
  290. package/dist/react-native/provider.js +19 -18
  291. package/dist/react-native/provider.js.map +1 -1
  292. package/dist/react-native/runtime-source.d.ts +22 -0
  293. package/dist/react-native/runtime-source.d.ts.map +1 -1
  294. package/dist/react-native/runtime-source.js +68 -5
  295. package/dist/react-native/runtime-source.js.map +1 -1
  296. package/dist/removed-api.d.ts +87 -0
  297. package/dist/removed-api.d.ts.map +1 -0
  298. package/dist/removed-api.js +95 -0
  299. package/dist/removed-api.js.map +1 -0
  300. package/dist/runtime/auth-secret-store.d.ts +0 -44
  301. package/dist/runtime/auth-secret-store.d.ts.map +1 -1
  302. package/dist/runtime/auth-secret-store.js +1 -103
  303. package/dist/runtime/auth-secret-store.js.map +1 -1
  304. package/dist/runtime/authority-changed-error.d.ts +5 -3
  305. package/dist/runtime/authority-changed-error.d.ts.map +1 -1
  306. package/dist/runtime/authority-changed-error.js +5 -3
  307. package/dist/runtime/authority-changed-error.js.map +1 -1
  308. package/dist/runtime/browser-worker-assets.d.ts +19 -1
  309. package/dist/runtime/browser-worker-assets.d.ts.map +1 -1
  310. package/dist/runtime/browser-worker-assets.js +23 -1
  311. package/dist/runtime/browser-worker-assets.js.map +1 -1
  312. package/dist/runtime/browser-worker-assets.metro.d.ts +28 -0
  313. package/dist/runtime/browser-worker-assets.metro.d.ts.map +1 -0
  314. package/dist/runtime/browser-worker-assets.metro.js +52 -0
  315. package/dist/runtime/browser-worker-assets.metro.js.map +1 -0
  316. package/dist/runtime/browser-worker-assets.native.d.ts +2 -0
  317. package/dist/runtime/browser-worker-assets.native.d.ts.map +1 -1
  318. package/dist/runtime/browser-worker-assets.native.js +2 -0
  319. package/dist/runtime/browser-worker-assets.native.js.map +1 -1
  320. package/dist/runtime/browser-worker-config.d.ts +23 -0
  321. package/dist/runtime/browser-worker-config.d.ts.map +1 -1
  322. package/dist/runtime/browser-worker-config.js +72 -4
  323. package/dist/runtime/browser-worker-config.js.map +1 -1
  324. package/dist/runtime/client-migrations.d.ts +6 -4
  325. package/dist/runtime/client-migrations.d.ts.map +1 -1
  326. package/dist/runtime/client-migrations.js +20 -2
  327. package/dist/runtime/client-migrations.js.map +1 -1
  328. package/dist/runtime/client.d.ts +46 -6
  329. package/dist/runtime/client.d.ts.map +1 -1
  330. package/dist/runtime/client.js +65 -13
  331. package/dist/runtime/client.js.map +1 -1
  332. package/dist/runtime/connection-manager/browser-connection-manager.d.ts +5 -1
  333. package/dist/runtime/connection-manager/browser-connection-manager.d.ts.map +1 -1
  334. package/dist/runtime/connection-manager/browser-connection-manager.js +38 -2
  335. package/dist/runtime/connection-manager/browser-connection-manager.js.map +1 -1
  336. package/dist/runtime/connection-manager/direct-connection-manager.d.ts +3 -1
  337. package/dist/runtime/connection-manager/direct-connection-manager.d.ts.map +1 -1
  338. package/dist/runtime/connection-manager/direct-connection-manager.js +7 -3
  339. package/dist/runtime/connection-manager/direct-connection-manager.js.map +1 -1
  340. package/dist/runtime/connection-manager/types.d.ts +23 -2
  341. package/dist/runtime/connection-manager/types.d.ts.map +1 -1
  342. package/dist/runtime/connection-manager/types.js +49 -6
  343. package/dist/runtime/connection-manager/types.js.map +1 -1
  344. package/dist/runtime/context.d.ts +5 -1
  345. package/dist/runtime/context.d.ts.map +1 -1
  346. package/dist/runtime/context.js.map +1 -1
  347. package/dist/runtime/core-tick-failed-error.d.ts +31 -0
  348. package/dist/runtime/core-tick-failed-error.d.ts.map +1 -0
  349. package/dist/runtime/core-tick-failed-error.js +45 -0
  350. package/dist/runtime/core-tick-failed-error.js.map +1 -0
  351. package/dist/runtime/credentialed-transport.d.ts +18 -3
  352. package/dist/runtime/credentialed-transport.d.ts.map +1 -1
  353. package/dist/runtime/credentialed-transport.js +34 -11
  354. package/dist/runtime/credentialed-transport.js.map +1 -1
  355. package/dist/runtime/db-replaced-error.d.ts +3 -1
  356. package/dist/runtime/db-replaced-error.d.ts.map +1 -1
  357. package/dist/runtime/db-replaced-error.js +4 -2
  358. package/dist/runtime/db-replaced-error.js.map +1 -1
  359. package/dist/runtime/db.d.ts +40 -8
  360. package/dist/runtime/db.d.ts.map +1 -1
  361. package/dist/runtime/db.js +76 -9
  362. package/dist/runtime/db.js.map +1 -1
  363. package/dist/runtime/default-runtime-source.d.ts.map +1 -1
  364. package/dist/runtime/default-runtime-source.js +6 -1
  365. package/dist/runtime/default-runtime-source.js.map +1 -1
  366. package/dist/runtime/delete-local-first-store.d.ts +12 -0
  367. package/dist/runtime/delete-local-first-store.d.ts.map +1 -0
  368. package/dist/runtime/delete-local-first-store.js +12 -0
  369. package/dist/runtime/delete-local-first-store.js.map +1 -0
  370. package/dist/runtime/index.d.ts +4 -4
  371. package/dist/runtime/index.d.ts.map +1 -1
  372. package/dist/runtime/index.js +2 -2
  373. package/dist/runtime/index.js.map +1 -1
  374. package/dist/runtime/local-first-upgrade.d.ts +9 -0
  375. package/dist/runtime/local-first-upgrade.d.ts.map +1 -1
  376. package/dist/runtime/local-first-upgrade.js.map +1 -1
  377. package/dist/runtime/metro-setup-error.d.ts +20 -0
  378. package/dist/runtime/metro-setup-error.d.ts.map +1 -0
  379. package/dist/runtime/metro-setup-error.js +22 -0
  380. package/dist/runtime/metro-setup-error.js.map +1 -0
  381. package/dist/runtime/native-artifact-fingerprint-napi.d.ts +1 -1
  382. package/dist/runtime/native-artifact-fingerprint-napi.js +1 -1
  383. package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -1
  384. package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +1 -1
  385. package/dist/runtime/native-artifact-fingerprint-wasm.js +1 -1
  386. package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -1
  387. package/dist/runtime/native-artifact-fingerprints.d.ts +2 -2
  388. package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts +4 -1
  389. package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts.map +1 -1
  390. package/dist/runtime/native-runtime/attached-browser-worker-connection.js +3 -0
  391. package/dist/runtime/native-runtime/attached-browser-worker-connection.js.map +1 -1
  392. package/dist/runtime/native-runtime/broker-worker-load-failure.d.ts +34 -0
  393. package/dist/runtime/native-runtime/broker-worker-load-failure.d.ts.map +1 -0
  394. package/dist/runtime/native-runtime/broker-worker-load-failure.js +61 -0
  395. package/dist/runtime/native-runtime/broker-worker-load-failure.js.map +1 -0
  396. package/dist/runtime/native-runtime/browser-follower-connection.d.ts +6 -1
  397. package/dist/runtime/native-runtime/browser-follower-connection.d.ts.map +1 -1
  398. package/dist/runtime/native-runtime/browser-follower-connection.js +9 -3
  399. package/dist/runtime/native-runtime/browser-follower-connection.js.map +1 -1
  400. package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts +12 -1
  401. package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts.map +1 -1
  402. package/dist/runtime/native-runtime/browser-shared-worker-connection.js +140 -7
  403. package/dist/runtime/native-runtime/browser-shared-worker-connection.js.map +1 -1
  404. package/dist/runtime/native-runtime/browser-worker-protocol.d.ts +29 -1
  405. package/dist/runtime/native-runtime/browser-worker-protocol.d.ts.map +1 -1
  406. package/dist/runtime/native-runtime/browser-worker-protocol.js.map +1 -1
  407. package/dist/runtime/native-runtime/http-stream-socket.d.ts +25 -7
  408. package/dist/runtime/native-runtime/http-stream-socket.d.ts.map +1 -1
  409. package/dist/runtime/native-runtime/http-stream-socket.js +148 -44
  410. package/dist/runtime/native-runtime/http-stream-socket.js.map +1 -1
  411. package/dist/runtime/native-runtime/native-error-code.d.ts +1 -1
  412. package/dist/runtime/native-runtime/native-error-code.d.ts.map +1 -1
  413. package/dist/runtime/native-runtime/native-error-code.js +1 -0
  414. package/dist/runtime/native-runtime/native-error-code.js.map +1 -1
  415. package/dist/runtime/native-runtime/native-runtime-adapter.d.ts +105 -7
  416. package/dist/runtime/native-runtime/native-runtime-adapter.d.ts.map +1 -1
  417. package/dist/runtime/native-runtime/native-runtime-adapter.js +306 -27
  418. package/dist/runtime/native-runtime/native-runtime-adapter.js.map +1 -1
  419. package/dist/runtime/native-runtime/session-renewal-wire.d.ts +48 -0
  420. package/dist/runtime/native-runtime/session-renewal-wire.d.ts.map +1 -0
  421. package/dist/runtime/native-runtime/session-renewal-wire.js +107 -0
  422. package/dist/runtime/native-runtime/session-renewal-wire.js.map +1 -0
  423. package/dist/runtime/native-runtime/stream-endpoint-memory.d.ts +22 -0
  424. package/dist/runtime/native-runtime/stream-endpoint-memory.d.ts.map +1 -0
  425. package/dist/runtime/native-runtime/stream-endpoint-memory.js +69 -0
  426. package/dist/runtime/native-runtime/stream-endpoint-memory.js.map +1 -0
  427. package/dist/runtime/native-runtime/websocket.d.ts +51 -1
  428. package/dist/runtime/native-runtime/websocket.d.ts.map +1 -1
  429. package/dist/runtime/native-runtime/websocket.js +187 -7
  430. package/dist/runtime/native-runtime/websocket.js.map +1 -1
  431. package/dist/runtime/page-handle.d.ts +83 -0
  432. package/dist/runtime/page-handle.d.ts.map +1 -0
  433. package/dist/runtime/page-handle.js +151 -0
  434. package/dist/runtime/page-handle.js.map +1 -0
  435. package/dist/runtime/removed-provider-props.d.ts +17 -0
  436. package/dist/runtime/removed-provider-props.d.ts.map +1 -0
  437. package/dist/runtime/removed-provider-props.js +16 -0
  438. package/dist/runtime/removed-provider-props.js.map +1 -0
  439. package/dist/runtime/row-transformer.d.ts.map +1 -1
  440. package/dist/runtime/row-transformer.js +20 -0
  441. package/dist/runtime/row-transformer.js.map +1 -1
  442. package/dist/runtime/runtime-config.d.ts +5 -1
  443. package/dist/runtime/runtime-config.d.ts.map +1 -1
  444. package/dist/runtime/runtime-config.js +5 -1
  445. package/dist/runtime/runtime-config.js.map +1 -1
  446. package/dist/runtime/runtime-source.d.ts +6 -1
  447. package/dist/runtime/runtime-source.d.ts.map +1 -1
  448. package/dist/runtime/runtime-source.js.map +1 -1
  449. package/dist/runtime/schema-metadata.d.ts +17 -0
  450. package/dist/runtime/schema-metadata.d.ts.map +1 -1
  451. package/dist/runtime/schema-metadata.js +28 -0
  452. package/dist/runtime/schema-metadata.js.map +1 -1
  453. package/dist/runtime/store-held-by-another-tab-error.d.ts +11 -0
  454. package/dist/runtime/store-held-by-another-tab-error.d.ts.map +1 -1
  455. package/dist/runtime/store-held-by-another-tab-error.js +11 -0
  456. package/dist/runtime/store-held-by-another-tab-error.js.map +1 -1
  457. package/dist/runtime/sync-status.d.ts +60 -1
  458. package/dist/runtime/sync-status.d.ts.map +1 -1
  459. package/dist/runtime/sync-status.js +64 -4
  460. package/dist/runtime/sync-status.js.map +1 -1
  461. package/dist/runtime/wasm-loader.d.ts.map +1 -1
  462. package/dist/runtime/wasm-loader.js +8 -1
  463. package/dist/runtime/wasm-loader.js.map +1 -1
  464. package/dist/schema-loader.d.ts +2 -0
  465. package/dist/schema-loader.d.ts.map +1 -1
  466. package/dist/schema-loader.js +7 -2
  467. package/dist/schema-loader.js.map +1 -1
  468. package/dist/schema-permissions.d.ts.map +1 -1
  469. package/dist/schema-permissions.js +19 -0
  470. package/dist/schema-permissions.js.map +1 -1
  471. package/dist/schema-source.d.ts.map +1 -1
  472. package/dist/schema-source.js +14 -0
  473. package/dist/schema-source.js.map +1 -1
  474. package/dist/session/backend-watch.d.ts +56 -15
  475. package/dist/session/backend-watch.d.ts.map +1 -1
  476. package/dist/session/backend-watch.js +127 -31
  477. package/dist/session/backend-watch.js.map +1 -1
  478. package/dist/session/config-options.d.ts +15 -0
  479. package/dist/session/config-options.d.ts.map +1 -0
  480. package/dist/session/config-options.js +55 -0
  481. package/dist/session/config-options.js.map +1 -0
  482. package/dist/session/consumer.d.ts +1 -1
  483. package/dist/session/consumer.js +1 -1
  484. package/dist/session/consumer.js.map +1 -1
  485. package/dist/session/create-jazz-session.d.ts +55 -21
  486. package/dist/session/create-jazz-session.d.ts.map +1 -1
  487. package/dist/session/create-jazz-session.js +215 -166
  488. package/dist/session/create-jazz-session.js.map +1 -1
  489. package/dist/session/follow-user.d.ts +30 -11
  490. package/dist/session/follow-user.d.ts.map +1 -1
  491. package/dist/session/follow-user.js +49 -9
  492. package/dist/session/follow-user.js.map +1 -1
  493. package/dist/session/jazz-session.d.ts +182 -0
  494. package/dist/session/jazz-session.d.ts.map +1 -0
  495. package/dist/session/jazz-session.js +459 -0
  496. package/dist/session/jazz-session.js.map +1 -0
  497. package/dist/session/no-kept-device-account-error.d.ts +6 -0
  498. package/dist/session/no-kept-device-account-error.d.ts.map +1 -0
  499. package/dist/session/no-kept-device-account-error.js +8 -0
  500. package/dist/session/no-kept-device-account-error.js.map +1 -0
  501. package/dist/session/replica-ledger.d.ts +164 -0
  502. package/dist/session/replica-ledger.d.ts.map +1 -0
  503. package/dist/session/replica-ledger.js +450 -0
  504. package/dist/session/replica-ledger.js.map +1 -0
  505. package/dist/session/state.d.ts +50 -13
  506. package/dist/session/state.d.ts.map +1 -1
  507. package/dist/session/state.js +158 -29
  508. package/dist/session/state.js.map +1 -1
  509. package/dist/solid/index.d.ts +3 -9
  510. package/dist/solid/index.d.ts.map +1 -1
  511. package/dist/solid/index.js +8 -11
  512. package/dist/solid/index.ssr.js +3 -6
  513. package/dist/solid/provider.d.ts +3 -3
  514. package/dist/solid/provider.d.ts.map +1 -1
  515. package/dist/solid/provider.js +23 -39
  516. package/dist/solid/provider.js.map +1 -1
  517. package/dist/solid/provider.ssr.js +6 -23
  518. package/dist/solid/provider.ssr.js.map +1 -1
  519. package/dist/solid/session.d.ts +42 -12
  520. package/dist/solid/session.d.ts.map +1 -1
  521. package/dist/solid/session.js +82 -35
  522. package/dist/solid/session.js.map +1 -1
  523. package/dist/solid/session.ssr.js +86 -23
  524. package/dist/solid/session.ssr.js.map +1 -1
  525. package/dist/svelte/JazzProvider.svelte +54 -20
  526. package/dist/svelte/JazzProvider.svelte.d.ts +14 -4
  527. package/dist/svelte/JazzProvider.svelte.d.ts.map +1 -1
  528. package/dist/svelte/JazzSvelteClientProvider.svelte +1 -7
  529. package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts +0 -1
  530. package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts.map +1 -1
  531. package/dist/svelte/JazzSvelteProvider.svelte +5 -4
  532. package/dist/svelte/JazzSvelteProvider.svelte.d.ts +2 -2
  533. package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +1 -1
  534. package/dist/svelte/index.d.ts +4 -12
  535. package/dist/svelte/index.d.ts.map +1 -1
  536. package/dist/svelte/index.js +4 -8
  537. package/dist/svelte/session-state.d.ts +14 -4
  538. package/dist/svelte/session-state.d.ts.map +1 -1
  539. package/dist/svelte/session-state.js +10 -4
  540. package/dist/testing/client-migrations.d.ts +8 -1
  541. package/dist/testing/client-migrations.d.ts.map +1 -1
  542. package/dist/testing/client-migrations.js +11 -0
  543. package/dist/testing/client-migrations.js.map +1 -1
  544. package/dist/testing/policy-test-app.d.ts.map +1 -1
  545. package/dist/testing/policy-test-app.js +5 -4
  546. package/dist/testing/policy-test-app.js.map +1 -1
  547. package/dist/testing/test-jazz.d.ts +2 -2
  548. package/dist/testing/test-jazz.d.ts.map +1 -1
  549. package/dist/testing/test-jazz.js +6 -3
  550. package/dist/testing/test-jazz.js.map +1 -1
  551. package/dist/thin/index.d.ts +7 -10
  552. package/dist/thin/index.d.ts.map +1 -1
  553. package/dist/thin/index.js +28 -11
  554. package/dist/thin/index.js.map +1 -1
  555. package/dist/thin/thin-runtime.d.ts +53 -3
  556. package/dist/thin/thin-runtime.d.ts.map +1 -1
  557. package/dist/thin/thin-runtime.js +256 -33
  558. package/dist/thin/thin-runtime.js.map +1 -1
  559. package/dist/typed-app.d.ts +10 -4
  560. package/dist/typed-app.d.ts.map +1 -1
  561. package/dist/typed-app.js +44 -18
  562. package/dist/typed-app.js.map +1 -1
  563. package/dist/vue/index.d.ts +3 -8
  564. package/dist/vue/index.d.ts.map +1 -1
  565. package/dist/vue/index.js +3 -5
  566. package/dist/vue/index.js.map +1 -1
  567. package/dist/vue/provider.d.ts +6 -27
  568. package/dist/vue/provider.d.ts.map +1 -1
  569. package/dist/vue/provider.js +10 -19
  570. package/dist/vue/provider.js.map +1 -1
  571. package/dist/vue/session.d.ts +29 -28
  572. package/dist/vue/session.d.ts.map +1 -1
  573. package/dist/vue/session.js +80 -23
  574. package/dist/vue/session.js.map +1 -1
  575. package/dist/web/create-jazz-client.d.ts +5 -1
  576. package/dist/web/create-jazz-client.d.ts.map +1 -1
  577. package/dist/web/create-jazz-client.js +30 -3
  578. package/dist/web/create-jazz-client.js.map +1 -1
  579. package/dist/window-client-storage.d.ts +4 -30
  580. package/dist/window-client-storage.d.ts.map +1 -1
  581. package/dist/window-client-storage.js +2 -63
  582. package/dist/window-client-storage.js.map +1 -1
  583. package/dist/worker/jazz-broker-worker-core.d.ts.map +1 -1
  584. package/dist/worker/jazz-broker-worker-core.js +118 -20
  585. package/dist/worker/jazz-broker-worker-core.js.map +1 -1
  586. package/dist/worker/jazz-broker-worker.js +787 -608
  587. package/dist/worker/jazz_wasm_bg.wasm +0 -0
  588. package/dist/worker/runtime-admission.d.ts +19 -0
  589. package/dist/worker/runtime-admission.d.ts.map +1 -0
  590. package/dist/worker/runtime-admission.js +34 -0
  591. package/dist/worker/runtime-admission.js.map +1 -0
  592. package/dist/worker/vite-dev-broker.d.ts +2 -0
  593. package/dist/worker/vite-dev-broker.d.ts.map +1 -0
  594. package/dist/worker/vite-dev-broker.js +8 -0
  595. package/dist/worker/vite-dev-broker.js.map +1 -0
  596. package/package.json +30 -10
  597. package/dist/backend/session-recheck.d.ts +0 -18
  598. package/dist/backend/session-recheck.d.ts.map +0 -1
  599. package/dist/backend/session-recheck.js +0 -57
  600. package/dist/backend/session-recheck.js.map +0 -1
  601. package/dist/dev/inspector-overlay/embedded/assets/esm-k3rsq4Gn.js +0 -1
  602. package/dist/dev/inspector-overlay/embedded/assets/index-C-btvLcw.js +0 -20
  603. package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CAMcDeUa.js +0 -3
  604. package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-Cc71x_6y.js +0 -1
  605. package/dist/dev/inspector-overlay/serve.d.ts +0 -46
  606. package/dist/dev/inspector-overlay/serve.d.ts.map +0 -1
  607. package/dist/dev/inspector-overlay/serve.js +0 -131
  608. package/dist/dev/inspector-overlay/serve.js.map +0 -1
  609. package/dist/dev-tools/auto-attach.d.ts +0 -11
  610. package/dist/dev-tools/auto-attach.d.ts.map +0 -1
  611. package/dist/dev-tools/auto-attach.js +0 -26
  612. package/dist/dev-tools/auto-attach.js.map +0 -1
  613. package/dist/expo/auth-secret-store.d.ts +0 -37
  614. package/dist/expo/auth-secret-store.d.ts.map +0 -1
  615. package/dist/expo/auth-secret-store.js +0 -139
  616. package/dist/expo/auth-secret-store.js.map +0 -1
  617. package/dist/expo/session.d.ts +0 -10
  618. package/dist/expo/session.d.ts.map +0 -1
  619. package/dist/expo/session.js +0 -5
  620. package/dist/expo/session.js.map +0 -1
  621. package/dist/expo/use-local-first-auth.d.ts +0 -12
  622. package/dist/expo/use-local-first-auth.d.ts.map +0 -1
  623. package/dist/expo/use-local-first-auth.js +0 -13
  624. package/dist/expo/use-local-first-auth.js.map +0 -1
  625. package/dist/react/devtools-auto-attach.d.ts +0 -2
  626. package/dist/react/devtools-auto-attach.d.ts.map +0 -1
  627. package/dist/react/devtools-auto-attach.js +0 -11
  628. package/dist/react/devtools-auto-attach.js.map +0 -1
  629. package/dist/react/session.d.ts +0 -18
  630. package/dist/react/session.d.ts.map +0 -1
  631. package/dist/react/session.js +0 -28
  632. package/dist/react/session.js.map +0 -1
  633. package/dist/react/use-local-first-auth.d.ts +0 -11
  634. package/dist/react/use-local-first-auth.d.ts.map +0 -1
  635. package/dist/react/use-local-first-auth.js +0 -13
  636. package/dist/react/use-local-first-auth.js.map +0 -1
  637. package/dist/react-core/app.d.ts +0 -31
  638. package/dist/react-core/app.d.ts.map +0 -1
  639. package/dist/react-core/app.js +0 -65
  640. package/dist/react-core/app.js.map +0 -1
  641. package/dist/react-core/use-account-state.d.ts +0 -4
  642. package/dist/react-core/use-account-state.d.ts.map +0 -1
  643. package/dist/react-core/use-account-state.js +0 -6
  644. package/dist/react-core/use-account-state.js.map +0 -1
  645. package/dist/react-core/use-local-first-auth.d.ts +0 -12
  646. package/dist/react-core/use-local-first-auth.d.ts.map +0 -1
  647. package/dist/react-core/use-local-first-auth.js +0 -14
  648. package/dist/react-core/use-local-first-auth.js.map +0 -1
  649. package/dist/react-native/session.d.ts +0 -10
  650. package/dist/react-native/session.d.ts.map +0 -1
  651. package/dist/react-native/session.js +0 -5
  652. package/dist/react-native/session.js.map +0 -1
  653. package/dist/react-native/use-local-first-auth.d.ts +0 -15
  654. package/dist/react-native/use-local-first-auth.d.ts.map +0 -1
  655. package/dist/react-native/use-local-first-auth.js +0 -14
  656. package/dist/react-native/use-local-first-auth.js.map +0 -1
  657. package/dist/runtime/local-first-auth-controller.d.ts +0 -29
  658. package/dist/runtime/local-first-auth-controller.d.ts.map +0 -1
  659. package/dist/runtime/local-first-auth-controller.js +0 -101
  660. package/dist/runtime/local-first-auth-controller.js.map +0 -1
  661. package/dist/session/app.d.ts +0 -58
  662. package/dist/session/app.d.ts.map +0 -1
  663. package/dist/session/app.js +0 -325
  664. package/dist/session/app.js.map +0 -1
  665. package/dist/session/create-jazz-app.d.ts +0 -11
  666. package/dist/session/create-jazz-app.d.ts.map +0 -1
  667. package/dist/session/create-jazz-app.js +0 -11
  668. package/dist/session/create-jazz-app.js.map +0 -1
  669. package/dist/session/left-behind-replicas.d.ts +0 -62
  670. package/dist/session/left-behind-replicas.d.ts.map +0 -1
  671. package/dist/session/left-behind-replicas.js +0 -146
  672. package/dist/session/left-behind-replicas.js.map +0 -1
  673. package/dist/solid/app.d.ts +0 -30
  674. package/dist/solid/app.d.ts.map +0 -1
  675. package/dist/solid/app.js +0 -95
  676. package/dist/solid/app.js.map +0 -1
  677. package/dist/solid/app.ssr.js +0 -109
  678. package/dist/solid/app.ssr.js.map +0 -1
  679. package/dist/solid/create-account-state.d.ts +0 -4
  680. package/dist/solid/create-account-state.d.ts.map +0 -1
  681. package/dist/solid/create-account-state.js +0 -10
  682. package/dist/solid/create-account-state.js.map +0 -1
  683. package/dist/solid/create-account-state.ssr.js +0 -12
  684. package/dist/solid/create-account-state.ssr.js.map +0 -1
  685. package/dist/solid/use-local-first-auth.d.ts +0 -11
  686. package/dist/solid/use-local-first-auth.d.ts.map +0 -1
  687. package/dist/solid/use-local-first-auth.js +0 -30
  688. package/dist/solid/use-local-first-auth.js.map +0 -1
  689. package/dist/solid/use-local-first-auth.ssr.js +0 -31
  690. package/dist/solid/use-local-first-auth.ssr.js.map +0 -1
  691. package/dist/svelte/JazzSessionClientProvider.svelte +0 -42
  692. package/dist/svelte/JazzSessionClientProvider.svelte.d.ts +0 -13
  693. package/dist/svelte/JazzSessionClientProvider.svelte.d.ts.map +0 -1
  694. package/dist/svelte/JazzSessionProvider.svelte +0 -68
  695. package/dist/svelte/JazzSessionProvider.svelte.d.ts +0 -19
  696. package/dist/svelte/JazzSessionProvider.svelte.d.ts.map +0 -1
  697. package/dist/svelte/account-state.d.ts +0 -5
  698. package/dist/svelte/account-state.d.ts.map +0 -1
  699. package/dist/svelte/account-state.js +0 -9
  700. package/dist/svelte/auth-state.d.ts +0 -23
  701. package/dist/svelte/auth-state.d.ts.map +0 -1
  702. package/dist/svelte/auth-state.js +0 -16
  703. package/dist/svelte/local-first-auth.svelte.d.ts +0 -50
  704. package/dist/svelte/local-first-auth.svelte.d.ts.map +0 -1
  705. package/dist/svelte/local-first-auth.svelte.js +0 -58
  706. package/dist/vue/app.d.ts +0 -76
  707. package/dist/vue/app.d.ts.map +0 -1
  708. package/dist/vue/app.js +0 -100
  709. package/dist/vue/app.js.map +0 -1
  710. package/dist/vue/use-account-state.d.ts +0 -5
  711. package/dist/vue/use-account-state.d.ts.map +0 -1
  712. package/dist/vue/use-account-state.js +0 -10
  713. package/dist/vue/use-account-state.js.map +0 -1
  714. package/dist/vue/use-local-first-auth.d.ts +0 -53
  715. package/dist/vue/use-local-first-auth.d.ts.map +0 -1
  716. package/dist/vue/use-local-first-auth.js +0 -67
  717. package/dist/vue/use-local-first-auth.js.map +0 -1
  718. /package/dist/dev/inspector-overlay/embedded/assets/{esm-CH5eVyQQ.js → esm-xNe3wI_B.js} +0 -0
  719. /package/dist/dev/inspector-overlay/embedded/assets/{node-foreground-node-lease.browser-Bm3gYjlT.js → node-foreground-node-lease.browser-CH8w-D6S.js} +0 -0
@@ -1,36 +1,40 @@
1
1
  import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
2
2
  import { verifyChallenge } from "../local-first-auth/server.js";
3
+ import { serverSigningKey } from "./signing-key.js";
3
4
  import { mkdir, readFile, writeFile } from "node:fs/promises";
4
5
  import { join, resolve } from "node:path";
5
6
  import { JazzCore } from "jazz-napi";
6
7
  import { registerInProcessTransport } from "../runtime/in-process-transport.js";
7
8
  import { accountAppId, localFirstAccountId } from "../accounts/local-first.js";
9
+ import { AUTHENTICATE_EXPIRES_AT_MISSING } from "../accounts/registry-client.js";
8
10
  import { LOCAL_FIRST_JWT_ISSUER, parseJwtPayload } from "../runtime/client-session.js";
9
11
  import { verifyLocalFirstToken } from "../runtime/local-first-token.js";
10
12
  import { endpointScope } from "../runtime/client-scope.js";
11
13
  import { PostcardWriter } from "../runtime/native-runtime/native-codec.js";
12
- import { encodeWebSocketFrameBatch } from "../runtime/native-runtime/websocket.js";
14
+ import { decodeWebSocketFrameBatch, encodeWebSocketFrameBatch, REAUTHENTICATE_WIRE_MESSAGE_PREFIX, } from "../runtime/native-runtime/websocket.js";
15
+ import { SESSION_RENEWAL_HEADER, SESSION_RENEWAL_PRELUDE_FIELD, WIRE_FRAME_RENEW, decodeRenewFrame, encodeRenewSoonFrame, } from "../runtime/native-runtime/session-renewal-wire.js";
13
16
  import { STREAM_RECORD_MESSAGE, STREAM_RECORD_SESSION, StreamRecordReader, encodeStreamClose, encodeStreamRecord, } from "../runtime/native-runtime/http-stream-socket.js";
14
17
  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";
18
+ import { shipsNoMigrations } from "../runtime/client-migrations.js";
19
+ import { deployApp } from "../dev/catalogue.js";
21
20
  import { DeploymentError } from "../dev/catalogue-api.js";
22
21
  import { backendDbAttributedTo, backendDbForSession, openJazzSession, } from "./create-jazz-session.js";
23
22
  import { BackendClientsUnavailable, backendClientVerifier, } from "./backend-clients.js";
24
23
  import { BACKEND_USER_ISSUER } from "./backend-issuer.js";
25
24
  import { earlyDb } from "./early-db.js";
26
- import { defaultCoreName, onVercelDeployment, onVercelHost, openVercelCore, refuseVercelAppId, } from "./vercel-store.js";
25
+ import { checkNamespaceOption, coreName, onVercelDeployment, onVercelHost, openVercelCore, refuseVercelAppId, refuseVercelName, } from "./vercel-store.js";
26
+ import { logStoreOpened } from "./store-log.js";
27
+ export { perBranch } from "./vercel-store.js";
27
28
  import { files } from "./blobs.js";
29
+ import { createInspector, inspectorSettings, newTokenSecret, } from "./inspect.js";
30
+ import { createInspectorUi } from "./inspect-ui.js";
28
31
  export { files, s3, vercelBlob, } from "./blobs.js";
29
- import { isSameAdmission, recheckEvery } from "./session-recheck.js";
32
+ import { AuthenticateExpiresAtError, reauthenticateAt, sessionDeadline, startTimer, withCheckedExpiry, } from "./session-expiry.js";
30
33
  import { NoJazzAccountError } from "./no-account-error.js";
31
- import { RequestAuthenticationError } from "./request-auth.js";
34
+ import { isAuthenticationUnavailableError, RequestAuthenticationError } from "./request-auth.js";
32
35
  import { optionalPeerImportError } from "./optional-peer.js";
33
36
  import { closingBeforeDeadline } from "./socket-deadline.js";
37
+ import { importWs, vercelUpgradesSockets } from "./ws-peer.js";
34
38
  /**
35
39
  * A SQLite core in this process, kept in the directory `path`. It generates
36
40
  * its app id on first start and keeps it beside its data, in `<path>/app-id`
@@ -78,20 +82,28 @@ export function remote(options) {
78
82
  throw new Error("remote(): appId must name the app the core serves (it is empty)");
79
83
  }
80
84
  let backendCredential;
85
+ let secret;
81
86
  if ("backendCredential" in options) {
82
87
  backendCredential = options.backendCredential;
83
88
  }
84
89
  else {
85
- const secret = options.secret;
90
+ secret = options.secret;
86
91
  if (secret === undefined && "adminSecret" in options) {
87
92
  throw new Error("remote(): `adminSecret` and `backendSecret` were replaced by one `secret`, the app's admin secret");
88
93
  }
89
94
  if (typeof secret !== "string" || !secret.trim()) {
90
95
  throw new Error("remote(): secret must be the app's admin secret (it is empty)");
91
96
  }
92
- backendCredential = () => secret;
97
+ const given = secret;
98
+ backendCredential = () => given;
93
99
  }
94
- return { kind: "remote", url: options.url.replace(/\/+$/, ""), appId, backendCredential };
100
+ return {
101
+ kind: "remote",
102
+ url: options.url.replace(/\/+$/, ""),
103
+ appId,
104
+ backendCredential,
105
+ ...(secret === undefined ? {} : { secret }),
106
+ };
95
107
  }
96
108
  /**
97
109
  * The store for apps deployed on Vercel. Use it in dev too: outside a
@@ -99,8 +111,11 @@ export function remote(options) {
99
111
  * `local`, by default `sqlite({ path: ".jazz/local" })`.
100
112
  *
101
113
  * Deployed, it runs a core in a persistent Vercel Sandbox in your own Vercel
102
- * project, with its data on a Drive: one for production and one per Git
103
- * branch for previews.
114
+ * project, with its data on a Drive. `namespace` (required) says which: the
115
+ * Sandbox is `jazz-<project>-<namespace>`, e.g. one core per environment
116
+ * with `namespace: ({ environment }) => environment`, or production's core
117
+ * and one per preview branch with
118
+ * `namespace: ({ environment, branch }) => environment === "production" ? "production" : perBranch(branch)`.
104
119
  * It is created on first use, wakes when a request needs it (about a second)
105
120
  * and stops after `idleMs` without requests or sockets. The function's Vercel
106
121
  * OIDC token is its only credential, so there are no secrets and no env vars:
@@ -120,10 +135,12 @@ export function remote(options) {
120
135
  * back. Branch cores are not deleted when a branch merges yet: each keeps its
121
136
  * Sandbox and a Drive of up to `maxDriveBytes` until you remove them.
122
137
  */
123
- export function vercel(options = {}) {
138
+ export function vercel(options) {
124
139
  // Refused here, not on the first deployed request: in dev the local
125
- // store runs and would never read it.
126
- refuseVercelAppId(options);
140
+ // store runs and would never read them.
141
+ refuseVercelAppId(options ?? {});
142
+ refuseVercelName(options ?? {});
143
+ checkNamespaceOption(options ?? {});
127
144
  const { local, ...rest } = options;
128
145
  return { kind: "vercel", options: rest, local: local ?? sqlite({ path: ".jazz/local" }) };
129
146
  }
@@ -141,9 +158,52 @@ function blobOptions(blobs) {
141
158
  }
142
159
  return { blobs: "files", ...(blobs.dir === undefined ? {} : { blobsDir: blobs.dir }) };
143
160
  }
161
+ /**
162
+ * The marker's brand, registered globally like `createJazz`'s store registry:
163
+ * a bundler may load this module more than once (Next dev evaluates it per
164
+ * route), and a shared Jazz must still recognise a marker made by another copy.
165
+ */
166
+ const LOCAL_FIRST_GUEST_BRAND = Symbol.for("jazz-tools.acceptDeviceAccounts.guest");
144
167
  const LOCAL_FIRST_GUEST = Object.freeze({
168
+ [LOCAL_FIRST_GUEST_BRAND]: true,
145
169
  kind: "jazz:local-first-guest",
146
170
  });
171
+ /** Whether `answer` is {@link acceptDeviceAccounts}'s marker, from any copy of this module. */
172
+ function isLocalFirstGuest(answer) {
173
+ return (typeof answer === "object" &&
174
+ answer !== null &&
175
+ answer[LOCAL_FIRST_GUEST_BRAND] === true);
176
+ }
177
+ /**
178
+ * `authenticate`'s answer, checked: a user must have a string `userId`. Any
179
+ * other answer is a bug in the app's `authenticate`, said so here rather than
180
+ * as a failure from the core about a missing identity.
181
+ */
182
+ function checkedUser(answer) {
183
+ const userId = answer?.userId;
184
+ if (typeof answer === "object" && answer !== null && typeof userId === "string" && userId !== "")
185
+ return answer;
186
+ throw new TypeError(`createJazz: authenticate must return { userId: string, expiresAt: number }, acceptDeviceAccounts(request) or null; it returned ${describeAnswer(answer)}`);
187
+ }
188
+ /**
189
+ * `authenticate`'s answer for an error message: its shape, never its values,
190
+ * since a wrong answer may well be a token or a session.
191
+ */
192
+ function describeAnswer(answer) {
193
+ if (typeof answer !== "object" || answer === null)
194
+ return kindOf(answer);
195
+ const keys = Reflect.ownKeys(answer).map(String);
196
+ const detail = "userId" in answer ? `, userId: ${kindOf(answer.userId)}` : "";
197
+ return `an object with keys [${keys.join(", ")}]${detail}`;
198
+ }
199
+ function kindOf(value) {
200
+ if (value === null || value === undefined)
201
+ return String(value);
202
+ if (value === "")
203
+ return "an empty string";
204
+ const type = Array.isArray(value) ? "array" : typeof value;
205
+ return `${/^[aeiou]/.test(type) ? "an" : "a"} ${type}`;
206
+ }
147
207
  /** `request` without the credentials a browser sends with it (its cookies, an `Authorization` header). */
148
208
  function withoutCredentials(request) {
149
209
  const headers = new Headers(request.headers);
@@ -152,30 +212,42 @@ function withoutCredentials(request) {
152
212
  return new Request(request.url, { method: request.method, headers });
153
213
  }
154
214
  /**
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.
215
+ * Let this request through as a device account, when it comes from one: an
216
+ * account whose key lives on the user's device, with no user in your auth.
217
+ * It's how your app lets people in as guests, and a local-first friendly way
218
+ * to sign in at all. Device accounts are refused unless `authenticate`
219
+ * returns this, since only your permissions stand between them and your
220
+ * data.
158
221
  *
159
222
  * ```ts
160
223
  * authenticate: async (request) => {
161
224
  * const session = await auth.api.getSession({ headers: request.headers });
162
- * return session ? { userId: session.user.id } : acceptLocalFirstAuth(request);
225
+ * if (!session) return acceptDeviceAccounts(request);
226
+ * return {
227
+ * userId: session.user.id,
228
+ * expiresAt: Math.floor(session.session.expiresAt.getTime() / 1000),
229
+ * };
163
230
  * },
164
231
  * ```
165
232
  *
166
- * An app with no sign-in of its own, where every browser is a guest, passes
167
- * it as is: `authenticate: acceptLocalFirstAuth`.
233
+ * An app with no sign-in of its own, where every browser has a device
234
+ * account, passes it as is: `authenticate: acceptDeviceAccounts`.
235
+ *
236
+ * For a request that is not a device account's, it means the same as `null`:
237
+ * no one is signed in.
168
238
  *
169
- * For a request that is not a guest's, it means the same as `null`: no one
170
- * is signed in.
239
+ * A device account's request may also carry a user's cookie: someone signed
240
+ * in (or up) on that browser, and the device account still uploads its
241
+ * writes before it links to them. Jazz then asks `authenticate` about the
242
+ * request without its cookies and `Authorization` header, so the device
243
+ * account is let in as it would be on its own.
171
244
  *
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.
245
+ * This gates device accounts' sync only. Linking one to a user who signs up
246
+ * (`linkDeviceAccount()`) is authorised by your sign-in (`authenticate`
247
+ * naming that user) plus the device key's proof of a one-time challenge, so
248
+ * it works even when your app doesn't accept device accounts for sync.
177
249
  */
178
- export function acceptLocalFirstAuth(_request) {
250
+ export function acceptDeviceAccounts(_request) {
179
251
  return LOCAL_FIRST_GUEST;
180
252
  }
181
253
  const DEFAULT_BASE_PATH = "/jazz";
@@ -185,6 +257,11 @@ const DEFAULT_BASE_PATH = "/jazz";
185
257
  const PRELUDE_DEADLINE_MS = 30_000;
186
258
  /** On createJazz's 426 for a socket path: this endpoint serves the HTTP stream. */
187
259
  const STREAM_AVAILABLE_HEADER = "x-jazz-stream";
260
+ /** The answer for a socket path where this host can't upgrade sockets. */
261
+ const useHttpStream = () => new Response("WebSocket upgrade not available here; use the HTTP stream", {
262
+ status: 426,
263
+ headers: { [STREAM_AVAILABLE_HEADER]: "1" },
264
+ });
188
265
  /** The stream session's key, on each send and close (see `openStream`). */
189
266
  const STREAM_KEY_HEADER = "x-jazz-stream-key";
190
267
  const PUBLIC_APP_ROUTES = /^\/apps\/[^/]+\/(schemas|schema\/[^/]+)$/;
@@ -206,6 +283,27 @@ const ACCESS_HEADER = "x-jazz-backend-access";
206
283
  // What the secret slots carry to a remote core: the access stated next to
207
284
  // the backend credential decides what a request gets, not these.
208
285
  const STAND_IN_SECRET = "stated-by-backend-credential";
286
+ /**
287
+ * The app's secret, when this backend holds it: `remote()`'s `secret`, or
288
+ * an in-process core's own. A core reached with a backend credential holds
289
+ * only {@link STAND_IN_SECRET}, which is no secret.
290
+ */
291
+ function appSecretOf(store, core) {
292
+ if (store.kind === "remote" && store.secret)
293
+ return store.secret;
294
+ return core.adminSecret === STAND_IN_SECRET ? undefined : core.adminSecret;
295
+ }
296
+ /**
297
+ * The refusal of every local-first identity by a core that admits none: one
298
+ * an older jazz-tools started with local-first auth off (cores have no such
299
+ * switch since 2.0.0-alpha.62), or a Jazz Cloud app's with it turned off.
300
+ */
301
+ const LOCAL_FIRST_AUTH_DISABLED = "local_first_auth_disabled";
302
+ /**
303
+ * What such a core tells a guest's session (jazz-server's
304
+ * `LOCAL_FIRST_AUTH_DISABLED_MESSAGE` before 2.0.0-alpha.62).
305
+ */
306
+ const CORE_REFUSES_GUESTS = "Local-first auth is not enabled";
209
307
  // What a browser's request to a public route carries on to a remote core:
210
308
  // never its cookies or its app session.
211
309
  const REMOTE_FORWARDED_HEADERS = ["accept", "content-type", "if-none-match"];
@@ -216,6 +314,10 @@ const MAX_STREAM_MESSAGE_BYTES = 2 * 1024 * 1024;
216
314
  * client ignored flow control and its session ends.
217
315
  */
218
316
  const MAX_WAITING_SESSION_BYTES = 32 * 1024 * 1024;
317
+ /** What `inspector` is when createJazz isn't given one: one object, so the Inspector reads it once. */
318
+ const NO_INSPECTOR_OPTIONS = Object.freeze({});
319
+ /** The peer address of requests that came through a Node handler, where Jazz can know it. */
320
+ const remoteAddresses = new WeakMap();
219
321
  function headerPairs(headers) {
220
322
  const pairs = [];
221
323
  headers.forEach((value, name) => {
@@ -267,10 +369,22 @@ function inProcessWebSocket(open) {
267
369
  this.finish(1011, error instanceof Error ? error.message : String(error));
268
370
  return;
269
371
  }
270
- this.readyState = 1;
271
- this.emit("open");
372
+ // Open only once the core's side is: a session that never reaches
373
+ // the core then closes without having opened, which a client (and
374
+ // the vercel() store's waking socket) can tell from a session that
375
+ // dropped.
376
+ const opened = this.session.opened;
377
+ if (!opened)
378
+ return this.markOpen();
379
+ void opened.then(() => this.markOpen());
272
380
  });
273
381
  }
382
+ markOpen() {
383
+ if (this.readyState !== 0)
384
+ return;
385
+ this.readyState = 1;
386
+ this.emit("open");
387
+ }
274
388
  addEventListener(type, listener) {
275
389
  const list = this.listeners.get(type) ?? [];
276
390
  list.push(listener);
@@ -340,31 +454,16 @@ function inProcessWebSocket(open) {
340
454
  }
341
455
  /** The app's schema versions, migrations and permissions, as its code declares them. */
342
456
  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
457
  // Published, never activated: this backend's sessions are pinned to its
357
458
  // bundle, so deployments of the app serve side by side and a rollback is
358
459
  // 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
- })),
460
+ const deployed = await deployApp({
461
+ appId: options.appId,
462
+ serverUrl: origin,
463
+ adminSecret: options.adminSecret,
464
+ app: options.app,
367
465
  permissions: options.permissions,
466
+ allowDroppingHistory: options.allowDroppingHistory,
368
467
  }).catch((error) => {
369
468
  // A core without `/bundles` predates per-deployment permissions; it
370
469
  // must not be handed a deployment it would activate for every backend.
@@ -409,6 +508,7 @@ export function pinnedSocket(socket, bundle) {
409
508
  return socket.sendWithRoom ? socket.sendWithRoom(pinned) : socket.send(pinned);
410
509
  },
411
510
  close: () => socket.close(),
511
+ ...(socket.opened ? { opened: socket.opened } : {}),
412
512
  };
413
513
  }
414
514
  /**
@@ -504,6 +604,33 @@ async function keptAppId(dir) {
504
604
  }
505
605
  return appId;
506
606
  }
607
+ /**
608
+ * The secret an in-process SQLite core's agent tokens are signed with, kept
609
+ * beside its data in `<path>/inspect-token-secret` (mode 0600) so tokens
610
+ * survive restarts. Deleting the file revokes every token.
611
+ */
612
+ async function keptTokenSecret(dir) {
613
+ const file = join(dir, "inspect-token-secret");
614
+ try {
615
+ const kept = (await readFile(file, "utf8")).trim();
616
+ if (kept)
617
+ return kept;
618
+ }
619
+ catch (error) {
620
+ if (error.code !== "ENOENT")
621
+ throw error;
622
+ }
623
+ const secret = newTokenSecret();
624
+ try {
625
+ await writeFile(file, `${secret}\n`, { flag: "wx", mode: 0o600 });
626
+ return secret;
627
+ }
628
+ catch (error) {
629
+ if (error.code !== "EEXIST")
630
+ throw error;
631
+ return (await readFile(file, "utf8")).trim();
632
+ }
633
+ }
507
634
  /**
508
635
  * Serverless functions have no disk that outlives an instance (or none
509
636
  * writable at all), so a sqlite store there loses data silently.
@@ -594,6 +721,10 @@ function openRemoteCore(appId, target, bundle) {
594
721
  let ws;
595
722
  const queued = [];
596
723
  let ended = false;
724
+ let markOpened;
725
+ const opened = new Promise((resolve) => {
726
+ markOpened = resolve;
727
+ });
597
728
  const finish = (code, reason) => {
598
729
  if (ended)
599
730
  return;
@@ -609,6 +740,8 @@ function openRemoteCore(appId, target, bundle) {
609
740
  ws.addEventListener("open", () => {
610
741
  for (const data of queued.splice(0))
611
742
  ws.send(data);
743
+ if (!ended)
744
+ markOpened();
612
745
  });
613
746
  ws.addEventListener("message", (event) => {
614
747
  const data = typeof event.data === "string"
@@ -646,6 +779,7 @@ function openRemoteCore(appId, target, bundle) {
646
779
  ended = true;
647
780
  ws?.close();
648
781
  },
782
+ opened,
649
783
  };
650
784
  }
651
785
  // This process's own clients (the backend's session) reach the core
@@ -677,6 +811,8 @@ function signedOut(operation) {
677
811
  /** How long `close()` waits for pending writes to reach the core. */
678
812
  const CLOSE_SYNC_TIMEOUT_MS = 10_000;
679
813
  function jazzSettings(options) {
814
+ if (options.recheckSeconds !== undefined)
815
+ 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
816
  const basePath = (options.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
681
817
  const publicUrls = [options.publicUrl ?? []].flat().map((value) => {
682
818
  try {
@@ -713,6 +849,14 @@ function jazzSettings(options) {
713
849
  function runningStore(store) {
714
850
  return store.kind === "vercel" && !onVercelDeployment() ? store.local : store;
715
851
  }
852
+ /** The line a store logs when it opens (a `vercel()` core logs its own). */
853
+ function storeOpenedLine(store) {
854
+ if (store.kind === "sqlite")
855
+ return `jazz: store sqlite at ${store.path}`;
856
+ if (store.kind === "memory")
857
+ return "jazz: store memory (its data lasts as long as this process)";
858
+ return `jazz: store remote at ${store.url} (app ${store.appId})`;
859
+ }
716
860
  /**
717
861
  * Open `store` and apply the schema, migrations and permissions `options`
718
862
  * declare to its core.
@@ -733,8 +877,13 @@ async function openJazz(initial, store) {
733
877
  openRemote: ({ appId, url, backendCredential }) => openRemoteCore(appId, { url, backendCredential }, bundle),
734
878
  })
735
879
  : await openInProcessCore(store, bundle);
880
+ // A vercel() core says which it opened itself.
881
+ if (store.kind !== "vercel")
882
+ logStoreOpened(storeOpenedLine(store));
736
883
  const appId = core.appId;
737
884
  const issuer = BACKEND_USER_ISSUER;
885
+ // An in-memory store's agent tokens last as long as its data: this process.
886
+ const memoryTokenSecret = newTokenSecret();
738
887
  /** Publish `next`'s bundle: what it is pinned by. Publishing one already published changes nothing. */
739
888
  const publish = (next) => applyBundle(core.serverUrl, { ...next, appId, adminSecret: core.adminSecret });
740
889
  /** Publish `next`'s bundle and open the backend's own session on it. */
@@ -773,6 +922,7 @@ async function openJazz(initial, store) {
773
922
  */
774
923
  async function reload(next) {
775
924
  const settings = jazzSettings(next);
925
+ inspectorSettings(next.inspector ?? NO_INSPECTOR_OPTIONS);
776
926
  // The same app and permissions (a reload of a module that imports them
777
927
  // unchanged, or a hot reload that rebuilt equal ones): the bundle, and
778
928
  // the backend's session with its writes and `forReqUser` dbs, stay.
@@ -817,6 +967,22 @@ async function openJazz(initial, store) {
817
967
  timer.unref?.();
818
968
  retiring.add(closeOld);
819
969
  }
970
+ // An `authenticate` that returns expired answers, or none at all, is a
971
+ // bug in the app: said once per process.
972
+ let warnedExpiredAnswer = false;
973
+ function warnExpiredAnswer() {
974
+ if (warnedExpiredAnswer)
975
+ return;
976
+ warnedExpiredAnswer = true;
977
+ 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.");
978
+ }
979
+ let warnedMissingExpiry = false;
980
+ function warnMissingExpiry(error) {
981
+ if (warnedMissingExpiry)
982
+ return;
983
+ warnedMissingExpiry = true;
984
+ console.error(error.message);
985
+ }
820
986
  /**
821
987
  * Who sent `request`: a scoped backend client's user, or the user the
822
988
  * app's own `authenticate` names. A trusted backend client has no user.
@@ -824,34 +990,64 @@ async function openJazz(initial, store) {
824
990
  async function authenticate(request) {
825
991
  const client = await backendClients.resolve(request);
826
992
  if (client !== null)
827
- return client !== "refused" && client.kind === "user" ? client.user : null;
993
+ return client !== "refused" && client.kind === "user"
994
+ ? { ...client.user, expiresAt: client.expiresAt }
995
+ : null;
828
996
  const answer = await askAuthenticate(request);
829
- return answer === LOCAL_FIRST_GUEST ? null : answer;
997
+ if (answer === null || isLocalFirstGuest(answer))
998
+ return null;
999
+ const user = withCheckedExpiry(checkedUser(answer));
1000
+ // An answer that has already expired names no one, here and in every
1001
+ // other place that asks (who is signed in, sign-in, forReqUser), so a
1002
+ // client can't be told it is signed in while its sync is refused.
1003
+ if (user.expiresAt * 1000 <= Date.now()) {
1004
+ warnExpiredAnswer();
1005
+ return null;
1006
+ }
1007
+ return user;
830
1008
  }
831
1009
  async function askAuthenticate(request) {
832
1010
  if (!options.authenticate)
833
1011
  return null;
834
- return (await options.authenticate(request)) ?? null;
1012
+ try {
1013
+ return (await options.authenticate(request)) ?? null;
1014
+ }
1015
+ catch (error) {
1016
+ // The app's own code failed (a missing auth secret, its session store
1017
+ // down). Its own API calls (forReqUser) get the error as it is; a Jazz
1018
+ // route answers 500 and logs it, rather than reject (see `handle`).
1019
+ const thrown = isObject(error) ? error : new Error(String(error));
1020
+ thrownByAuthenticate.add(thrown);
1021
+ throw thrown;
1022
+ }
835
1023
  }
836
- /** Whether the app lets `request` in as a local-first guest (`acceptLocalFirstAuth`). */
1024
+ /** Whether the app lets `request` in as a device account (`acceptDeviceAccounts`). */
837
1025
  let warnedGuestsOff = false;
838
1026
  async function acceptsGuest(request) {
839
1027
  const answer = await askAuthenticate(request);
840
- if (answer === LOCAL_FIRST_GUEST)
1028
+ if (isLocalFirstGuest(answer))
841
1029
  return true;
842
1030
  // A user is signed in on this browser too: one who just signed up, whose
843
1031
  // guest still uploads its writes before it links to them. A guest is
844
1032
  // bound to its own key, never to that user, and whether the app lets
845
1033
  // guests in doesn't depend on who else is signed in: ask as the request
846
1034
  // would be without the user's credentials.
847
- if (answer && (await askAuthenticate(withoutCredentials(request))) === LOCAL_FIRST_GUEST)
1035
+ if (answer && isLocalFirstGuest(await askAuthenticate(withoutCredentials(request))))
848
1036
  return true;
849
1037
  if (!warnedGuestsOff) {
850
1038
  warnedGuestsOff = true;
851
- console.warn("createJazz: refused a local-first guest. To let guests sync, return acceptLocalFirstAuth(request) from authenticate for them.");
1039
+ console.warn("createJazz: refused a local-first guest. To let guests sync, return acceptDeviceAccounts(request) from authenticate for them.");
852
1040
  }
853
1041
  return false;
854
1042
  }
1043
+ /** Say once that the core turns every local-first guest away, whatever `authenticate` says. */
1044
+ let warnedGuestsOffOnCore = false;
1045
+ function warnGuestsOffOnCore() {
1046
+ if (warnedGuestsOffOnCore)
1047
+ return;
1048
+ warnedGuestsOffOnCore = true;
1049
+ console.error("createJazz: the core refuses local-first guests (local_first_auth_disabled), so device accounts can't sync or link. It runs an older jazz-tools with local-first auth off: upgrade it (a vercel() core is restarted on the newer version by the next deployment), or turn it on for a Jazz Cloud app with `jazz-tools apps auth set <appId> --allow-local-first-auth true`.");
1050
+ }
855
1051
  /** One admin account request to the core: this backend vouches for the identities. */
856
1052
  async function adminAccounts(operation, body) {
857
1053
  const response = await core.handle("POST", `/apps/${encodeURIComponent(accountAppId(appId))}/admin/accounts/${operation}`, [
@@ -959,14 +1155,19 @@ async function openJazz(initial, store) {
959
1155
  * `authenticate` names, and whether the core already holds an account for
960
1156
  * them. A browser's session asks this to follow the backend; only a sign-in
961
1157
  * (`backend-sign-in`) or a link (`backend-link`) assigns an account, so a
962
- * local-first guest whose user has none yet can still link to them.
1158
+ * local-first guest whose user has none yet can still link to them. No one
1159
+ * signed in answers 200 `{ user: null }`, not 401.
963
1160
  */
964
1161
  async function backendUser(request) {
965
1162
  if (request.method !== "POST")
966
1163
  return new Response(null, { status: 405 });
967
1164
  const user = await authenticate(request);
1165
+ // No one signed in is an answer, not a refused request: 200, so a
1166
+ // signed-out page load logs no red 4xx in devtools. The body has no
1167
+ // `identity`, which every client (alpha.60 on) reads as signed out.
1168
+ // Clients still read a 401 as signed out too, for older backends.
968
1169
  if (!user)
969
- return new Response("signed_out", { status: 401 });
1170
+ return Response.json({ user: null }, { headers: { "Cache-Control": "no-store" } });
970
1171
  let account;
971
1172
  try {
972
1173
  account = await existingAccountOf(user.userId);
@@ -978,19 +1179,103 @@ async function openJazz(initial, store) {
978
1179
  return new Response("identity_not_authorized", { status: 403 });
979
1180
  throw error;
980
1181
  }
981
- return Response.json({ account, identity: identity(user.userId), claims: user.claims ?? {} }, { headers: { "Cache-Control": "no-store" } });
1182
+ // A browser renewing its open sync session in place (see
1183
+ // `session-renewal-wire.ts`) gets a ticket for it, on this answer.
1184
+ const renewing = request.headers.get(SESSION_RENEWAL_HEADER);
1185
+ const renewal = renewing && renewing.length <= 128 ? issueRenewalTicket(user, renewing) : undefined;
1186
+ return Response.json({
1187
+ account,
1188
+ identity: identity(user.userId),
1189
+ claims: user.claims ?? {},
1190
+ ...(renewal ? { renewal } : {}),
1191
+ }, { headers: { "Cache-Control": "no-store" } });
1192
+ }
1193
+ /**
1194
+ * Renewal tickets: what lets a sync session be extended over its open
1195
+ * socket. The browser's ordinary request (which carried its cookies, maybe
1196
+ * refreshed by `refresh`) may reach another instance than the one holding
1197
+ * the socket, so the answer travels back through the browser, signed with
1198
+ * a key every instance of this app derives from the core's admin secret
1199
+ * (or, without one, a key of this instance's own: see below).
1200
+ * A ticket names the user, the one session it renews, the claims it was
1201
+ * issued with and the new expiry, and is good for a minute.
1202
+ */
1203
+ // A core reached with a backend credential (`vercel()`, `remote()`) holds
1204
+ // only a public stand-in secret here; `remote()`'s own `secret`, when
1205
+ // given, is the app's. Without either, each
1206
+ // instance signs with a key of its own, and a ticket renews only a socket
1207
+ // the instance that issued it holds. Elsewhere, the session reconnects at
1208
+ // its expiry, as without renewal.
1209
+ const appSecret = store.kind === "remote" && store.secret
1210
+ ? store.secret
1211
+ : core.adminSecret !== STAND_IN_SECRET
1212
+ ? core.adminSecret
1213
+ : undefined;
1214
+ const renewalKey = appSecret === undefined
1215
+ ? randomBytes(32)
1216
+ : createHmac("sha256", appSecret)
1217
+ .update(`jazz-session-renewal-v1\0${accountAppId(appId)}`)
1218
+ .digest();
1219
+ const RENEWAL_TICKET_TTL_SECONDS = 60;
1220
+ const renewalMac = (payload) => createHmac("sha256", renewalKey).update(payload).digest("base64url");
1221
+ const claimsDigest = (claims) => createHmac("sha256", renewalKey)
1222
+ .update(stableJson(claims ?? {}))
1223
+ .digest("base64url");
1224
+ function issueRenewalTicket(user, session) {
1225
+ const payload = Buffer.from(JSON.stringify({
1226
+ v: 1,
1227
+ sub: user.userId,
1228
+ ses: session,
1229
+ cl: claimsDigest(user.claims),
1230
+ until: user.expiresAt,
1231
+ exp: Math.floor(Date.now() / 1000) + RENEWAL_TICKET_TTL_SECONDS,
1232
+ })).toString("base64url");
1233
+ return `${payload}.${renewalMac(payload)}`;
1234
+ }
1235
+ /**
1236
+ * The new expiry (Unix seconds) a ticket gives session `session` of
1237
+ * `userId` admitted with `claims`, when this backend issued it for that
1238
+ * session and it is still fresh; else null.
1239
+ */
1240
+ function readRenewalTicket(ticket, session, userId, claims) {
1241
+ const [payload, mac, extra] = ticket.split(".");
1242
+ if (!payload || !mac || extra !== undefined)
1243
+ return null;
1244
+ const expected = Buffer.from(renewalMac(payload));
1245
+ const given = Buffer.from(mac);
1246
+ if (expected.length !== given.length || !timingSafeEqual(expected, given))
1247
+ return null;
1248
+ let read;
1249
+ try {
1250
+ read = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
1251
+ }
1252
+ catch {
1253
+ return null;
1254
+ }
1255
+ const now = Date.now() / 1000;
1256
+ if (read.v !== 1 ||
1257
+ read.sub !== userId ||
1258
+ read.ses !== session ||
1259
+ read.cl !== claimsDigest(claims) ||
1260
+ typeof read.exp !== "number" ||
1261
+ read.exp <= now ||
1262
+ typeof read.until !== "number" ||
1263
+ !Number.isFinite(read.until) ||
1264
+ read.until <= now) {
1265
+ return null;
1266
+ }
1267
+ return read.until;
982
1268
  }
983
1269
  /**
984
1270
  * Link challenges: a guest links only on a proof made for one challenge,
985
1271
  * never on its sync token, so a leaked token can't link it to someone
986
1272
  * else. A challenge names the user it links to and expires quickly; it is
987
- * signed with a key only this app's backend instances share (derived from
988
- * the core's admin secret), and its nonce becomes the link's single-use
989
- * intent id at the core, so a proof works once.
1273
+ * signed with a key only this app's backend holds (derived from the app's
1274
+ * secret, or, where the store has none, this instance's own: see
1275
+ * `serverSigningKey`), and its nonce becomes the link's single-use intent
1276
+ * id at the core, so a proof works once.
990
1277
  */
991
- const challengeKey = createHmac("sha256", core.adminSecret)
992
- .update(`jazz-link-challenge-v1\0${accountAppId(appId)}`)
993
- .digest();
1278
+ const challengeKey = serverSigningKey("jazz-link-challenge-v1", accountAppId(appId), appSecretOf(store, core));
994
1279
  const LINK_CHALLENGE_TTL_SECONDS = 120;
995
1280
  const challengeMac = (payload) => createHmac("sha256", challengeKey).update(payload).digest("base64url");
996
1281
  function issueLinkChallenge(userId) {
@@ -1085,7 +1370,9 @@ async function openJazz(initial, store) {
1085
1370
  catch (error) {
1086
1371
  // A guest key an earlier link retired: only that link's own user
1087
1372
  // gets an answer (the retry of a link whose response was lost).
1088
- if (error.status !== 403 || !(await userIs(account)))
1373
+ if (error.status !== 403 ||
1374
+ error.code === LOCAL_FIRST_AUTH_DISABLED ||
1375
+ !(await userIs(account)))
1089
1376
  throw error;
1090
1377
  guestRevoked = true;
1091
1378
  }
@@ -1111,6 +1398,14 @@ async function openJazz(initial, store) {
1111
1398
  }
1112
1399
  catch (error) {
1113
1400
  const status = error.status;
1401
+ // A core that admits no local-first accounts refuses every guest, not
1402
+ // this user's link: say that, not that the user has another account.
1403
+ if (error.code === LOCAL_FIRST_AUTH_DISABLED) {
1404
+ warnGuestsOffOnCore();
1405
+ // A setup problem on the backend's side, not a refusal of this link:
1406
+ // 503, so the client tries again later.
1407
+ return new Response(LOCAL_FIRST_AUTH_DISABLED, { status: 503 });
1408
+ }
1114
1409
  // Only the core's own refusals refuse the link for good: an invalid
1115
1410
  // link intent (400), a retired or foreign identity (403), a user with
1116
1411
  // no account to check (404), an identity of another account (409).
@@ -1139,7 +1434,9 @@ async function openJazz(initial, store) {
1139
1434
  const expiresAt = Math.floor(Date.now() / 1000) + (options.sessionTtlSeconds ?? 3600);
1140
1435
  return Response.json({ account, identity: identity(user.userId), claims: user.claims ?? {}, expiresAt }, { headers: { "Cache-Control": "no-store" } });
1141
1436
  }
1142
- function openClientSession(request, onEvent) {
1437
+ /** The sessions this instance serves, for the Inspector's `sessions`. */
1438
+ const liveSessions = new Set();
1439
+ function openClientSession(request, onEvent, transport) {
1143
1440
  // The core socket opens once the prelude is admitted, with the access
1144
1441
  // that admission needs: a vouched user's session is the backend's, and
1145
1442
  // so is the endpoint it vouches for on a guest's behalf; a guest signed
@@ -1148,32 +1445,101 @@ async function openJazz(initial, store) {
1148
1445
  let ended = false;
1149
1446
  let userId;
1150
1447
  let trusted = false;
1151
- let recheck;
1448
+ // Users `revokeUser` named while this session's admission ran.
1449
+ let admitting = true;
1450
+ const revokedWhileAdmitting = new Set();
1152
1451
  // A session that never sends its prelude ends too.
1153
- let expiry = setTimeout(() => {
1452
+ let stopExpiry = startTimer(() => {
1154
1453
  onEvent(null, { kind: "close", code: 1008, reason: "no sign-in in time" });
1155
1454
  end();
1156
1455
  }, PRELUDE_DEADLINE_MS);
1157
- expiry.unref?.();
1158
1456
  const end = () => {
1159
1457
  if (ended)
1160
1458
  return;
1161
1459
  ended = true;
1162
- if (expiry)
1163
- clearTimeout(expiry);
1164
- recheck?.();
1460
+ liveSessions.delete(live);
1461
+ stopExpiry?.();
1165
1462
  socket?.close();
1166
1463
  };
1464
+ // A signed-in browser's session renewed in place (see
1465
+ // `session-renewal-wire.ts`): the id its tickets name, and the claims
1466
+ // it was admitted with, which a ticket must match.
1467
+ let renewal;
1468
+ // Tell the client when to renew: well before the session must end, so
1469
+ // a background tab's throttled timer still makes it.
1470
+ const tellRenewal = (at) => {
1471
+ if (!renewal || ended)
1472
+ return;
1473
+ renewal.told = true;
1474
+ const left = at - Date.now();
1475
+ // Too close to the expiry to renew: the session reconnects then.
1476
+ if (left < MIN_RENEWAL_NOTICE_MS)
1477
+ return;
1478
+ onEvent(null, {
1479
+ kind: "message",
1480
+ data: Buffer.from(encodeWebSocketFrameBatch([
1481
+ encodeRenewSoonFrame(renewal.session, Math.max(left - RENEWAL_LEAD_MS, left / 2)),
1482
+ ])),
1483
+ });
1484
+ };
1485
+ let renewalAt = 0;
1486
+ // A ticket the client brings back over the socket: extend the session to
1487
+ // the expiry `authenticate` gave on the client's renewal request. A
1488
+ // ticket that doesn't hold changes nothing, and the session ends at its
1489
+ // expiry as before.
1490
+ const renew = (ticket) => {
1491
+ if (!renewal || !userId || ended)
1492
+ return;
1493
+ const until = readRenewalTicket(ticket, renewal.session, userId, renewal.claims);
1494
+ if (until === null)
1495
+ return;
1496
+ const now = Date.now();
1497
+ const at = reauthenticateAt(now, sessionDeadline(now, until, options.sessionTtlSeconds));
1498
+ if (at === null)
1499
+ return;
1500
+ if (at <= renewalAt) {
1501
+ // Renewed, but no later than before (the app's `refresh` keeps a
1502
+ // token until it nearly expires): ask again, closer to the expiry.
1503
+ tellRenewal(renewalAt);
1504
+ return;
1505
+ }
1506
+ renewalAt = at;
1507
+ stopExpiry?.();
1508
+ stopExpiry = startTimer(reauthenticate, at - now);
1509
+ tellRenewal(at);
1510
+ };
1511
+ // Ask the client to connect again, so the app's auth decides on a new
1512
+ // request: a planned reconnect the client doesn't show as an outage.
1513
+ const reauthenticate = () => {
1514
+ if (ended)
1515
+ return;
1516
+ onEvent(null, { kind: "message", data: reauthenticateBatch() });
1517
+ onEvent(null, { kind: "close", code: 1008, reason: "reauthenticate" });
1518
+ end();
1519
+ };
1167
1520
  const admit = async (prelude) => {
1168
- const admitted = await admitPrelude(request, prelude);
1169
- if (!admitted || ended) {
1521
+ const admitted = await admitPrelude(request, prelude).finally(() => (admitting = false));
1522
+ if (admitted &&
1523
+ admitted !== UNVERIFIED_CREDENTIAL &&
1524
+ admitted.userId !== undefined &&
1525
+ revokedWhileAdmitting.has(admitted.userId) &&
1526
+ !ended) {
1527
+ // Admitted on an answer `authenticate` gave before the app revoked
1528
+ // this user: refused as the sessions `revokeUser` ended are.
1529
+ clientSession.revoke("revokeUser");
1530
+ return false;
1531
+ }
1532
+ if (!admitted || admitted === UNVERIFIED_CREDENTIAL || ended) {
1170
1533
  // An auth failure, not a dropped link: the client stops retrying and
1171
1534
  // reports `offline: auth`, and its session asks the backend whether
1172
- // anyone is still signed in.
1535
+ // anyone is still signed in. A credential that was sent and not
1536
+ // accepted is `invalid` to the client; none at all is `missing`.
1173
1537
  if (!ended)
1174
1538
  onEvent(null, {
1175
1539
  kind: "message",
1176
- data: authFailedBatch("session missing: not signed in"),
1540
+ data: authFailedBatch(admitted === UNVERIFIED_CREDENTIAL
1541
+ ? "session invalid: this backend did not accept the credential the client sent"
1542
+ : "session missing: not signed in"),
1177
1543
  });
1178
1544
  onEvent(null, { kind: "close", code: 1008, reason: "not signed in" });
1179
1545
  end();
@@ -1181,34 +1547,60 @@ async function openJazz(initial, store) {
1181
1547
  }
1182
1548
  userId = admitted.userId;
1183
1549
  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);
1550
+ stopExpiry?.();
1551
+ const admittedAt = Date.now();
1552
+ if (admitted.user) {
1553
+ // A signed-in user's session holds until the expiry `authenticate`
1554
+ // gave it, and at most `sessionTtlSeconds`. Shortly before, the
1555
+ // client is asked to connect again, so `authenticate` decides on its
1556
+ // new request with current cookies.
1557
+ const at = reauthenticateAt(admittedAt, sessionDeadline(admittedAt, admitted.user.expiresAt, options.sessionTtlSeconds));
1558
+ if (at === null) {
1559
+ // `authenticate` named the user with an answer already expired.
1560
+ warnExpiredAnswer();
1561
+ onEvent(null, {
1562
+ kind: "message",
1563
+ data: authFailedBatch("session expired: authenticate returned an expiresAt in the past"),
1564
+ });
1565
+ onEvent(null, { kind: "close", code: 1008, reason: "session expired" });
1566
+ end();
1567
+ return false;
1568
+ }
1569
+ stopExpiry = startTimer(reauthenticate, at - admittedAt);
1570
+ renewalAt = at;
1571
+ // Told once the core's hello reached the client, which takes no
1572
+ // other frame before it.
1573
+ if (admitted.renewal)
1574
+ renewal = { session: randomUUID(), claims: admitted.user.claims, told: false };
1575
+ }
1576
+ else if (admitted.guest) {
1577
+ // A guest's key is its credential; the app lets it in anew each
1578
+ // `sessionTtlSeconds`, the same way.
1579
+ const ttl = (options.sessionTtlSeconds ?? 3600) * 1000;
1580
+ stopExpiry = startTimer(reauthenticate, ttl);
1206
1581
  }
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);
1582
+ else {
1583
+ // A backend client's session ends with its token, so it reconnects
1584
+ // with a fresh one.
1585
+ const ttl = Math.min((options.sessionTtlSeconds ?? 3600) * 1000, admitted.expiresAt === undefined ? Infinity : admitted.expiresAt * 1000 - admittedAt);
1586
+ stopExpiry = startTimer(end, ttl);
1210
1587
  }
1211
- socket = core.openSocket(headerPairs(request.headers), onEvent, admitted.access);
1588
+ // A guest's session the core refuses because it admits no device
1589
+ // accounts at all: the client only goes offline, so say why here.
1590
+ // The core refuses in its first message, so only that one is looked at.
1591
+ let firstFromCore = admitted.guest === true;
1592
+ const relay = (error, event) => {
1593
+ if (firstFromCore && event.kind === "message" && event.data) {
1594
+ firstFromCore = false;
1595
+ const { buffer, byteOffset, byteLength } = event.data;
1596
+ if (Buffer.from(buffer, byteOffset, byteLength).includes(CORE_REFUSES_GUESTS))
1597
+ warnGuestsOffOnCore();
1598
+ }
1599
+ onEvent(error, event);
1600
+ if (renewal && !renewal.told && event.kind === "message")
1601
+ tellRenewal(renewalAt);
1602
+ };
1603
+ socket = core.openSocket(headerPairs(request.headers), relay, admitted.access);
1212
1604
  return socket.send(admitted.prelude);
1213
1605
  };
1214
1606
  // Messages after the prelude wait for its admission, in order.
@@ -1220,6 +1612,14 @@ async function openJazz(initial, store) {
1220
1612
  const deliver = (data) => {
1221
1613
  if (ended)
1222
1614
  return Promise.resolve(false);
1615
+ // A renewal ticket is for this backend, never for the core.
1616
+ if (renewal && chain) {
1617
+ const ticket = renewalTicketIn(data);
1618
+ if (ticket !== null) {
1619
+ renew(ticket);
1620
+ return Promise.resolve(true);
1621
+ }
1622
+ }
1223
1623
  if (waitingBytes + data.byteLength > MAX_WAITING_SESSION_BYTES) {
1224
1624
  // 1013 (try again later): the client may come back and send at the
1225
1625
  // pace this host takes.
@@ -1264,7 +1664,16 @@ async function openJazz(initial, store) {
1264
1664
  }
1265
1665
  else {
1266
1666
  // The core is unreachable or failed (5xx), or the app's own
1267
- // `authenticate` threw: the client tries again later.
1667
+ // `authenticate` threw: the client tries again later. An
1668
+ // `authenticate` without `expiresAt` fails the same way every
1669
+ // time: say why, once.
1670
+ if (error instanceof AuthenticateExpiresAtError)
1671
+ warnMissingExpiry(error);
1672
+ if (isAuthenticationUnavailableError(error))
1673
+ console.error(error);
1674
+ else if (isThrownByAuthenticate(error)) {
1675
+ console.error(AUTHENTICATE_THREW_MESSAGE, error);
1676
+ }
1268
1677
  onEvent(null, { kind: "close", code: 1011, reason: "admission failed" });
1269
1678
  }
1270
1679
  end();
@@ -1273,7 +1682,7 @@ async function openJazz(initial, store) {
1273
1682
  .then(taken);
1274
1683
  return chain;
1275
1684
  };
1276
- return {
1685
+ const clientSession = {
1277
1686
  send(data) {
1278
1687
  if (ended)
1279
1688
  return false;
@@ -1282,6 +1691,19 @@ async function openJazz(initial, store) {
1282
1691
  },
1283
1692
  deliver,
1284
1693
  close: end,
1694
+ revoke(reason) {
1695
+ if (ended)
1696
+ return;
1697
+ // A refusal the client doesn't retry: its session asks the backend
1698
+ // who is signed in, and signs out if no one is.
1699
+ onEvent(null, { kind: "message", data: authFailedBatch(`session revoked: ${reason}`) });
1700
+ onEvent(null, { kind: "close", code: 1008, reason: "session revoked" });
1701
+ end();
1702
+ },
1703
+ revokeWhileAdmitting(revoked) {
1704
+ if (admitting && !ended)
1705
+ revokedWhileAdmitting.add(revoked);
1706
+ },
1285
1707
  get userId() {
1286
1708
  return userId;
1287
1709
  },
@@ -1289,13 +1711,19 @@ async function openJazz(initial, store) {
1289
1711
  return trusted;
1290
1712
  },
1291
1713
  };
1714
+ const live = { session: clientSession, transport, openedAt: Date.now() };
1715
+ liveSessions.add(live);
1716
+ return clientSession;
1292
1717
  }
1293
1718
  /**
1294
1719
  * Turn a browser prelude into one the core admits on this backend's word:
1295
1720
  * the user `authenticate` finds on this request, with their account and
1296
1721
  * claims, vouched for with the backend secret. A local-first guest's
1297
1722
  * prelude passes through: the core verifies its self-signed token. Any
1298
- * other credential, or a prelude naming another user, is refused.
1723
+ * other credential, or a prelude naming another user, is refused: with
1724
+ * {@link UNVERIFIED_CREDENTIAL} when the client sent a token or backend
1725
+ * client credential that doesn't verify here, with `null` when it sent
1726
+ * none that names anyone.
1299
1727
  */
1300
1728
  async function admitPrelude(request, prelude) {
1301
1729
  let parsed;
@@ -1305,10 +1733,15 @@ async function openJazz(initial, store) {
1305
1733
  catch {
1306
1734
  return null;
1307
1735
  }
1736
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
1737
+ return null;
1738
+ // Between the client and this backend only: the core never sees it.
1739
+ const renewal = parsed[SESSION_RENEWAL_PRELUDE_FIELD] === 1;
1740
+ delete parsed[SESSION_RENEWAL_PRELUDE_FIELD];
1308
1741
  const auth = (parsed.auth && typeof parsed.auth === "object" ? parsed.auth : parsed);
1309
1742
  const client = await backendClients.resolve(request);
1310
1743
  if (client === "refused")
1311
- return null;
1744
+ return UNVERIFIED_CREDENTIAL;
1312
1745
  if (client?.kind === "backend") {
1313
1746
  // A trusted backend client syncs with this backend's authority: it
1314
1747
  // states a backend secret (any stand-in) and, to act for a user, that
@@ -1338,17 +1771,20 @@ async function openJazz(initial, store) {
1338
1771
  if (token !== undefined && token !== null) {
1339
1772
  const localFirst = typeof token === "string" && parseJwtPayload(token)?.iss === LOCAL_FIRST_JWT_ISSUER;
1340
1773
  const alone = others.every((key) => parsed[key] == null && auth[key] == null);
1774
+ // A token this backend can't verify (an external JWT, a forged or
1775
+ // malformed one), or one sent with other credentials or for another
1776
+ // endpoint: a credential that was presented and not accepted.
1341
1777
  if (!localFirst || !alone || parsed.local_first_audience != null)
1342
- return null;
1778
+ return UNVERIFIED_CREDENTIAL;
1343
1779
  // A guest has no user here: its session is bound to its own key.
1344
1780
  if (client)
1345
- return null;
1781
+ return UNVERIFIED_CREDENTIAL;
1346
1782
  const audience = guestAudience(request, token);
1347
1783
  if (!audience)
1348
- return null;
1784
+ return UNVERIFIED_CREDENTIAL;
1349
1785
  // Guests are off unless the app's `authenticate` lets this one in.
1350
1786
  if (!(await acceptsGuest(request)))
1351
- return null;
1787
+ return UNVERIFIED_CREDENTIAL;
1352
1788
  if (audience.endpoint === undefined) {
1353
1789
  // Its own token decides who it is; the backend's secret only vouches
1354
1790
  // for the bundle this socket is pinned to (see `pinnedSocket`).
@@ -1407,6 +1843,8 @@ async function openJazz(initial, store) {
1407
1843
  access: "backend",
1408
1844
  trusted: false,
1409
1845
  expiresAt: client?.expiresAt,
1846
+ // A scoped backend client's session ends with its token instead.
1847
+ ...(renewal && !client ? { renewal: true } : {}),
1410
1848
  };
1411
1849
  }
1412
1850
  // HTTP stream sessions, by id, with the key that proves a request comes
@@ -1414,6 +1852,11 @@ async function openJazz(initial, store) {
1414
1852
  const streams = new Map();
1415
1853
  // Sockets accepted for clients, so close() can end them.
1416
1854
  const clientSockets = new Set();
1855
+ // Why stream sessions this process served lately ended, by id: a send that
1856
+ // arrives after its session ended (refused at sign-in, say) is told that,
1857
+ // not that it reached the wrong instance.
1858
+ const endedStreams = new Map();
1859
+ const ENDED_STREAMS_KEPT = 1000;
1417
1860
  function openStream(request) {
1418
1861
  const id = randomUUID();
1419
1862
  // The id goes in URLs (and so in logs); the key only in a header.
@@ -1425,6 +1868,10 @@ async function openJazz(initial, store) {
1425
1868
  return;
1426
1869
  closed = true;
1427
1870
  streams.delete(id);
1871
+ endedStreams.set(id, { key, reason: reason || `closed (${code})` });
1872
+ if (endedStreams.size > ENDED_STREAMS_KEPT) {
1873
+ endedStreams.delete(endedStreams.keys().next().value);
1874
+ }
1428
1875
  try {
1429
1876
  controller.enqueue(encodeStreamClose(code, reason));
1430
1877
  controller.close();
@@ -1454,7 +1901,7 @@ async function openJazz(initial, store) {
1454
1901
  else if (event.kind === "close") {
1455
1902
  end(event.code ?? 1000, event.reason ?? "");
1456
1903
  }
1457
- });
1904
+ }, "stream");
1458
1905
  }
1459
1906
  catch (error) {
1460
1907
  return new Response(error instanceof Error ? error.message : String(error), { status: 503 });
@@ -1469,6 +1916,10 @@ async function openJazz(initial, store) {
1469
1916
  },
1470
1917
  });
1471
1918
  }
1919
+ function holdsKey(request, key) {
1920
+ const given = Buffer.from(request.headers.get(STREAM_KEY_HEADER) ?? "", "base64url");
1921
+ return given.length === key.length && timingSafeEqual(given, key);
1922
+ }
1472
1923
  /**
1473
1924
  * The stream session `id`, when `request` comes from the client that
1474
1925
  * opened it (it carries the session's key) and, once the session is
@@ -1479,11 +1930,16 @@ async function openJazz(initial, store) {
1479
1930
  async function ownStream(id, request) {
1480
1931
  const entry = streams.get(id);
1481
1932
  if (!entry) {
1933
+ const ended = endedStreams.get(id);
1934
+ if (ended !== undefined) {
1935
+ if (!holdsKey(request, ended.key))
1936
+ return new Response("not this stream's client", { status: 403 });
1937
+ return new Response(`stream session ended: ${ended.reason}`, { status: 410 });
1938
+ }
1482
1939
  // Sessions live in the process that opened them.
1483
1940
  return new Response("unknown stream session: HTTP stream sessions need a single backend instance or sticky routing", { status: 404 });
1484
1941
  }
1485
- const given = Buffer.from(request.headers.get(STREAM_KEY_HEADER) ?? "", "base64url");
1486
- if (given.length !== entry.key.length || !timingSafeEqual(given, entry.key)) {
1942
+ if (!holdsKey(request, entry.key)) {
1487
1943
  return new Response("not this stream's client", { status: 403 });
1488
1944
  }
1489
1945
  const socket = entry.session;
@@ -1500,6 +1956,42 @@ async function openJazz(initial, store) {
1500
1956
  }
1501
1957
  return socket;
1502
1958
  }
1959
+ /**
1960
+ * A client's DELETE, ending its stream session. The key alone proves the
1961
+ * client here, unless the request is signed in as someone else: clients
1962
+ * end their sessions as they sign out, once the app's sign-in has gone, so
1963
+ * a signed-out request may end the session it holds the key of. A session
1964
+ * that already ended is done (204): its client often learns that only
1965
+ * from this answer (#5187).
1966
+ */
1967
+ async function endStream(id, request) {
1968
+ const entry = streams.get(id);
1969
+ if (!entry) {
1970
+ const ended = endedStreams.get(id);
1971
+ if (ended && holdsKey(request, ended.key))
1972
+ return new Response(null, { status: 204 });
1973
+ const refused = await ownStream(id, request);
1974
+ return refused instanceof Response ? refused : new Response(null, { status: 204 });
1975
+ }
1976
+ if (!holdsKey(request, entry.key)) {
1977
+ return new Response("not this stream's client", { status: 403 });
1978
+ }
1979
+ const socket = entry.session;
1980
+ if (socket.trusted) {
1981
+ const client = await backendClients.resolve(request);
1982
+ if (client === null || client === "refused" || client.kind !== "backend") {
1983
+ return new Response("not this backend client", { status: 403 });
1984
+ }
1985
+ }
1986
+ else if (socket.userId !== undefined) {
1987
+ const user = await authenticate(request);
1988
+ if (user && user.userId !== socket.userId) {
1989
+ return new Response("signed in as someone else", { status: 403 });
1990
+ }
1991
+ }
1992
+ socket.close();
1993
+ return new Response(null, { status: 204 });
1994
+ }
1503
1995
  /**
1504
1996
  * Pass a send's records to the session as they arrive, each once the core
1505
1997
  * has room for it: the body is not read ahead of the core, so a client
@@ -1583,7 +2075,7 @@ async function openJazz(initial, store) {
1583
2075
  else if (event.kind === "close") {
1584
2076
  close(sendableCloseCode(event.code), event.reason ?? "");
1585
2077
  }
1586
- });
2078
+ }, "socket");
1587
2079
  }
1588
2080
  catch (error) {
1589
2081
  close(1013, error instanceof Error ? error.message : String(error));
@@ -1825,6 +2317,34 @@ async function openJazz(initial, store) {
1825
2317
  return await route(request, upgrades);
1826
2318
  }
1827
2319
  catch (error) {
2320
+ if (error instanceof AuthenticateExpiresAtError) {
2321
+ // The app's own setup is wrong, the same way on every request: tell
2322
+ // the client by a stable code it explains (naming the fix), and log
2323
+ // the detail (what `authenticate` returned) here once. The response
2324
+ // carries nothing of the app's answer.
2325
+ warnMissingExpiry(error);
2326
+ return new Response(AUTHENTICATE_EXPIRES_AT_MISSING, {
2327
+ status: 500,
2328
+ headers: { "Cache-Control": "no-store" },
2329
+ });
2330
+ }
2331
+ if (isAuthenticationUnavailableError(error)) {
2332
+ // The identity provider is down, not the app's code: the client
2333
+ // retries and stays signed in. The reason stays in the logs.
2334
+ console.error(error);
2335
+ return new Response(AUTHENTICATION_UNAVAILABLE, {
2336
+ status: 503,
2337
+ headers: { "Retry-After": "5", "Cache-Control": "no-store" },
2338
+ });
2339
+ }
2340
+ if (isThrownByAuthenticate(error)) {
2341
+ // The reason (it can name the app's internals) stays in the logs.
2342
+ console.error(AUTHENTICATE_THREW_MESSAGE, error);
2343
+ return new Response(AUTHENTICATE_FAILED, {
2344
+ status: 500,
2345
+ headers: { "Cache-Control": "no-store" },
2346
+ });
2347
+ }
1828
2348
  if (!(error instanceof BackendClientsUnavailable))
1829
2349
  throw error;
1830
2350
  // The reason stays in the backend's logs.
@@ -1835,6 +2355,28 @@ async function openJazz(initial, store) {
1835
2355
  });
1836
2356
  }
1837
2357
  }
2358
+ /**
2359
+ * `handle(request)`, through the app's `refresh` middleware when it has
2360
+ * one: the one route a browser asks before its sync session expires.
2361
+ */
2362
+ async function refreshThen(request, handle) {
2363
+ if (!options.refresh)
2364
+ return handle(request);
2365
+ // Only the browser's own POST, which `route` checked the origin of: a
2366
+ // cross-site navigation (a GET) must never rotate the app's session.
2367
+ if (request.method !== "POST")
2368
+ return new Response(null, { status: 405 });
2369
+ const response = await options.refresh(request, (next) => {
2370
+ if (!isRequestLike(next)) {
2371
+ throw new TypeError("createJazz: refresh must call next with a Request");
2372
+ }
2373
+ return handle(next);
2374
+ });
2375
+ if (!isResponseLike(response)) {
2376
+ throw new TypeError("createJazz: refresh must return the Response next gave it (or another)");
2377
+ }
2378
+ return response;
2379
+ }
1838
2380
  async function route(request, upgrades) {
1839
2381
  const path = innerPath(request);
1840
2382
  if (path === null)
@@ -1842,11 +2384,14 @@ async function openJazz(initial, store) {
1842
2384
  if (request.method !== "GET" && request.method !== "HEAD" && !originAllowed(request)) {
1843
2385
  return new Response("origin not allowed", { status: 403 });
1844
2386
  }
2387
+ if (path === "/inspect" || path.startsWith("/inspect/")) {
2388
+ return inspector.handle(request, path);
2389
+ }
1845
2390
  if (/^\/apps\/[^/]+\/accounts\/backend-sign-in$/.test(path)) {
1846
2391
  return backendSignIn(request);
1847
2392
  }
1848
2393
  if (/^\/apps\/[^/]+\/accounts\/backend-user$/.test(path)) {
1849
- return backendUser(request);
2394
+ return refreshThen(request, backendUser);
1850
2395
  }
1851
2396
  if (/^\/apps\/[^/]+\/backend\/admit$/.test(path)) {
1852
2397
  return admitBackendClient(request);
@@ -1867,13 +2412,8 @@ async function openJazz(initial, store) {
1867
2412
  return openStream(request);
1868
2413
  if (id && request.method === "POST")
1869
2414
  return streamSend(id, request);
1870
- if (id && request.method === "DELETE") {
1871
- const socket = await ownStream(id, request);
1872
- if (socket instanceof Response)
1873
- return socket;
1874
- socket.close();
1875
- return new Response(null, { status: 204 });
1876
- }
2415
+ if (id && request.method === "DELETE")
2416
+ return endStream(id, request);
1877
2417
  return new Response(null, { status: 405 });
1878
2418
  }
1879
2419
  if (path.endsWith("/ws")) {
@@ -1889,10 +2429,7 @@ async function openJazz(initial, store) {
1889
2429
  if (upgrades) {
1890
2430
  return new Response("Upgrade to a WebSocket", { status: 426 });
1891
2431
  }
1892
- return new Response("WebSocket upgrade not available here; use the HTTP stream", {
1893
- status: 426,
1894
- headers: { [STREAM_AVAILABLE_HEADER]: "1" },
1895
- });
2432
+ return useHttpStream();
1896
2433
  }
1897
2434
  if (!PUBLIC_APP_ROUTES.test(path))
1898
2435
  return new Response("Not found", { status: 404 });
@@ -1909,12 +2446,20 @@ async function openJazz(initial, store) {
1909
2446
  }
1910
2447
  async function nextHandler(request) {
1911
2448
  const path = innerPath(request);
2449
+ // On Vercel this handler upgrades sockets (below), once `ws` is
2450
+ // installed; elsewhere (next dev) only if attach() runs on the same
2451
+ // server. Where it can't, a socket gets the HTTP stream marker, as a
2452
+ // plain request for the socket path does.
2453
+ const onVercel = onVercelHost();
2454
+ const vercelUpgrades = onVercel && (await vercelUpgradesSockets());
1912
2455
  if (request.method === "GET" &&
1913
2456
  path?.endsWith("/ws") &&
1914
2457
  request.headers.get("upgrade")?.toLowerCase() === "websocket" &&
1915
- onVercelHost()) {
2458
+ onVercel) {
1916
2459
  if (!originAllowed(request))
1917
2460
  return new Response("origin not allowed", { status: 403 });
2461
+ if (!vercelUpgrades)
2462
+ return useHttpStream();
1918
2463
  // An optional peer: a literal import inside `try`, so bundlers report
1919
2464
  // a missing one at runtime, not on every route (see importSandboxSdk).
1920
2465
  let vercelFunctions;
@@ -1931,9 +2476,7 @@ async function openJazz(initial, store) {
1931
2476
  const deadline = vercelFunctions.getDeadline?.()?.getTime();
1932
2477
  return upgradeWebSocket((ws) => acceptSocket(request, deadline === undefined ? ws : closingBeforeDeadline(ws, deadline)), { maxPayload: MAX_STREAM_MESSAGE_BYTES });
1933
2478
  }
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());
2479
+ return handle(request, upgradesSockets || vercelUpgrades);
1937
2480
  }
1938
2481
  function nodeRequest(req) {
1939
2482
  const host = req.headers.host ?? "localhost";
@@ -1974,11 +2517,15 @@ async function openJazz(initial, store) {
1974
2517
  else if (hasBody) {
1975
2518
  body = req;
1976
2519
  }
1977
- return new Request(`http://${host}${req.url ?? "/"}`, {
2520
+ const request = new Request(`http://${host}${req.url ?? "/"}`, {
1978
2521
  method: req.method,
1979
2522
  headers,
1980
2523
  ...(body === undefined ? {} : { body, duplex: "half" }),
1981
2524
  });
2525
+ const address = req.socket?.remoteAddress;
2526
+ if (address)
2527
+ remoteAddresses.set(request, address);
2528
+ return request;
1982
2529
  }
1983
2530
  function nodeHandler(req, res, next) {
1984
2531
  // Only Jazz's own paths: a request for the app passes on untouched, its
@@ -2047,6 +2594,63 @@ async function openJazz(initial, store) {
2047
2594
  upgradesSockets = true;
2048
2595
  attached = true;
2049
2596
  }
2597
+ // The Inspector follows `reload`: it reads the current options each time.
2598
+ let keptSecret;
2599
+ let schemaOf = null;
2600
+ const inspector = createInspector({
2601
+ appId,
2602
+ get basePath() {
2603
+ return basePath;
2604
+ },
2605
+ get publicUrls() {
2606
+ return publicUrls;
2607
+ },
2608
+ schema: () => {
2609
+ if (schemaOf?.app !== options.app) {
2610
+ schemaOf = { app: options.app, schema: resolveSchemaSource(options.app) };
2611
+ }
2612
+ return schemaOf.schema;
2613
+ },
2614
+ get permissions() {
2615
+ return options.permissions;
2616
+ },
2617
+ db: () => backend.db,
2618
+ dbAs: async (user) => backendDbForSession(backend, await sessionFor(user, "inspect `as`")),
2619
+ sessions: () => [...liveSessions].map(({ session: live, transport, openedAt }) => ({
2620
+ userId: live.userId ?? null,
2621
+ kind: live.trusted ? "backend-client" : live.userId === undefined ? "guest" : "user",
2622
+ transport,
2623
+ openedAt,
2624
+ })),
2625
+ get hook() {
2626
+ return options.inspect;
2627
+ },
2628
+ get options() {
2629
+ return options.inspector ?? NO_INSPECTOR_OPTIONS;
2630
+ },
2631
+ tokenSecret: async () => {
2632
+ const configured = options.inspector?.tokenSecret;
2633
+ if (configured !== undefined)
2634
+ return configured;
2635
+ if (store.kind === "remote")
2636
+ return store.secret ?? null;
2637
+ if (store.kind === "sqlite") {
2638
+ // Read once; a failed read is tried again on the next call.
2639
+ keptSecret ??= keptTokenSecret(store.path).catch((error) => {
2640
+ keptSecret = undefined;
2641
+ throw error;
2642
+ });
2643
+ return keptSecret;
2644
+ }
2645
+ if (store.kind === "memory")
2646
+ return memoryTokenSecret;
2647
+ // A Vercel core's only credential is the function's OIDC token: there
2648
+ // is no shared secret to sign with.
2649
+ return null;
2650
+ },
2651
+ remoteAddress: (request) => remoteAddresses.get(request),
2652
+ serveUi: createInspectorUi(),
2653
+ });
2050
2654
  let closing;
2051
2655
  return {
2052
2656
  appId,
@@ -2085,6 +2689,24 @@ async function openJazz(initial, store) {
2085
2689
  throw new Error("createAccountFor: pass the user's id, as your authenticate names it");
2086
2690
  return accountOf(userId);
2087
2691
  },
2692
+ async revokeUser(userId) {
2693
+ if (typeof userId !== "string" || userId === "")
2694
+ throw new Error("revokeUser: pass the user's id, as your authenticate names it");
2695
+ let ended = 0;
2696
+ for (const { session } of [...liveSessions]) {
2697
+ if (session.trusted)
2698
+ continue;
2699
+ // A session still signing in may turn out to be theirs: its
2700
+ // `authenticate` may have read their cookie before the app ended it.
2701
+ if (session.userId === undefined)
2702
+ session.revokeWhileAdmitting(userId);
2703
+ if (session.userId !== userId)
2704
+ continue;
2705
+ session.revoke("revokeUser");
2706
+ ended += 1;
2707
+ }
2708
+ return ended;
2709
+ },
2088
2710
  close() {
2089
2711
  closing ??= (async () => {
2090
2712
  // Every client connection ends, so the host's own shutdown (which
@@ -2135,6 +2757,55 @@ async function openJazz(initial, store) {
2135
2757
  */
2136
2758
  export function createJazz(options) {
2137
2759
  jazzSettings(options);
2760
+ refuseNoMigrationsOnPersistentStore(options);
2761
+ return openFacade(options);
2762
+ }
2763
+ /**
2764
+ * `createJazz` for a test harness that fronts a test core with `remote()`
2765
+ * (`startTestJazz`): its apps may be defined in code with
2766
+ * `{ migrations: "none" }`, as a test's are. Not exported to apps.
2767
+ */
2768
+ export function createTestJazz(options) {
2769
+ jazzSettings(options);
2770
+ return openFacade(options);
2771
+ }
2772
+ /**
2773
+ * The fix for an app on `{ migrations: "none" }` with a store that keeps its
2774
+ * data: what `createJazz` says when it refuses one.
2775
+ */
2776
+ export function noMigrationsOnPersistentStoreMessage(kind) {
2777
+ return (`createJazz: defineApp(schema, { migrations: "none" }) ships no schema history, so this ${kind}() store ` +
2778
+ "could not follow your first schema change. " +
2779
+ 'Add `import { migrations } from "./migrations"` to schema.ts, pass `{ migrations }` to defineApp, ' +
2780
+ "then run `npx jazz-tools migrations create`: it records schema.ts as the app's first version in migrations/index.ts. " +
2781
+ '"none" is only for memory() stores and tests. See https://jazz.tools/docs/schemas/migrations');
2782
+ }
2783
+ /**
2784
+ * An app on `{ migrations: "none" }` ships no schema history: a store that
2785
+ * keeps its data (`sqlite()`, `vercel()`, `remote()`) would refuse the app at
2786
+ * its first schema change. Refused when `createJazz` is called, before
2787
+ * anything opens. `vercel()` is refused even outside a deployment, where it
2788
+ * runs its `local` store: it is the deployment's store that keeps the data.
2789
+ */
2790
+ function refuseNoMigrationsOnPersistentStore(options) {
2791
+ if (options.store.kind === "memory")
2792
+ return;
2793
+ let schema;
2794
+ try {
2795
+ schema = resolveSchemaSource(options.app);
2796
+ }
2797
+ catch {
2798
+ // Not an app: opening the store says so.
2799
+ return;
2800
+ }
2801
+ if (shipsNoMigrations(schema)) {
2802
+ throw new Error(noMigrationsOnPersistentStoreMessage(options.store.kind));
2803
+ }
2804
+ }
2805
+ function openFacade(options) {
2806
+ // Checked at startup, so a missing `ws` is in the logs before the first socket.
2807
+ if (onVercelHost())
2808
+ void vercelUpgradesSockets();
2138
2809
  const store = runningStore(options.store);
2139
2810
  const key = storeKey(store);
2140
2811
  const entries = registry();
@@ -2182,12 +2853,12 @@ function storeKey(store) {
2182
2853
  return `sqlite:${resolve(store.path)}`;
2183
2854
  if (store.kind === "vercel") {
2184
2855
  const project = store.options.credentials?.projectId ?? process.env.VERCEL_PROJECT_ID;
2185
- let name = store.options.name;
2856
+ let name;
2186
2857
  try {
2187
- name ??= project ? defaultCoreName(project, process.env) : undefined;
2858
+ name = project ? coreName(project, store.options.namespace, process.env).name : undefined;
2188
2859
  }
2189
2860
  catch {
2190
- // A preview without a branch: its open reports that, not createJazz.
2861
+ // No namespace for this deployment: its open reports that, not createJazz.
2191
2862
  }
2192
2863
  // Without a name the core is unknown: its open reports that.
2193
2864
  return name ? `vercel:${name}` : undefined;
@@ -2473,8 +3144,11 @@ function unreachableCore(url, error) {
2473
3144
  return new Error(`createJazz: could not reach the Jazz core at ${url} (${why}); this Jazz tries again on its next use`, { cause: error });
2474
3145
  }
2475
3146
  async function socketUpgrader() {
2476
- const { WebSocketServer } = (await import("ws"));
2477
- return new WebSocketServer({ noServer: true, maxPayload: MAX_STREAM_MESSAGE_BYTES });
3147
+ const { WebSocketServer } = await importWs("attach()");
3148
+ return new WebSocketServer({
3149
+ noServer: true,
3150
+ maxPayload: MAX_STREAM_MESSAGE_BYTES,
3151
+ });
2478
3152
  }
2479
3153
  /** A sync socket's path below `basePath`. */
2480
3154
  const SOCKET_PATH = /^\/apps\/[^/]+\/ws$/;
@@ -2528,16 +3202,35 @@ const UNAVAILABLE_BODY = "Jazz is unavailable; try again shortly";
2528
3202
  * process, alive. (A Fetch response can't tell an HTTP/2 host, which drops
2529
3203
  * the header with a warning; nodeHandler leaves it off there.)
2530
3204
  */
2531
- function storeUnavailable(retryAfter, closed) {
2532
- return new Response(UNAVAILABLE_BODY, {
3205
+ function storeUnavailable(retryAfter, closed, error) {
3206
+ const why = devStoreError(closed ? undefined : error);
3207
+ return new Response(why ? `${UNAVAILABLE_BODY}: ${why}` : UNAVAILABLE_BODY, {
2533
3208
  status: 503,
2534
3209
  headers: {
2535
3210
  "content-type": "text/plain",
2536
3211
  "retry-after": String(retryAfter),
3212
+ ...(why ? { [STORE_ERROR_HEADER]: "1" } : {}),
2537
3213
  ...(closed ? { connection: "close" } : {}),
2538
3214
  },
2539
3215
  });
2540
3216
  }
3217
+ /**
3218
+ * Header on a 503 whose body says why the store did not open. Only in
3219
+ * development (NODE_ENV "development"): there the reason (a deploy the store
3220
+ * refused, say) otherwise shows only in the server log, while the browser
3221
+ * sees a generic refusal and retries (#5053). The client's socket probe
3222
+ * reads it and logs it in the browser console.
3223
+ */
3224
+ const STORE_ERROR_HEADER = "x-jazz-store-error";
3225
+ /** Why the store did not open, for a 503's body in development; else undefined. */
3226
+ function devStoreError(error) {
3227
+ if (error === undefined || typeof process === "undefined")
3228
+ return undefined;
3229
+ if (process.env.NODE_ENV !== "development")
3230
+ return undefined;
3231
+ const message = error instanceof Error ? error.message : String(error);
3232
+ return `the store did not open: ${message}`;
3233
+ }
2541
3234
  const storeUnavailableUpgrade = (retryAfter) => `HTTP/1.1 503 Service Unavailable\r\nRetry-After: ${retryAfter}\r\nConnection: close\r\n\r\n`;
2542
3235
  const BAD_UPGRADE = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n";
2543
3236
  /** The `Jazz` every `createJazz` for one store returns. */
@@ -2556,7 +3249,7 @@ function facade(entry) {
2556
3249
  }
2557
3250
  catch (error) {
2558
3251
  logUnavailable(error);
2559
- return storeUnavailable(retryAfterSeconds(entry), entry.closing !== undefined);
3252
+ return storeUnavailable(retryAfterSeconds(entry), entry.closing !== undefined, error);
2560
3253
  }
2561
3254
  };
2562
3255
  const handle = async (request) => {
@@ -2649,7 +3342,10 @@ function facade(entry) {
2649
3342
  if (entry.closing && req.httpVersionMajor < 2)
2650
3343
  res.setHeader("connection", "close");
2651
3344
  res.setHeader("content-type", "text/plain");
2652
- res.end(UNAVAILABLE_BODY);
3345
+ const why = devStoreError(entry.closing ? undefined : error);
3346
+ if (why)
3347
+ res.setHeader(STORE_ERROR_HEADER, "1");
3348
+ res.end(why ? `${UNAVAILABLE_BODY}: ${why}` : UNAVAILABLE_BODY);
2653
3349
  });
2654
3350
  },
2655
3351
  acceptSocket(request, ws) {
@@ -2672,6 +3368,7 @@ function facade(entry) {
2672
3368
  withAttribution: async (request) => (await use()).withAttribution(request),
2673
3369
  accountFor: async (request) => (await use()).accountFor(request),
2674
3370
  createAccountFor: async (userId) => (await use()).createAccountFor(userId),
3371
+ revokeUser: async (userId) => (await use()).revokeUser(userId),
2675
3372
  linkIdentity: async (link) => (await use()).linkIdentity(link),
2676
3373
  async ready() {
2677
3374
  await use();
@@ -2706,7 +3403,98 @@ function refusalCode(error) {
2706
3403
  const code = /: ([a-z_]{1,80})$/.exec(message)?.[1];
2707
3404
  return code ?? "refused";
2708
3405
  }
3406
+ /** How long before a sync session must end its client is asked to renew it, at most. */
3407
+ const RENEWAL_LEAD_MS = 60_000;
3408
+ /** The least time before a session must end that a renewal is still asked for. */
3409
+ const MIN_RENEWAL_NOTICE_MS = 2_000;
3410
+ /**
3411
+ * The ticket in `batch` when it is a client's lone renew frame (see
3412
+ * `session-renewal-wire.ts`), else null. Looks at a few bytes before
3413
+ * decoding anything, so sync traffic passes untouched.
3414
+ */
3415
+ function renewalTicketIn(batch) {
3416
+ if (batch.byteLength > 4096 || batch[0] !== 1)
3417
+ return null;
3418
+ let offset = 1;
3419
+ while (offset < batch.byteLength && (batch[offset] & 0x80) !== 0)
3420
+ offset += 1;
3421
+ if (batch[offset + 1] !== WIRE_FRAME_RENEW)
3422
+ return null;
3423
+ try {
3424
+ const frames = decodeWebSocketFrameBatch(batch);
3425
+ return frames.length === 1 ? decodeRenewFrame(frames[0]) : null;
3426
+ }
3427
+ catch {
3428
+ return null;
3429
+ }
3430
+ }
3431
+ /** JSON with object keys sorted, so equal claims always digest alike. */
3432
+ function stableJson(value) {
3433
+ if (Array.isArray(value))
3434
+ return `[${value.map(stableJson).join(",")}]`;
3435
+ if (value && typeof value === "object") {
3436
+ const entries = Object.entries(value)
3437
+ .filter(([, item]) => item !== undefined)
3438
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
3439
+ return `{${entries.map(([key, item]) => `${JSON.stringify(key)}:${stableJson(item)}`).join(",")}}`;
3440
+ }
3441
+ return JSON.stringify(value) ?? "null";
3442
+ }
3443
+ /** A fetch `Request`, also from another realm or framework (Next's `NextRequest`). */
3444
+ function isRequestLike(value) {
3445
+ return (!!value &&
3446
+ typeof value === "object" &&
3447
+ typeof value.url === "string" &&
3448
+ typeof value.headers?.get === "function");
3449
+ }
3450
+ /** A fetch `Response`, also from another realm or framework (Next's `NextResponse`). */
3451
+ function isResponseLike(value) {
3452
+ return (!!value &&
3453
+ typeof value === "object" &&
3454
+ typeof value.status === "number" &&
3455
+ typeof value.headers?.get === "function");
3456
+ }
2709
3457
  /** A WireFrame::Error batch with code AuthFailed and retry Never. */
3458
+ /**
3459
+ * The error a session sends its client when the expiry its app's auth gave
3460
+ * it is near: `auth_failed` with `after_resume` retry, which a client takes
3461
+ * as "connect again now" (`isReauthenticateWireError`). A client that
3462
+ * doesn't know it takes it as a refused credential and asks its backend.
3463
+ */
3464
+ function reauthenticateBatch() {
3465
+ const frame = new PostcardWriter();
3466
+ frame.u64(1); // WireFrame::Error
3467
+ frame.u64(3); // WireErrorCode::AuthFailed
3468
+ frame.u64(2); // WireRetry::AfterResume
3469
+ frame.string(`${REAUTHENTICATE_WIRE_MESSAGE_PREFIX} the session reached the expiry authenticate gave it`);
3470
+ return Buffer.from(encodeWebSocketFrameBatch([frame.finish()]));
3471
+ }
3472
+ /**
3473
+ * What `admitPrelude` answers for a credential the client sent that doesn't
3474
+ * verify on this backend: the client reports it as `invalid`, not `missing`.
3475
+ */
3476
+ const UNVERIFIED_CREDENTIAL = "unverified-credential";
3477
+ /**
3478
+ * What a Jazz route answers (500) when the app's `authenticate` threw. The
3479
+ * error goes to the backend's log; the response carries only this code.
3480
+ */
3481
+ const AUTHENTICATE_FAILED = "authenticate_failed";
3482
+ /**
3483
+ * What a Jazz route answers (503, with Retry-After) when the app's
3484
+ * `authenticate` could not check a credential because its identity
3485
+ * provider is unreachable (`fromJWT`'s JWKS).
3486
+ */
3487
+ const AUTHENTICATION_UNAVAILABLE = "authentication_unavailable";
3488
+ /** What the backend logs, before the error, when the app's `authenticate` threw. */
3489
+ const AUTHENTICATE_THREW_MESSAGE = "createJazz: your authenticate threw, so Jazz answered this request with a 500. Fix the error below (a missing secret or environment variable is a common cause); authenticate should return null for a request with no signed-in user.";
3490
+ /** Errors the app's `authenticate` threw (or rejected with), as they reach a route. */
3491
+ const thrownByAuthenticate = new WeakSet();
3492
+ function isThrownByAuthenticate(error) {
3493
+ return isObject(error) && thrownByAuthenticate.has(error);
3494
+ }
3495
+ function isObject(value) {
3496
+ return (typeof value === "object" && value !== null) || typeof value === "function";
3497
+ }
2710
3498
  function authFailedBatch(message) {
2711
3499
  const frame = new PostcardWriter();
2712
3500
  frame.u64(1); // WireFrame::Error