@terreno/syncdb 57.21.0 → 58.0.0-beta.1

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 (476) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +7 -7
  3. package/dist/api/apiError.d.ts +43 -0
  4. package/dist/api/apiError.d.ts.map +1 -0
  5. package/dist/api/apiError.js +28 -0
  6. package/dist/api/apiError.js.map +1 -0
  7. package/dist/api/apiFetch.d.ts +44 -0
  8. package/dist/api/apiFetch.d.ts.map +1 -0
  9. package/dist/api/apiFetch.js +203 -0
  10. package/dist/api/apiFetch.js.map +1 -0
  11. package/dist/api/client.d.ts +70 -0
  12. package/dist/api/client.d.ts.map +1 -0
  13. package/dist/api/client.js +240 -0
  14. package/dist/api/client.js.map +1 -0
  15. package/dist/api/client.test.d.ts +2 -0
  16. package/dist/api/client.test.d.ts.map +1 -0
  17. package/dist/api/client.test.js +588 -0
  18. package/dist/api/client.test.js.map +1 -0
  19. package/dist/app/app.d.ts +13 -0
  20. package/dist/app/app.d.ts.map +1 -0
  21. package/dist/app/app.js +13 -0
  22. package/dist/app/app.js.map +1 -0
  23. package/dist/app/devConsoleLogger.d.ts +18 -0
  24. package/dist/app/devConsoleLogger.d.ts.map +1 -0
  25. package/dist/app/devConsoleLogger.js +147 -0
  26. package/dist/app/devConsoleLogger.js.map +1 -0
  27. package/dist/app/devConsoleLogger.test.d.ts +2 -0
  28. package/dist/app/devConsoleLogger.test.d.ts.map +1 -0
  29. package/dist/app/devConsoleLogger.test.js +202 -0
  30. package/dist/app/devConsoleLogger.test.js.map +1 -0
  31. package/dist/app/mcpTools.d.ts +32 -0
  32. package/dist/app/mcpTools.d.ts.map +1 -0
  33. package/dist/app/mcpTools.js +61 -0
  34. package/dist/app/mcpTools.js.map +1 -0
  35. package/dist/app/permissions.d.ts +26 -0
  36. package/dist/app/permissions.d.ts.map +1 -0
  37. package/dist/app/permissions.js +37 -0
  38. package/dist/app/permissions.js.map +1 -0
  39. package/dist/app/permissions.test.d.ts +2 -0
  40. package/dist/app/permissions.test.d.ts.map +1 -0
  41. package/dist/app/permissions.test.js +36 -0
  42. package/dist/app/permissions.test.js.map +1 -0
  43. package/dist/app/upgradeCheck.d.ts +46 -0
  44. package/dist/app/upgradeCheck.d.ts.map +1 -0
  45. package/dist/app/upgradeCheck.js +121 -0
  46. package/dist/app/upgradeCheck.js.map +1 -0
  47. package/dist/auth/SessionProvider.d.ts +40 -0
  48. package/dist/auth/SessionProvider.d.ts.map +1 -0
  49. package/dist/auth/SessionProvider.js +44 -0
  50. package/dist/auth/SessionProvider.js.map +1 -0
  51. package/dist/auth/SessionProvider.test.d.ts +2 -0
  52. package/dist/auth/SessionProvider.test.d.ts.map +1 -0
  53. package/dist/auth/SessionProvider.test.js +240 -0
  54. package/dist/auth/SessionProvider.test.js.map +1 -0
  55. package/dist/auth/TerrenoAccountSecurityScreen.d.ts +25 -0
  56. package/dist/auth/TerrenoAccountSecurityScreen.d.ts.map +1 -0
  57. package/dist/auth/TerrenoAccountSecurityScreen.js +21 -0
  58. package/dist/auth/TerrenoAccountSecurityScreen.js.map +1 -0
  59. package/dist/auth/TerrenoLoginScreen.d.ts +62 -0
  60. package/dist/auth/TerrenoLoginScreen.d.ts.map +1 -0
  61. package/dist/auth/TerrenoLoginScreen.js +45 -0
  62. package/dist/auth/TerrenoLoginScreen.js.map +1 -0
  63. package/dist/auth/auth.d.ts +36 -0
  64. package/dist/auth/auth.d.ts.map +1 -0
  65. package/dist/auth/auth.js +35 -0
  66. package/dist/auth/auth.js.map +1 -0
  67. package/dist/auth/betterAuthAdapter.d.ts +1 -1
  68. package/dist/auth/betterAuthClient.d.ts +276 -0
  69. package/dist/auth/betterAuthClient.d.ts.map +1 -0
  70. package/dist/auth/betterAuthClient.js +744 -0
  71. package/dist/auth/betterAuthClient.js.map +1 -0
  72. package/dist/auth/betterAuthClient.types.test.d.ts +2 -0
  73. package/dist/auth/betterAuthClient.types.test.d.ts.map +1 -0
  74. package/dist/auth/betterAuthClient.types.test.js +151 -0
  75. package/dist/auth/betterAuthClient.types.test.js.map +1 -0
  76. package/dist/auth/betterAuthClientRegistry.d.ts +51 -0
  77. package/dist/auth/betterAuthClientRegistry.d.ts.map +1 -0
  78. package/dist/auth/betterAuthClientRegistry.js +69 -0
  79. package/dist/auth/betterAuthClientRegistry.js.map +1 -0
  80. package/dist/auth/betterAuthClientRegistry.test.d.ts +2 -0
  81. package/dist/auth/betterAuthClientRegistry.test.d.ts.map +1 -0
  82. package/dist/auth/betterAuthClientRegistry.test.js +91 -0
  83. package/dist/auth/betterAuthClientRegistry.test.js.map +1 -0
  84. package/dist/auth/betterAuthTypes.d.ts +172 -0
  85. package/dist/auth/betterAuthTypes.d.ts.map +1 -0
  86. package/dist/auth/betterAuthTypes.js +7 -0
  87. package/dist/auth/betterAuthTypes.js.map +1 -0
  88. package/dist/auth/jwtAuthAdapter.d.ts +102 -0
  89. package/dist/auth/jwtAuthAdapter.d.ts.map +1 -0
  90. package/dist/auth/jwtAuthAdapter.js +282 -0
  91. package/dist/auth/jwtAuthAdapter.js.map +1 -0
  92. package/dist/auth/jwtAuthAdapter.test.d.ts +2 -0
  93. package/dist/auth/jwtAuthAdapter.test.d.ts.map +1 -0
  94. package/dist/auth/jwtAuthAdapter.test.js +614 -0
  95. package/dist/auth/jwtAuthAdapter.test.js.map +1 -0
  96. package/dist/auth/loginErrors.d.ts +75 -0
  97. package/dist/auth/loginErrors.d.ts.map +1 -0
  98. package/dist/auth/loginErrors.js +154 -0
  99. package/dist/auth/loginErrors.js.map +1 -0
  100. package/dist/auth/loginErrors.test.d.ts +2 -0
  101. package/dist/auth/loginErrors.test.d.ts.map +1 -0
  102. package/dist/auth/loginErrors.test.js +70 -0
  103. package/dist/auth/loginErrors.test.js.map +1 -0
  104. package/dist/auth/ownEntry.d.ts +8 -0
  105. package/dist/auth/ownEntry.d.ts.map +1 -0
  106. package/dist/auth/ownEntry.js +13 -0
  107. package/dist/auth/ownEntry.js.map +1 -0
  108. package/dist/auth/ownEntry.test.d.ts +2 -0
  109. package/dist/auth/ownEntry.test.d.ts.map +1 -0
  110. package/dist/auth/ownEntry.test.js +18 -0
  111. package/dist/auth/ownEntry.test.js.map +1 -0
  112. package/dist/auth/platform.d.ts +3 -0
  113. package/dist/auth/platform.d.ts.map +1 -0
  114. package/dist/auth/platform.js +4 -0
  115. package/dist/auth/platform.js.map +1 -0
  116. package/dist/auth/rememberedAccounts.d.ts +126 -0
  117. package/dist/auth/rememberedAccounts.d.ts.map +1 -0
  118. package/dist/auth/rememberedAccounts.js +399 -0
  119. package/dist/auth/rememberedAccounts.js.map +1 -0
  120. package/dist/auth/rememberedAccounts.test.d.ts +2 -0
  121. package/dist/auth/rememberedAccounts.test.d.ts.map +1 -0
  122. package/dist/auth/rememberedAccounts.test.js +676 -0
  123. package/dist/auth/rememberedAccounts.test.js.map +1 -0
  124. package/dist/auth/session.d.ts +118 -0
  125. package/dist/auth/session.d.ts.map +1 -0
  126. package/dist/auth/session.js +370 -0
  127. package/dist/auth/session.js.map +1 -0
  128. package/dist/auth/session.test.d.ts +2 -0
  129. package/dist/auth/session.test.d.ts.map +1 -0
  130. package/dist/auth/session.test.js +825 -0
  131. package/dist/auth/session.test.js.map +1 -0
  132. package/dist/auth/tokenExpiry.d.ts +70 -0
  133. package/dist/auth/tokenExpiry.d.ts.map +1 -0
  134. package/dist/auth/tokenExpiry.js +123 -0
  135. package/dist/auth/tokenExpiry.js.map +1 -0
  136. package/dist/auth/types.d.ts +1 -1
  137. package/dist/auth/types.js +1 -1
  138. package/dist/auth/useAccountSecurity.d.ts +183 -0
  139. package/dist/auth/useAccountSecurity.d.ts.map +1 -0
  140. package/dist/auth/useAccountSecurity.js +399 -0
  141. package/dist/auth/useAccountSecurity.js.map +1 -0
  142. package/dist/auth/useAccountSecurity.types.test.d.ts +2 -0
  143. package/dist/auth/useAccountSecurity.types.test.d.ts.map +1 -0
  144. package/dist/auth/useAccountSecurity.types.test.js +21 -0
  145. package/dist/auth/useAccountSecurity.types.test.js.map +1 -0
  146. package/dist/auth/useAuthMethods.d.ts +67 -0
  147. package/dist/auth/useAuthMethods.d.ts.map +1 -0
  148. package/dist/auth/useAuthMethods.js +77 -0
  149. package/dist/auth/useAuthMethods.js.map +1 -0
  150. package/dist/auth/useAuthMethods.test.d.ts +2 -0
  151. package/dist/auth/useAuthMethods.test.d.ts.map +1 -0
  152. package/dist/auth/useAuthMethods.test.js +145 -0
  153. package/dist/auth/useAuthMethods.test.js.map +1 -0
  154. package/dist/auth/useJwtAuth.d.ts +31 -0
  155. package/dist/auth/useJwtAuth.d.ts.map +1 -0
  156. package/dist/auth/useJwtAuth.js +58 -0
  157. package/dist/auth/useJwtAuth.js.map +1 -0
  158. package/dist/auth/useJwtAuth.test.d.ts +2 -0
  159. package/dist/auth/useJwtAuth.test.d.ts.map +1 -0
  160. package/dist/auth/useJwtAuth.test.js +165 -0
  161. package/dist/auth/useJwtAuth.test.js.map +1 -0
  162. package/dist/auth/useLoginController.d.ts +248 -0
  163. package/dist/auth/useLoginController.d.ts.map +1 -0
  164. package/dist/auth/useLoginController.js +671 -0
  165. package/dist/auth/useLoginController.js.map +1 -0
  166. package/dist/auth/useLoginController.types.test.d.ts +2 -0
  167. package/dist/auth/useLoginController.types.test.d.ts.map +1 -0
  168. package/dist/auth/useLoginController.types.test.js +19 -0
  169. package/dist/auth/useLoginController.types.test.js.map +1 -0
  170. package/dist/buildNumber.d.ts +34 -0
  171. package/dist/buildNumber.d.ts.map +1 -0
  172. package/dist/buildNumber.js +62 -0
  173. package/dist/buildNumber.js.map +1 -0
  174. package/dist/buildNumber.test.d.ts +2 -0
  175. package/dist/buildNumber.test.d.ts.map +1 -0
  176. package/dist/buildNumber.test.js +114 -0
  177. package/dist/buildNumber.test.js.map +1 -0
  178. package/dist/client.d.ts +10 -1
  179. package/dist/client.d.ts.map +1 -1
  180. package/dist/client.js +237 -184
  181. package/dist/client.js.map +1 -1
  182. package/dist/client.socketEvents.test.d.ts +2 -0
  183. package/dist/client.socketEvents.test.d.ts.map +1 -0
  184. package/dist/client.socketEvents.test.js +64 -0
  185. package/dist/client.socketEvents.test.js.map +1 -0
  186. package/dist/client.test.js +60 -1
  187. package/dist/client.test.js.map +1 -1
  188. package/dist/codegen/cli.js +23 -12
  189. package/dist/codegen/cli.js.map +1 -1
  190. package/dist/codegen/cli.test.js +57 -0
  191. package/dist/codegen/cli.test.js.map +1 -1
  192. package/dist/codegen/discoverCollections.d.ts.map +1 -1
  193. package/dist/codegen/discoverCollections.js +4 -0
  194. package/dist/codegen/discoverCollections.js.map +1 -1
  195. package/dist/codegen/discoverOperations.d.ts +11 -0
  196. package/dist/codegen/discoverOperations.d.ts.map +1 -0
  197. package/dist/codegen/discoverOperations.js +135 -0
  198. package/dist/codegen/discoverOperations.js.map +1 -0
  199. package/dist/codegen/emitApi.d.ts +8 -0
  200. package/dist/codegen/emitApi.d.ts.map +1 -0
  201. package/dist/codegen/emitApi.js +312 -0
  202. package/dist/codegen/emitApi.js.map +1 -0
  203. package/dist/codegen/emitApi.test.d.ts +2 -0
  204. package/dist/codegen/emitApi.test.d.ts.map +1 -0
  205. package/dist/codegen/emitApi.test.js +360 -0
  206. package/dist/codegen/emitApi.test.js.map +1 -0
  207. package/dist/codegen/emitSdk.js +2 -2
  208. package/dist/codegen/generate.d.ts +6 -1
  209. package/dist/codegen/generate.d.ts.map +1 -1
  210. package/dist/codegen/generate.js +18 -0
  211. package/dist/codegen/generate.js.map +1 -1
  212. package/dist/codegen/generate.test.js +53 -1
  213. package/dist/codegen/generate.test.js.map +1 -1
  214. package/dist/codegen/hookNames.d.ts +11 -0
  215. package/dist/codegen/hookNames.d.ts.map +1 -1
  216. package/dist/codegen/hookNames.js +23 -0
  217. package/dist/codegen/hookNames.js.map +1 -1
  218. package/dist/codegen/safeIdentifiers.d.ts +5 -1
  219. package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
  220. package/dist/codegen/safeIdentifiers.js +7 -2
  221. package/dist/codegen/safeIdentifiers.js.map +1 -1
  222. package/dist/codegen/safeIdentifiers.test.js +9 -0
  223. package/dist/codegen/safeIdentifiers.test.js.map +1 -1
  224. package/dist/codegen/types.d.ts +46 -1
  225. package/dist/codegen/types.d.ts.map +1 -1
  226. package/dist/config/baseUrl.d.ts +13 -0
  227. package/dist/config/baseUrl.d.ts.map +1 -0
  228. package/dist/config/baseUrl.js +49 -0
  229. package/dist/config/baseUrl.js.map +1 -0
  230. package/dist/config/baseUrl.test.d.ts +2 -0
  231. package/dist/config/baseUrl.test.d.ts.map +1 -0
  232. package/dist/config/baseUrl.test.js +42 -0
  233. package/dist/config/baseUrl.test.js.map +1 -0
  234. package/dist/config/resolveBaseUrls.d.ts +53 -0
  235. package/dist/config/resolveBaseUrls.d.ts.map +1 -0
  236. package/dist/config/resolveBaseUrls.js +80 -0
  237. package/dist/config/resolveBaseUrls.js.map +1 -0
  238. package/dist/config/resolveBaseUrls.test.d.ts +2 -0
  239. package/dist/config/resolveBaseUrls.test.d.ts.map +1 -0
  240. package/dist/config/resolveBaseUrls.test.js +265 -0
  241. package/dist/config/resolveBaseUrls.test.js.map +1 -0
  242. package/dist/crypto/keyProviders.d.ts +2 -2
  243. package/dist/crypto/keyProviders.d.ts.map +1 -1
  244. package/dist/crypto/keyProviders.js +15 -4
  245. package/dist/crypto/keyProviders.js.map +1 -1
  246. package/dist/crypto/keyProviders.test.js +19 -0
  247. package/dist/crypto/keyProviders.test.js.map +1 -1
  248. package/dist/crypto/types.d.ts +5 -0
  249. package/dist/crypto/types.d.ts.map +1 -1
  250. package/dist/flags/flagTestServer.d.ts +19 -0
  251. package/dist/flags/flagTestServer.d.ts.map +1 -0
  252. package/dist/flags/flagTestServer.js +58 -0
  253. package/dist/flags/flagTestServer.js.map +1 -0
  254. package/dist/flags/useFeatureFlags.d.ts +30 -0
  255. package/dist/flags/useFeatureFlags.d.ts.map +1 -0
  256. package/dist/flags/useFeatureFlags.js +83 -0
  257. package/dist/flags/useFeatureFlags.js.map +1 -0
  258. package/dist/flags/useFeatureFlags.test.d.ts +2 -0
  259. package/dist/flags/useFeatureFlags.test.d.ts.map +1 -0
  260. package/dist/flags/useFeatureFlags.test.js +116 -0
  261. package/dist/flags/useFeatureFlags.test.js.map +1 -0
  262. package/dist/flags/useTerrenoFeatureFlags.d.ts +50 -0
  263. package/dist/flags/useTerrenoFeatureFlags.d.ts.map +1 -0
  264. package/dist/flags/useTerrenoFeatureFlags.js +125 -0
  265. package/dist/flags/useTerrenoFeatureFlags.js.map +1 -0
  266. package/dist/flags/useTerrenoFeatureFlags.test.d.ts +2 -0
  267. package/dist/flags/useTerrenoFeatureFlags.test.d.ts.map +1 -0
  268. package/dist/flags/useTerrenoFeatureFlags.test.js +259 -0
  269. package/dist/flags/useTerrenoFeatureFlags.test.js.map +1 -0
  270. package/dist/index.d.ts +2 -2
  271. package/dist/index.d.ts.map +1 -1
  272. package/dist/index.js +1 -1
  273. package/dist/index.js.map +1 -1
  274. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts +2 -0
  275. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts.map +1 -0
  276. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js +94 -0
  277. package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js.map +1 -0
  278. package/dist/isolated/TerrenoLoginScreen.isolated.d.ts +2 -0
  279. package/dist/isolated/TerrenoLoginScreen.isolated.d.ts.map +1 -0
  280. package/dist/isolated/TerrenoLoginScreen.isolated.js +183 -0
  281. package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -0
  282. package/dist/isolated/betterAuthClient.isolated.d.ts +2 -0
  283. package/dist/isolated/betterAuthClient.isolated.d.ts.map +1 -0
  284. package/dist/isolated/betterAuthClient.isolated.js +1734 -0
  285. package/dist/isolated/betterAuthClient.isolated.js.map +1 -0
  286. package/dist/isolated/betterAuthClient.native.isolated.d.ts +2 -0
  287. package/dist/isolated/betterAuthClient.native.isolated.d.ts.map +1 -0
  288. package/dist/isolated/betterAuthClient.native.isolated.js +153 -0
  289. package/dist/isolated/betterAuthClient.native.isolated.js.map +1 -0
  290. package/dist/isolated/mcpTools.isolated.d.ts +2 -0
  291. package/dist/isolated/mcpTools.isolated.d.ts.map +1 -0
  292. package/dist/isolated/mcpTools.isolated.js +197 -0
  293. package/dist/isolated/mcpTools.isolated.js.map +1 -0
  294. package/dist/isolated/rememberedAccounts.native.isolated.d.ts +2 -0
  295. package/dist/isolated/rememberedAccounts.native.isolated.d.ts.map +1 -0
  296. package/dist/isolated/rememberedAccounts.native.isolated.js +50 -0
  297. package/dist/isolated/rememberedAccounts.native.isolated.js.map +1 -0
  298. package/dist/isolated/sessionLogout.isolated.d.ts +2 -0
  299. package/dist/isolated/sessionLogout.isolated.d.ts.map +1 -0
  300. package/dist/isolated/sessionLogout.isolated.js +133 -0
  301. package/dist/isolated/sessionLogout.isolated.js.map +1 -0
  302. package/dist/isolated/tokenExpiry.isolated.d.ts +2 -0
  303. package/dist/isolated/tokenExpiry.isolated.d.ts.map +1 -0
  304. package/dist/isolated/tokenExpiry.isolated.js +232 -0
  305. package/dist/isolated/tokenExpiry.isolated.js.map +1 -0
  306. package/dist/isolated/upgradeCheck.isolated.d.ts +2 -0
  307. package/dist/isolated/upgradeCheck.isolated.d.ts.map +1 -0
  308. package/dist/isolated/upgradeCheck.isolated.js +241 -0
  309. package/dist/isolated/upgradeCheck.isolated.js.map +1 -0
  310. package/dist/isolated/useAccountSecurity.isolated.d.ts +2 -0
  311. package/dist/isolated/useAccountSecurity.isolated.d.ts.map +1 -0
  312. package/dist/isolated/useAccountSecurity.isolated.js +851 -0
  313. package/dist/isolated/useAccountSecurity.isolated.js.map +1 -0
  314. package/dist/isolated/useAccountSecurity.native.isolated.d.ts +2 -0
  315. package/dist/isolated/useAccountSecurity.native.isolated.d.ts.map +1 -0
  316. package/dist/isolated/useAccountSecurity.native.isolated.js +52 -0
  317. package/dist/isolated/useAccountSecurity.native.isolated.js.map +1 -0
  318. package/dist/isolated/useLoginController.isolated.d.ts +2 -0
  319. package/dist/isolated/useLoginController.isolated.d.ts.map +1 -0
  320. package/dist/isolated/useLoginController.isolated.js +1116 -0
  321. package/dist/isolated/useLoginController.isolated.js.map +1 -0
  322. package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -1
  323. package/dist/persisters/defaultPersisterFactory.native.js +2 -0
  324. package/dist/persisters/defaultPersisterFactory.native.js.map +1 -1
  325. package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -1
  326. package/dist/persisters/encryptedIndexedDbPersister.js +3 -0
  327. package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -1
  328. package/dist/persisters/types.d.ts +6 -0
  329. package/dist/persisters/types.d.ts.map +1 -1
  330. package/dist/query/queryWindows.js +2 -2
  331. package/dist/query/queryWindows.js.map +1 -1
  332. package/dist/react/apiHooks.d.ts +87 -0
  333. package/dist/react/apiHooks.d.ts.map +1 -0
  334. package/dist/react/apiHooks.js +195 -0
  335. package/dist/react/apiHooks.js.map +1 -0
  336. package/dist/react/apiHooks.test.d.ts +2 -0
  337. package/dist/react/apiHooks.test.d.ts.map +1 -0
  338. package/dist/react/apiHooks.test.js +366 -0
  339. package/dist/react/apiHooks.test.js.map +1 -0
  340. package/dist/react/index.d.ts +2 -0
  341. package/dist/react/index.d.ts.map +1 -1
  342. package/dist/react/index.js +2 -0
  343. package/dist/react/index.js.map +1 -1
  344. package/dist/react/provider.d.ts +2 -0
  345. package/dist/react/provider.d.ts.map +1 -1
  346. package/dist/react/provider.js +2 -0
  347. package/dist/react/provider.js.map +1 -1
  348. package/dist/react/useSocketEvent.d.ts +27 -0
  349. package/dist/react/useSocketEvent.d.ts.map +1 -0
  350. package/dist/react/useSocketEvent.js +36 -0
  351. package/dist/react/useSocketEvent.js.map +1 -0
  352. package/dist/react/useSocketEvent.test.d.ts +2 -0
  353. package/dist/react/useSocketEvent.test.d.ts.map +1 -0
  354. package/dist/react/useSocketEvent.test.js +76 -0
  355. package/dist/react/useSocketEvent.test.js.map +1 -0
  356. package/dist/sync/replayCoordinator.js +1 -1
  357. package/dist/sync/replayCoordinator.js.map +1 -1
  358. package/dist/sync/socketTransport.d.ts.map +1 -1
  359. package/dist/sync/socketTransport.js +14 -1
  360. package/dist/sync/socketTransport.js.map +1 -1
  361. package/dist/sync/socketTransport.test.js +42 -0
  362. package/dist/sync/socketTransport.test.js.map +1 -1
  363. package/dist/sync/transport.d.ts +9 -0
  364. package/dist/sync/transport.d.ts.map +1 -1
  365. package/dist/sync/transport.js +13 -0
  366. package/dist/sync/transport.js.map +1 -1
  367. package/dist/testing/fakeTransport.d.ts +5 -1
  368. package/dist/testing/fakeTransport.d.ts.map +1 -1
  369. package/dist/testing/fakeTransport.js +26 -0
  370. package/dist/testing/fakeTransport.js.map +1 -1
  371. package/dist/testing/fakeTransport.test.js +15 -0
  372. package/dist/testing/fakeTransport.test.js.map +1 -1
  373. package/package.json +93 -8
  374. package/src/api/apiError.ts +47 -0
  375. package/src/api/apiFetch.ts +245 -0
  376. package/src/api/client.test.ts +711 -0
  377. package/src/api/client.ts +367 -0
  378. package/src/app/app.ts +30 -0
  379. package/src/app/devConsoleLogger.test.ts +246 -0
  380. package/src/app/devConsoleLogger.ts +173 -0
  381. package/src/app/mcpTools.ts +101 -0
  382. package/src/app/permissions.test.ts +44 -0
  383. package/src/app/permissions.ts +58 -0
  384. package/src/app/upgradeCheck.ts +177 -0
  385. package/src/auth/SessionProvider.test.tsx +286 -0
  386. package/src/auth/SessionProvider.tsx +87 -0
  387. package/src/auth/TerrenoAccountSecurityScreen.tsx +56 -0
  388. package/src/auth/TerrenoLoginScreen.tsx +131 -0
  389. package/src/auth/auth.ts +117 -0
  390. package/src/auth/betterAuthAdapter.ts +1 -1
  391. package/src/auth/betterAuthClient.ts +997 -0
  392. package/src/auth/betterAuthClient.types.test.ts +197 -0
  393. package/src/auth/betterAuthClientRegistry.test.ts +114 -0
  394. package/src/auth/betterAuthClientRegistry.ts +99 -0
  395. package/src/auth/betterAuthTypes.ts +189 -0
  396. package/src/auth/jwtAuthAdapter.test.ts +754 -0
  397. package/src/auth/jwtAuthAdapter.ts +420 -0
  398. package/src/auth/loginErrors.test.ts +97 -0
  399. package/src/auth/loginErrors.ts +249 -0
  400. package/src/auth/ownEntry.test.ts +22 -0
  401. package/src/auth/ownEntry.ts +15 -0
  402. package/src/auth/platform.ts +4 -0
  403. package/src/auth/rememberedAccounts.test.ts +844 -0
  404. package/src/auth/rememberedAccounts.ts +568 -0
  405. package/src/auth/session.test.ts +976 -0
  406. package/src/auth/session.ts +509 -0
  407. package/src/auth/tokenExpiry.ts +185 -0
  408. package/src/auth/types.ts +1 -1
  409. package/src/auth/useAccountSecurity.ts +678 -0
  410. package/src/auth/useAccountSecurity.types.test.ts +28 -0
  411. package/src/auth/useAuthMethods.test.ts +181 -0
  412. package/src/auth/useAuthMethods.ts +137 -0
  413. package/src/auth/useJwtAuth.test.tsx +202 -0
  414. package/src/auth/useJwtAuth.ts +102 -0
  415. package/src/auth/useLoginController.ts +1038 -0
  416. package/src/auth/useLoginController.types.test.ts +26 -0
  417. package/src/buildNumber.test.ts +139 -0
  418. package/src/buildNumber.ts +75 -0
  419. package/src/client.socketEvents.test.ts +77 -0
  420. package/src/client.test.ts +73 -1
  421. package/src/client.ts +87 -18
  422. package/src/codegen/cli.test.ts +66 -0
  423. package/src/codegen/cli.ts +23 -12
  424. package/src/codegen/discoverCollections.ts +4 -0
  425. package/src/codegen/discoverOperations.ts +172 -0
  426. package/src/codegen/emitApi.test.tsx +445 -0
  427. package/src/codegen/emitApi.ts +396 -0
  428. package/src/codegen/emitSdk.ts +2 -2
  429. package/src/codegen/fixtures/openapi.api.json +840 -0
  430. package/src/codegen/generate.test.ts +54 -1
  431. package/src/codegen/generate.ts +20 -1
  432. package/src/codegen/hookNames.ts +35 -0
  433. package/src/codegen/safeIdentifiers.test.ts +20 -0
  434. package/src/codegen/safeIdentifiers.ts +7 -2
  435. package/src/codegen/types.ts +45 -1
  436. package/src/config/baseUrl.test.ts +53 -0
  437. package/src/config/baseUrl.ts +68 -0
  438. package/src/config/resolveBaseUrls.test.ts +308 -0
  439. package/src/config/resolveBaseUrls.ts +118 -0
  440. package/src/crypto/keyProviders.test.ts +23 -0
  441. package/src/crypto/keyProviders.ts +15 -4
  442. package/src/crypto/types.ts +5 -0
  443. package/src/flags/flagTestServer.ts +77 -0
  444. package/src/flags/useFeatureFlags.test.tsx +146 -0
  445. package/src/flags/useFeatureFlags.ts +130 -0
  446. package/src/flags/useTerrenoFeatureFlags.test.tsx +329 -0
  447. package/src/flags/useTerrenoFeatureFlags.ts +188 -0
  448. package/src/index.ts +2 -1
  449. package/src/isolated/TerrenoAccountSecurityScreen.isolated.tsx +123 -0
  450. package/src/isolated/TerrenoLoginScreen.isolated.tsx +256 -0
  451. package/src/isolated/betterAuthClient.isolated.ts +2198 -0
  452. package/src/isolated/betterAuthClient.native.isolated.ts +173 -0
  453. package/src/isolated/mcpTools.isolated.ts +259 -0
  454. package/src/isolated/rememberedAccounts.native.isolated.ts +63 -0
  455. package/src/isolated/sessionLogout.isolated.ts +152 -0
  456. package/src/isolated/tokenExpiry.isolated.ts +271 -0
  457. package/src/isolated/upgradeCheck.isolated.tsx +321 -0
  458. package/src/isolated/useAccountSecurity.isolated.ts +1089 -0
  459. package/src/isolated/useAccountSecurity.native.isolated.ts +61 -0
  460. package/src/isolated/useLoginController.isolated.ts +1384 -0
  461. package/src/persisters/defaultPersisterFactory.native.ts +7 -1
  462. package/src/persisters/encryptedIndexedDbPersister.ts +3 -0
  463. package/src/persisters/types.ts +6 -0
  464. package/src/query/queryWindows.ts +2 -2
  465. package/src/react/apiHooks.test.tsx +473 -0
  466. package/src/react/apiHooks.tsx +336 -0
  467. package/src/react/index.ts +2 -0
  468. package/src/react/provider.tsx +3 -0
  469. package/src/react/useSocketEvent.test.tsx +96 -0
  470. package/src/react/useSocketEvent.ts +59 -0
  471. package/src/sync/replayCoordinator.ts +1 -1
  472. package/src/sync/socketTransport.test.ts +49 -0
  473. package/src/sync/socketTransport.ts +15 -0
  474. package/src/sync/transport.ts +25 -0
  475. package/src/testing/fakeTransport.test.ts +18 -0
  476. package/src/testing/fakeTransport.ts +36 -5
package/dist/client.js CHANGED
@@ -194,6 +194,12 @@ export const createSyncDb = (config) => {
194
194
  let unbindDeltaHandler;
195
195
  /** True once a start() has completed without a matching stop() (E1 double-start guard). */
196
196
  let isStarted = false;
197
+ // Bumped synchronously by every stop()/signOut() CALL, before it queues on the
198
+ // lifecycle mutex. `generation` only changes once the stop runs, which is after
199
+ // any start() ahead of it in the queue has finished, so this is how a start()
200
+ // already running (or still queued) learns the host app logged out and stops
201
+ // before opening persistence or connecting the transport without a session.
202
+ let stopRequests = 0;
197
203
  /**
198
204
  * Queue `op` onto the lifecycle mutex; resolves/rejects with `op`'s own
199
205
  * outcome once every previously-queued op has settled. `lifecycle` itself
@@ -1068,7 +1074,7 @@ export const createSyncDb = (config) => {
1068
1074
  * "error" for the remainder of the session.
1069
1075
  */
1070
1076
  let persistenceMode = "durable";
1071
- const createAndStartPersister = async (userId) => {
1077
+ const createAndStartPersister = async (userId, { isSuperseded } = {}) => {
1072
1078
  // Reset per-call: a fresh persister/load attempt starts optimistic even
1073
1079
  // if a PRIOR persister instance (e.g. before a wipe-and-rebuild) had
1074
1080
  // flagged a load failure.
@@ -1126,11 +1132,26 @@ export const createSyncDb = (config) => {
1126
1132
  // app supplying its own storage backend can still opt into E3 SyncStatus
1127
1133
  // surfacing; the default factory already received the same callbacks
1128
1134
  // above (at creation time) and ignores this second copy.
1129
- persister = factory({
1135
+ const created = factory({
1130
1136
  databaseName: config.name,
1131
1137
  hooks: { onDecryptFailure, onLoadFailure, onSaveFailure },
1132
1138
  store: store.raw,
1133
1139
  });
1140
+ persister = created;
1141
+ // Resolve the encryption key now, while the session that start() resolved is
1142
+ // still valid. Otherwise the first fetch happens on the first (debounced) save,
1143
+ // and a logout in that window leaves every save, including stop()'s flush of
1144
+ // pending outbox writes, failing with a 401 from /sync/key. A failure here
1145
+ // (offline cold start) is not fatal: saves retry the key and report through
1146
+ // onSaveFailure.
1147
+ await created.prepare?.().catch(() => { });
1148
+ if (isSuperseded?.()) {
1149
+ // A stop() arrived while the key was resolving. Nothing has loaded into this
1150
+ // persister, so drop it without saving rather than let stop() flush it.
1151
+ persister = undefined;
1152
+ await created.destroy();
1153
+ return;
1154
+ }
1134
1155
  await persister.startAutoLoad();
1135
1156
  // Read through a function call: `onLoadFailure` (invoked synchronously
1136
1157
  // from inside `startAutoLoad()`, not after it returns) mutates
@@ -1475,150 +1496,172 @@ export const createSyncDb = (config) => {
1475
1496
  * `await` — belt-and-suspenders against any future call site that manages
1476
1497
  * to bypass the mutex (e.g. a direct call from a test), and cheap enough to
1477
1498
  * always do.
1499
+ *
1500
+ * A stop()/signOut() call also cancels a start() that is running or queued
1501
+ * ahead of it (see `stopRequests`): the start() returns at its next check, so
1502
+ * a logout mid-start never opens persistence or connects the transport after
1503
+ * the session is gone. Pending local writes still reach storage through
1504
+ * stop()'s flush, which uses the key start() resolved up front.
1478
1505
  */
1479
- const start = async () => withLifecycle(async () => {
1480
- if (isStarted) {
1481
- // E1: double-start() is a no-op rather than a second full
1482
- // initialization — calling start() again would double-register the
1483
- // transport/auth-change listeners and leak a second reconcile timer.
1484
- // A caller that wants a hard restart should stop() first.
1485
- return;
1486
- }
1487
- generation += 1;
1488
- const myGeneration = generation;
1489
- const authRetryAttempts = Math.max(1, config.startAuthRetryAttempts ?? DEFAULT_START_AUTH_RETRY_ATTEMPTS);
1490
- const authRetryDelayMs = config.startAuthRetryDelayMs ?? DEFAULT_START_AUTH_RETRY_DELAY_MS;
1491
- let userId = null;
1492
- for (let attempt = 1; attempt <= authRetryAttempts; attempt += 1) {
1493
- userId = await config.authProvider.getUserId();
1494
- if (userId || attempt === authRetryAttempts) {
1495
- break;
1496
- }
1497
- await sleep(authRetryDelayMs);
1498
- if (generation !== myGeneration) {
1499
- // A stop() (or another start()) ran while we were retrying auth
1500
- // resolution — abandon this attempt, see the generation check below.
1506
+ const start = async () => {
1507
+ const stopRequestsAtCall = stopRequests;
1508
+ return withLifecycle(async () => {
1509
+ if (isStarted) {
1510
+ // E1: double-start() is a no-op rather than a second full
1511
+ // initialization — calling start() again would double-register the
1512
+ // transport/auth-change listeners and leak a second reconcile timer.
1513
+ // A caller that wants a hard restart should stop() first.
1501
1514
  return;
1502
1515
  }
1503
- }
1504
- if (!userId) {
1505
- throw new Error("createSyncDb.start() requires an authenticated user");
1506
- }
1507
- if (generation !== myGeneration) {
1508
- // A stop() (or another start()) ran while awaiting the auth
1509
- // provider — that operation now owns the lifecycle; abandon this one
1510
- // rather than initializing state a newer generation doesn't expect.
1511
- return;
1512
- }
1513
- simulatedOffline = false;
1514
- setAuthPaused(false);
1515
- // Re-open the cross-window debug bridge a previous stop()/signOut() closed.
1516
- attachDebugBridge();
1517
- await createAndStartPersister(userId);
1518
- if (generation !== myGeneration) {
1519
- return;
1520
- }
1521
- const { userChanged } = await runUserCheck(userId);
1522
- if (generation !== myGeneration) {
1523
- return;
1524
- }
1525
- if (userChanged) {
1526
- // 9.4: a different user's data was just wiped — invalidate any live
1527
- // connection authenticated as that user (and its deltas) before the
1528
- // connect below re-handshakes as the new one.
1529
- connectionEpoch += 1;
1516
+ if (stopRequests !== stopRequestsAtCall) {
1517
+ // A stop() was called after this start() but before it ran: the host app
1518
+ // already logged out, so there is nothing to start.
1519
+ return;
1520
+ }
1521
+ generation += 1;
1522
+ const myGeneration = generation;
1523
+ // Superseded by a later lifecycle op, or cancelled by a stop()/signOut() call
1524
+ // that is still queued behind this start().
1525
+ const isCancelled = () => generation !== myGeneration || stopRequests !== stopRequestsAtCall;
1526
+ const authRetryAttempts = Math.max(1, config.startAuthRetryAttempts ?? DEFAULT_START_AUTH_RETRY_ATTEMPTS);
1527
+ const authRetryDelayMs = config.startAuthRetryDelayMs ?? DEFAULT_START_AUTH_RETRY_DELAY_MS;
1528
+ let userId = null;
1529
+ for (let attempt = 1; attempt <= authRetryAttempts; attempt += 1) {
1530
+ userId = await config.authProvider.getUserId();
1531
+ if (userId || attempt === authRetryAttempts) {
1532
+ break;
1533
+ }
1534
+ await sleep(authRetryDelayMs);
1535
+ if (isCancelled()) {
1536
+ // A stop() (or another start()) ran while we were retrying auth
1537
+ // resolution — abandon this attempt, see the generation check below.
1538
+ return;
1539
+ }
1540
+ }
1541
+ if (isCancelled()) {
1542
+ // A stop() (or another start()) ran while awaiting the auth
1543
+ // provider — that operation now owns the lifecycle; abandon this one
1544
+ // rather than initializing state a newer generation doesn't expect.
1545
+ // Checked before the no-user error: a logout that cancels this start()
1546
+ // is expected, not a failure.
1547
+ return;
1548
+ }
1549
+ if (!userId) {
1550
+ throw new Error("createSyncDb.start() requires an authenticated user");
1551
+ }
1552
+ simulatedOffline = false;
1553
+ setAuthPaused(false);
1554
+ // Re-open the cross-window debug bridge a previous stop()/signOut() closed.
1555
+ attachDebugBridge();
1556
+ await createAndStartPersister(userId, { isSuperseded: isCancelled });
1557
+ if (isCancelled()) {
1558
+ return;
1559
+ }
1560
+ const { userChanged } = await runUserCheck(userId);
1561
+ if (isCancelled()) {
1562
+ return;
1563
+ }
1564
+ if (userChanged) {
1565
+ // 9.4: a different user's data was just wiped — invalidate any live
1566
+ // connection authenticated as that user (and its deltas) before the
1567
+ // connect below re-handshakes as the new one.
1568
+ connectionEpoch += 1;
1569
+ transport.disconnect();
1570
+ setConnected(false);
1571
+ }
1572
+ // C2: migrate any legacy snapshot:{collection} cursors before the first discovery
1573
+ // so the per-stream bootstrap path starts from a clean cursor set. This is a cheap,
1574
+ // idempotent fast-path — Phase E's schema-version wipe (runUserCheck ->
1575
+ // wipeAndRebootstrap) already re-bootstraps any store still on v1, so in practice no
1576
+ // v2 store carries legacy `snapshot:` cursors. Kept because it costs one table scan
1577
+ // and lets a v2-with-legacy-cursors store (which should not exist) recover without a
1578
+ // full wipe; after the first run there are no `snapshot:` keys left, so it no-ops.
1579
+ migrateLegacySnapshotCursors();
1580
+ // A1: startup crash recovery, before the first replayOutbox() — repair
1581
+ // any outbox rows stranded mid-lifecycle by a prior crash/reload (inFlight
1582
+ // never resolved, acked-with-still-pending entity, conflicted with no
1583
+ // conflict row written).
1584
+ const recovery = outbox.recoverStartupState({ userId });
1585
+ // Clear husk conflict rows a pre-fix build left behind (see
1586
+ // pruneGhostConflicts) before recovery's counts are reported, so a store
1587
+ // carrying them recovers without a wipe.
1588
+ const prunedConflicts = pruneGhostConflicts({ store });
1589
+ debugLog?.record({
1590
+ detail: { ...recovery, prunedConflicts },
1591
+ direction: "system",
1592
+ label: `startup recovery (${recovery.recoveredInFlight.length} inFlight, ${recovery.releasedEntities.length} released, ${recovery.clearedOrphanPendings.length} orphan pendings cleared, ${recovery.repairedConflicts.length} conflicts repaired, ${prunedConflicts.length} husk conflicts pruned)`,
1593
+ type: "reconcile",
1594
+ });
1595
+ bindDeltaHandler();
1596
+ unsubscribers.push(() => {
1597
+ unbindDeltaHandler?.();
1598
+ unbindDeltaHandler = undefined;
1599
+ });
1600
+ unsubscribers.push(transport.onStatusChange(handleStatusChange));
1601
+ const unsubscribeSubscribed = transport.onSubscribed?.((subscribed) => {
1602
+ void catchUpSubscribedStreams(subscribed).catch(warn("subscribe catch-up failed"));
1603
+ });
1604
+ if (unsubscribeSubscribed) {
1605
+ unsubscribers.push(unsubscribeSubscribed);
1606
+ }
1607
+ unsubscribers.push(config.authProvider.onAuthChange(handleAuthChange));
1608
+ try {
1609
+ await transport.connect();
1610
+ }
1611
+ catch (error) {
1612
+ // Local-first: start succeeds offline; reconnection/status events pick
1613
+ // up syncing when connectivity returns.
1614
+ warn("transport connect failed; starting offline")(error);
1615
+ }
1616
+ if (isCancelled()) {
1617
+ return;
1618
+ }
1619
+ subscribeConfiguredCollections();
1620
+ // C2: run an initial stream discovery + per-stream bootstrap on start (not only via
1621
+ // the reconnect status event) so a client that starts offline-then-online, or with a
1622
+ // warm socket, still backfills newly-joined streams and drains legacy cursors.
1623
+ void reconcile().catch(warn("startup reconcile failed"));
1624
+ // Drop persisted membership of windows nobody has shown for a while (rows stay).
1625
+ queryWindows.pruneStale();
1626
+ startReconcileTimer();
1627
+ isStarted = true;
1628
+ void replayOutbox().catch(warn("startup replay failed"));
1629
+ });
1630
+ };
1631
+ const stop = async () => {
1632
+ stopRequests += 1;
1633
+ return withLifecycle(async () => {
1634
+ generation += 1;
1635
+ isStarted = false;
1636
+ closeDebugBridge();
1637
+ stopReconcileTimer();
1638
+ simulatedOffline = false;
1639
+ for (const unsubscribe of unsubscribers) {
1640
+ unsubscribe();
1641
+ }
1642
+ unsubscribers = [];
1530
1643
  transport.disconnect();
1531
1644
  setConnected(false);
1532
- }
1533
- // C2: migrate any legacy snapshot:{collection} cursors before the first discovery
1534
- // so the per-stream bootstrap path starts from a clean cursor set. This is a cheap,
1535
- // idempotent fast-path — Phase E's schema-version wipe (runUserCheck ->
1536
- // wipeAndRebootstrap) already re-bootstraps any store still on v1, so in practice no
1537
- // v2 store carries legacy `snapshot:` cursors. Kept because it costs one table scan
1538
- // and lets a v2-with-legacy-cursors store (which should not exist) recover without a
1539
- // full wipe; after the first run there are no `snapshot:` keys left, so it no-ops.
1540
- migrateLegacySnapshotCursors();
1541
- // A1: startup crash recovery, before the first replayOutbox() — repair
1542
- // any outbox rows stranded mid-lifecycle by a prior crash/reload (inFlight
1543
- // never resolved, acked-with-still-pending entity, conflicted with no
1544
- // conflict row written).
1545
- const recovery = outbox.recoverStartupState({ userId });
1546
- // Clear husk conflict rows a pre-fix build left behind (see
1547
- // pruneGhostConflicts) before recovery's counts are reported, so a store
1548
- // carrying them recovers without a wipe.
1549
- const prunedConflicts = pruneGhostConflicts({ store });
1550
- debugLog?.record({
1551
- detail: { ...recovery, prunedConflicts },
1552
- direction: "system",
1553
- label: `startup recovery (${recovery.recoveredInFlight.length} inFlight, ${recovery.releasedEntities.length} released, ${recovery.clearedOrphanPendings.length} orphan pendings cleared, ${recovery.repairedConflicts.length} conflicts repaired, ${prunedConflicts.length} husk conflicts pruned)`,
1554
- type: "reconcile",
1555
- });
1556
- bindDeltaHandler();
1557
- unsubscribers.push(() => {
1558
- unbindDeltaHandler?.();
1559
- unbindDeltaHandler = undefined;
1560
- });
1561
- unsubscribers.push(transport.onStatusChange(handleStatusChange));
1562
- const unsubscribeSubscribed = transport.onSubscribed?.((subscribed) => {
1563
- void catchUpSubscribedStreams(subscribed).catch(warn("subscribe catch-up failed"));
1645
+ queryWindows.reset();
1646
+ coordinator.dispose(currentUserId ? { userId: currentUserId } : undefined);
1647
+ // Capture the persister into a local BEFORE the awaits below: this is
1648
+ // the exact fix for the original bug (a later start() calling
1649
+ // createAndStartPersister() reassigns the module-level `persister`
1650
+ // binding, so re-reading it after the await would destroy the NEW
1651
+ // user's persister instead of this stop()'s). The mutex already
1652
+ // prevents that interleaving, but capturing the local costs nothing and
1653
+ // remains correct even if that invariant is ever relaxed.
1654
+ const persisterToStop = persister;
1655
+ persister = undefined;
1656
+ currentUserId = undefined;
1657
+ if (persisterToStop) {
1658
+ // Flush any pending autosave so a clean stop never loses local writes.
1659
+ await persisterToStop.save();
1660
+ clearPendingDurableConflicts();
1661
+ await persisterToStop.destroy();
1662
+ }
1564
1663
  });
1565
- if (unsubscribeSubscribed) {
1566
- unsubscribers.push(unsubscribeSubscribed);
1567
- }
1568
- unsubscribers.push(config.authProvider.onAuthChange(handleAuthChange));
1569
- try {
1570
- await transport.connect();
1571
- }
1572
- catch (error) {
1573
- // Local-first: start succeeds offline; reconnection/status events pick
1574
- // up syncing when connectivity returns.
1575
- warn("transport connect failed; starting offline")(error);
1576
- }
1577
- if (generation !== myGeneration) {
1578
- return;
1579
- }
1580
- subscribeConfiguredCollections();
1581
- // C2: run an initial stream discovery + per-stream bootstrap on start (not only via
1582
- // the reconnect status event) so a client that starts offline-then-online, or with a
1583
- // warm socket, still backfills newly-joined streams and drains legacy cursors.
1584
- void reconcile().catch(warn("startup reconcile failed"));
1585
- // Drop persisted membership of windows nobody has shown for a while (rows stay).
1586
- queryWindows.pruneStale();
1587
- startReconcileTimer();
1588
- isStarted = true;
1589
- void replayOutbox().catch(warn("startup replay failed"));
1590
- });
1591
- const stop = async () => withLifecycle(async () => {
1592
- generation += 1;
1593
- isStarted = false;
1594
- closeDebugBridge();
1595
- stopReconcileTimer();
1596
- simulatedOffline = false;
1597
- for (const unsubscribe of unsubscribers) {
1598
- unsubscribe();
1599
- }
1600
- unsubscribers = [];
1601
- transport.disconnect();
1602
- setConnected(false);
1603
- queryWindows.reset();
1604
- coordinator.dispose(currentUserId ? { userId: currentUserId } : undefined);
1605
- // Capture the persister into a local BEFORE the awaits below: this is
1606
- // the exact fix for the original bug (a later start() calling
1607
- // createAndStartPersister() reassigns the module-level `persister`
1608
- // binding, so re-reading it after the await would destroy the NEW
1609
- // user's persister instead of this stop()'s). The mutex already
1610
- // prevents that interleaving, but capturing the local costs nothing and
1611
- // remains correct even if that invariant is ever relaxed.
1612
- const persisterToStop = persister;
1613
- persister = undefined;
1614
- currentUserId = undefined;
1615
- if (persisterToStop) {
1616
- // Flush any pending autosave so a clean stop never loses local writes.
1617
- await persisterToStop.save();
1618
- clearPendingDurableConflicts();
1619
- await persisterToStop.destroy();
1620
- }
1621
- });
1664
+ };
1622
1665
  const goOffline = () => {
1623
1666
  if (simulatedOffline) {
1624
1667
  return;
@@ -1860,51 +1903,60 @@ export const createSyncDb = (config) => {
1860
1903
  * reconcile/replay from the signed-out session sees itself superseded and
1861
1904
  * stands down instead of writing into a store that no longer has an owner.
1862
1905
  */
1863
- const signOut = async () => withLifecycle(async () => {
1864
- generation += 1;
1865
- isStarted = false;
1866
- closeDebugBridge();
1867
- const userId = currentUserId;
1868
- stopReconcileTimer();
1869
- simulatedOffline = false;
1870
- for (const unsubscribe of unsubscribers) {
1871
- unsubscribe();
1872
- }
1873
- unsubscribers = [];
1874
- connectionEpoch += 1;
1875
- transport.disconnect();
1876
- setConnected(false);
1877
- setAuthPaused(false);
1878
- currentUserId = undefined;
1879
- // Capture and clear the persister before awaiting, exactly as stop() does:
1880
- // it is destroyed below (or by the wipe), so leaving the module-level
1881
- // binding pointing at it would hand a later start() a dead persister.
1882
- const persisterToStop = persister;
1883
- persister = undefined;
1884
- if (userId && config.wipeOnSignOut) {
1885
- coordinator.dispose({ userId });
1886
- // E3(f): the strongest wipe case must also drop the cached derived
1887
- // encryption key — the same rationale as the different-user wipe.
1888
- await wipeLocalData({
1889
- databaseNames: [config.name],
1890
- keyCacheDbNames: [DEFAULT_KEY_CACHE_DB_NAME],
1891
- persister: persisterToStop,
1892
- store,
1893
- });
1894
- clearPendingDurableConflicts();
1895
- lastSeqJumpReconcileAt.clear();
1896
- queryWindows.reset();
1897
- return;
1898
- }
1899
- coordinator.dispose(userId ? { userId } : undefined);
1900
- if (persisterToStop) {
1901
- // Flush any pending autosave so a sign-out without a wipe never loses
1902
- // local writes (they belong to the user who may sign back in).
1903
- await persisterToStop.save();
1904
- clearPendingDurableConflicts();
1905
- await persisterToStop.destroy();
1906
+ const signOut = async () => {
1907
+ stopRequests += 1;
1908
+ return withLifecycle(async () => {
1909
+ generation += 1;
1910
+ isStarted = false;
1911
+ closeDebugBridge();
1912
+ const userId = currentUserId;
1913
+ stopReconcileTimer();
1914
+ simulatedOffline = false;
1915
+ for (const unsubscribe of unsubscribers) {
1916
+ unsubscribe();
1917
+ }
1918
+ unsubscribers = [];
1919
+ connectionEpoch += 1;
1920
+ transport.disconnect();
1921
+ setConnected(false);
1922
+ setAuthPaused(false);
1923
+ currentUserId = undefined;
1924
+ // Capture and clear the persister before awaiting, exactly as stop() does:
1925
+ // it is destroyed below (or by the wipe), so leaving the module-level
1926
+ // binding pointing at it would hand a later start() a dead persister.
1927
+ const persisterToStop = persister;
1928
+ persister = undefined;
1929
+ if (userId && config.wipeOnSignOut) {
1930
+ coordinator.dispose({ userId });
1931
+ // E3(f): the strongest wipe case must also drop the cached derived
1932
+ // encryption key — the same rationale as the different-user wipe.
1933
+ await wipeLocalData({
1934
+ databaseNames: [config.name],
1935
+ keyCacheDbNames: [DEFAULT_KEY_CACHE_DB_NAME],
1936
+ persister: persisterToStop,
1937
+ store,
1938
+ });
1939
+ clearPendingDurableConflicts();
1940
+ lastSeqJumpReconcileAt.clear();
1941
+ queryWindows.reset();
1942
+ return;
1943
+ }
1944
+ coordinator.dispose(userId ? { userId } : undefined);
1945
+ if (persisterToStop) {
1946
+ // Flush any pending autosave so a sign-out without a wipe never loses
1947
+ // local writes (they belong to the user who may sign back in).
1948
+ await persisterToStop.save();
1949
+ clearPendingDurableConflicts();
1950
+ await persisterToStop.destroy();
1951
+ }
1952
+ });
1953
+ };
1954
+ const onSocketEvent = (event, handler) => {
1955
+ if (!transport.onEvent) {
1956
+ return () => { };
1906
1957
  }
1907
- });
1958
+ return transport.onEvent(event, handler);
1959
+ };
1908
1960
  const client = {
1909
1961
  debug: debugLog,
1910
1962
  forceResync,
@@ -1913,6 +1965,7 @@ export const createSyncDb = (config) => {
1913
1965
  goOnline,
1914
1966
  hydrateWindow,
1915
1967
  mutate,
1968
+ onSocketEvent,
1916
1969
  onStatusChange,
1917
1970
  outbox,
1918
1971
  queryWindows,