@terreno/syncdb 57.20.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 +93 -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 +96 -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
@@ -0,0 +1,744 @@
1
+ /**
2
+ * Better Auth client factory for React Native/Expo applications.
3
+ *
4
+ * Provides a configured Better Auth client with Expo-specific storage
5
+ * and deep linking support.
6
+ */
7
+ import { expoClient } from "@better-auth/expo/client";
8
+ import { passkeyClient } from "@better-auth/passkey/client";
9
+ import AsyncStorage from "@react-native-async-storage/async-storage";
10
+ import { lastLoginMethodClient, multiSessionClient, oneTimeTokenClient, twoFactorClient, } from "better-auth/client/plugins";
11
+ import { createAuthClient } from "better-auth/react";
12
+ import * as SecureStore from "expo-secure-store";
13
+ import { bearerTokenKey, DEFAULT_STORAGE_PREFIX, getBetterAuthBearerToken, handoffClients, resolveBearerStorage, } from "./betterAuthClientRegistry";
14
+ import { IsWeb } from "./platform";
15
+ export { getBetterAuthBearerToken, getBetterAuthClientWebAuth } from "./betterAuthClientRegistry";
16
+ /**
17
+ * True in a browser (react-native-web), false on iOS/Android. Evaluated per call (not at
18
+ * import) so syncdb never imports react-native and tests can flip it with a `document` stub.
19
+ */
20
+ const detectIsWeb = () => typeof document !== "undefined";
21
+ /**
22
+ * Storage adapter for Better Auth that works on both web and native.
23
+ * Uses SecureStore on native platforms and AsyncStorage on web.
24
+ *
25
+ * The native branch must be **synchronous**: `@better-auth/expo`'s client plugin reads the
26
+ * cookie jar inline (`getCookie(storage.getItem(name) || "{}")` followed by `JSON.parse`)
27
+ * while building request headers, and it sets `credentials: "omit"` on native so that
28
+ * stored jar is the only way a session token reaches the server. A promise-returning
29
+ * `getItem` fails the parse, yielding an empty jar and unauthenticated requests.
30
+ * `expo-secure-store` exposes sync `getItem`/`setItem` alongside the `*Async` variants.
31
+ * `@better-auth/expo` 1.7 also calls the async pair (`getItemAsync`/`setItemAsync`) on its
32
+ * serialized read/write path, so the native adapter provides both.
33
+ *
34
+ * The web branch stays async: the plugin short-circuits on web (`if (isWeb) return`) and
35
+ * lets the browser manage cookies, so it never reads this adapter there.
36
+ *
37
+ * `isWeb` is exposed as a parameter so the adapter can be unit tested
38
+ * without having to re-load the module for each platform.
39
+ */
40
+ export const createStorageAdapter = (isWeb = detectIsWeb()) => {
41
+ if (isWeb) {
42
+ return {
43
+ getItem: (key) => {
44
+ if (typeof window !== "undefined") {
45
+ return AsyncStorage.getItem(key);
46
+ }
47
+ return Promise.resolve(null);
48
+ },
49
+ removeItem: (key) => {
50
+ if (typeof window !== "undefined") {
51
+ return AsyncStorage.removeItem(key);
52
+ }
53
+ return Promise.resolve();
54
+ },
55
+ setItem: (key, value) => {
56
+ if (typeof window !== "undefined") {
57
+ return AsyncStorage.setItem(key, value);
58
+ }
59
+ return Promise.resolve();
60
+ },
61
+ };
62
+ }
63
+ // Native platform - use SecureStore's synchronous API (see note above).
64
+ return {
65
+ getItem: (key) => SecureStore.getItem(key),
66
+ getItemAsync: (key) => SecureStore.getItemAsync(key),
67
+ removeItem: (key) => SecureStore.deleteItemAsync(key),
68
+ setItem: (key, value) => SecureStore.setItem(key, value),
69
+ setItemAsync: (key, value) => SecureStore.setItemAsync(key, value),
70
+ };
71
+ };
72
+ /**
73
+ * Drops cookie-jar entries that `@better-auth/expo` cannot read.
74
+ *
75
+ * The plugin keeps its jar as `{[name]: {value, expires}}` and reads it with
76
+ * `Object.entries(jar).reduce((acc, [name, cookie]) => cookie.expires ? ... )`. That property
77
+ * access throws on any entry whose value is not an object, and it runs inside the plugin's
78
+ * `init()` hook, ahead of *every* native request. One malformed entry therefore makes all
79
+ * requests throw before a socket is opened - sign-in included, so the app can never write a
80
+ * good jar over the bad one and stays permanently unable to reach the API. Discarding the
81
+ * unreadable entries degrades to "signed out", which signing in again recovers from.
82
+ */
83
+ export const repairCookieJar = (stored) => {
84
+ if (!stored) {
85
+ return stored;
86
+ }
87
+ let parsed;
88
+ try {
89
+ parsed = JSON.parse(stored);
90
+ }
91
+ catch {
92
+ // The plugin already tolerates unparseable jars by falling back to an empty one.
93
+ return stored;
94
+ }
95
+ // A non-object jar (including the literal `null`) makes the plugin's `Object.entries` throw.
96
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
97
+ return null;
98
+ }
99
+ const entries = Object.entries(parsed);
100
+ const readable = entries.filter(([, cookie]) => typeof cookie === "object" && cookie !== null);
101
+ if (readable.length === entries.length) {
102
+ return stored;
103
+ }
104
+ console.warn(`[terreno/syncdb] Discarded ${entries.length - readable.length} unreadable Better Auth cookie ` +
105
+ "entry/entries; sign in again to restore the session.");
106
+ return JSON.stringify(Object.fromEntries(readable));
107
+ };
108
+ /**
109
+ * Wraps a storage adapter so reads of the Better Auth cookie jar are repaired first. Only the
110
+ * jar key is touched, because the plugin stores unrelated shapes under its other keys (the
111
+ * cached session payload holds plain strings and numbers, which `repairCookieJar` would strip).
112
+ */
113
+ export const withCookieJarRepair = ({ cookieJarKey, storage, }) => ({
114
+ ...storage,
115
+ getItem: (key) => {
116
+ const stored = storage.getItem(key);
117
+ if (key !== cookieJarKey) {
118
+ return stored;
119
+ }
120
+ if (stored instanceof Promise) {
121
+ return stored.then(repairCookieJar);
122
+ }
123
+ return repairCookieJar(stored);
124
+ },
125
+ // The 1.7 plugin reads through the async path too, so the jar is repaired there as well.
126
+ ...(storage.getItemAsync
127
+ ? {
128
+ getItemAsync: async (key) => {
129
+ const stored = await storage.getItemAsync(key);
130
+ return key === cookieJarKey ? repairCookieJar(stored) : stored;
131
+ },
132
+ }
133
+ : {}),
134
+ });
135
+ const isAuthEndpoint = (url, endpoint) => {
136
+ return new URL(url.toString(), "http://localhost").pathname.endsWith(endpoint);
137
+ };
138
+ /**
139
+ * The header `@terreno/api` uses to carry Better Auth's signed challenge cookies (two-factor,
140
+ * trust-device, passkey) to and from clients that send no cookies.
141
+ */
142
+ const AUTH_CHALLENGE_HEADER = "X-Terreno-Auth-Challenge";
143
+ // Sent when nothing is held, so the server still knows to answer with the header.
144
+ const AUTH_CHALLENGE_EMPTY = "-";
145
+ // Better Auth paths whose requests read challenge cookies (a trusted device is checked at sign-in).
146
+ const AUTH_CHALLENGE_PATHS = ["/two-factor/", "/passkey/", "/sign-in/"];
147
+ // Successful calls to these end the two-factor challenge.
148
+ const TWO_FACTOR_VERIFY_PATHS = [
149
+ "/two-factor/verify-totp",
150
+ "/two-factor/verify-otp",
151
+ "/two-factor/verify-backup-code",
152
+ ];
153
+ const authChallengeKey = (storagePrefix) => {
154
+ return `${storagePrefix ?? DEFAULT_STORAGE_PREFIX}_auth_challenge`;
155
+ };
156
+ const isChallengeEndpoint = (url) => {
157
+ const { pathname } = new URL(url.toString(), "http://localhost");
158
+ return AUTH_CHALLENGE_PATHS.some((path) => pathname.includes(path));
159
+ };
160
+ // Cookie names carry Better Auth's prefix (`better-auth.trust_device`, maybe `__Secure-`).
161
+ const isCookieNamed = (name, cookie) => {
162
+ return name === cookie || name.endsWith(`.${cookie}`);
163
+ };
164
+ const sentBearerToken = (headers) => {
165
+ const authorization = headers.get("authorization");
166
+ if (!authorization?.startsWith("Bearer ")) {
167
+ return null;
168
+ }
169
+ return authorization.slice("Bearer ".length);
170
+ };
171
+ /**
172
+ * better-fetch options that authenticate every Better Auth call with a stored bearer token and
173
+ * no cookies. They are client-wide defaults: per-call hooks still run alongside them, but a
174
+ * per-call `auth` or `credentials` overrides them.
175
+ */
176
+ const createWebBearerFetchOptions = ({ bearerStorage, storagePrefix, }) => {
177
+ // Resolved per access so a client created before `window` exists (SSR) still finds storage.
178
+ const storage = () => resolveBearerStorage(bearerStorage);
179
+ const tokenKey = bearerTokenKey(storagePrefix);
180
+ const readToken = () => storage().getItem(tokenKey);
181
+ // The challenge cookies the server handed over, as `name=value` pairs, beside the bearer.
182
+ const challengeKey = authChallengeKey(storagePrefix);
183
+ const readChallenge = () => {
184
+ const stored = storage().getItem(challengeKey);
185
+ return new URLSearchParams(stored && stored !== AUTH_CHALLENGE_EMPTY ? stored : "");
186
+ };
187
+ const writeChallenge = (pairs) => {
188
+ if (pairs.size === 0) {
189
+ storage().removeItem(challengeKey);
190
+ return;
191
+ }
192
+ storage().setItem(challengeKey, pairs.toString());
193
+ };
194
+ // Keeps only the entries `keep` accepts.
195
+ const filterChallenge = (keep) => {
196
+ const pairs = readChallenge();
197
+ for (const name of Array.from(pairs.keys())) {
198
+ if (!keep(name)) {
199
+ pairs.delete(name);
200
+ }
201
+ }
202
+ writeChallenge(pairs);
203
+ };
204
+ // Counts sign-outs, so a token issued by a request that was in flight across one is dropped.
205
+ let signOutCount = 0;
206
+ const signOutCountAtRequest = new WeakMap();
207
+ // Runs after the request headers are built and before fetch, so the sign-out request still
208
+ // carries the token for the server to revoke while the device forgets it whatever happens next.
209
+ // Challenge calls carry the held challenge cookies; nothing else ever sees them.
210
+ const onRequest = (context) => {
211
+ if (isAuthEndpoint(context.url, "/sign-out")) {
212
+ signOutCount += 1;
213
+ storage().removeItem(tokenKey);
214
+ // A trusted device stays trusted across sign-outs; pending challenges do not.
215
+ filterChallenge((name) => isCookieNamed(name, "trust_device"));
216
+ }
217
+ signOutCountAtRequest.set(context, signOutCount);
218
+ if (isChallengeEndpoint(context.url)) {
219
+ const held = readChallenge();
220
+ context.headers.set(AUTH_CHALLENGE_HEADER, held.size > 0 ? held.toString() : AUTH_CHALLENGE_EMPTY);
221
+ }
222
+ };
223
+ // Runs for every status before onSuccess (so before onTwoFactorRedirect), since a refused
224
+ // verify can also expire a challenge. An empty value means the server expired that cookie.
225
+ const onResponse = (context) => {
226
+ const header = context.response.headers.get(AUTH_CHALLENGE_HEADER);
227
+ if (header) {
228
+ const pairs = readChallenge();
229
+ for (const [name, value] of new URLSearchParams(header)) {
230
+ if (value) {
231
+ pairs.set(name, value);
232
+ }
233
+ else {
234
+ pairs.delete(name);
235
+ }
236
+ }
237
+ writeChallenge(pairs);
238
+ }
239
+ const isVerified = context.response.ok &&
240
+ TWO_FACTOR_VERIFY_PATHS.some((path) => isAuthEndpoint(context.request.url, path));
241
+ // The challenge and the sign-in's "don't remember me" belong to the finished sign-in.
242
+ if (isVerified) {
243
+ filterChallenge((name) => !isCookieNamed(name, "two_factor") && !isCookieNamed(name, "dont_remember"));
244
+ }
245
+ };
246
+ // Only 2xx responses reach onSuccess, so a failed or 5xx get-session never clears the token.
247
+ const onSuccess = (context) => {
248
+ const issuedToken = context.response.headers.get("set-auth-token");
249
+ // A sign-in waiting on a second factor has no session yet; any token it carries is dead.
250
+ if (context.data?.twoFactorRedirect) {
251
+ return;
252
+ }
253
+ if (issuedToken) {
254
+ // better-fetch hands onSuccess the same context object that onRequest saw.
255
+ const countAtRequest = signOutCountAtRequest.get(context.request) ?? signOutCount;
256
+ if (countAtRequest === signOutCount) {
257
+ storage().setItem(tokenKey, issuedToken);
258
+ }
259
+ return;
260
+ }
261
+ if (!isAuthEndpoint(context.request.url, "/get-session")) {
262
+ return;
263
+ }
264
+ if (context.data?.session) {
265
+ return;
266
+ }
267
+ // The server rejected the token this request sent. A token stored while it was in flight
268
+ // (a sign-in that finished first) is newer and must survive.
269
+ if (sentBearerToken(context.request.headers) === readToken()) {
270
+ storage().removeItem(tokenKey);
271
+ }
272
+ };
273
+ return {
274
+ auth: { token: () => readToken() ?? undefined, type: "Bearer" },
275
+ credentials: "omit",
276
+ onRequest,
277
+ onResponse,
278
+ onSuccess,
279
+ };
280
+ };
281
+ // Better Auth appends `/api/auth` to a baseURL that has no path of its own.
282
+ const resolveAuthBaseURL = (baseURL) => {
283
+ const trimmed = baseURL.replace(/\/+$/, "");
284
+ try {
285
+ if (new URL(baseURL).pathname.replace(/\/+$/, "") !== "") {
286
+ return trimmed;
287
+ }
288
+ }
289
+ catch {
290
+ // Better Auth rejects such a baseURL itself when the client is created.
291
+ }
292
+ return `${trimmed}/api/auth`;
293
+ };
294
+ /**
295
+ * Builds the client plugins for the enabled features, in BetterAuthFeaturePlugins order. They go
296
+ * after the expo plugin: better-fetch runs plugin hooks in order, so on native the expo plugin
297
+ * stores the 2FA challenge cookie before `onTwoFactorRedirect` runs, and its request hook adds the
298
+ * stored cookies to every feature call.
299
+ */
300
+ const createFeaturePlugins = (features) => {
301
+ if (!features) {
302
+ return [];
303
+ }
304
+ const plugins = [];
305
+ if (features.twoFactor) {
306
+ plugins.push(twoFactorClient(features.twoFactor === true ? undefined : features.twoFactor));
307
+ }
308
+ if (features.passkey) {
309
+ // Same declared-vs-structural mismatch as expoClient below.
310
+ plugins.push(passkeyClient());
311
+ }
312
+ if (features.multiSession) {
313
+ plugins.push(multiSessionClient());
314
+ }
315
+ if (features.lastLoginMethod) {
316
+ plugins.push(lastLoginMethodClient());
317
+ }
318
+ if (features.oneTimeToken) {
319
+ plugins.push(oneTimeTokenClient());
320
+ }
321
+ return plugins;
322
+ };
323
+ /**
324
+ * Creates a Better Auth client configured for Expo/React Native.
325
+ *
326
+ * Pass `webAuth: "bearer"` when the web frontend and the API are on different sites: the web
327
+ * client then authenticates with a stored bearer token instead of cookies. Read that token
328
+ * elsewhere with `getBetterAuthBearerToken`.
329
+ *
330
+ * Pass `features` to add the client plugins for the Better Auth features the server enables.
331
+ * Each one adds a typed namespace: `client.twoFactor`, `client.passkey`, `client.multiSession`,
332
+ * `client.oneTimeToken`, and `client.getLastUsedLoginMethod`.
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * const authClient = createBetterAuthClient({
337
+ * baseURL: "http://localhost:3000",
338
+ * features: {passkey: true, twoFactor: {onTwoFactorRedirect: () => router.push("/2fa")}},
339
+ * scheme: "terreno",
340
+ * });
341
+ *
342
+ * // Use for social login
343
+ * await authClient.signIn.social({
344
+ * provider: "google",
345
+ * });
346
+ *
347
+ * // Get current session
348
+ * const session = await authClient.getSession();
349
+ *
350
+ * // Feature namespaces are typed
351
+ * await authClient.twoFactor.enable({password});
352
+ * ```
353
+ */
354
+ export const createBetterAuthClient = (config) => {
355
+ const storagePrefix = config.storagePrefix ?? DEFAULT_STORAGE_PREFIX;
356
+ // Mirrors the plugin's own `cookieName = `${storagePrefix}_cookie``.
357
+ const storage = withCookieJarRepair({
358
+ cookieJarKey: `${storagePrefix}_cookie`,
359
+ storage: createStorageAdapter(),
360
+ });
361
+ // `expoClient` declares `getActions` against a narrowed `BetterFetch<CreateFetchOption, ...>`
362
+ // while `BetterAuthClientPlugin` declares the unparameterized `BetterFetch`, so the plugin
363
+ // does not structurally satisfy its own contract. Runtime behaviour is unaffected; the
364
+ // narrow `ExpoAuthClientPlugin` keeps the full client type (see its note).
365
+ const expoAuthPlugin = expoClient({
366
+ scheme: config.scheme,
367
+ // The plugin's storage type is strictly sync (`getItem: (key) => string | null`),
368
+ // which the native branch satisfies. The union-typed web branch is async but
369
+ // unreachable here, since the plugin skips storage entirely on web.
370
+ storage: storage,
371
+ storagePrefix,
372
+ });
373
+ // Native and cookie mode pass exactly the options they always have.
374
+ const isWebBearer = IsWeb && config.webAuth === "bearer";
375
+ const client = createAuthClient({
376
+ baseURL: config.baseURL,
377
+ plugins: [expoAuthPlugin, ...createFeaturePlugins(config.features)],
378
+ ...(isWebBearer
379
+ ? {
380
+ fetchOptions: createWebBearerFetchOptions({
381
+ bearerStorage: config.bearerStorage,
382
+ storagePrefix,
383
+ }),
384
+ }
385
+ : {}),
386
+ });
387
+ handoffClients.set(client, {
388
+ authBaseURL: resolveAuthBaseURL(config.baseURL),
389
+ bearerStorage: config.bearerStorage,
390
+ isWebBearer,
391
+ storagePrefix,
392
+ });
393
+ // The plugins are built at runtime from `features`; BetterAuthClientFor is their type.
394
+ return client;
395
+ };
396
+ // URL parameters of the OAuth handoff: T12's server puts the one-time token in the fragment as
397
+ // `ott`, and the sign-in's nonce comes back in the callback query as `handoff`.
398
+ const HANDOFF_TOKEN_PARAM = "ott";
399
+ const HANDOFF_NONCE_PARAM = "handoff";
400
+ const HANDOFF_NONCE_BYTES = 32;
401
+ const handoffNonceKey = (storagePrefix) => {
402
+ return `${storagePrefix}_oauth_handoff_nonce`;
403
+ };
404
+ const NOT_WEB_BEARER_MESSAGE = 'signInSocialWithHandoff needs a web client from createBetterAuthClient({webAuth: "bearer"}). ' +
405
+ "Use authClient.signIn.social on native and in cookie mode.";
406
+ const createHandoffNonce = () => {
407
+ // A crypto-random nonce only: a guessable one would let a planted token through.
408
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(HANDOFF_NONCE_BYTES));
409
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
410
+ };
411
+ // Compares every character so the time taken does not depend on where the strings differ.
412
+ const nonceMatches = (received, stored) => {
413
+ if (received.length !== stored.length) {
414
+ return false;
415
+ }
416
+ let difference = 0;
417
+ for (let index = 0; index < received.length; index += 1) {
418
+ difference |= received.charCodeAt(index) ^ stored.charCodeAt(index);
419
+ }
420
+ return difference === 0;
421
+ };
422
+ const decodeParamPart = (part) => {
423
+ try {
424
+ return decodeURIComponent(part.replace(/\+/g, " "));
425
+ }
426
+ catch {
427
+ return null;
428
+ }
429
+ };
430
+ /**
431
+ * Splits a raw query or fragment (without its `?` or `#`) into the values of `name` and the
432
+ * other parts, kept byte-for-byte so stripping never re-encodes what the app put there.
433
+ */
434
+ const takeParam = (raw, name) => {
435
+ const kept = [];
436
+ const values = [];
437
+ for (const part of raw.split("&")) {
438
+ if (part === "") {
439
+ continue;
440
+ }
441
+ const separator = part.indexOf("=");
442
+ const key = separator === -1 ? part : part.slice(0, separator);
443
+ if (decodeParamPart(key) !== name) {
444
+ kept.push(part);
445
+ continue;
446
+ }
447
+ values.push(separator === -1 ? "" : decodeParamPart(part.slice(separator + 1)));
448
+ }
449
+ return { kept, values };
450
+ };
451
+ const sessionStorageOrNull = () => {
452
+ try {
453
+ return window.sessionStorage ?? null;
454
+ }
455
+ catch {
456
+ return null;
457
+ }
458
+ };
459
+ // Reads and removes the nonce in one step, so each sign-in's nonce is good for one return only.
460
+ const takeStoredNonce = (storagePrefix) => {
461
+ const storage = sessionStorageOrNull();
462
+ if (!storage) {
463
+ return null;
464
+ }
465
+ try {
466
+ const nonce = storage.getItem(handoffNonceKey(storagePrefix));
467
+ storage.removeItem(handoffNonceKey(storagePrefix));
468
+ return nonce;
469
+ }
470
+ catch {
471
+ return null;
472
+ }
473
+ };
474
+ // Appends `handoff=<nonce>` to the query as written, so the app's own parameters reach the
475
+ // return page byte-for-byte. Any `handoff` already there is replaced.
476
+ const withHandoffNonce = (url, nonce) => {
477
+ const parsed = new URL(url, window.location.href);
478
+ const { kept } = takeParam(parsed.search.slice(1), HANDOFF_NONCE_PARAM);
479
+ kept.push(`${HANDOFF_NONCE_PARAM}=${nonce}`);
480
+ return `${parsed.origin}${parsed.pathname}?${kept.join("&")}${parsed.hash}`;
481
+ };
482
+ /**
483
+ * Starts a social or generic OAuth sign-in for a web client in bearer mode. It stores a random
484
+ * nonce in sessionStorage and navigates the whole page to the server's
485
+ * `GET {basePath}/oauth-handoff/start`, with `handoff=<nonce>` added to `callbackURL` (and to
486
+ * `errorCallbackURL`). A top-level navigation keeps Better Auth's OAuth state cookie
487
+ * first-party on the API's origin. After the provider, the page comes back to `callbackURL`
488
+ * with `#ott=<token>`, and `completeBetterAuthOAuthHandoff` exchanges it for the bearer.
489
+ *
490
+ * `callbackURL` defaults to `/` on the current origin (pass the full path for an app served
491
+ * under a sub-path). It is resolved against the current page, and its path must be one of the
492
+ * server's `oauthHandoff.callbackPaths` (default `["/"]`) on one of its
493
+ * `oauthHandoff.webOrigins`, or the server answers 400. `errorCallbackURL` defaults to
494
+ * `callbackURL`; a failed start or callback comes back there with `?error=`. It is always sent,
495
+ * because without one Better Auth sends callback errors to its own error page on the API.
496
+ *
497
+ * Throws on native, in cookie mode, for a client `createBetterAuthClient` did not make, and
498
+ * when sessionStorage cannot hold the nonce. Use `authClient.signIn.social` in those cases.
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * <SocialLoginButton
503
+ * provider="google"
504
+ * onPress={() => signInSocialWithHandoff({client: authClient, provider: "google"})}
505
+ * />
506
+ * ```
507
+ */
508
+ export const signInSocialWithHandoff = ({ callbackURL = "/", client, errorCallbackURL, provider, }) => {
509
+ const config = handoffClients.get(client);
510
+ if (!IsWeb || typeof window === "undefined" || !config?.isWebBearer) {
511
+ throw new Error(NOT_WEB_BEARER_MESSAGE);
512
+ }
513
+ const nonce = createHandoffNonce();
514
+ const start = new URL(`${config.authBaseURL}/oauth-handoff/start`);
515
+ start.searchParams.set("provider", provider);
516
+ start.searchParams.set("callbackURL", withHandoffNonce(callbackURL, nonce));
517
+ start.searchParams.set("errorCallbackURL", withHandoffNonce(errorCallbackURL ?? callbackURL, nonce));
518
+ // Throws when storage is blocked: without a stored nonce the return would be refused anyway.
519
+ window.sessionStorage.setItem(handoffNonceKey(config.storagePrefix), nonce);
520
+ window.location.assign(start.toString());
521
+ };
522
+ /**
523
+ * Removes the handoff from the page URL and returns the one-time token when this tab started
524
+ * the sign-in, or null. Runs synchronously, so a second call made before the first finishes
525
+ * finds a clean URL.
526
+ */
527
+ const takeHandoffToken = (client) => {
528
+ let current;
529
+ try {
530
+ current = new URL(window.location.href);
531
+ }
532
+ catch {
533
+ return null;
534
+ }
535
+ const query = takeParam(current.search.slice(1), HANDOFF_NONCE_PARAM);
536
+ // The server only puts the token in the fragment. An `ott` in the query was planted: it is
537
+ // removed from the URL with the rest and never sent.
538
+ const queryToken = takeParam(query.kept.join("&"), HANDOFF_TOKEN_PARAM);
539
+ const fragment = takeParam(current.hash.slice(1), HANDOFF_TOKEN_PARAM);
540
+ const hasHandoff = query.values.length > 0 || queryToken.values.length > 0 || fragment.values.length > 0;
541
+ if (!hasHandoff) {
542
+ return null;
543
+ }
544
+ const config = handoffClients.get(client);
545
+ const storedNonce = config ? takeStoredNonce(config.storagePrefix) : null;
546
+ // The token leaves the address bar, and so history, before anything else can read or send it.
547
+ const search = queryToken.kept.length > 0 ? `?${queryToken.kept.join("&")}` : "";
548
+ const hash = fragment.kept.length > 0 ? `#${fragment.kept.join("&")}` : "";
549
+ try {
550
+ window.history.replaceState(window.history.state, "", `${current.pathname}${search}${hash}`);
551
+ }
552
+ catch (error) {
553
+ console.warn("[terreno/syncdb] Could not remove the OAuth handoff from the URL; not verifying", {
554
+ errorName: error instanceof Error ? error.name : typeof error,
555
+ });
556
+ return null;
557
+ }
558
+ if (!config?.isWebBearer || fragment.values.length !== 1 || query.values.length !== 1) {
559
+ return null;
560
+ }
561
+ const [token] = fragment.values;
562
+ const [receivedNonce] = query.values;
563
+ // A token without the nonce this tab stored was planted, so it is never sent.
564
+ if (!token || !receivedNonce || !storedNonce || !nonceMatches(receivedNonce, storedNonce)) {
565
+ return null;
566
+ }
567
+ return { config, token };
568
+ };
569
+ const verifyHandoffToken = async ({ client, config, token, }) => {
570
+ let issuedToken = null;
571
+ try {
572
+ // Through the client, so bearer mode's hooks store the token and apply the sign-out guard.
573
+ const result = await client.$fetch("/one-time-token/verify", {
574
+ body: { token },
575
+ method: "POST",
576
+ onSuccess: (context) => {
577
+ issuedToken = context.response.headers.get("set-auth-token");
578
+ },
579
+ });
580
+ if (result.error) {
581
+ console.warn("[terreno/syncdb] OAuth handoff verify was refused", {
582
+ status: result.error.status,
583
+ });
584
+ return false;
585
+ }
586
+ if (!issuedToken) {
587
+ return false;
588
+ }
589
+ const stored = getBetterAuthBearerToken({
590
+ bearerStorage: config.bearerStorage,
591
+ storagePrefix: config.storagePrefix,
592
+ });
593
+ if (stored !== issuedToken) {
594
+ return false;
595
+ }
596
+ }
597
+ catch (error) {
598
+ console.warn("[terreno/syncdb] OAuth handoff verify failed", {
599
+ errorName: error instanceof Error ? error.name : typeof error,
600
+ });
601
+ return false;
602
+ }
603
+ // `$fetch` skips the session signal that the client's own routes send, so a mounted
604
+ // `useSession` refetches with the new token.
605
+ client.$store?.notify("$sessionSignal");
606
+ return true;
607
+ };
608
+ const pendingHandoffs = new WeakMap();
609
+ /**
610
+ * Finishes a sign-in that `signInSocialWithHandoff` started, on the page the provider sent the
611
+ * browser back to. Await it once at startup, before anything reads the session, before any code
612
+ * acts on other query parameters, and before Sentry or analytics start.
613
+ *
614
+ * When the URL has `#ott=<token>` and `?handoff=` equal to the nonce this tab stored, it removes
615
+ * `ott`, `handoff` and the stored nonce (`history.replaceState`), then exchanges the token at
616
+ * `POST {basePath}/one-time-token/verify`. Bearer mode stores the `set-auth-token` that comes
617
+ * back. Other query and fragment parts are kept. A token without a matching nonce, or an `ott`
618
+ * in the query (the server only uses the fragment), is removed from the URL and never sent. Native, cookie mode, and a page without `ott` make no request.
619
+ *
620
+ * Resolves `true` only when a bearer token was stored, and never rejects. A return with
621
+ * `?error=` (such as `provider_not_found` or `sign_in_failed`) resolves `false` and leaves the
622
+ * error in the URL for the app to show. Calls made while one is running share its result.
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * await completeBetterAuthOAuthHandoff({client: authClient});
627
+ * await session.refresh(); // useSession() from @terreno/syncdb/auth
628
+ * ```
629
+ */
630
+ export const completeBetterAuthOAuthHandoff = ({ client, }) => {
631
+ if (!IsWeb || typeof window === "undefined") {
632
+ return Promise.resolve(false);
633
+ }
634
+ const pending = pendingHandoffs.get(client);
635
+ if (pending !== undefined) {
636
+ return pending;
637
+ }
638
+ const handoff = takeHandoffToken(client);
639
+ if (!handoff) {
640
+ return Promise.resolve(false);
641
+ }
642
+ const result = verifyHandoffToken({ client, ...handoff }).finally(() => {
643
+ pendingHandoffs.delete(client);
644
+ });
645
+ pendingHandoffs.set(client, result);
646
+ return result;
647
+ };
648
+ const toLinkError = (error) => ({
649
+ status: error.status,
650
+ ...(error.code !== undefined ? { code: error.code } : {}),
651
+ ...(error.message !== undefined ? { message: error.message } : {}),
652
+ });
653
+ const isHttpURL = (url) => {
654
+ if (typeof url !== "string") {
655
+ return false;
656
+ }
657
+ try {
658
+ const { protocol } = new URL(url);
659
+ return protocol === "http:" || protocol === "https:";
660
+ }
661
+ catch {
662
+ return false;
663
+ }
664
+ };
665
+ // Posts the token from a hidden form, a top-level navigation, so the token stays out of the
666
+ // page URL, history, and access logs, and the API sets the state cookie first-party.
667
+ const submitLinkForm = (startURL, token) => {
668
+ const form = window.document.createElement("form");
669
+ form.method = "POST";
670
+ form.action = startURL;
671
+ form.style.display = "none";
672
+ const field = window.document.createElement("input");
673
+ field.type = "hidden";
674
+ field.name = "token";
675
+ field.value = token;
676
+ form.appendChild(field);
677
+ window.document.body.appendChild(form);
678
+ form.submit();
679
+ };
680
+ /**
681
+ * Links a social or generic OAuth provider to the signed-in user.
682
+ *
683
+ * On web in bearer mode (`createBetterAuthClient({webAuth: "bearer"})`), a `POST /link-social`
684
+ * fetch from another site cannot set Better Auth's OAuth state cookie on the API's origin. So
685
+ * this posts `{provider, callbackURL, errorCallbackURL}` to the server's
686
+ * `POST {basePath}/oauth-handoff/link-intent` with the bearer, then submits the single-use token
687
+ * it returns in a hidden form (method POST) to `startURL`, which redirects the page to the
688
+ * provider. The provider sends the page back to `callbackURL`, with no token: linking creates no
689
+ * session. A failure after the form comes back to `errorCallbackURL` with `?error=`.
690
+ *
691
+ * Both URLs are resolved against the current page and may be any page on one of the server's
692
+ * `oauthHandoff.webOrigins` that its `trustedOrigins` allows. `oauthHandoff.callbackPaths` do not
693
+ * apply, since no token travels on a link's return. `errorCallbackURL` defaults to
694
+ * `callbackURL`. The page must not be served with `Referrer-Policy: no-referrer` or
695
+ * `same-origin`: the form's `Origin` header is then `null`, and the server refuses the start.
696
+ *
697
+ * In cookie mode and on native it calls `client.linkSocial` as before.
698
+ *
699
+ * Resolves `{error: null}` once the browser is on its way (or `linkSocial` succeeded), and
700
+ * `{error}` when the server refused, such as 403 `LINKING_DISABLED` when linking is off. It never
701
+ * submits the form after a refusal.
702
+ *
703
+ * @example
704
+ * ```typescript
705
+ * const {error} = await linkSocialWithHandoff({
706
+ * callbackURL: "/settings/security",
707
+ * client: authClient,
708
+ * errorCallbackURL: "/settings/security",
709
+ * provider: "google",
710
+ * });
711
+ * ```
712
+ */
713
+ export const linkSocialWithHandoff = async ({ callbackURL, client, errorCallbackURL, provider, }) => {
714
+ const config = handoffClients.get(client);
715
+ if (!IsWeb || typeof window === "undefined" || !config?.isWebBearer) {
716
+ const result = await client.linkSocial({
717
+ callbackURL,
718
+ provider,
719
+ ...(errorCallbackURL !== undefined ? { errorCallbackURL } : {}),
720
+ });
721
+ return { error: result.error ? toLinkError(result.error) : null };
722
+ }
723
+ const toAbsolute = (url) => new URL(url, window.location.href).toString();
724
+ // Without an error page, Better Auth would send a failed link to its own page on the API.
725
+ const intent = await client.$fetch("/oauth-handoff/link-intent", {
726
+ body: {
727
+ callbackURL: toAbsolute(callbackURL),
728
+ errorCallbackURL: toAbsolute(errorCallbackURL ?? callbackURL),
729
+ provider,
730
+ },
731
+ method: "POST",
732
+ });
733
+ if (intent.error) {
734
+ return { error: toLinkError(intent.error) };
735
+ }
736
+ const { startURL, token } = intent.data ?? {};
737
+ if (!token || !isHttpURL(startURL)) {
738
+ console.warn("[terreno/syncdb] The link intent answered without a usable token or start URL");
739
+ return { error: { message: "The link intent answered without a token", status: 500 } };
740
+ }
741
+ submitLinkForm(startURL, token);
742
+ return { error: null };
743
+ };
744
+ //# sourceMappingURL=betterAuthClient.js.map