@userflow-tech/react-native 0.1.0 → 0.2.0

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 (850) hide show
  1. package/README.md +114 -68
  2. package/app.plugin.js +13 -0
  3. package/babel-plugin/index.d.ts +43 -0
  4. package/babel-plugin/index.d.ts.map +1 -0
  5. package/babel-plugin/index.js +862 -0
  6. package/babel-plugin/index.js.map +1 -0
  7. package/babel-plugin.js +13 -0
  8. package/docs/anchoring.md +141 -13
  9. package/docs/deep-linking.md +20 -17
  10. package/docs/theme-mapping.md +44 -15
  11. package/docs/troubleshooting.md +37 -30
  12. package/expo-plugin/withUserflow.d.ts +17 -0
  13. package/expo-plugin/withUserflow.d.ts.map +1 -0
  14. package/expo-plugin/withUserflow.js +99 -0
  15. package/expo-plugin/withUserflow.js.map +1 -0
  16. package/lib/commonjs/anchors/AutoAnchorRegistry.js +125 -3
  17. package/lib/commonjs/anchors/AutoAnchorRegistry.js.map +1 -1
  18. package/lib/commonjs/anchors/anchorChangeTicker.js +10 -0
  19. package/lib/commonjs/anchors/anchorChangeTicker.js.map +1 -1
  20. package/lib/commonjs/anchors/autoAnchor.js +1 -1
  21. package/lib/commonjs/anchors/elementConditionEvaluator.js +25 -12
  22. package/lib/commonjs/anchors/elementConditionEvaluator.js.map +1 -1
  23. package/lib/commonjs/anchors/fiber/FiberScanRoot.js +11 -47
  24. package/lib/commonjs/anchors/fiber/FiberScanRoot.js.map +1 -1
  25. package/lib/commonjs/anchors/fiber/FiberScanRootStore.js +50 -0
  26. package/lib/commonjs/anchors/fiber/FiberScanRootStore.js.map +1 -0
  27. package/lib/commonjs/anchors/fiber/fiberInternals.js +145 -3
  28. package/lib/commonjs/anchors/fiber/fiberInternals.js.map +1 -1
  29. package/lib/commonjs/anchors/fiber/indexHostFibers.js +129 -0
  30. package/lib/commonjs/anchors/fiber/indexHostFibers.js.map +1 -0
  31. package/lib/commonjs/anchors/fiber/readHostContent.js +131 -0
  32. package/lib/commonjs/anchors/fiber/readHostContent.js.map +1 -0
  33. package/lib/commonjs/anchors/fiberAnchorCache.js +50 -0
  34. package/lib/commonjs/anchors/fiberAnchorCache.js.map +1 -0
  35. package/lib/commonjs/anchors/hintsCodec.js +1 -1
  36. package/lib/commonjs/anchors/resolveAnchorHost.js +15 -21
  37. package/lib/commonjs/anchors/resolveAnchorHost.js.map +1 -1
  38. package/lib/commonjs/anchors/resolveAutoAnchorHost.js +171 -0
  39. package/lib/commonjs/anchors/resolveAutoAnchorHost.js.map +1 -0
  40. package/lib/commonjs/anchors/semanticMatcher.js +285 -0
  41. package/lib/commonjs/anchors/semanticMatcher.js.map +1 -0
  42. package/lib/commonjs/authoring/ElementPickerOverlay.js +490 -0
  43. package/lib/commonjs/authoring/ElementPickerOverlay.js.map +1 -0
  44. package/lib/commonjs/authoring/capturePickerScreenshot.js +73 -0
  45. package/lib/commonjs/authoring/capturePickerScreenshot.js.map +1 -0
  46. package/lib/commonjs/authoring/chrome/ChromeBarTransition.js +94 -0
  47. package/lib/commonjs/authoring/chrome/ChromeBarTransition.js.map +1 -0
  48. package/lib/commonjs/authoring/chrome/ChromeBottomSheet.js +64 -0
  49. package/lib/commonjs/authoring/chrome/ChromeBottomSheet.js.map +1 -0
  50. package/lib/commonjs/authoring/chrome/ChromeButton.js +94 -0
  51. package/lib/commonjs/authoring/chrome/ChromeButton.js.map +1 -0
  52. package/lib/commonjs/authoring/chrome/ChromeDialog.js +131 -0
  53. package/lib/commonjs/authoring/chrome/ChromeDialog.js.map +1 -0
  54. package/lib/commonjs/authoring/chrome/ChromeIcon.js +39 -0
  55. package/lib/commonjs/authoring/chrome/ChromeIcon.js.map +1 -0
  56. package/lib/commonjs/authoring/chrome/ChromeTooltip.js +88 -0
  57. package/lib/commonjs/authoring/chrome/ChromeTooltip.js.map +1 -0
  58. package/lib/commonjs/authoring/chrome/ChromeTopBar.js +110 -0
  59. package/lib/commonjs/authoring/chrome/ChromeTopBar.js.map +1 -0
  60. package/lib/commonjs/authoring/chrome/DoubleTapBridge.js +57 -0
  61. package/lib/commonjs/authoring/chrome/DoubleTapBridge.js.map +1 -0
  62. package/lib/commonjs/authoring/chrome/doubleTapMonitor.js +80 -0
  63. package/lib/commonjs/authoring/chrome/doubleTapMonitor.js.map +1 -0
  64. package/lib/commonjs/authoring/chrome/icons/arrow-left-from-bracket.png +0 -0
  65. package/lib/commonjs/authoring/chrome/icons/arrow-left-from-bracket@2x.png +0 -0
  66. package/lib/commonjs/authoring/chrome/icons/arrow-left-from-bracket@3x.png +0 -0
  67. package/lib/commonjs/authoring/chrome/icons/arrow-rotate-left.png +0 -0
  68. package/lib/commonjs/authoring/chrome/icons/arrow-rotate-left@2x.png +0 -0
  69. package/lib/commonjs/authoring/chrome/icons/arrow-rotate-left@3x.png +0 -0
  70. package/lib/commonjs/authoring/chrome/icons/userflow-logomark.png +0 -0
  71. package/lib/commonjs/authoring/chrome/icons/userflow-logomark@2x.png +0 -0
  72. package/lib/commonjs/authoring/chrome/icons/userflow-logomark@3x.png +0 -0
  73. package/lib/commonjs/authoring/chrome/icons/xmark.png +0 -0
  74. package/lib/commonjs/authoring/chrome/icons/xmark@2x.png +0 -0
  75. package/lib/commonjs/authoring/chrome/icons/xmark@3x.png +0 -0
  76. package/lib/commonjs/authoring/chrome/tokens.js +150 -0
  77. package/lib/commonjs/authoring/chrome/tokens.js.map +1 -0
  78. package/lib/commonjs/authoring/doubleTap.js +23 -0
  79. package/lib/commonjs/authoring/doubleTap.js.map +1 -0
  80. package/lib/commonjs/authoring/elementPickerController.js +102 -0
  81. package/lib/commonjs/authoring/elementPickerController.js.map +1 -0
  82. package/lib/commonjs/authoring/fingerprintFromInstance.js +195 -0
  83. package/lib/commonjs/authoring/fingerprintFromInstance.js.map +1 -0
  84. package/lib/commonjs/authoring/hitTest.js +106 -0
  85. package/lib/commonjs/authoring/hitTest.js.map +1 -0
  86. package/lib/commonjs/content/RichContentRenderer.js +12 -2
  87. package/lib/commonjs/content/RichContentRenderer.js.map +1 -1
  88. package/lib/commonjs/content/StepButton.js +19 -4
  89. package/lib/commonjs/content/StepButton.js.map +1 -1
  90. package/lib/commonjs/content/resolveStepButtonChrome.js +8 -6
  91. package/lib/commonjs/content/resolveStepButtonChrome.js.map +1 -1
  92. package/lib/commonjs/content/themeColor.js +11 -0
  93. package/lib/commonjs/content/themeColor.js.map +1 -1
  94. package/lib/commonjs/deviceContext.js +158 -0
  95. package/lib/commonjs/deviceContext.js.map +1 -0
  96. package/lib/commonjs/expo-router/useUserflowExpoRouter.js +40 -4
  97. package/lib/commonjs/expo-router/useUserflowExpoRouter.js.map +1 -1
  98. package/lib/commonjs/hostAppVersion.js +242 -0
  99. package/lib/commonjs/hostAppVersion.js.map +1 -0
  100. package/lib/commonjs/index.js +118 -5
  101. package/lib/commonjs/index.js.map +1 -1
  102. package/lib/commonjs/lifecycle.js +2 -0
  103. package/lib/commonjs/lifecycle.js.map +1 -1
  104. package/lib/commonjs/navigation/WithUserflowReactNavigation.js +17 -8
  105. package/lib/commonjs/navigation/WithUserflowReactNavigation.js.map +1 -1
  106. package/lib/commonjs/navigation/isOverlayPresentation.js +64 -0
  107. package/lib/commonjs/navigation/isOverlayPresentation.js.map +1 -0
  108. package/lib/commonjs/pairing/PairingController.js +29 -2
  109. package/lib/commonjs/pairing/PairingController.js.map +1 -1
  110. package/lib/commonjs/pairing/PreviewModeBanner.js +211 -84
  111. package/lib/commonjs/pairing/PreviewModeBanner.js.map +1 -1
  112. package/lib/commonjs/pairing/diagnostics.js +11 -2
  113. package/lib/commonjs/pairing/diagnostics.js.map +1 -1
  114. package/lib/commonjs/pairing/elementPickerRelay.js +91 -0
  115. package/lib/commonjs/pairing/elementPickerRelay.js.map +1 -0
  116. package/lib/commonjs/pairing/resolvePreviewChrome.js +52 -0
  117. package/lib/commonjs/pairing/resolvePreviewChrome.js.map +1 -0
  118. package/lib/commonjs/pairing/tokenStorage.js +25 -2
  119. package/lib/commonjs/pairing/tokenStorage.js.map +1 -1
  120. package/lib/commonjs/pairing/usePairingState.js +3 -1
  121. package/lib/commonjs/pairing/usePairingState.js.map +1 -1
  122. package/lib/commonjs/runtime/FlowRenderer.js +45 -21
  123. package/lib/commonjs/runtime/FlowRenderer.js.map +1 -1
  124. package/lib/commonjs/runtime/FlowSurfaceFade.js +47 -24
  125. package/lib/commonjs/runtime/FlowSurfaceFade.js.map +1 -1
  126. package/lib/commonjs/runtime/TargetPressBridge.js +13 -44
  127. package/lib/commonjs/runtime/TargetPressBridge.js.map +1 -1
  128. package/lib/commonjs/runtime/UserflowProvider.js +74 -20
  129. package/lib/commonjs/runtime/UserflowProvider.js.map +1 -1
  130. package/lib/commonjs/runtime/changedTouchPoints.js +48 -0
  131. package/lib/commonjs/runtime/changedTouchPoints.js.map +1 -0
  132. package/lib/commonjs/runtime/flowEngine.js +3 -1
  133. package/lib/commonjs/runtime/flowEngine.js.map +1 -1
  134. package/lib/commonjs/runtime/flowSessionViewState.js +32 -7
  135. package/lib/commonjs/runtime/flowSessionViewState.js.map +1 -1
  136. package/lib/commonjs/runtime/useFlowSessionState.js +2 -1
  137. package/lib/commonjs/runtime/useFlowSessionState.js.map +1 -1
  138. package/lib/commonjs/screenTracker.js +46 -4
  139. package/lib/commonjs/screenTracker.js.map +1 -1
  140. package/lib/commonjs/surfaces/CardFade.js +31 -0
  141. package/lib/commonjs/surfaces/CardFade.js.map +1 -0
  142. package/lib/commonjs/surfaces/CloseButton.js +11 -6
  143. package/lib/commonjs/surfaces/CloseButton.js.map +1 -1
  144. package/lib/commonjs/surfaces/ModalSurface.js +50 -34
  145. package/lib/commonjs/surfaces/ModalSurface.js.map +1 -1
  146. package/lib/commonjs/surfaces/TooltipSurface.js +366 -87
  147. package/lib/commonjs/surfaces/TooltipSurface.js.map +1 -1
  148. package/lib/commonjs/surfaces/cardTransition.js +70 -0
  149. package/lib/commonjs/surfaces/cardTransition.js.map +1 -0
  150. package/lib/commonjs/surfaces/resolveHighlightChrome.js +109 -0
  151. package/lib/commonjs/surfaces/resolveHighlightChrome.js.map +1 -0
  152. package/lib/commonjs/surfaces/resolveModalLayout.js +7 -3
  153. package/lib/commonjs/surfaces/resolveModalLayout.js.map +1 -1
  154. package/lib/commonjs/surfaces/resolveTooltipLayout.js +0 -4
  155. package/lib/commonjs/surfaces/resolveTooltipLayout.js.map +1 -1
  156. package/lib/commonjs/surfaces/surfaceInteractionConfig.js +33 -0
  157. package/lib/commonjs/surfaces/surfaceInteractionConfig.js.map +1 -0
  158. package/lib/commonjs/surfaces/surfaceLayoutInsets.js +128 -0
  159. package/lib/commonjs/surfaces/surfaceLayoutInsets.js.map +1 -0
  160. package/lib/commonjs/surfaces/themeChrome.js +4 -1
  161. package/lib/commonjs/surfaces/themeChrome.js.map +1 -1
  162. package/lib/commonjs/surfaces/tooltip/TooltipBubble.js +142 -21
  163. package/lib/commonjs/surfaces/tooltip/TooltipBubble.js.map +1 -1
  164. package/lib/commonjs/surfaces/tooltip/TooltipCutout.js +100 -47
  165. package/lib/commonjs/surfaces/tooltip/TooltipCutout.js.map +1 -1
  166. package/lib/commonjs/surfaces/tooltip/TooltipHighlight.js +124 -0
  167. package/lib/commonjs/surfaces/tooltip/TooltipHighlight.js.map +1 -0
  168. package/lib/commonjs/surfaces/tooltip/computeTooltipPosition.js +67 -13
  169. package/lib/commonjs/surfaces/tooltip/computeTooltipPosition.js.map +1 -1
  170. package/lib/commonjs/surfaces/tooltip/inferTooltipPlacement.js +88 -19
  171. package/lib/commonjs/surfaces/tooltip/inferTooltipPlacement.js.map +1 -1
  172. package/lib/commonjs/surfaces/tooltip/placementDiagnostics.js +52 -0
  173. package/lib/commonjs/surfaces/tooltip/placementDiagnostics.js.map +1 -0
  174. package/lib/commonjs/surfaces/tooltip/rect.js +12 -0
  175. package/lib/commonjs/surfaces/tooltip/rect.js.map +1 -1
  176. package/lib/commonjs/surfaces/tooltip/resolveSideCardWidth.js +103 -0
  177. package/lib/commonjs/surfaces/tooltip/resolveSideCardWidth.js.map +1 -0
  178. package/lib/commonjs/version.js +1 -1
  179. package/lib/module/anchors/AutoAnchorRegistry.js +126 -3
  180. package/lib/module/anchors/AutoAnchorRegistry.js.map +1 -1
  181. package/lib/module/anchors/anchorChangeTicker.js +10 -0
  182. package/lib/module/anchors/anchorChangeTicker.js.map +1 -1
  183. package/lib/module/anchors/autoAnchor.js +1 -1
  184. package/lib/module/anchors/elementConditionEvaluator.js +25 -12
  185. package/lib/module/anchors/elementConditionEvaluator.js.map +1 -1
  186. package/lib/module/anchors/fiber/FiberScanRoot.js +2 -43
  187. package/lib/module/anchors/fiber/FiberScanRoot.js.map +1 -1
  188. package/lib/module/anchors/fiber/FiberScanRootStore.js +46 -0
  189. package/lib/module/anchors/fiber/FiberScanRootStore.js.map +1 -0
  190. package/lib/module/anchors/fiber/fiberInternals.js +139 -3
  191. package/lib/module/anchors/fiber/fiberInternals.js.map +1 -1
  192. package/lib/module/anchors/fiber/indexHostFibers.js +122 -0
  193. package/lib/module/anchors/fiber/indexHostFibers.js.map +1 -0
  194. package/lib/module/anchors/fiber/readHostContent.js +127 -0
  195. package/lib/module/anchors/fiber/readHostContent.js.map +1 -0
  196. package/lib/module/anchors/fiberAnchorCache.js +40 -0
  197. package/lib/module/anchors/fiberAnchorCache.js.map +1 -0
  198. package/lib/module/anchors/hintsCodec.js +1 -1
  199. package/lib/module/anchors/resolveAnchorHost.js +15 -21
  200. package/lib/module/anchors/resolveAnchorHost.js.map +1 -1
  201. package/lib/module/anchors/resolveAutoAnchorHost.js +167 -0
  202. package/lib/module/anchors/resolveAutoAnchorHost.js.map +1 -0
  203. package/lib/module/anchors/semanticMatcher.js +280 -0
  204. package/lib/module/anchors/semanticMatcher.js.map +1 -0
  205. package/lib/module/authoring/ElementPickerOverlay.js +485 -0
  206. package/lib/module/authoring/ElementPickerOverlay.js.map +1 -0
  207. package/lib/module/authoring/capturePickerScreenshot.js +68 -0
  208. package/lib/module/authoring/capturePickerScreenshot.js.map +1 -0
  209. package/lib/module/authoring/chrome/ChromeBarTransition.js +88 -0
  210. package/lib/module/authoring/chrome/ChromeBarTransition.js.map +1 -0
  211. package/lib/module/authoring/chrome/ChromeBottomSheet.js +59 -0
  212. package/lib/module/authoring/chrome/ChromeBottomSheet.js.map +1 -0
  213. package/lib/module/authoring/chrome/ChromeButton.js +89 -0
  214. package/lib/module/authoring/chrome/ChromeButton.js.map +1 -0
  215. package/lib/module/authoring/chrome/ChromeDialog.js +126 -0
  216. package/lib/module/authoring/chrome/ChromeDialog.js.map +1 -0
  217. package/lib/module/authoring/chrome/ChromeIcon.js +33 -0
  218. package/lib/module/authoring/chrome/ChromeIcon.js.map +1 -0
  219. package/lib/module/authoring/chrome/ChromeTooltip.js +82 -0
  220. package/lib/module/authoring/chrome/ChromeTooltip.js.map +1 -0
  221. package/lib/module/authoring/chrome/ChromeTopBar.js +104 -0
  222. package/lib/module/authoring/chrome/ChromeTopBar.js.map +1 -0
  223. package/lib/module/authoring/chrome/DoubleTapBridge.js +52 -0
  224. package/lib/module/authoring/chrome/DoubleTapBridge.js.map +1 -0
  225. package/lib/module/authoring/chrome/doubleTapMonitor.js +75 -0
  226. package/lib/module/authoring/chrome/doubleTapMonitor.js.map +1 -0
  227. package/lib/module/authoring/chrome/icons/arrow-left-from-bracket.png +0 -0
  228. package/lib/module/authoring/chrome/icons/arrow-left-from-bracket@2x.png +0 -0
  229. package/lib/module/authoring/chrome/icons/arrow-left-from-bracket@3x.png +0 -0
  230. package/lib/module/authoring/chrome/icons/arrow-rotate-left.png +0 -0
  231. package/lib/module/authoring/chrome/icons/arrow-rotate-left@2x.png +0 -0
  232. package/lib/module/authoring/chrome/icons/arrow-rotate-left@3x.png +0 -0
  233. package/lib/module/authoring/chrome/icons/userflow-logomark.png +0 -0
  234. package/lib/module/authoring/chrome/icons/userflow-logomark@2x.png +0 -0
  235. package/lib/module/authoring/chrome/icons/userflow-logomark@3x.png +0 -0
  236. package/lib/module/authoring/chrome/icons/xmark.png +0 -0
  237. package/lib/module/authoring/chrome/icons/xmark@2x.png +0 -0
  238. package/lib/module/authoring/chrome/icons/xmark@3x.png +0 -0
  239. package/lib/module/authoring/chrome/tokens.js +146 -0
  240. package/lib/module/authoring/chrome/tokens.js.map +1 -0
  241. package/lib/module/authoring/doubleTap.js +18 -0
  242. package/lib/module/authoring/doubleTap.js.map +1 -0
  243. package/lib/module/authoring/elementPickerController.js +97 -0
  244. package/lib/module/authoring/elementPickerController.js.map +1 -0
  245. package/lib/module/authoring/fingerprintFromInstance.js +187 -0
  246. package/lib/module/authoring/fingerprintFromInstance.js.map +1 -0
  247. package/lib/module/authoring/hitTest.js +100 -0
  248. package/lib/module/authoring/hitTest.js.map +1 -0
  249. package/lib/module/content/RichContentRenderer.js +12 -2
  250. package/lib/module/content/RichContentRenderer.js.map +1 -1
  251. package/lib/module/content/StepButton.js +19 -4
  252. package/lib/module/content/StepButton.js.map +1 -1
  253. package/lib/module/content/resolveStepButtonChrome.js +8 -6
  254. package/lib/module/content/resolveStepButtonChrome.js.map +1 -1
  255. package/lib/module/content/themeColor.js +10 -0
  256. package/lib/module/content/themeColor.js.map +1 -1
  257. package/lib/module/deviceContext.js +142 -0
  258. package/lib/module/deviceContext.js.map +1 -0
  259. package/lib/module/expo-router/useUserflowExpoRouter.js +42 -6
  260. package/lib/module/expo-router/useUserflowExpoRouter.js.map +1 -1
  261. package/lib/module/hostAppVersion.js +225 -0
  262. package/lib/module/hostAppVersion.js.map +1 -0
  263. package/lib/module/index.js +119 -6
  264. package/lib/module/index.js.map +1 -1
  265. package/lib/module/lifecycle.js +2 -0
  266. package/lib/module/lifecycle.js.map +1 -1
  267. package/lib/module/navigation/WithUserflowReactNavigation.js +18 -9
  268. package/lib/module/navigation/WithUserflowReactNavigation.js.map +1 -1
  269. package/lib/module/navigation/isOverlayPresentation.js +58 -0
  270. package/lib/module/navigation/isOverlayPresentation.js.map +1 -0
  271. package/lib/module/pairing/PairingController.js +30 -3
  272. package/lib/module/pairing/PairingController.js.map +1 -1
  273. package/lib/module/pairing/PreviewModeBanner.js +212 -85
  274. package/lib/module/pairing/PreviewModeBanner.js.map +1 -1
  275. package/lib/module/pairing/diagnostics.js +10 -2
  276. package/lib/module/pairing/diagnostics.js.map +1 -1
  277. package/lib/module/pairing/elementPickerRelay.js +87 -0
  278. package/lib/module/pairing/elementPickerRelay.js.map +1 -0
  279. package/lib/module/pairing/resolvePreviewChrome.js +48 -0
  280. package/lib/module/pairing/resolvePreviewChrome.js.map +1 -0
  281. package/lib/module/pairing/tokenStorage.js +24 -2
  282. package/lib/module/pairing/tokenStorage.js.map +1 -1
  283. package/lib/module/pairing/usePairingState.js +3 -1
  284. package/lib/module/pairing/usePairingState.js.map +1 -1
  285. package/lib/module/runtime/FlowRenderer.js +45 -21
  286. package/lib/module/runtime/FlowRenderer.js.map +1 -1
  287. package/lib/module/runtime/FlowSurfaceFade.js +49 -26
  288. package/lib/module/runtime/FlowSurfaceFade.js.map +1 -1
  289. package/lib/module/runtime/TargetPressBridge.js +12 -43
  290. package/lib/module/runtime/TargetPressBridge.js.map +1 -1
  291. package/lib/module/runtime/UserflowProvider.js +74 -20
  292. package/lib/module/runtime/UserflowProvider.js.map +1 -1
  293. package/lib/module/runtime/changedTouchPoints.js +43 -0
  294. package/lib/module/runtime/changedTouchPoints.js.map +1 -0
  295. package/lib/module/runtime/flowEngine.js +3 -1
  296. package/lib/module/runtime/flowEngine.js.map +1 -1
  297. package/lib/module/runtime/flowSessionViewState.js +32 -7
  298. package/lib/module/runtime/flowSessionViewState.js.map +1 -1
  299. package/lib/module/runtime/useFlowSessionState.js +2 -1
  300. package/lib/module/runtime/useFlowSessionState.js.map +1 -1
  301. package/lib/module/screenTracker.js +42 -4
  302. package/lib/module/screenTracker.js.map +1 -1
  303. package/lib/module/surfaces/CardFade.js +26 -0
  304. package/lib/module/surfaces/CardFade.js.map +1 -0
  305. package/lib/module/surfaces/CloseButton.js +10 -6
  306. package/lib/module/surfaces/CloseButton.js.map +1 -1
  307. package/lib/module/surfaces/ModalSurface.js +52 -36
  308. package/lib/module/surfaces/ModalSurface.js.map +1 -1
  309. package/lib/module/surfaces/TooltipSurface.js +368 -90
  310. package/lib/module/surfaces/TooltipSurface.js.map +1 -1
  311. package/lib/module/surfaces/cardTransition.js +64 -0
  312. package/lib/module/surfaces/cardTransition.js.map +1 -0
  313. package/lib/module/surfaces/resolveHighlightChrome.js +102 -0
  314. package/lib/module/surfaces/resolveHighlightChrome.js.map +1 -0
  315. package/lib/module/surfaces/resolveModalLayout.js +7 -3
  316. package/lib/module/surfaces/resolveModalLayout.js.map +1 -1
  317. package/lib/module/surfaces/resolveTooltipLayout.js +1 -4
  318. package/lib/module/surfaces/resolveTooltipLayout.js.map +1 -1
  319. package/lib/module/surfaces/surfaceInteractionConfig.js +27 -0
  320. package/lib/module/surfaces/surfaceInteractionConfig.js.map +1 -0
  321. package/lib/module/surfaces/surfaceLayoutInsets.js +119 -0
  322. package/lib/module/surfaces/surfaceLayoutInsets.js.map +1 -0
  323. package/lib/module/surfaces/themeChrome.js +3 -1
  324. package/lib/module/surfaces/themeChrome.js.map +1 -1
  325. package/lib/module/surfaces/tooltip/TooltipBubble.js +143 -22
  326. package/lib/module/surfaces/tooltip/TooltipBubble.js.map +1 -1
  327. package/lib/module/surfaces/tooltip/TooltipCutout.js +100 -47
  328. package/lib/module/surfaces/tooltip/TooltipCutout.js.map +1 -1
  329. package/lib/module/surfaces/tooltip/TooltipHighlight.js +118 -0
  330. package/lib/module/surfaces/tooltip/TooltipHighlight.js.map +1 -0
  331. package/lib/module/surfaces/tooltip/computeTooltipPosition.js +67 -13
  332. package/lib/module/surfaces/tooltip/computeTooltipPosition.js.map +1 -1
  333. package/lib/module/surfaces/tooltip/inferTooltipPlacement.js +87 -19
  334. package/lib/module/surfaces/tooltip/inferTooltipPlacement.js.map +1 -1
  335. package/lib/module/surfaces/tooltip/placementDiagnostics.js +43 -0
  336. package/lib/module/surfaces/tooltip/placementDiagnostics.js.map +1 -0
  337. package/lib/module/surfaces/tooltip/rect.js +11 -0
  338. package/lib/module/surfaces/tooltip/rect.js.map +1 -1
  339. package/lib/module/surfaces/tooltip/resolveSideCardWidth.js +96 -0
  340. package/lib/module/surfaces/tooltip/resolveSideCardWidth.js.map +1 -0
  341. package/lib/module/version.js +1 -1
  342. package/lib/typescript/commonjs/src/anchors/AutoAnchorRegistry.d.ts +27 -1
  343. package/lib/typescript/commonjs/src/anchors/AutoAnchorRegistry.d.ts.map +1 -1
  344. package/lib/typescript/commonjs/src/anchors/anchorChangeTicker.d.ts +2 -0
  345. package/lib/typescript/commonjs/src/anchors/anchorChangeTicker.d.ts.map +1 -1
  346. package/lib/typescript/commonjs/src/anchors/autoAnchor.d.ts +1 -1
  347. package/lib/typescript/commonjs/src/anchors/elementConditionEvaluator.d.ts +14 -10
  348. package/lib/typescript/commonjs/src/anchors/elementConditionEvaluator.d.ts.map +1 -1
  349. package/lib/typescript/commonjs/src/anchors/fiber/FiberScanRoot.d.ts +1 -20
  350. package/lib/typescript/commonjs/src/anchors/fiber/FiberScanRoot.d.ts.map +1 -1
  351. package/lib/typescript/commonjs/src/anchors/fiber/FiberScanRootStore.d.ts +21 -0
  352. package/lib/typescript/commonjs/src/anchors/fiber/FiberScanRootStore.d.ts.map +1 -0
  353. package/lib/typescript/commonjs/src/anchors/fiber/fiberInternals.d.ts +42 -1
  354. package/lib/typescript/commonjs/src/anchors/fiber/fiberInternals.d.ts.map +1 -1
  355. package/lib/typescript/commonjs/src/anchors/fiber/indexHostFibers.d.ts +42 -0
  356. package/lib/typescript/commonjs/src/anchors/fiber/indexHostFibers.d.ts.map +1 -0
  357. package/lib/typescript/commonjs/src/anchors/fiber/readHostContent.d.ts +17 -0
  358. package/lib/typescript/commonjs/src/anchors/fiber/readHostContent.d.ts.map +1 -0
  359. package/lib/typescript/commonjs/src/anchors/fiberAnchorCache.d.ts +20 -0
  360. package/lib/typescript/commonjs/src/anchors/fiberAnchorCache.d.ts.map +1 -0
  361. package/lib/typescript/commonjs/src/anchors/hintsCodec.d.ts +1 -1
  362. package/lib/typescript/commonjs/src/anchors/resolveAnchorHost.d.ts +5 -5
  363. package/lib/typescript/commonjs/src/anchors/resolveAnchorHost.d.ts.map +1 -1
  364. package/lib/typescript/commonjs/src/anchors/resolveAutoAnchorHost.d.ts +38 -0
  365. package/lib/typescript/commonjs/src/anchors/resolveAutoAnchorHost.d.ts.map +1 -0
  366. package/lib/typescript/commonjs/src/anchors/semanticMatcher.d.ts +48 -0
  367. package/lib/typescript/commonjs/src/anchors/semanticMatcher.d.ts.map +1 -0
  368. package/lib/typescript/commonjs/src/authoring/ElementPickerOverlay.d.ts +7 -0
  369. package/lib/typescript/commonjs/src/authoring/ElementPickerOverlay.d.ts.map +1 -0
  370. package/lib/typescript/commonjs/src/authoring/capturePickerScreenshot.d.ts +11 -0
  371. package/lib/typescript/commonjs/src/authoring/capturePickerScreenshot.d.ts.map +1 -0
  372. package/lib/typescript/commonjs/src/authoring/chrome/ChromeBarTransition.d.ts +32 -0
  373. package/lib/typescript/commonjs/src/authoring/chrome/ChromeBarTransition.d.ts.map +1 -0
  374. package/lib/typescript/commonjs/src/authoring/chrome/ChromeBottomSheet.d.ts +13 -0
  375. package/lib/typescript/commonjs/src/authoring/chrome/ChromeBottomSheet.d.ts.map +1 -0
  376. package/lib/typescript/commonjs/src/authoring/chrome/ChromeButton.d.ts +20 -0
  377. package/lib/typescript/commonjs/src/authoring/chrome/ChromeButton.d.ts.map +1 -0
  378. package/lib/typescript/commonjs/src/authoring/chrome/ChromeDialog.d.ts +14 -0
  379. package/lib/typescript/commonjs/src/authoring/chrome/ChromeDialog.d.ts.map +1 -0
  380. package/lib/typescript/commonjs/src/authoring/chrome/ChromeIcon.d.ts +13 -0
  381. package/lib/typescript/commonjs/src/authoring/chrome/ChromeIcon.d.ts.map +1 -0
  382. package/lib/typescript/commonjs/src/authoring/chrome/ChromeTooltip.d.ts +17 -0
  383. package/lib/typescript/commonjs/src/authoring/chrome/ChromeTooltip.d.ts.map +1 -0
  384. package/lib/typescript/commonjs/src/authoring/chrome/ChromeTopBar.d.ts +25 -0
  385. package/lib/typescript/commonjs/src/authoring/chrome/ChromeTopBar.d.ts.map +1 -0
  386. package/lib/typescript/commonjs/src/authoring/chrome/DoubleTapBridge.d.ts +12 -0
  387. package/lib/typescript/commonjs/src/authoring/chrome/DoubleTapBridge.d.ts.map +1 -0
  388. package/lib/typescript/commonjs/src/authoring/chrome/doubleTapMonitor.d.ts +26 -0
  389. package/lib/typescript/commonjs/src/authoring/chrome/doubleTapMonitor.d.ts.map +1 -0
  390. package/lib/typescript/commonjs/src/authoring/chrome/tokens.d.ts +141 -0
  391. package/lib/typescript/commonjs/src/authoring/chrome/tokens.d.ts.map +1 -0
  392. package/lib/typescript/commonjs/src/authoring/doubleTap.d.ts +14 -0
  393. package/lib/typescript/commonjs/src/authoring/doubleTap.d.ts.map +1 -0
  394. package/lib/typescript/commonjs/src/authoring/elementPickerController.d.ts +59 -0
  395. package/lib/typescript/commonjs/src/authoring/elementPickerController.d.ts.map +1 -0
  396. package/lib/typescript/commonjs/src/authoring/fingerprintFromInstance.d.ts +26 -0
  397. package/lib/typescript/commonjs/src/authoring/fingerprintFromInstance.d.ts.map +1 -0
  398. package/lib/typescript/commonjs/src/authoring/hitTest.d.ts +31 -0
  399. package/lib/typescript/commonjs/src/authoring/hitTest.d.ts.map +1 -0
  400. package/lib/typescript/commonjs/src/content/RichContentRenderer.d.ts +6 -1
  401. package/lib/typescript/commonjs/src/content/RichContentRenderer.d.ts.map +1 -1
  402. package/lib/typescript/commonjs/src/content/StepButton.d.ts.map +1 -1
  403. package/lib/typescript/commonjs/src/content/resolveStepButtonChrome.d.ts.map +1 -1
  404. package/lib/typescript/commonjs/src/content/themeColor.d.ts +5 -0
  405. package/lib/typescript/commonjs/src/content/themeColor.d.ts.map +1 -1
  406. package/lib/typescript/commonjs/src/deviceContext.d.ts +66 -0
  407. package/lib/typescript/commonjs/src/deviceContext.d.ts.map +1 -0
  408. package/lib/typescript/commonjs/src/expo-router/useUserflowExpoRouter.d.ts.map +1 -1
  409. package/lib/typescript/commonjs/src/hostAppVersion.d.ts +69 -0
  410. package/lib/typescript/commonjs/src/hostAppVersion.d.ts.map +1 -0
  411. package/lib/typescript/commonjs/src/index.d.ts +53 -2
  412. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  413. package/lib/typescript/commonjs/src/lifecycle.d.ts +6 -0
  414. package/lib/typescript/commonjs/src/lifecycle.d.ts.map +1 -1
  415. package/lib/typescript/commonjs/src/navigation/WithUserflowReactNavigation.d.ts.map +1 -1
  416. package/lib/typescript/commonjs/src/navigation/isOverlayPresentation.d.ts +14 -0
  417. package/lib/typescript/commonjs/src/navigation/isOverlayPresentation.d.ts.map +1 -0
  418. package/lib/typescript/commonjs/src/pairing/PairingController.d.ts +7 -0
  419. package/lib/typescript/commonjs/src/pairing/PairingController.d.ts.map +1 -1
  420. package/lib/typescript/commonjs/src/pairing/PreviewModeBanner.d.ts +6 -1
  421. package/lib/typescript/commonjs/src/pairing/PreviewModeBanner.d.ts.map +1 -1
  422. package/lib/typescript/commonjs/src/pairing/diagnostics.d.ts +5 -0
  423. package/lib/typescript/commonjs/src/pairing/diagnostics.d.ts.map +1 -1
  424. package/lib/typescript/commonjs/src/pairing/elementPickerRelay.d.ts +11 -0
  425. package/lib/typescript/commonjs/src/pairing/elementPickerRelay.d.ts.map +1 -0
  426. package/lib/typescript/commonjs/src/pairing/resolvePreviewChrome.d.ts +16 -0
  427. package/lib/typescript/commonjs/src/pairing/resolvePreviewChrome.d.ts.map +1 -0
  428. package/lib/typescript/commonjs/src/pairing/tokenStorage.d.ts +2 -0
  429. package/lib/typescript/commonjs/src/pairing/tokenStorage.d.ts.map +1 -1
  430. package/lib/typescript/commonjs/src/pairing/usePairingState.d.ts.map +1 -1
  431. package/lib/typescript/commonjs/src/runtime/FlowRenderer.d.ts +6 -3
  432. package/lib/typescript/commonjs/src/runtime/FlowRenderer.d.ts.map +1 -1
  433. package/lib/typescript/commonjs/src/runtime/FlowSurfaceFade.d.ts +20 -7
  434. package/lib/typescript/commonjs/src/runtime/FlowSurfaceFade.d.ts.map +1 -1
  435. package/lib/typescript/commonjs/src/runtime/TargetPressBridge.d.ts +5 -1
  436. package/lib/typescript/commonjs/src/runtime/TargetPressBridge.d.ts.map +1 -1
  437. package/lib/typescript/commonjs/src/runtime/UserflowProvider.d.ts +6 -4
  438. package/lib/typescript/commonjs/src/runtime/UserflowProvider.d.ts.map +1 -1
  439. package/lib/typescript/commonjs/src/runtime/changedTouchPoints.d.ts +10 -0
  440. package/lib/typescript/commonjs/src/runtime/changedTouchPoints.d.ts.map +1 -0
  441. package/lib/typescript/commonjs/src/runtime/flowEngine.d.ts.map +1 -1
  442. package/lib/typescript/commonjs/src/runtime/flowSessionViewState.d.ts +12 -3
  443. package/lib/typescript/commonjs/src/runtime/flowSessionViewState.d.ts.map +1 -1
  444. package/lib/typescript/commonjs/src/runtime/useFlowSessionState.d.ts +1 -0
  445. package/lib/typescript/commonjs/src/runtime/useFlowSessionState.d.ts.map +1 -1
  446. package/lib/typescript/commonjs/src/screenTracker.d.ts +21 -3
  447. package/lib/typescript/commonjs/src/screenTracker.d.ts.map +1 -1
  448. package/lib/typescript/commonjs/src/surfaces/CardFade.d.ts +12 -0
  449. package/lib/typescript/commonjs/src/surfaces/CardFade.d.ts.map +1 -0
  450. package/lib/typescript/commonjs/src/surfaces/CloseButton.d.ts +8 -2
  451. package/lib/typescript/commonjs/src/surfaces/CloseButton.d.ts.map +1 -1
  452. package/lib/typescript/commonjs/src/surfaces/MadeWithUserflow.d.ts +1 -1
  453. package/lib/typescript/commonjs/src/surfaces/ModalSurface.d.ts +1 -1
  454. package/lib/typescript/commonjs/src/surfaces/ModalSurface.d.ts.map +1 -1
  455. package/lib/typescript/commonjs/src/surfaces/TooltipSurface.d.ts +12 -1
  456. package/lib/typescript/commonjs/src/surfaces/TooltipSurface.d.ts.map +1 -1
  457. package/lib/typescript/commonjs/src/surfaces/cardTransition.d.ts +31 -0
  458. package/lib/typescript/commonjs/src/surfaces/cardTransition.d.ts.map +1 -0
  459. package/lib/typescript/commonjs/src/surfaces/resolveHighlightChrome.d.ts +44 -0
  460. package/lib/typescript/commonjs/src/surfaces/resolveHighlightChrome.d.ts.map +1 -0
  461. package/lib/typescript/commonjs/src/surfaces/resolveModalLayout.d.ts +1 -1
  462. package/lib/typescript/commonjs/src/surfaces/resolveModalLayout.d.ts.map +1 -1
  463. package/lib/typescript/commonjs/src/surfaces/resolveTooltipLayout.d.ts +0 -7
  464. package/lib/typescript/commonjs/src/surfaces/resolveTooltipLayout.d.ts.map +1 -1
  465. package/lib/typescript/commonjs/src/surfaces/surfaceInteractionConfig.d.ts +15 -0
  466. package/lib/typescript/commonjs/src/surfaces/surfaceInteractionConfig.d.ts.map +1 -0
  467. package/lib/typescript/commonjs/src/surfaces/surfaceLayoutInsets.d.ts +38 -0
  468. package/lib/typescript/commonjs/src/surfaces/surfaceLayoutInsets.d.ts.map +1 -0
  469. package/lib/typescript/commonjs/src/surfaces/themeChrome.d.ts +3 -1
  470. package/lib/typescript/commonjs/src/surfaces/themeChrome.d.ts.map +1 -1
  471. package/lib/typescript/commonjs/src/surfaces/tooltip/TooltipBubble.d.ts +21 -6
  472. package/lib/typescript/commonjs/src/surfaces/tooltip/TooltipBubble.d.ts.map +1 -1
  473. package/lib/typescript/commonjs/src/surfaces/tooltip/TooltipCutout.d.ts +18 -10
  474. package/lib/typescript/commonjs/src/surfaces/tooltip/TooltipCutout.d.ts.map +1 -1
  475. package/lib/typescript/commonjs/src/surfaces/tooltip/TooltipHighlight.d.ts +25 -0
  476. package/lib/typescript/commonjs/src/surfaces/tooltip/TooltipHighlight.d.ts.map +1 -0
  477. package/lib/typescript/commonjs/src/surfaces/tooltip/computeTooltipPosition.d.ts +23 -0
  478. package/lib/typescript/commonjs/src/surfaces/tooltip/computeTooltipPosition.d.ts.map +1 -1
  479. package/lib/typescript/commonjs/src/surfaces/tooltip/inferTooltipPlacement.d.ts +47 -1
  480. package/lib/typescript/commonjs/src/surfaces/tooltip/inferTooltipPlacement.d.ts.map +1 -1
  481. package/lib/typescript/commonjs/src/surfaces/tooltip/placementDiagnostics.d.ts +39 -0
  482. package/lib/typescript/commonjs/src/surfaces/tooltip/placementDiagnostics.d.ts.map +1 -0
  483. package/lib/typescript/commonjs/src/surfaces/tooltip/rect.d.ts +2 -0
  484. package/lib/typescript/commonjs/src/surfaces/tooltip/rect.d.ts.map +1 -1
  485. package/lib/typescript/commonjs/src/surfaces/tooltip/resolveSideCardWidth.d.ts +76 -0
  486. package/lib/typescript/commonjs/src/surfaces/tooltip/resolveSideCardWidth.d.ts.map +1 -0
  487. package/lib/typescript/commonjs/src/version.d.ts +1 -1
  488. package/lib/typescript/module/src/anchors/AutoAnchorRegistry.d.ts +27 -1
  489. package/lib/typescript/module/src/anchors/AutoAnchorRegistry.d.ts.map +1 -1
  490. package/lib/typescript/module/src/anchors/anchorChangeTicker.d.ts +2 -0
  491. package/lib/typescript/module/src/anchors/anchorChangeTicker.d.ts.map +1 -1
  492. package/lib/typescript/module/src/anchors/autoAnchor.d.ts +1 -1
  493. package/lib/typescript/module/src/anchors/elementConditionEvaluator.d.ts +14 -10
  494. package/lib/typescript/module/src/anchors/elementConditionEvaluator.d.ts.map +1 -1
  495. package/lib/typescript/module/src/anchors/fiber/FiberScanRoot.d.ts +1 -20
  496. package/lib/typescript/module/src/anchors/fiber/FiberScanRoot.d.ts.map +1 -1
  497. package/lib/typescript/module/src/anchors/fiber/FiberScanRootStore.d.ts +21 -0
  498. package/lib/typescript/module/src/anchors/fiber/FiberScanRootStore.d.ts.map +1 -0
  499. package/lib/typescript/module/src/anchors/fiber/fiberInternals.d.ts +42 -1
  500. package/lib/typescript/module/src/anchors/fiber/fiberInternals.d.ts.map +1 -1
  501. package/lib/typescript/module/src/anchors/fiber/indexHostFibers.d.ts +42 -0
  502. package/lib/typescript/module/src/anchors/fiber/indexHostFibers.d.ts.map +1 -0
  503. package/lib/typescript/module/src/anchors/fiber/readHostContent.d.ts +17 -0
  504. package/lib/typescript/module/src/anchors/fiber/readHostContent.d.ts.map +1 -0
  505. package/lib/typescript/module/src/anchors/fiberAnchorCache.d.ts +20 -0
  506. package/lib/typescript/module/src/anchors/fiberAnchorCache.d.ts.map +1 -0
  507. package/lib/typescript/module/src/anchors/hintsCodec.d.ts +1 -1
  508. package/lib/typescript/module/src/anchors/resolveAnchorHost.d.ts +5 -5
  509. package/lib/typescript/module/src/anchors/resolveAnchorHost.d.ts.map +1 -1
  510. package/lib/typescript/module/src/anchors/resolveAutoAnchorHost.d.ts +38 -0
  511. package/lib/typescript/module/src/anchors/resolveAutoAnchorHost.d.ts.map +1 -0
  512. package/lib/typescript/module/src/anchors/semanticMatcher.d.ts +48 -0
  513. package/lib/typescript/module/src/anchors/semanticMatcher.d.ts.map +1 -0
  514. package/lib/typescript/module/src/authoring/ElementPickerOverlay.d.ts +7 -0
  515. package/lib/typescript/module/src/authoring/ElementPickerOverlay.d.ts.map +1 -0
  516. package/lib/typescript/module/src/authoring/capturePickerScreenshot.d.ts +11 -0
  517. package/lib/typescript/module/src/authoring/capturePickerScreenshot.d.ts.map +1 -0
  518. package/lib/typescript/module/src/authoring/chrome/ChromeBarTransition.d.ts +32 -0
  519. package/lib/typescript/module/src/authoring/chrome/ChromeBarTransition.d.ts.map +1 -0
  520. package/lib/typescript/module/src/authoring/chrome/ChromeBottomSheet.d.ts +13 -0
  521. package/lib/typescript/module/src/authoring/chrome/ChromeBottomSheet.d.ts.map +1 -0
  522. package/lib/typescript/module/src/authoring/chrome/ChromeButton.d.ts +20 -0
  523. package/lib/typescript/module/src/authoring/chrome/ChromeButton.d.ts.map +1 -0
  524. package/lib/typescript/module/src/authoring/chrome/ChromeDialog.d.ts +14 -0
  525. package/lib/typescript/module/src/authoring/chrome/ChromeDialog.d.ts.map +1 -0
  526. package/lib/typescript/module/src/authoring/chrome/ChromeIcon.d.ts +13 -0
  527. package/lib/typescript/module/src/authoring/chrome/ChromeIcon.d.ts.map +1 -0
  528. package/lib/typescript/module/src/authoring/chrome/ChromeTooltip.d.ts +17 -0
  529. package/lib/typescript/module/src/authoring/chrome/ChromeTooltip.d.ts.map +1 -0
  530. package/lib/typescript/module/src/authoring/chrome/ChromeTopBar.d.ts +25 -0
  531. package/lib/typescript/module/src/authoring/chrome/ChromeTopBar.d.ts.map +1 -0
  532. package/lib/typescript/module/src/authoring/chrome/DoubleTapBridge.d.ts +12 -0
  533. package/lib/typescript/module/src/authoring/chrome/DoubleTapBridge.d.ts.map +1 -0
  534. package/lib/typescript/module/src/authoring/chrome/doubleTapMonitor.d.ts +26 -0
  535. package/lib/typescript/module/src/authoring/chrome/doubleTapMonitor.d.ts.map +1 -0
  536. package/lib/typescript/module/src/authoring/chrome/tokens.d.ts +141 -0
  537. package/lib/typescript/module/src/authoring/chrome/tokens.d.ts.map +1 -0
  538. package/lib/typescript/module/src/authoring/doubleTap.d.ts +14 -0
  539. package/lib/typescript/module/src/authoring/doubleTap.d.ts.map +1 -0
  540. package/lib/typescript/module/src/authoring/elementPickerController.d.ts +59 -0
  541. package/lib/typescript/module/src/authoring/elementPickerController.d.ts.map +1 -0
  542. package/lib/typescript/module/src/authoring/fingerprintFromInstance.d.ts +26 -0
  543. package/lib/typescript/module/src/authoring/fingerprintFromInstance.d.ts.map +1 -0
  544. package/lib/typescript/module/src/authoring/hitTest.d.ts +31 -0
  545. package/lib/typescript/module/src/authoring/hitTest.d.ts.map +1 -0
  546. package/lib/typescript/module/src/content/RichContentRenderer.d.ts +6 -1
  547. package/lib/typescript/module/src/content/RichContentRenderer.d.ts.map +1 -1
  548. package/lib/typescript/module/src/content/StepButton.d.ts.map +1 -1
  549. package/lib/typescript/module/src/content/resolveStepButtonChrome.d.ts.map +1 -1
  550. package/lib/typescript/module/src/content/themeColor.d.ts +5 -0
  551. package/lib/typescript/module/src/content/themeColor.d.ts.map +1 -1
  552. package/lib/typescript/module/src/deviceContext.d.ts +66 -0
  553. package/lib/typescript/module/src/deviceContext.d.ts.map +1 -0
  554. package/lib/typescript/module/src/expo-router/useUserflowExpoRouter.d.ts.map +1 -1
  555. package/lib/typescript/module/src/hostAppVersion.d.ts +69 -0
  556. package/lib/typescript/module/src/hostAppVersion.d.ts.map +1 -0
  557. package/lib/typescript/module/src/index.d.ts +53 -2
  558. package/lib/typescript/module/src/index.d.ts.map +1 -1
  559. package/lib/typescript/module/src/lifecycle.d.ts +6 -0
  560. package/lib/typescript/module/src/lifecycle.d.ts.map +1 -1
  561. package/lib/typescript/module/src/navigation/WithUserflowReactNavigation.d.ts.map +1 -1
  562. package/lib/typescript/module/src/navigation/isOverlayPresentation.d.ts +14 -0
  563. package/lib/typescript/module/src/navigation/isOverlayPresentation.d.ts.map +1 -0
  564. package/lib/typescript/module/src/pairing/PairingController.d.ts +7 -0
  565. package/lib/typescript/module/src/pairing/PairingController.d.ts.map +1 -1
  566. package/lib/typescript/module/src/pairing/PreviewModeBanner.d.ts +6 -1
  567. package/lib/typescript/module/src/pairing/PreviewModeBanner.d.ts.map +1 -1
  568. package/lib/typescript/module/src/pairing/diagnostics.d.ts +5 -0
  569. package/lib/typescript/module/src/pairing/diagnostics.d.ts.map +1 -1
  570. package/lib/typescript/module/src/pairing/elementPickerRelay.d.ts +11 -0
  571. package/lib/typescript/module/src/pairing/elementPickerRelay.d.ts.map +1 -0
  572. package/lib/typescript/module/src/pairing/resolvePreviewChrome.d.ts +16 -0
  573. package/lib/typescript/module/src/pairing/resolvePreviewChrome.d.ts.map +1 -0
  574. package/lib/typescript/module/src/pairing/tokenStorage.d.ts +2 -0
  575. package/lib/typescript/module/src/pairing/tokenStorage.d.ts.map +1 -1
  576. package/lib/typescript/module/src/pairing/usePairingState.d.ts.map +1 -1
  577. package/lib/typescript/module/src/runtime/FlowRenderer.d.ts +6 -3
  578. package/lib/typescript/module/src/runtime/FlowRenderer.d.ts.map +1 -1
  579. package/lib/typescript/module/src/runtime/FlowSurfaceFade.d.ts +20 -7
  580. package/lib/typescript/module/src/runtime/FlowSurfaceFade.d.ts.map +1 -1
  581. package/lib/typescript/module/src/runtime/TargetPressBridge.d.ts +5 -1
  582. package/lib/typescript/module/src/runtime/TargetPressBridge.d.ts.map +1 -1
  583. package/lib/typescript/module/src/runtime/UserflowProvider.d.ts +6 -4
  584. package/lib/typescript/module/src/runtime/UserflowProvider.d.ts.map +1 -1
  585. package/lib/typescript/module/src/runtime/changedTouchPoints.d.ts +10 -0
  586. package/lib/typescript/module/src/runtime/changedTouchPoints.d.ts.map +1 -0
  587. package/lib/typescript/module/src/runtime/flowEngine.d.ts.map +1 -1
  588. package/lib/typescript/module/src/runtime/flowSessionViewState.d.ts +12 -3
  589. package/lib/typescript/module/src/runtime/flowSessionViewState.d.ts.map +1 -1
  590. package/lib/typescript/module/src/runtime/useFlowSessionState.d.ts +1 -0
  591. package/lib/typescript/module/src/runtime/useFlowSessionState.d.ts.map +1 -1
  592. package/lib/typescript/module/src/screenTracker.d.ts +21 -3
  593. package/lib/typescript/module/src/screenTracker.d.ts.map +1 -1
  594. package/lib/typescript/module/src/surfaces/CardFade.d.ts +12 -0
  595. package/lib/typescript/module/src/surfaces/CardFade.d.ts.map +1 -0
  596. package/lib/typescript/module/src/surfaces/CloseButton.d.ts +8 -2
  597. package/lib/typescript/module/src/surfaces/CloseButton.d.ts.map +1 -1
  598. package/lib/typescript/module/src/surfaces/MadeWithUserflow.d.ts +1 -1
  599. package/lib/typescript/module/src/surfaces/ModalSurface.d.ts +1 -1
  600. package/lib/typescript/module/src/surfaces/ModalSurface.d.ts.map +1 -1
  601. package/lib/typescript/module/src/surfaces/TooltipSurface.d.ts +12 -1
  602. package/lib/typescript/module/src/surfaces/TooltipSurface.d.ts.map +1 -1
  603. package/lib/typescript/module/src/surfaces/cardTransition.d.ts +31 -0
  604. package/lib/typescript/module/src/surfaces/cardTransition.d.ts.map +1 -0
  605. package/lib/typescript/module/src/surfaces/resolveHighlightChrome.d.ts +44 -0
  606. package/lib/typescript/module/src/surfaces/resolveHighlightChrome.d.ts.map +1 -0
  607. package/lib/typescript/module/src/surfaces/resolveModalLayout.d.ts +1 -1
  608. package/lib/typescript/module/src/surfaces/resolveModalLayout.d.ts.map +1 -1
  609. package/lib/typescript/module/src/surfaces/resolveTooltipLayout.d.ts +0 -7
  610. package/lib/typescript/module/src/surfaces/resolveTooltipLayout.d.ts.map +1 -1
  611. package/lib/typescript/module/src/surfaces/surfaceInteractionConfig.d.ts +15 -0
  612. package/lib/typescript/module/src/surfaces/surfaceInteractionConfig.d.ts.map +1 -0
  613. package/lib/typescript/module/src/surfaces/surfaceLayoutInsets.d.ts +38 -0
  614. package/lib/typescript/module/src/surfaces/surfaceLayoutInsets.d.ts.map +1 -0
  615. package/lib/typescript/module/src/surfaces/themeChrome.d.ts +3 -1
  616. package/lib/typescript/module/src/surfaces/themeChrome.d.ts.map +1 -1
  617. package/lib/typescript/module/src/surfaces/tooltip/TooltipBubble.d.ts +21 -6
  618. package/lib/typescript/module/src/surfaces/tooltip/TooltipBubble.d.ts.map +1 -1
  619. package/lib/typescript/module/src/surfaces/tooltip/TooltipCutout.d.ts +18 -10
  620. package/lib/typescript/module/src/surfaces/tooltip/TooltipCutout.d.ts.map +1 -1
  621. package/lib/typescript/module/src/surfaces/tooltip/TooltipHighlight.d.ts +25 -0
  622. package/lib/typescript/module/src/surfaces/tooltip/TooltipHighlight.d.ts.map +1 -0
  623. package/lib/typescript/module/src/surfaces/tooltip/computeTooltipPosition.d.ts +23 -0
  624. package/lib/typescript/module/src/surfaces/tooltip/computeTooltipPosition.d.ts.map +1 -1
  625. package/lib/typescript/module/src/surfaces/tooltip/inferTooltipPlacement.d.ts +47 -1
  626. package/lib/typescript/module/src/surfaces/tooltip/inferTooltipPlacement.d.ts.map +1 -1
  627. package/lib/typescript/module/src/surfaces/tooltip/placementDiagnostics.d.ts +39 -0
  628. package/lib/typescript/module/src/surfaces/tooltip/placementDiagnostics.d.ts.map +1 -0
  629. package/lib/typescript/module/src/surfaces/tooltip/rect.d.ts +2 -0
  630. package/lib/typescript/module/src/surfaces/tooltip/rect.d.ts.map +1 -1
  631. package/lib/typescript/module/src/surfaces/tooltip/resolveSideCardWidth.d.ts +76 -0
  632. package/lib/typescript/module/src/surfaces/tooltip/resolveSideCardWidth.d.ts.map +1 -0
  633. package/lib/typescript/module/src/version.d.ts +1 -1
  634. package/package.json +32 -18
  635. package/src/anchors/AutoAnchorRegistry.ts +140 -3
  636. package/src/anchors/anchorChangeTicker.ts +10 -0
  637. package/src/anchors/autoAnchor.ts +1 -1
  638. package/src/anchors/elementConditionEvaluator.ts +29 -16
  639. package/src/anchors/fiber/FiberScanRoot.tsx +2 -50
  640. package/src/anchors/fiber/FiberScanRootStore.ts +51 -0
  641. package/src/anchors/fiber/fiberInternals.ts +166 -3
  642. package/src/anchors/fiber/indexHostFibers.ts +136 -0
  643. package/src/anchors/fiber/readHostContent.ts +146 -0
  644. package/src/anchors/fiberAnchorCache.ts +45 -0
  645. package/src/anchors/hintsCodec.ts +1 -1
  646. package/src/anchors/resolveAnchorHost.ts +23 -23
  647. package/src/anchors/resolveAutoAnchorHost.ts +180 -0
  648. package/src/anchors/semanticMatcher.ts +361 -0
  649. package/src/authoring/ElementPickerOverlay.tsx +553 -0
  650. package/src/authoring/capturePickerScreenshot.ts +90 -0
  651. package/src/authoring/chrome/ChromeBarTransition.tsx +106 -0
  652. package/src/authoring/chrome/ChromeBottomSheet.tsx +69 -0
  653. package/src/authoring/chrome/ChromeButton.tsx +103 -0
  654. package/src/authoring/chrome/ChromeDialog.tsx +121 -0
  655. package/src/authoring/chrome/ChromeIcon.tsx +40 -0
  656. package/src/authoring/chrome/ChromeTooltip.tsx +89 -0
  657. package/src/authoring/chrome/ChromeTopBar.tsx +126 -0
  658. package/src/authoring/chrome/DoubleTapBridge.tsx +60 -0
  659. package/src/authoring/chrome/doubleTapMonitor.ts +80 -0
  660. package/src/authoring/chrome/icons/arrow-left-from-bracket.png +0 -0
  661. package/src/authoring/chrome/icons/arrow-left-from-bracket@2x.png +0 -0
  662. package/src/authoring/chrome/icons/arrow-left-from-bracket@3x.png +0 -0
  663. package/src/authoring/chrome/icons/arrow-rotate-left.png +0 -0
  664. package/src/authoring/chrome/icons/arrow-rotate-left@2x.png +0 -0
  665. package/src/authoring/chrome/icons/arrow-rotate-left@3x.png +0 -0
  666. package/src/authoring/chrome/icons/userflow-logomark.png +0 -0
  667. package/src/authoring/chrome/icons/userflow-logomark@2x.png +0 -0
  668. package/src/authoring/chrome/icons/userflow-logomark@3x.png +0 -0
  669. package/src/authoring/chrome/icons/xmark.png +0 -0
  670. package/src/authoring/chrome/icons/xmark@2x.png +0 -0
  671. package/src/authoring/chrome/icons/xmark@3x.png +0 -0
  672. package/src/authoring/chrome/tokens.ts +106 -0
  673. package/src/authoring/doubleTap.ts +27 -0
  674. package/src/authoring/elementPickerController.ts +135 -0
  675. package/src/authoring/fingerprintFromInstance.ts +152 -0
  676. package/src/authoring/hitTest.ts +133 -0
  677. package/src/content/RichContentRenderer.tsx +22 -1
  678. package/src/content/StepButton.tsx +17 -2
  679. package/src/content/resolveStepButtonChrome.ts +12 -6
  680. package/src/content/themeColor.ts +10 -0
  681. package/src/deviceContext.ts +168 -0
  682. package/src/expo-router/useUserflowExpoRouter.ts +47 -4
  683. package/src/hostAppVersion.ts +258 -0
  684. package/src/index.ts +148 -4
  685. package/src/lifecycle.ts +8 -0
  686. package/src/navigation/WithUserflowReactNavigation.tsx +23 -7
  687. package/src/navigation/isOverlayPresentation.ts +76 -0
  688. package/src/pairing/PairingController.ts +32 -3
  689. package/src/pairing/PreviewModeBanner.tsx +250 -94
  690. package/src/pairing/diagnostics.ts +10 -2
  691. package/src/pairing/elementPickerRelay.ts +100 -0
  692. package/src/pairing/resolvePreviewChrome.ts +57 -0
  693. package/src/pairing/tokenStorage.ts +31 -2
  694. package/src/pairing/usePairingState.ts +2 -0
  695. package/src/runtime/FlowRenderer.tsx +55 -27
  696. package/src/runtime/FlowSurfaceFade.tsx +51 -30
  697. package/src/runtime/TargetPressBridge.tsx +14 -32
  698. package/src/runtime/UserflowProvider.tsx +76 -13
  699. package/src/runtime/changedTouchPoints.ts +34 -0
  700. package/src/runtime/flowEngine.ts +2 -0
  701. package/src/runtime/flowSessionViewState.ts +42 -4
  702. package/src/runtime/useFlowSessionState.ts +2 -0
  703. package/src/screenTracker.ts +46 -4
  704. package/src/surfaces/CardFade.tsx +18 -0
  705. package/src/surfaces/CloseButton.tsx +17 -7
  706. package/src/surfaces/MadeWithUserflow.tsx +1 -1
  707. package/src/surfaces/ModalSurface.tsx +48 -35
  708. package/src/surfaces/TooltipSurface.tsx +406 -86
  709. package/src/surfaces/cardTransition.ts +67 -0
  710. package/src/surfaces/resolveHighlightChrome.ts +139 -0
  711. package/src/surfaces/resolveModalLayout.ts +16 -8
  712. package/src/surfaces/resolveTooltipLayout.ts +1 -14
  713. package/src/surfaces/surfaceInteractionConfig.ts +25 -0
  714. package/src/surfaces/surfaceLayoutInsets.tsx +135 -0
  715. package/src/surfaces/themeChrome.ts +5 -3
  716. package/src/surfaces/tooltip/TooltipBubble.tsx +154 -19
  717. package/src/surfaces/tooltip/TooltipCutout.tsx +106 -49
  718. package/src/surfaces/tooltip/TooltipHighlight.tsx +144 -0
  719. package/src/surfaces/tooltip/computeTooltipPosition.ts +98 -12
  720. package/src/surfaces/tooltip/inferTooltipPlacement.ts +107 -18
  721. package/src/surfaces/tooltip/placementDiagnostics.ts +70 -0
  722. package/src/surfaces/tooltip/rect.ts +11 -0
  723. package/src/surfaces/tooltip/resolveSideCardWidth.ts +121 -0
  724. package/src/version.ts +1 -1
  725. package/vendor/core/LICENSE +76 -0
  726. package/vendor/core/README.md +9 -0
  727. package/vendor/core/dist/attributes.d.ts +15 -0
  728. package/vendor/core/dist/attributes.d.ts.map +1 -0
  729. package/vendor/core/dist/attributes.js +55 -0
  730. package/vendor/core/dist/attributes.js.map +1 -0
  731. package/vendor/core/dist/constants.d.ts +21 -0
  732. package/vendor/core/dist/constants.d.ts.map +1 -0
  733. package/vendor/core/dist/constants.js +21 -0
  734. package/vendor/core/dist/constants.js.map +1 -0
  735. package/vendor/core/dist/engine/ClientConditionEngine.d.ts +68 -0
  736. package/vendor/core/dist/engine/ClientConditionEngine.d.ts.map +1 -0
  737. package/vendor/core/dist/engine/ClientConditionEngine.js +197 -0
  738. package/vendor/core/dist/engine/ClientConditionEngine.js.map +1 -0
  739. package/vendor/core/dist/engine/FlowSessionEngine.d.ts +160 -0
  740. package/vendor/core/dist/engine/FlowSessionEngine.d.ts.map +1 -0
  741. package/vendor/core/dist/engine/FlowSessionEngine.js +571 -0
  742. package/vendor/core/dist/engine/FlowSessionEngine.js.map +1 -0
  743. package/vendor/core/dist/engine/PairingEngine.d.ts +135 -0
  744. package/vendor/core/dist/engine/PairingEngine.d.ts.map +1 -0
  745. package/vendor/core/dist/engine/PairingEngine.js +396 -0
  746. package/vendor/core/dist/engine/PairingEngine.js.map +1 -0
  747. package/vendor/core/dist/engine/UserflowCore.d.ts +145 -0
  748. package/vendor/core/dist/engine/UserflowCore.d.ts.map +1 -0
  749. package/vendor/core/dist/engine/UserflowCore.js +329 -0
  750. package/vendor/core/dist/engine/UserflowCore.js.map +1 -0
  751. package/vendor/core/dist/engine/conditionOperators.d.ts +16 -0
  752. package/vendor/core/dist/engine/conditionOperators.d.ts.map +1 -0
  753. package/vendor/core/dist/engine/conditionOperators.js +168 -0
  754. package/vendor/core/dist/engine/conditionOperators.js.map +1 -0
  755. package/vendor/core/dist/engine/handleActions.d.ts +42 -0
  756. package/vendor/core/dist/engine/handleActions.d.ts.map +1 -0
  757. package/vendor/core/dist/engine/handleActions.js +198 -0
  758. package/vendor/core/dist/engine/handleActions.js.map +1 -0
  759. package/vendor/core/dist/engine/interpolateSessionData.d.ts +7 -0
  760. package/vendor/core/dist/engine/interpolateSessionData.d.ts.map +1 -0
  761. package/vendor/core/dist/engine/interpolateSessionData.js +29 -0
  762. package/vendor/core/dist/engine/interpolateSessionData.js.map +1 -0
  763. package/vendor/core/dist/engine/simpleObservable.d.ts +13 -0
  764. package/vendor/core/dist/engine/simpleObservable.d.ts.map +1 -0
  765. package/vendor/core/dist/engine/simpleObservable.js +29 -0
  766. package/vendor/core/dist/engine/simpleObservable.js.map +1 -0
  767. package/vendor/core/dist/engine/trackCondition.d.ts +25 -0
  768. package/vendor/core/dist/engine/trackCondition.d.ts.map +1 -0
  769. package/vendor/core/dist/engine/trackCondition.js +177 -0
  770. package/vendor/core/dist/engine/trackCondition.js.map +1 -0
  771. package/vendor/core/dist/engine/trackStepTriggers.d.ts +21 -0
  772. package/vendor/core/dist/engine/trackStepTriggers.d.ts.map +1 -0
  773. package/vendor/core/dist/engine/trackStepTriggers.js +49 -0
  774. package/vendor/core/dist/engine/trackStepTriggers.js.map +1 -0
  775. package/vendor/core/dist/errors.d.ts +9 -0
  776. package/vendor/core/dist/errors.d.ts.map +1 -0
  777. package/vendor/core/dist/errors.js +15 -0
  778. package/vendor/core/dist/errors.js.map +1 -0
  779. package/vendor/core/dist/eventAttributes.d.ts +7 -0
  780. package/vendor/core/dist/eventAttributes.d.ts.map +1 -0
  781. package/vendor/core/dist/eventAttributes.js +31 -0
  782. package/vendor/core/dist/eventAttributes.js.map +1 -0
  783. package/vendor/core/dist/index.d.ts +31 -0
  784. package/vendor/core/dist/index.d.ts.map +1 -0
  785. package/vendor/core/dist/index.js +22 -0
  786. package/vendor/core/dist/index.js.map +1 -0
  787. package/vendor/core/dist/normalizeAttributes.d.ts +8 -0
  788. package/vendor/core/dist/normalizeAttributes.d.ts.map +1 -0
  789. package/vendor/core/dist/normalizeAttributes.js +127 -0
  790. package/vendor/core/dist/normalizeAttributes.js.map +1 -0
  791. package/vendor/core/dist/transport/backoff.d.ts +11 -0
  792. package/vendor/core/dist/transport/backoff.d.ts.map +1 -0
  793. package/vendor/core/dist/transport/backoff.js +17 -0
  794. package/vendor/core/dist/transport/backoff.js.map +1 -0
  795. package/vendor/core/dist/transport/pairing.d.ts +121 -0
  796. package/vendor/core/dist/transport/pairing.d.ts.map +1 -0
  797. package/vendor/core/dist/transport/pairing.js +551 -0
  798. package/vendor/core/dist/transport/pairing.js.map +1 -0
  799. package/vendor/core/dist/transport/phoenix.d.ts +228 -0
  800. package/vendor/core/dist/transport/phoenix.d.ts.map +1 -0
  801. package/vendor/core/dist/transport/phoenix.js +811 -0
  802. package/vendor/core/dist/transport/phoenix.js.map +1 -0
  803. package/vendor/core/dist/transport/rateLimiter.d.ts +17 -0
  804. package/vendor/core/dist/transport/rateLimiter.d.ts.map +1 -0
  805. package/vendor/core/dist/transport/rateLimiter.js +30 -0
  806. package/vendor/core/dist/transport/rateLimiter.js.map +1 -0
  807. package/vendor/core/dist/transport/scheduler.d.ts +12 -0
  808. package/vendor/core/dist/transport/scheduler.d.ts.map +1 -0
  809. package/vendor/core/dist/transport/scheduler.js +11 -0
  810. package/vendor/core/dist/transport/scheduler.js.map +1 -0
  811. package/vendor/core/dist/types.d.ts +60 -0
  812. package/vendor/core/dist/types.d.ts.map +1 -0
  813. package/vendor/core/dist/types.js +2 -0
  814. package/vendor/core/dist/types.js.map +1 -0
  815. package/vendor/core/dist/version.d.ts +3 -0
  816. package/vendor/core/dist/version.d.ts.map +1 -0
  817. package/vendor/core/dist/version.js +3 -0
  818. package/vendor/core/dist/version.js.map +1 -0
  819. package/vendor/core/package.json +20 -0
  820. package/vendor/protocol/LICENSE +76 -0
  821. package/vendor/protocol/README.md +8 -0
  822. package/vendor/protocol/dist/attributes.d.ts +43 -0
  823. package/vendor/protocol/dist/attributes.d.ts.map +1 -0
  824. package/vendor/protocol/dist/attributes.js +15 -0
  825. package/vendor/protocol/dist/attributes.js.map +1 -0
  826. package/vendor/protocol/dist/autoData.d.ts +232 -0
  827. package/vendor/protocol/dist/autoData.d.ts.map +1 -0
  828. package/vendor/protocol/dist/autoData.js +78 -0
  829. package/vendor/protocol/dist/autoData.js.map +1 -0
  830. package/vendor/protocol/dist/events.d.ts +24 -0
  831. package/vendor/protocol/dist/events.d.ts.map +1 -0
  832. package/vendor/protocol/dist/events.js +8 -0
  833. package/vendor/protocol/dist/events.js.map +1 -0
  834. package/vendor/protocol/dist/flows.d.ts +360 -0
  835. package/vendor/protocol/dist/flows.d.ts.map +1 -0
  836. package/vendor/protocol/dist/flows.js +201 -0
  837. package/vendor/protocol/dist/flows.js.map +1 -0
  838. package/vendor/protocol/dist/index.d.ts +25 -0
  839. package/vendor/protocol/dist/index.d.ts.map +1 -0
  840. package/vendor/protocol/dist/index.js +17 -0
  841. package/vendor/protocol/dist/index.js.map +1 -0
  842. package/vendor/protocol/dist/messages.d.ts +187 -0
  843. package/vendor/protocol/dist/messages.d.ts.map +1 -0
  844. package/vendor/protocol/dist/messages.js +61 -0
  845. package/vendor/protocol/dist/messages.js.map +1 -0
  846. package/vendor/protocol/dist/pairing.d.ts +82 -0
  847. package/vendor/protocol/dist/pairing.d.ts.map +1 -0
  848. package/vendor/protocol/dist/pairing.js +146 -0
  849. package/vendor/protocol/dist/pairing.js.map +1 -0
  850. package/vendor/protocol/package.json +17 -0
@@ -0,0 +1,811 @@
1
+ import { isServerMessage, TargetPlatform } from '@userflow-tech/protocol';
2
+ import { UserflowAuthError, UserflowRateLimitError } from '../errors.js';
3
+ import { CORE_VERSION } from '../version.js';
4
+ import { createBackoff } from './backoff.js';
5
+ import { createRateLimiter, RATE_LIMIT_PER_MINUTE } from './rateLimiter.js';
6
+ import { defaultScheduler } from './scheduler.js';
7
+ const TIMEOUT_MS = 15000;
8
+ const HEARTBEAT_INTERVAL_MS = 30000;
9
+ /**
10
+ * How long to wait for a heartbeat reply before declaring the socket dead.
11
+ * A short, bounded liveness window (vs. waiting a full heartbeat interval)
12
+ * means a silently-dropped socket is detected in seconds instead of up to two
13
+ * intervals. Capped at the heartbeat interval so tiny test intervals behave.
14
+ */
15
+ const HEARTBEAT_REPLY_TIMEOUT_MS = 10000;
16
+ /** WebSocket.OPEN readyState, referenced without the DOM/global type. */
17
+ const WS_OPEN = 1;
18
+ const PHOENIX_TOPIC = 'phoenix';
19
+ const DEFAULT_CLIENT_CONTEXT = {
20
+ pageUrl: '',
21
+ viewportWidth: 390,
22
+ viewportHeight: 844,
23
+ };
24
+ /** Builds the Phoenix websocket URL for a given endpoint and client token. */
25
+ export function buildWsUrl(serverEndpoint, clientToken) {
26
+ const host = serverEndpoint.replace(/\/$/, '');
27
+ const path = `/end-users/${encodeURIComponent(clientToken)}/socket/websocket?vsn=2.0.0`;
28
+ if (host.startsWith('http://'))
29
+ return `ws://${host.slice('http://'.length)}${path}`;
30
+ if (host.startsWith('https://'))
31
+ return `wss://${host.slice('https://'.length)}${path}`;
32
+ if (host.startsWith('ws://') || host.startsWith('wss://'))
33
+ return `${host}${path}`;
34
+ return `wss://${host}${path}`;
35
+ }
36
+ function uuid() {
37
+ const webcrypto = globalThis.crypto;
38
+ if (webcrypto?.randomUUID)
39
+ return webcrypto.randomUUID();
40
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
41
+ const rand = (Math.random() * 16) | 0;
42
+ const value = char === 'x' ? rand : (rand & 0x3) | 0x8;
43
+ return value.toString(16);
44
+ });
45
+ }
46
+ function endUserJoinPayload(signature = null, flowSessionId = null, clientContext = DEFAULT_CLIENT_CONTEXT, clientConditions = []) {
47
+ return {
48
+ protocolVersion: 2,
49
+ userflowClientBuild: `mobile-${CORE_VERSION}`,
50
+ signature,
51
+ groupExternalId: null,
52
+ groupSignature: null,
53
+ flowSessionId,
54
+ checklistSessionId: null,
55
+ resourceCenterSessionId: null,
56
+ launchers: [],
57
+ trackers: [],
58
+ hasDraftSession: false,
59
+ clientConditions,
60
+ clientContext,
61
+ // Without this the server treats the socket as a web client and
62
+ // check_sessions immediately unsets any React Native draft preview.
63
+ targetPlatform: TargetPlatform.REACT_NATIVE,
64
+ };
65
+ }
66
+ function isSignatureRequiredError(error) {
67
+ return error instanceof UserflowAuthError && error.message.includes('user_signature_required');
68
+ }
69
+ function isNonIdempotentAttributeChange(value) {
70
+ if (value == null || typeof value !== 'object' || Array.isArray(value)) {
71
+ return false;
72
+ }
73
+ return 'add' in value || 'subtract' in value || 'append' in value || 'prepend' in value;
74
+ }
75
+ function attributesHaveNonIdempotentOps(attributes) {
76
+ if (attributes == null || typeof attributes !== 'object' || Array.isArray(attributes)) {
77
+ return false;
78
+ }
79
+ return Object.values(attributes).some(isNonIdempotentAttributeChange);
80
+ }
81
+ /** Idempotent client_message payloads may be replayed after a dropped ack. */
82
+ function isReplayableClientMessage(payload) {
83
+ if (payload == null || typeof payload !== 'object') {
84
+ return true;
85
+ }
86
+ const record = payload;
87
+ if (record.kind === 'UpsertUser') {
88
+ return !attributesHaveNonIdempotentOps(record.attributes);
89
+ }
90
+ if (record.kind === 'UpsertGroup') {
91
+ return (!attributesHaveNonIdempotentOps(record.groupAttributes) &&
92
+ !attributesHaveNonIdempotentOps(record.membershipAttributes));
93
+ }
94
+ return true;
95
+ }
96
+ function joinError(response) {
97
+ if (response && typeof response === 'object') {
98
+ const err = response;
99
+ if (err.code && err.message)
100
+ return `${err.code}: ${err.message}`;
101
+ if (err.message)
102
+ return err.message;
103
+ }
104
+ return 'channel join rejected';
105
+ }
106
+ function resolveSocketCtor(ctor) {
107
+ const provided = ctor ?? globalThis.WebSocket;
108
+ if (!provided) {
109
+ throw new UserflowAuthError('No WebSocket implementation is available');
110
+ }
111
+ return provided;
112
+ }
113
+ /**
114
+ * A resilient Phoenix websocket connection to the Userflow end-user endpoint.
115
+ * It speaks the v2 serialized frame protocol (`[joinRef, ref, topic, event,
116
+ * payload]`), tracks an explicit lifecycle, auto-reconnects with backoff,
117
+ * heartbeats to keep the socket alive, queues outbound pushes while
118
+ * disconnected, and can be suspended/resumed for app background handling.
119
+ *
120
+ * Liveness: each heartbeat arms a short reply deadline so a silently-dropped
121
+ * socket is detected in seconds rather than up to two heartbeat intervals.
122
+ * {@link ensureAlive} fires an immediate probe (e.g. on foreground or when the
123
+ * host reports connectivity restored) so recovery does not wait for the next
124
+ * scheduled heartbeat. This keeps recovery fast with zero external
125
+ * dependencies; a host-provided network signal that calls `ensureAlive` is an
126
+ * optional optimization, not a requirement.
127
+ */
128
+ export class PhoenixConnection {
129
+ constructor(clientToken, serverEndpoint, socketCtor, options) {
130
+ this.clientToken = clientToken;
131
+ this.serverEndpoint = serverEndpoint;
132
+ this.socketCtor = socketCtor;
133
+ this.ws = null;
134
+ this.ref = 0;
135
+ this.pending = new Map();
136
+ this.channelJoinRef = null;
137
+ this.channelTopic = null;
138
+ this.channelJoined = false;
139
+ this.state = 'disconnected';
140
+ this.shouldBeConnected = false;
141
+ this.desiredTopic = null;
142
+ this.desiredJoinSignature = null;
143
+ this.outbound = [];
144
+ this.establishPromise = null;
145
+ this.pendingConnect = null;
146
+ this.reconnectHandle = null;
147
+ this.heartbeatHandle = null;
148
+ this.heartbeatReplyHandle = null;
149
+ this.pendingHeartbeatRef = null;
150
+ this.activeFlowSessionId = null;
151
+ this.clientContext = { ...DEFAULT_CLIENT_CONTEXT };
152
+ this.clientConditions = [];
153
+ this.serverMessageHandlers = new Set();
154
+ /** Kinds already warned about this connection lifetime (reset on disconnect). */
155
+ this.warnedUnhandledKinds = new Set();
156
+ this.scheduler = options?.scheduler ?? defaultScheduler;
157
+ this.backoff = createBackoff(options?.reconnectLadderMs);
158
+ this.heartbeatIntervalMs = options?.heartbeatIntervalMs ?? HEARTBEAT_INTERVAL_MS;
159
+ this.heartbeatReplyTimeoutMs =
160
+ options?.heartbeatReplyTimeoutMs ??
161
+ Math.min(HEARTBEAT_REPLY_TIMEOUT_MS, this.heartbeatIntervalMs);
162
+ this.rateLimitCapacity = options?.rateLimit?.capacity ?? RATE_LIMIT_PER_MINUTE;
163
+ this.rateLimiter = createRateLimiter({
164
+ ...(options?.rateLimit?.capacity !== undefined
165
+ ? { capacity: options.rateLimit.capacity }
166
+ : {}),
167
+ ...(options?.rateLimit?.intervalMs !== undefined
168
+ ? { intervalMs: options.rateLimit.intervalMs }
169
+ : {}),
170
+ ...(options?.rateLimit?.now !== undefined ? { now: options.rateLimit.now } : {}),
171
+ });
172
+ this.warn = options?.warn ?? ((message) => console.warn(message));
173
+ }
174
+ /** The current lifecycle state (observability + tests). */
175
+ getState() {
176
+ return this.state;
177
+ }
178
+ /**
179
+ * Subscribe to inbound `server_message` frames on the joined end-user channel.
180
+ * Returns an unsubscribe function. Unknown message kinds are ignored (warned
181
+ * once per kind per connection lifetime).
182
+ */
183
+ onServerMessage(handler) {
184
+ this.serverMessageHandlers.add(handler);
185
+ return () => {
186
+ this.serverMessageHandlers.delete(handler);
187
+ };
188
+ }
189
+ /**
190
+ * Remember the active flow session id so every (re)join can resume it.
191
+ * Pass `null` when the session ends.
192
+ */
193
+ setFlowSessionId(flowSessionId) {
194
+ this.activeFlowSessionId = flowSessionId;
195
+ }
196
+ /** The flow session id currently included in end-user join payloads. */
197
+ getFlowSessionId() {
198
+ return this.activeFlowSessionId;
199
+ }
200
+ /**
201
+ * Remember the client-condition snapshot so every (re)join can seed the
202
+ * server's tracked/true/false sets. Pass the current engine snapshot
203
+ * (including `isTrue: null` unknowns).
204
+ */
205
+ setClientConditions(clientConditions) {
206
+ this.clientConditions = clientConditions.map((entry) => ({ ...entry }));
207
+ }
208
+ /** The client-condition snapshot currently included in end-user join payloads. */
209
+ getClientConditions() {
210
+ return this.clientConditions.map((entry) => ({ ...entry }));
211
+ }
212
+ /** The client context currently included in end-user join payloads. */
213
+ getClientContext() {
214
+ return { ...this.clientContext };
215
+ }
216
+ /**
217
+ * Remember client context so every (re)join reports the latest screen/URL.
218
+ * Does not push to the server; use {@link updateClientContext} for that.
219
+ */
220
+ setClientContext(clientContext) {
221
+ this.clientContext = { ...clientContext };
222
+ }
223
+ /**
224
+ * Update remembered client context and push `UpdateClientContext` when joined.
225
+ * Mirrors the web client's URL-change → `pushUpdateClientContext` path.
226
+ */
227
+ updateClientContext(clientContext) {
228
+ this.clientContext = { ...clientContext };
229
+ if (!this.channelTopic || !this.channelJoined) {
230
+ return Promise.resolve();
231
+ }
232
+ return this.enqueuePush('client_message', {
233
+ kind: 'UpdateClientContext',
234
+ clientContext: this.clientContext,
235
+ });
236
+ }
237
+ /**
238
+ * Push a Phase 3 client message on the joined channel. Reuses the outbound
239
+ * queue. `ToggleClientCondition` skips the rate limiter (web parity: meta
240
+ * messages must not be starved by UpsertUser / GoToStep traffic, and
241
+ * condition churn must not fail closed until the next rejoin).
242
+ * `BeginBatch` / `EndBatch` are the same class of meta message.
243
+ */
244
+ send(message) {
245
+ if (!this.channelTopic || !this.channelJoined) {
246
+ return Promise.reject(new UserflowAuthError('Not joined to an end-user channel'));
247
+ }
248
+ return this.enqueuePush('client_message', message, {
249
+ skipRateLimit: message.kind === 'ToggleClientCondition' ||
250
+ message.kind === 'BeginBatch' ||
251
+ message.kind === 'EndBatch',
252
+ });
253
+ }
254
+ /** Validates the client token by probing an anonymous end-user channel join. */
255
+ async validate() {
256
+ await this.openSocket();
257
+ try {
258
+ try {
259
+ await this.join(`end_users:anon-${uuid()}`, endUserJoinPayload());
260
+ }
261
+ catch (error) {
262
+ if (!isSignatureRequiredError(error))
263
+ throw error;
264
+ }
265
+ }
266
+ finally {
267
+ this.disconnect();
268
+ }
269
+ }
270
+ /** Joins the end-user channel for `userId` and upserts the given attributes. */
271
+ async identify(userId, attributes, signature = null) {
272
+ this.shouldBeConnected = true;
273
+ this.desiredJoinSignature = signature;
274
+ await this.ensureJoined(`end_users:${userId}`);
275
+ await this.enqueuePush('client_message', { kind: 'UpsertUser', attributes });
276
+ }
277
+ /** Joins (or re-joins) the end-user channel when the socket dropped since identify. */
278
+ async ensureEndUserChannel(userId, signature = null) {
279
+ this.shouldBeConnected = true;
280
+ this.desiredJoinSignature = signature;
281
+ await this.ensureJoined(`end_users:${userId}`);
282
+ }
283
+ /** Upserts a group and the current user's membership on the joined channel. */
284
+ async group(payload) {
285
+ if (!this.channelTopic || !this.channelJoined) {
286
+ return Promise.reject(new UserflowAuthError('Not joined to an end-user channel'));
287
+ }
288
+ await this.enqueuePush('client_message', {
289
+ kind: 'UpsertGroup',
290
+ groupExternalId: payload.groupExternalId,
291
+ groupSignature: payload.groupSignature,
292
+ groupAttributes: payload.groupAttributes,
293
+ membershipAttributes: payload.membershipAttributes,
294
+ });
295
+ }
296
+ /** Push `UpsertUser` on an already-joined channel (no re-identify). */
297
+ async updateUser(attributes) {
298
+ if (!this.channelTopic || !this.channelJoined) {
299
+ return Promise.reject(new UserflowAuthError('Not joined to an end-user channel'));
300
+ }
301
+ await this.enqueuePush('client_message', { kind: 'UpsertUser', attributes });
302
+ }
303
+ /** Intentional teardown: stop everything, reject queued/in-flight work, clear intent. */
304
+ disconnect() {
305
+ this.shouldBeConnected = false;
306
+ this.desiredTopic = null;
307
+ this.desiredJoinSignature = null;
308
+ this.activeFlowSessionId = null;
309
+ this.clientContext = { ...DEFAULT_CLIENT_CONTEXT };
310
+ this.clientConditions = [];
311
+ this.warnedUnhandledKinds.clear();
312
+ this.state = 'disconnected';
313
+ this.cancelReconnect();
314
+ this.stopHeartbeat();
315
+ this.abortPendingConnect(new UserflowAuthError('Connection closed'));
316
+ this.discardInFlightPushes();
317
+ this.rejectPending(new UserflowAuthError('Connection closed'));
318
+ this.rejectQueue(new UserflowAuthError('Connection closed'));
319
+ this.detachAndClose(this.ws);
320
+ this.resetChannel();
321
+ }
322
+ /** Background handling: close but keep intent + queued pushes so `resume()` recovers. */
323
+ suspend() {
324
+ if (this.state === 'suspended')
325
+ return;
326
+ this.state = 'suspended';
327
+ this.cancelReconnect();
328
+ this.stopHeartbeat();
329
+ this.abortPendingConnect(new UserflowAuthError('Connection suspended'));
330
+ this.discardInFlightPushes();
331
+ this.rejectPending(new UserflowAuthError('Connection suspended'));
332
+ this.detachAndClose(this.ws);
333
+ this.resetChannel();
334
+ }
335
+ /** Foreground handling: reconnect, rejoin the desired topic, and flush the queue. */
336
+ resume() {
337
+ if (this.state !== 'suspended')
338
+ return;
339
+ if (!this.shouldBeConnected) {
340
+ this.state = 'disconnected';
341
+ return;
342
+ }
343
+ this.state = 'reconnecting';
344
+ this.attemptEstablish();
345
+ }
346
+ /**
347
+ * Eager reconnect when the host reports connectivity restored.
348
+ * No-op while suspended (lifecycle owns that path), while already connecting /
349
+ * connected, or when the SDK does not intend to be connected.
350
+ */
351
+ reconnectNow() {
352
+ if (!this.shouldBeConnected)
353
+ return;
354
+ if (this.state === 'suspended' || this.state === 'connecting' || this.state === 'connected') {
355
+ return;
356
+ }
357
+ this.cancelReconnect();
358
+ this.backoff.reset();
359
+ this.state = 'reconnecting';
360
+ this.attemptEstablish();
361
+ }
362
+ /**
363
+ * Verify the connection is really alive right now and recover fast if not.
364
+ * Called on foreground and other "the socket may have silently died" moments.
365
+ *
366
+ * - connected: fire an immediate heartbeat probe with a short reply deadline;
367
+ * a dead socket is detected within {@link heartbeatReplyTimeoutMs} instead of
368
+ * waiting for the next scheduled heartbeat.
369
+ * - reconnecting / disconnected (with intent): reconnect eagerly.
370
+ * - suspended / connecting: no-op (those paths already own recovery).
371
+ *
372
+ * This is the zero-dependency liveness path; it does not require any
373
+ * host-provided network signal.
374
+ */
375
+ ensureAlive() {
376
+ if (!this.shouldBeConnected)
377
+ return;
378
+ if (this.state === 'connected' && this.ws) {
379
+ // A beat is already outstanding — its reply deadline will catch a death.
380
+ if (this.pendingHeartbeatRef !== null)
381
+ return;
382
+ this.clearHeartbeatTimer();
383
+ this.sendHeartbeat();
384
+ return;
385
+ }
386
+ this.reconnectNow();
387
+ }
388
+ async ensureJoined(topic) {
389
+ this.desiredTopic = topic;
390
+ if (this.state === 'connected' && this.channelTopic === topic && this.channelJoined) {
391
+ return;
392
+ }
393
+ if (this.state === 'connected' && this.channelTopic !== topic && this.ws) {
394
+ this.detachAndClose(this.ws);
395
+ this.resetChannel();
396
+ }
397
+ this.cancelReconnect();
398
+ await this.establish();
399
+ }
400
+ establish() {
401
+ if (this.establishPromise)
402
+ return this.establishPromise;
403
+ this.establishPromise = this.doEstablish().finally(() => {
404
+ this.establishPromise = null;
405
+ });
406
+ return this.establishPromise;
407
+ }
408
+ async doEstablish() {
409
+ this.state = 'connecting';
410
+ await this.openSocket();
411
+ if (this.desiredTopic) {
412
+ await this.joinChannel(this.desiredTopic);
413
+ }
414
+ this.state = 'connected';
415
+ this.backoff.reset();
416
+ this.startHeartbeat();
417
+ this.flush();
418
+ }
419
+ attemptEstablish() {
420
+ void this.establish().catch(() => {
421
+ if (this.shouldBeConnected && this.state !== 'suspended') {
422
+ this.scheduleReconnect();
423
+ }
424
+ });
425
+ }
426
+ openSocket() {
427
+ return new Promise((resolve, reject) => {
428
+ const SocketCtor = resolveSocketCtor(this.socketCtor);
429
+ const ws = new SocketCtor(buildWsUrl(this.serverEndpoint, this.clientToken));
430
+ this.ws = ws;
431
+ let settled = false;
432
+ const timer = this.scheduler.setTimeout(() => {
433
+ if (settled)
434
+ return;
435
+ settled = true;
436
+ this.pendingConnect = null;
437
+ this.detachAndClose(ws);
438
+ reject(new UserflowAuthError('WebSocket connection timed out'));
439
+ }, TIMEOUT_MS);
440
+ const finish = () => {
441
+ settled = true;
442
+ this.pendingConnect = null;
443
+ this.scheduler.clearTimeout(timer);
444
+ };
445
+ this.pendingConnect = {
446
+ reject: (error) => {
447
+ if (settled)
448
+ return;
449
+ finish();
450
+ this.detachAndClose(ws);
451
+ reject(error);
452
+ },
453
+ };
454
+ ws.onopen = () => {
455
+ if (settled)
456
+ return;
457
+ finish();
458
+ resolve();
459
+ };
460
+ ws.onmessage = (event) => this.handleMessage(event);
461
+ ws.onerror = () => {
462
+ if (!settled) {
463
+ finish();
464
+ this.detachAndClose(ws);
465
+ reject(new UserflowAuthError('WebSocket connection failed'));
466
+ }
467
+ else {
468
+ this.onSocketDown(ws);
469
+ }
470
+ };
471
+ ws.onclose = () => {
472
+ if (!settled) {
473
+ finish();
474
+ this.detachAndClose(ws);
475
+ reject(new UserflowAuthError('WebSocket closed before connect completed'));
476
+ }
477
+ else {
478
+ this.onSocketDown(ws);
479
+ }
480
+ };
481
+ });
482
+ }
483
+ onSocketDown(socket) {
484
+ if (this.ws !== socket)
485
+ return;
486
+ this.detachAndClose(socket);
487
+ this.channelJoined = false;
488
+ this.channelJoinRef = null;
489
+ this.stopHeartbeat();
490
+ this.discardInFlightPushes();
491
+ this.rejectPending(new UserflowAuthError('Connection dropped'));
492
+ if (this.shouldBeConnected && this.state !== 'suspended') {
493
+ this.state = 'reconnecting';
494
+ this.scheduleReconnect();
495
+ }
496
+ else {
497
+ this.state = 'disconnected';
498
+ }
499
+ }
500
+ scheduleReconnect() {
501
+ if (this.reconnectHandle !== null)
502
+ return;
503
+ const delay = this.backoff.nextDelay();
504
+ this.reconnectHandle = this.scheduler.setTimeout(() => {
505
+ this.reconnectHandle = null;
506
+ if (!this.shouldBeConnected || this.state === 'suspended')
507
+ return;
508
+ this.attemptEstablish();
509
+ }, delay);
510
+ }
511
+ cancelReconnect() {
512
+ if (this.reconnectHandle !== null) {
513
+ this.scheduler.clearTimeout(this.reconnectHandle);
514
+ this.reconnectHandle = null;
515
+ }
516
+ }
517
+ startHeartbeat() {
518
+ this.stopHeartbeat();
519
+ this.scheduleNextHeartbeat();
520
+ }
521
+ stopHeartbeat() {
522
+ this.clearHeartbeatTimer();
523
+ this.clearHeartbeatReplyTimer();
524
+ this.pendingHeartbeatRef = null;
525
+ }
526
+ scheduleNextHeartbeat() {
527
+ this.clearHeartbeatTimer();
528
+ this.heartbeatHandle = this.scheduler.setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
529
+ }
530
+ clearHeartbeatTimer() {
531
+ if (this.heartbeatHandle !== null) {
532
+ this.scheduler.clearTimeout(this.heartbeatHandle);
533
+ this.heartbeatHandle = null;
534
+ }
535
+ }
536
+ clearHeartbeatReplyTimer() {
537
+ if (this.heartbeatReplyHandle !== null) {
538
+ this.scheduler.clearTimeout(this.heartbeatReplyHandle);
539
+ this.heartbeatReplyHandle = null;
540
+ }
541
+ }
542
+ /**
543
+ * Send one heartbeat and arm a short reply deadline. The next heartbeat is
544
+ * scheduled when the reply lands (see {@link handleMessage}); if the deadline
545
+ * fires first with the beat still pending, the socket is declared dead.
546
+ */
547
+ sendHeartbeat() {
548
+ this.heartbeatHandle = null;
549
+ if (this.state !== 'connected' || !this.ws)
550
+ return;
551
+ // A prior beat was never answered (defensive; the reply timer normally
552
+ // catches this first).
553
+ if (this.pendingHeartbeatRef !== null) {
554
+ this.onSocketDown(this.ws);
555
+ return;
556
+ }
557
+ const ref = this.nextRef();
558
+ this.pendingHeartbeatRef = ref;
559
+ this.ws.send(JSON.stringify([null, ref, PHOENIX_TOPIC, 'heartbeat', {}]));
560
+ this.armHeartbeatReplyTimeout();
561
+ }
562
+ armHeartbeatReplyTimeout() {
563
+ this.clearHeartbeatReplyTimer();
564
+ this.heartbeatReplyHandle = this.scheduler.setTimeout(() => {
565
+ this.heartbeatReplyHandle = null;
566
+ if (this.state !== 'connected' || !this.ws)
567
+ return;
568
+ if (this.pendingHeartbeatRef !== null) {
569
+ this.onSocketDown(this.ws);
570
+ }
571
+ }, this.heartbeatReplyTimeoutMs);
572
+ }
573
+ handleMessage(event) {
574
+ let frame;
575
+ try {
576
+ frame = JSON.parse(String(event.data));
577
+ }
578
+ catch {
579
+ return;
580
+ }
581
+ if (!Array.isArray(frame) || frame.length < 5)
582
+ return;
583
+ const [, id, topic, eventName, payload] = frame;
584
+ if (eventName === 'server_message') {
585
+ this.dispatchServerMessage(topic, payload);
586
+ return;
587
+ }
588
+ if (eventName !== 'phx_reply' || typeof id !== 'string')
589
+ return;
590
+ if (topic === PHOENIX_TOPIC && id === this.pendingHeartbeatRef) {
591
+ this.pendingHeartbeatRef = null;
592
+ this.clearHeartbeatReplyTimer();
593
+ if (this.state === 'connected')
594
+ this.scheduleNextHeartbeat();
595
+ return;
596
+ }
597
+ const wait = this.pending.get(id);
598
+ if (!wait || wait.topic !== topic)
599
+ return;
600
+ this.pending.delete(id);
601
+ this.scheduler.clearTimeout(wait.timer);
602
+ const reply = payload;
603
+ if (reply.status === 'ok') {
604
+ wait.ok();
605
+ return;
606
+ }
607
+ wait.fail(new UserflowAuthError(`${topic}: ${joinError(reply.response)}`));
608
+ }
609
+ dispatchServerMessage(topic, payload) {
610
+ if (!this.channelTopic || topic !== this.channelTopic)
611
+ return;
612
+ if (!isServerMessage(payload)) {
613
+ if (typeof payload === 'object' &&
614
+ payload !== null &&
615
+ 'kind' in payload &&
616
+ typeof payload.kind === 'string') {
617
+ const kind = payload.kind;
618
+ if (!this.warnedUnhandledKinds.has(kind)) {
619
+ this.warnedUnhandledKinds.add(kind);
620
+ this.warn(`Userflow: ignoring unsupported server message kind "${kind}" ` +
621
+ '(not implemented by the mobile SDK)');
622
+ }
623
+ }
624
+ return;
625
+ }
626
+ for (const handler of this.serverMessageHandlers) {
627
+ try {
628
+ handler(payload);
629
+ }
630
+ catch {
631
+ // Never let a subscriber break the socket message loop.
632
+ }
633
+ }
634
+ }
635
+ nextRef() {
636
+ this.ref += 1;
637
+ return String(this.ref);
638
+ }
639
+ async joinChannel(topic) {
640
+ this.channelTopic = topic;
641
+ await this.join(topic, endUserJoinPayload(this.desiredJoinSignature, this.activeFlowSessionId, this.clientContext, this.clientConditions));
642
+ this.channelJoined = true;
643
+ }
644
+ join(topic, payload) {
645
+ return this.request(topic, (joinRef, ref) => {
646
+ if (topic.startsWith('end_users:')) {
647
+ this.channelJoinRef = joinRef;
648
+ }
649
+ return [joinRef, ref, topic, 'phx_join', payload];
650
+ });
651
+ }
652
+ request(topic, buildFrame) {
653
+ return new Promise((ok, fail) => {
654
+ if (!this.ws || this.ws.readyState !== WS_OPEN) {
655
+ fail(new UserflowAuthError('WebSocket is not open'));
656
+ return;
657
+ }
658
+ const joinRef = topic.startsWith('end_users:')
659
+ ? (this.channelJoinRef ?? this.nextRef())
660
+ : this.nextRef();
661
+ const ref = this.nextRef();
662
+ const timer = this.scheduler.setTimeout(() => {
663
+ const wait = this.pending.get(ref);
664
+ if (!wait)
665
+ return;
666
+ this.pending.delete(ref);
667
+ wait.fail(new UserflowAuthError(`${topic}: reply timed out`));
668
+ }, TIMEOUT_MS);
669
+ this.pending.set(ref, { topic, timer, ok, fail });
670
+ this.ws.send(JSON.stringify(buildFrame(joinRef, ref)));
671
+ });
672
+ }
673
+ /**
674
+ * Enqueue an outbound push. Only `client_message` events pass through here.
675
+ * Channel joins (`phx_join`) and heartbeats bypass this gate. Meta messages
676
+ * such as `ToggleClientCondition` may set `skipRateLimit` so condition
677
+ * updates are not dropped under UpsertUser / GoToStep load.
678
+ */
679
+ enqueuePush(event, payload, options) {
680
+ if (!options?.skipRateLimit && !this.rateLimiter.tryAcquire()) {
681
+ return Promise.reject(new UserflowRateLimitError(`Client message rate limit exceeded (${this.rateLimitCapacity}/min)`));
682
+ }
683
+ return new Promise((resolve, reject) => {
684
+ this.outbound.push({
685
+ event,
686
+ payload,
687
+ inFlight: false,
688
+ inFlightRef: null,
689
+ replay: isReplayableClientMessage(payload),
690
+ resolve,
691
+ reject,
692
+ });
693
+ this.flush();
694
+ });
695
+ }
696
+ flush() {
697
+ if (this.state !== 'connected' || !this.channelJoined || !this.ws)
698
+ return;
699
+ for (const item of this.outbound) {
700
+ if (item.inFlight)
701
+ continue;
702
+ this.sendPush(item);
703
+ }
704
+ }
705
+ sendPush(item) {
706
+ if (!this.ws || !this.channelTopic || !this.channelJoinRef)
707
+ return;
708
+ const topic = this.channelTopic;
709
+ const joinRef = this.channelJoinRef;
710
+ const ref = this.nextRef();
711
+ const timer = this.scheduler.setTimeout(() => {
712
+ const wait = this.pending.get(ref);
713
+ if (!wait)
714
+ return;
715
+ this.pending.delete(ref);
716
+ wait.fail(new UserflowAuthError(`${topic}: reply timed out`));
717
+ }, TIMEOUT_MS);
718
+ this.pending.set(ref, {
719
+ topic,
720
+ timer,
721
+ ok: () => {
722
+ this.removeFromQueue(item);
723
+ item.resolve();
724
+ },
725
+ fail: (error) => {
726
+ this.removeFromQueue(item);
727
+ item.reject(error);
728
+ },
729
+ });
730
+ item.inFlight = true;
731
+ item.inFlightRef = ref;
732
+ this.ws.send(JSON.stringify([joinRef, ref, topic, item.event, item.payload]));
733
+ }
734
+ removeFromQueue(item) {
735
+ const index = this.outbound.indexOf(item);
736
+ if (index !== -1)
737
+ this.outbound.splice(index, 1);
738
+ }
739
+ /**
740
+ * On a drop/suspend, forget the in-flight reply for each queued push.
741
+ * Idempotent messages are reset and re-sent after the next (re)join
742
+ * (at-least-once). Non-idempotent attribute ops (`add` / `subtract` /
743
+ * `append` / `prepend`) are rejected instead, so a lost ack cannot apply
744
+ * the mutation twice.
745
+ */
746
+ discardInFlightPushes() {
747
+ const kept = [];
748
+ for (const item of this.outbound) {
749
+ if (item.inFlight && item.inFlightRef) {
750
+ const wait = this.pending.get(item.inFlightRef);
751
+ if (wait) {
752
+ this.scheduler.clearTimeout(wait.timer);
753
+ this.pending.delete(item.inFlightRef);
754
+ }
755
+ if (!item.replay) {
756
+ item.reject(new UserflowAuthError('Connection dropped before acknowledgement'));
757
+ continue;
758
+ }
759
+ }
760
+ item.inFlight = false;
761
+ item.inFlightRef = null;
762
+ kept.push(item);
763
+ }
764
+ this.outbound = kept;
765
+ }
766
+ rejectPending(error) {
767
+ for (const wait of this.pending.values()) {
768
+ this.scheduler.clearTimeout(wait.timer);
769
+ wait.fail(error);
770
+ }
771
+ this.pending.clear();
772
+ this.pendingHeartbeatRef = null;
773
+ }
774
+ rejectQueue(error) {
775
+ const items = this.outbound;
776
+ this.outbound = [];
777
+ for (const item of items)
778
+ item.reject(error);
779
+ }
780
+ abortPendingConnect(error) {
781
+ const pending = this.pendingConnect;
782
+ this.pendingConnect = null;
783
+ pending?.reject(error);
784
+ }
785
+ detachAndClose(ws) {
786
+ if (!ws)
787
+ return;
788
+ ws.onopen = null;
789
+ ws.onmessage = null;
790
+ ws.onerror = null;
791
+ ws.onclose = null;
792
+ try {
793
+ ws.close();
794
+ }
795
+ catch {
796
+ // ignore
797
+ }
798
+ if (this.ws === ws)
799
+ this.ws = null;
800
+ }
801
+ resetChannel() {
802
+ this.channelJoinRef = null;
803
+ this.channelTopic = null;
804
+ this.channelJoined = false;
805
+ }
806
+ }
807
+ /** Convenience helper: open a connection, validate credentials, and close it. */
808
+ export function validateCredentials(clientToken, serverEndpoint, socketCtor) {
809
+ return new PhoenixConnection(clientToken, serverEndpoint, socketCtor).validate();
810
+ }
811
+ //# sourceMappingURL=phoenix.js.map