@blimu/react 0.7.0 → 1.1.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 (452) hide show
  1. package/dist/_virtual/index.cjs +5 -1
  2. package/dist/_virtual/index.cjs.map +1 -1
  3. package/dist/_virtual/index.js +3 -3
  4. package/dist/_virtual/index2.cjs +4 -1
  5. package/dist/_virtual/index2.cjs.map +1 -1
  6. package/dist/_virtual/index2.js +2 -2
  7. package/dist/_virtual/use-sync-external-store-shim.development.cjs +4 -1
  8. package/dist/_virtual/use-sync-external-store-shim.development.cjs.map +1 -1
  9. package/dist/_virtual/use-sync-external-store-shim.development.js +2 -2
  10. package/dist/_virtual/use-sync-external-store-shim.production.cjs +4 -1
  11. package/dist/_virtual/use-sync-external-store-shim.production.cjs.map +1 -1
  12. package/dist/_virtual/use-sync-external-store-shim.production.js +2 -2
  13. package/dist/client/auth.service.cjs +249 -1
  14. package/dist/client/auth.service.cjs.map +1 -1
  15. package/dist/client/auth.service.d.ts.map +1 -1
  16. package/dist/client/auth.service.js +195 -95
  17. package/dist/client/auth.service.js.map +1 -1
  18. package/dist/client/external-store.cjs +26 -1
  19. package/dist/client/external-store.cjs.map +1 -1
  20. package/dist/client/external-store.js +22 -8
  21. package/dist/client/external-store.js.map +1 -1
  22. package/dist/client/runtime-client.cjs +136 -1
  23. package/dist/client/runtime-client.cjs.map +1 -1
  24. package/dist/client/runtime-client.js +86 -52
  25. package/dist/client/runtime-client.js.map +1 -1
  26. package/dist/components/index.cjs +13 -0
  27. package/dist/components/index.cjs.map +1 -0
  28. package/dist/components/index.js +13 -0
  29. package/dist/components/index.js.map +1 -0
  30. package/dist/components/members-list.cjs +132 -1
  31. package/dist/components/members-list.cjs.map +1 -1
  32. package/dist/components/members-list.js +69 -64
  33. package/dist/components/members-list.js.map +1 -1
  34. package/dist/components/redirect-to-sign-in.cjs +34 -1
  35. package/dist/components/redirect-to-sign-in.cjs.map +1 -1
  36. package/dist/components/redirect-to-sign-in.js +28 -20
  37. package/dist/components/redirect-to-sign-in.js.map +1 -1
  38. package/dist/components/sign-in-button.cjs +36 -1
  39. package/dist/components/sign-in-button.cjs.map +1 -1
  40. package/dist/components/sign-in-button.js +25 -21
  41. package/dist/components/sign-in-button.js.map +1 -1
  42. package/dist/components/ui/avatar.cjs +42 -1
  43. package/dist/components/ui/avatar.cjs.map +1 -1
  44. package/dist/components/ui/avatar.js +23 -23
  45. package/dist/components/ui/avatar.js.map +1 -1
  46. package/dist/components/ui/dropdown-menu.cjs +148 -1
  47. package/dist/components/ui/dropdown-menu.cjs.map +1 -1
  48. package/dist/components/ui/dropdown-menu.js +83 -81
  49. package/dist/components/ui/dropdown-menu.js.map +1 -1
  50. package/dist/components/user-avatar.cjs +22 -1
  51. package/dist/components/user-avatar.cjs.map +1 -1
  52. package/dist/components/user-avatar.js +16 -16
  53. package/dist/components/user-avatar.js.map +1 -1
  54. package/dist/components/user-button/styles.cjs +39 -1
  55. package/dist/components/user-button/styles.cjs.map +1 -1
  56. package/dist/components/user-button/styles.js +6 -5
  57. package/dist/components/user-button/styles.js.map +1 -1
  58. package/dist/components/user-button/user-button.cjs +98 -1
  59. package/dist/components/user-button/user-button.cjs.map +1 -1
  60. package/dist/components/user-button/user-button.js +64 -58
  61. package/dist/components/user-button/user-button.js.map +1 -1
  62. package/dist/hooks/index.cjs +14 -0
  63. package/dist/hooks/index.cjs.map +1 -0
  64. package/dist/hooks/index.d.ts +1 -0
  65. package/dist/hooks/index.d.ts.map +1 -1
  66. package/dist/hooks/index.js +14 -0
  67. package/dist/hooks/index.js.map +1 -0
  68. package/dist/hooks/use-auth.cjs +44 -1
  69. package/dist/hooks/use-auth.cjs.map +1 -1
  70. package/dist/hooks/use-auth.d.ts +13 -15
  71. package/dist/hooks/use-auth.d.ts.map +1 -1
  72. package/dist/hooks/use-auth.js +30 -26
  73. package/dist/hooks/use-auth.js.map +1 -1
  74. package/dist/hooks/use-client.cjs +9 -1
  75. package/dist/hooks/use-client.cjs.map +1 -1
  76. package/dist/hooks/use-client.d.ts +1 -1
  77. package/dist/hooks/use-client.d.ts.map +1 -1
  78. package/dist/hooks/use-client.js +6 -5
  79. package/dist/hooks/use-client.js.map +1 -1
  80. package/dist/hooks/use-members.cjs +60 -1
  81. package/dist/hooks/use-members.cjs.map +1 -1
  82. package/dist/hooks/use-members.js +53 -41
  83. package/dist/hooks/use-members.js.map +1 -1
  84. package/dist/hooks/use-store.cjs +17 -1
  85. package/dist/hooks/use-store.cjs.map +1 -1
  86. package/dist/hooks/use-store.js +7 -7
  87. package/dist/hooks/use-store.js.map +1 -1
  88. package/dist/index.cjs +37 -1
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.ts +1 -1
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +35 -35
  93. package/dist/lib/utils.cjs +8 -1
  94. package/dist/lib/utils.cjs.map +1 -1
  95. package/dist/lib/utils.js +5 -5
  96. package/dist/lib/utils.js.map +1 -1
  97. package/dist/lib/variants.cjs +46 -1
  98. package/dist/lib/variants.cjs.map +1 -1
  99. package/dist/lib/variants.js +6 -5
  100. package/dist/lib/variants.js.map +1 -1
  101. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.cjs +721 -1
  102. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.cjs.map +1 -1
  103. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +571 -377
  104. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js.map +1 -1
  105. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs +625 -1
  106. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs.map +1 -1
  107. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +539 -316
  108. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js.map +1 -1
  109. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs +313 -1
  110. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs.map +1 -1
  111. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +261 -172
  112. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js.map +1 -1
  113. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs +154 -1
  114. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs.map +1 -1
  115. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs +173 -1
  116. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs.map +1 -1
  117. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +144 -107
  118. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -1
  119. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +111 -87
  120. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js.map +1 -1
  121. package/dist/node_modules/@radix-ui/primitive/dist/index.cjs +11 -1
  122. package/dist/node_modules/@radix-ui/primitive/dist/index.cjs.map +1 -1
  123. package/dist/node_modules/@radix-ui/primitive/dist/index.js +7 -5
  124. package/dist/node_modules/@radix-ui/primitive/dist/index.js.map +1 -1
  125. package/dist/node_modules/@radix-ui/react-arrow/dist/index.cjs +42 -1
  126. package/dist/node_modules/@radix-ui/react-arrow/dist/index.cjs.map +1 -1
  127. package/dist/node_modules/@radix-ui/react-arrow/dist/index.js +17 -16
  128. package/dist/node_modules/@radix-ui/react-arrow/dist/index.js.map +1 -1
  129. package/dist/node_modules/@radix-ui/react-avatar/dist/index.cjs +140 -1
  130. package/dist/node_modules/@radix-ui/react-avatar/dist/index.cjs.map +1 -1
  131. package/dist/node_modules/@radix-ui/react-avatar/dist/index.js +105 -57
  132. package/dist/node_modules/@radix-ui/react-avatar/dist/index.js.map +1 -1
  133. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.cjs +80 -1
  134. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
  135. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.js +49 -41
  136. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.js.map +1 -1
  137. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.cjs +56 -1
  138. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
  139. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js +17 -10
  140. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -1
  141. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.cjs +119 -1
  142. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
  143. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.js +86 -42
  144. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -1
  145. package/dist/node_modules/@radix-ui/react-collection/dist/index.cjs +70 -1
  146. package/dist/node_modules/@radix-ui/react-collection/dist/index.cjs.map +1 -1
  147. package/dist/node_modules/@radix-ui/react-collection/dist/index.js +57 -37
  148. package/dist/node_modules/@radix-ui/react-collection/dist/index.js.map +1 -1
  149. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +56 -1
  150. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.map +1 -1
  151. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js +29 -19
  152. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js.map +1 -1
  153. package/dist/node_modules/@radix-ui/react-context/dist/index.cjs +79 -1
  154. package/dist/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
  155. package/dist/node_modules/@radix-ui/react-context/dist/index.js +48 -39
  156. package/dist/node_modules/@radix-ui/react-context/dist/index.js.map +1 -1
  157. package/dist/node_modules/@radix-ui/react-direction/dist/index.cjs +27 -1
  158. package/dist/node_modules/@radix-ui/react-direction/dist/index.cjs.map +1 -1
  159. package/dist/node_modules/@radix-ui/react-direction/dist/index.js +6 -6
  160. package/dist/node_modules/@radix-ui/react-direction/dist/index.js.map +1 -1
  161. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs +229 -1
  162. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs.map +1 -1
  163. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +182 -97
  164. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js.map +1 -1
  165. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs +296 -1
  166. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs.map +1 -1
  167. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js +232 -167
  168. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js.map +1 -1
  169. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs +46 -1
  170. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs.map +1 -1
  171. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js +23 -11
  172. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js.map +1 -1
  173. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs +224 -1
  174. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs.map +1 -1
  175. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js +169 -98
  176. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js.map +1 -1
  177. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs +31 -1
  178. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs.map +1 -1
  179. package/dist/node_modules/@radix-ui/react-id/dist/index.js +11 -10
  180. package/dist/node_modules/@radix-ui/react-id/dist/index.js.map +1 -1
  181. package/dist/node_modules/@radix-ui/react-menu/dist/index.cjs +845 -1
  182. package/dist/node_modules/@radix-ui/react-menu/dist/index.cjs.map +1 -1
  183. package/dist/node_modules/@radix-ui/react-menu/dist/index.js +662 -442
  184. package/dist/node_modules/@radix-ui/react-menu/dist/index.js.map +1 -1
  185. package/dist/node_modules/@radix-ui/react-popper/dist/index.cjs +308 -1
  186. package/dist/node_modules/@radix-ui/react-popper/dist/index.cjs.map +1 -1
  187. package/dist/node_modules/@radix-ui/react-popper/dist/index.js +209 -137
  188. package/dist/node_modules/@radix-ui/react-popper/dist/index.js.map +1 -1
  189. package/dist/node_modules/@radix-ui/react-portal/dist/index.cjs +34 -1
  190. package/dist/node_modules/@radix-ui/react-portal/dist/index.cjs.map +1 -1
  191. package/dist/node_modules/@radix-ui/react-portal/dist/index.js +14 -12
  192. package/dist/node_modules/@radix-ui/react-portal/dist/index.js.map +1 -1
  193. package/dist/node_modules/@radix-ui/react-presence/dist/index.cjs +145 -1
  194. package/dist/node_modules/@radix-ui/react-presence/dist/index.cjs.map +1 -1
  195. package/dist/node_modules/@radix-ui/react-presence/dist/index.js +103 -45
  196. package/dist/node_modules/@radix-ui/react-presence/dist/index.js.map +1 -1
  197. package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs +61 -1
  198. package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
  199. package/dist/node_modules/@radix-ui/react-primitive/dist/index.js +21 -14
  200. package/dist/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -1
  201. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.cjs +244 -1
  202. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.cjs.map +1 -1
  203. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js +179 -135
  204. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js.map +1 -1
  205. package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs +105 -1
  206. package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
  207. package/dist/node_modules/@radix-ui/react-slot/dist/index.js +74 -35
  208. package/dist/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -1
  209. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs +28 -1
  210. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs.map +1 -1
  211. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js +8 -7
  212. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js.map +1 -1
  213. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs +86 -1
  214. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs.map +1 -1
  215. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js +57 -40
  216. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js.map +1 -1
  217. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs +34 -1
  218. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs.map +1 -1
  219. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +13 -10
  220. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js.map +1 -1
  221. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.cjs +15 -1
  222. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.cjs.map +1 -1
  223. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +8 -8
  224. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js.map +1 -1
  225. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs +23 -1
  226. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs.map +1 -1
  227. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js +3 -3
  228. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js.map +1 -1
  229. package/dist/node_modules/@radix-ui/react-use-size/dist/index.cjs +56 -1
  230. package/dist/node_modules/@radix-ui/react-use-size/dist/index.cjs.map +1 -1
  231. package/dist/node_modules/@radix-ui/react-use-size/dist/index.js +34 -22
  232. package/dist/node_modules/@radix-ui/react-use-size/dist/index.js.map +1 -1
  233. package/dist/node_modules/aria-hidden/dist/es2015/index.cjs +122 -1
  234. package/dist/node_modules/aria-hidden/dist/es2015/index.cjs.map +1 -1
  235. package/dist/node_modules/aria-hidden/dist/es2015/index.js +111 -41
  236. package/dist/node_modules/aria-hidden/dist/es2015/index.js.map +1 -1
  237. package/dist/node_modules/class-variance-authority/dist/index.cjs +45 -1
  238. package/dist/node_modules/class-variance-authority/dist/index.cjs.map +1 -1
  239. package/dist/node_modules/class-variance-authority/dist/index.js +40 -30
  240. package/dist/node_modules/class-variance-authority/dist/index.js.map +1 -1
  241. package/dist/node_modules/clsx/dist/clsx.cjs +17 -1
  242. package/dist/node_modules/clsx/dist/clsx.cjs.map +1 -1
  243. package/dist/node_modules/clsx/dist/clsx.js +13 -13
  244. package/dist/node_modules/clsx/dist/clsx.js.map +1 -1
  245. package/dist/node_modules/get-nonce/dist/es2015/index.cjs +9 -1
  246. package/dist/node_modules/get-nonce/dist/es2015/index.cjs.map +1 -1
  247. package/dist/node_modules/get-nonce/dist/es2015/index.js +5 -3
  248. package/dist/node_modules/get-nonce/dist/es2015/index.js.map +1 -1
  249. package/dist/node_modules/js-cookie/dist/js.cookie.cjs +98 -1
  250. package/dist/node_modules/js-cookie/dist/js.cookie.cjs.map +1 -1
  251. package/dist/node_modules/js-cookie/dist/js.cookie.js +69 -43
  252. package/dist/node_modules/js-cookie/dist/js.cookie.js.map +1 -1
  253. package/dist/node_modules/jwt-decode/build/esm/index.cjs +58 -1
  254. package/dist/node_modules/jwt-decode/build/esm/index.cjs.map +1 -1
  255. package/dist/node_modules/jwt-decode/build/esm/index.js +36 -30
  256. package/dist/node_modules/jwt-decode/build/esm/index.js.map +1 -1
  257. package/dist/node_modules/lucide-react/dist/esm/Icon.cjs +34 -1
  258. package/dist/node_modules/lucide-react/dist/esm/Icon.cjs.map +1 -1
  259. package/dist/node_modules/lucide-react/dist/esm/Icon.js +25 -25
  260. package/dist/node_modules/lucide-react/dist/esm/Icon.js.map +1 -1
  261. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.cjs +21 -1
  262. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.cjs.map +1 -1
  263. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.js +16 -15
  264. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.js.map +1 -1
  265. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.cjs +13 -1
  266. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.cjs.map +1 -1
  267. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.js +2 -2
  268. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.js.map +1 -1
  269. package/dist/node_modules/lucide-react/dist/esm/icons/check.cjs +7 -1
  270. package/dist/node_modules/lucide-react/dist/esm/icons/check.cjs.map +1 -1
  271. package/dist/node_modules/lucide-react/dist/esm/icons/check.js +5 -4
  272. package/dist/node_modules/lucide-react/dist/esm/icons/check.js.map +1 -1
  273. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.cjs +7 -1
  274. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.cjs.map +1 -1
  275. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.js +5 -4
  276. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.js.map +1 -1
  277. package/dist/node_modules/lucide-react/dist/esm/icons/circle.cjs +7 -1
  278. package/dist/node_modules/lucide-react/dist/esm/icons/circle.cjs.map +1 -1
  279. package/dist/node_modules/lucide-react/dist/esm/icons/circle.js +5 -4
  280. package/dist/node_modules/lucide-react/dist/esm/icons/circle.js.map +1 -1
  281. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.cjs +11 -1
  282. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.cjs.map +1 -1
  283. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.js +6 -5
  284. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.js.map +1 -1
  285. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.cjs +26 -1
  286. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.cjs.map +1 -1
  287. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.js +22 -14
  288. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.js.map +1 -1
  289. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.cjs +27 -1
  290. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.cjs.map +1 -1
  291. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js +8 -8
  292. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js.map +1 -1
  293. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs +197 -4
  294. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs.map +1 -1
  295. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js +163 -98
  296. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js.map +1 -1
  297. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.cjs +55 -1
  298. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.cjs.map +1 -1
  299. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js +31 -24
  300. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js.map +1 -1
  301. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs +19 -1
  302. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs.map +1 -1
  303. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +12 -9
  304. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js.map +1 -1
  305. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs +102 -1
  306. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs.map +1 -1
  307. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js +85 -51
  308. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js.map +1 -1
  309. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.cjs +5 -1
  310. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.cjs.map +1 -1
  311. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js +3 -3
  312. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js.map +1 -1
  313. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs +6 -1
  314. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs.map +1 -1
  315. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js +5 -5
  316. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js.map +1 -1
  317. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs +62 -36
  318. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs.map +1 -1
  319. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js +41 -65
  320. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js.map +1 -1
  321. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs +10 -1
  322. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs.map +1 -1
  323. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js +8 -5
  324. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js.map +1 -1
  325. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs +37 -1
  326. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs.map +1 -1
  327. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js +28 -16
  328. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js.map +1 -1
  329. package/dist/node_modules/react-style-singleton/dist/es2015/component.cjs +13 -1
  330. package/dist/node_modules/react-style-singleton/dist/es2015/component.cjs.map +1 -1
  331. package/dist/node_modules/react-style-singleton/dist/es2015/component.js +9 -7
  332. package/dist/node_modules/react-style-singleton/dist/es2015/component.js.map +1 -1
  333. package/dist/node_modules/react-style-singleton/dist/es2015/hook.cjs +33 -1
  334. package/dist/node_modules/react-style-singleton/dist/es2015/hook.cjs.map +1 -1
  335. package/dist/node_modules/react-style-singleton/dist/es2015/hook.js +11 -10
  336. package/dist/node_modules/react-style-singleton/dist/es2015/hook.js.map +1 -1
  337. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.cjs +48 -1
  338. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.cjs.map +1 -1
  339. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js +35 -17
  340. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js.map +1 -1
  341. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.cjs +3014 -1
  342. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.cjs.map +1 -1
  343. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +804 -555
  344. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -1
  345. package/dist/node_modules/tailwindcss/dist/plugin.cjs +12 -1
  346. package/dist/node_modules/tailwindcss/dist/plugin.cjs.map +1 -1
  347. package/dist/node_modules/tailwindcss/dist/plugin.js +8 -8
  348. package/dist/node_modules/tailwindcss/dist/plugin.js.map +1 -1
  349. package/dist/node_modules/tslib/tslib.es6.cjs +38 -1
  350. package/dist/node_modules/tslib/tslib.es6.cjs.map +1 -1
  351. package/dist/node_modules/tslib/tslib.es6.js +33 -21
  352. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  353. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.cjs +11 -1
  354. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.cjs.map +1 -1
  355. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js +8 -3
  356. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js.map +1 -1
  357. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs +52 -1
  358. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs.map +1 -1
  359. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js +28 -19
  360. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js.map +1 -1
  361. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.cjs +29 -1
  362. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.cjs.map +1 -1
  363. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js +15 -11
  364. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js.map +1 -1
  365. package/dist/node_modules/use-sidecar/dist/es2015/exports.cjs +38 -1
  366. package/dist/node_modules/use-sidecar/dist/es2015/exports.cjs.map +1 -1
  367. package/dist/node_modules/use-sidecar/dist/es2015/exports.js +15 -12
  368. package/dist/node_modules/use-sidecar/dist/es2015/exports.js.map +1 -1
  369. package/dist/node_modules/use-sidecar/dist/es2015/medium.cjs +88 -1
  370. package/dist/node_modules/use-sidecar/dist/es2015/medium.cjs.map +1 -1
  371. package/dist/node_modules/use-sidecar/dist/es2015/medium.js +64 -43
  372. package/dist/node_modules/use-sidecar/dist/es2015/medium.js.map +1 -1
  373. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +68 -1
  374. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -1
  375. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +49 -39
  376. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
  377. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs +53 -1
  378. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs.map +1 -1
  379. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +39 -32
  380. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js.map +1 -1
  381. package/dist/node_modules/use-sync-external-store/shim/index.cjs +17 -1
  382. package/dist/node_modules/use-sync-external-store/shim/index.cjs.map +1 -1
  383. package/dist/node_modules/use-sync-external-store/shim/index.js +14 -7
  384. package/dist/node_modules/use-sync-external-store/shim/index.js.map +1 -1
  385. package/dist/providers/auth/auth.context.cjs +5 -1
  386. package/dist/providers/auth/auth.context.cjs.map +1 -1
  387. package/dist/providers/auth/auth.context.js +3 -3
  388. package/dist/providers/auth/auth.context.js.map +1 -1
  389. package/dist/providers/auth/auth.hook.cjs +12 -1
  390. package/dist/providers/auth/auth.hook.cjs.map +1 -1
  391. package/dist/providers/auth/auth.hook.js +8 -7
  392. package/dist/providers/auth/auth.hook.js.map +1 -1
  393. package/dist/providers/auth/auth.provider.cjs +37 -1
  394. package/dist/providers/auth/auth.provider.cjs.map +1 -1
  395. package/dist/providers/auth/auth.provider.js +31 -22
  396. package/dist/providers/auth/auth.provider.js.map +1 -1
  397. package/dist/providers/blimu/blimu.context.cjs +5 -1
  398. package/dist/providers/blimu/blimu.context.cjs.map +1 -1
  399. package/dist/providers/blimu/blimu.context.js +3 -3
  400. package/dist/providers/blimu/blimu.context.js.map +1 -1
  401. package/dist/providers/blimu/blimu.hook.cjs +12 -1
  402. package/dist/providers/blimu/blimu.hook.cjs.map +1 -1
  403. package/dist/providers/blimu/blimu.hook.js +8 -7
  404. package/dist/providers/blimu/blimu.hook.js.map +1 -1
  405. package/dist/providers/blimu/blimu.provider.cjs +71 -1
  406. package/dist/providers/blimu/blimu.provider.cjs.map +1 -1
  407. package/dist/providers/blimu/blimu.provider.js +32 -27
  408. package/dist/providers/blimu/blimu.provider.js.map +1 -1
  409. package/dist/providers/index.cjs +13 -0
  410. package/dist/providers/index.cjs.map +1 -0
  411. package/dist/providers/index.js +13 -0
  412. package/dist/providers/index.js.map +1 -0
  413. package/dist/providers/theme/theme.context.cjs +5 -1
  414. package/dist/providers/theme/theme.context.cjs.map +1 -1
  415. package/dist/providers/theme/theme.context.js +3 -3
  416. package/dist/providers/theme/theme.context.js.map +1 -1
  417. package/dist/providers/theme/theme.hook.cjs +12 -1
  418. package/dist/providers/theme/theme.hook.cjs.map +1 -1
  419. package/dist/providers/theme/theme.hook.js +8 -7
  420. package/dist/providers/theme/theme.hook.js.map +1 -1
  421. package/dist/providers/theme/theme.provider.cjs +104 -1
  422. package/dist/providers/theme/theme.provider.cjs.map +1 -1
  423. package/dist/providers/theme/theme.provider.js +85 -48
  424. package/dist/providers/theme/theme.provider.js.map +1 -1
  425. package/dist/tailwind.cjs +200 -0
  426. package/dist/tailwind.cjs.map +1 -0
  427. package/dist/{tailwind.plugin.js → tailwind.js} +6 -6
  428. package/dist/tailwind.js.map +1 -0
  429. package/dist/types/index.cjs +11 -1
  430. package/dist/types/index.cjs.map +1 -1
  431. package/dist/types/index.js +8 -8
  432. package/dist/types/index.js.map +1 -1
  433. package/dist/utils/publishable-key.cjs +62 -1
  434. package/dist/utils/publishable-key.cjs.map +1 -1
  435. package/dist/utils/publishable-key.js +52 -27
  436. package/dist/utils/publishable-key.js.map +1 -1
  437. package/package.json +41 -42
  438. package/dist/components.cjs +0 -2
  439. package/dist/components.cjs.map +0 -1
  440. package/dist/components.js +0 -13
  441. package/dist/components.js.map +0 -1
  442. package/dist/hooks.cjs +0 -2
  443. package/dist/hooks.cjs.map +0 -1
  444. package/dist/hooks.js +0 -14
  445. package/dist/hooks.js.map +0 -1
  446. package/dist/providers.cjs +0 -2
  447. package/dist/providers.cjs.map +0 -1
  448. package/dist/providers.js +0 -13
  449. package/dist/providers.js.map +0 -1
  450. package/dist/tailwind.plugin.cjs +0 -2
  451. package/dist/tailwind.plugin.cjs.map +0 -1
  452. package/dist/tailwind.plugin.js.map +0 -1
@@ -1,150 +1,250 @@
1
- import { Blimu as _, BlimuError as A } from "@blimu/client";
2
- import o from "../node_modules/js-cookie/dist/js.cookie.js";
3
- import { jwtDecode as C } from "../node_modules/jwt-decode/build/esm/index.js";
4
- const h = "__bli_session", S = "__lh_jwt", u = "__lh_jwt", m = 10, w = 1e3, E = (i) => Math.floor(i * w), b = (i) => Math.floor(i / w), p = () => b(Date.now()), P = (i) => E(i), v = (i, e) => {
5
- const s = P(i), r = E(e), t = Date.now();
6
- return Math.max(s - r - t, 0);
7
- }, f = (i, e) => {
8
- const s = p();
9
- return i - e < s;
1
+ import { Blimu, BlimuError } from "@blimu/client";
2
+ import api from "../node_modules/js-cookie/dist/js.cookie.js";
3
+ import { jwtDecode } from "../node_modules/jwt-decode/build/esm/index.js";
4
+ const SESSION_COOKIE_NAME = "__bli_session";
5
+ const LOCALHOST_JWT_URL_PARAM_NAME = "__lh_jwt";
6
+ const LOCALHOST_JWT_COOKIE_NAME = "__lh_jwt";
7
+ const SESSION_EXPIRATION_BUFFER = 10;
8
+ const SECONDS_TO_MS = 1e3;
9
+ const secondsToMilliseconds = (seconds) => Math.floor(seconds * SECONDS_TO_MS);
10
+ const millisecondsToSeconds = (ms) => Math.floor(ms / SECONDS_TO_MS);
11
+ const nowInSeconds = () => millisecondsToSeconds(Date.now());
12
+ const jwtExpToMilliseconds = (exp) => secondsToMilliseconds(exp);
13
+ const calculateTimeoutDelay = (expirationSeconds, bufferSeconds) => {
14
+ const expirationMS = jwtExpToMilliseconds(expirationSeconds);
15
+ const bufferMS = secondsToMilliseconds(bufferSeconds);
16
+ const nowMS = Date.now();
17
+ return Math.max(expirationMS - bufferMS - nowMS, 0);
10
18
  };
11
- class x {
12
- constructor(e, s, r, t, l) {
13
- this.isLive = e, this.client = s, this.store = r, this.pendingRefresher = null, this.refreshPromise = null, this.refreshingSignals = /* @__PURE__ */ new Set(), this.refreshingSignalAbortController = null, this.localClient = new _({
14
- baseURL: t,
19
+ const isExpiredIn = (expiration, buffer) => {
20
+ const now = nowInSeconds();
21
+ return expiration - buffer < now;
22
+ };
23
+ class AuthSessionService {
24
+ constructor(isLive, client, store, baseURL, publishableKey) {
25
+ this.isLive = isLive;
26
+ this.client = client;
27
+ this.store = store;
28
+ this.pendingRefresher = null;
29
+ this.refreshPromise = null;
30
+ this.refreshingSignals = /* @__PURE__ */ new Set();
31
+ this.refreshingSignalAbortController = null;
32
+ this.localClient = new Blimu({
33
+ baseURL,
15
34
  credentials: "include",
16
- headers: { "x-blimu-publishable-key": l }
17
- }), this.handleRequestError = this.handleRequestError.bind(this);
35
+ headers: { "x-blimu-publishable-key": publishableKey }
36
+ });
37
+ this.handleRequestError = this.handleRequestError.bind(this);
18
38
  }
19
39
  /**
20
40
  * Set cookie with appropriate security settings based on environment
21
41
  */
22
- setCookie(e, s, r = {}) {
23
- const t = {
42
+ setCookie(name, value, options = {}) {
43
+ const cookieOptions = {
24
44
  secure: this.isLive,
25
45
  // true for live environments, false for localhost
26
46
  sameSite: "lax",
27
47
  path: "/"
28
48
  };
29
- r.maxAge !== void 0 && (t.expires = r.maxAge / (1440 * 60)), o.set(e, s, t);
49
+ if (options.maxAge !== void 0) {
50
+ cookieOptions.expires = options.maxAge / (24 * 60 * 60);
51
+ }
52
+ api.set(name, value, cookieOptions);
30
53
  }
31
54
  getSessionPayload() {
32
- const e = o.get(h);
33
- return e ? C(e) : null;
55
+ const token = api.get(SESSION_COOKIE_NAME);
56
+ if (!token) {
57
+ return null;
58
+ }
59
+ const decoded = jwtDecode(token);
60
+ return decoded;
34
61
  }
35
62
  async getSessionToken() {
36
- const e = this.getSessionPayload();
37
- if (e)
38
- return this.refreshPromise ? (await this.refreshPromise, o.get(h)) : (f(e.exp, 0) && await this.refreshSession(), o.get(h));
63
+ const sessionPayload = this.getSessionPayload();
64
+ if (!sessionPayload) {
65
+ return void 0;
66
+ }
67
+ if (this.refreshPromise) {
68
+ await this.refreshPromise;
69
+ return api.get(SESSION_COOKIE_NAME);
70
+ }
71
+ if (isExpiredIn(sessionPayload.exp, 0)) {
72
+ await this.refreshSession();
73
+ }
74
+ return api.get(SESSION_COOKIE_NAME);
39
75
  }
40
- async handleRequestError(e) {
41
- return e instanceof A && [401, 500].includes(e.status) ? (o.remove(h), o.remove(u), {
42
- error: e.message,
43
- user: null
44
- }) : e instanceof DOMException ? {
45
- error: e.message,
46
- user: null
47
- } : e instanceof Error ? {
48
- error: e.message,
49
- user: null
50
- } : {
76
+ async handleRequestError(error) {
77
+ if (error instanceof BlimuError && [401, 500].includes(error.status)) {
78
+ api.remove(SESSION_COOKIE_NAME);
79
+ api.remove(LOCALHOST_JWT_COOKIE_NAME);
80
+ return {
81
+ error: error.message,
82
+ user: null
83
+ };
84
+ }
85
+ if (error instanceof DOMException)
86
+ return {
87
+ error: error.message,
88
+ user: null
89
+ };
90
+ if (error instanceof Error) {
91
+ return {
92
+ error: error.message,
93
+ user: null
94
+ };
95
+ }
96
+ return {
51
97
  error: "unknown error",
52
98
  user: null
53
99
  };
54
100
  }
55
- async initialize({ signal: e } = {}) {
56
- const s = new URL(window.location.href), r = s.searchParams.get(S) ?? void 0;
57
- if (r && (s.searchParams.delete(S), window.history.replaceState({}, "", s.toString())), r && this.setCookie(u, r, {
58
- maxAge: 720 * 60 * 60
59
- // 30 days
60
- }), o.get(u) && !o.get(h)) {
61
- const n = await this.refreshSession({ signal: e }).catch(this.handleRequestError);
62
- if ("error" in n) return n;
63
- }
64
- const l = this.getSessionPayload();
65
- if (!l)
101
+ async initialize({ signal } = {}) {
102
+ const url = new URL(window.location.href);
103
+ const localhostJWT = url.searchParams.get(LOCALHOST_JWT_URL_PARAM_NAME) ?? void 0;
104
+ if (localhostJWT) {
105
+ url.searchParams.delete(LOCALHOST_JWT_URL_PARAM_NAME);
106
+ window.history.replaceState({}, "", url.toString());
107
+ }
108
+ if (localhostJWT) {
109
+ this.setCookie(LOCALHOST_JWT_COOKIE_NAME, localhostJWT, {
110
+ maxAge: 30 * 24 * 60 * 60
111
+ // 30 days
112
+ });
113
+ }
114
+ const localhostJWTCookie = api.get(LOCALHOST_JWT_COOKIE_NAME);
115
+ console.log("localhostJWTCookie", localhostJWTCookie);
116
+ if (localhostJWTCookie && !api.get(SESSION_COOKIE_NAME)) {
117
+ const result2 = await this.refreshSession({ signal }).catch(this.handleRequestError);
118
+ if ("error" in result2) return result2;
119
+ }
120
+ const sessionPayload = this.getSessionPayload();
121
+ if (!sessionPayload) {
66
122
  return {
67
123
  error: null,
68
124
  user: null
69
125
  };
70
- if (f(l.exp, m)) {
71
- const n = await this.refreshSession().catch(this.handleRequestError);
72
- if ("error" in n) return n;
73
126
  }
74
- const a = await this.client.auth.getSession().catch(this.handleRequestError);
75
- return "error" in a ? a : {
127
+ if (isExpiredIn(sessionPayload.exp, SESSION_EXPIRATION_BUFFER)) {
128
+ const result2 = await this.refreshSession().catch(this.handleRequestError);
129
+ if ("error" in result2) return result2;
130
+ }
131
+ const result = await this.client.auth.getSession().catch(this.handleRequestError);
132
+ if ("error" in result) return result;
133
+ return {
76
134
  error: null,
77
- user: a.user
135
+ user: result.user
78
136
  };
79
137
  }
80
138
  scheduleRefresh() {
81
- const e = new AbortController();
82
- let s = !0, r = null;
83
- const t = () => {
84
- s = !0, this.pendingRefresher && (this.pendingRefresher(), this.pendingRefresher = null);
85
- }, l = () => {
86
- s = !1;
139
+ const abortController = new AbortController();
140
+ let isOnline = true;
141
+ let timeoutId = null;
142
+ const onlineHandler = () => {
143
+ isOnline = true;
144
+ if (this.pendingRefresher) {
145
+ this.pendingRefresher();
146
+ this.pendingRefresher = null;
147
+ }
148
+ };
149
+ const offlineHandler = () => {
150
+ isOnline = false;
87
151
  };
88
- window.addEventListener("online", t), window.addEventListener("offline", l);
89
- const a = () => {
90
- r !== null && (window.clearTimeout(r), r = null);
91
- const n = this.getSessionPayload();
92
- if (!n || f(n.exp, 0)) return;
93
- const d = v(n.exp, m);
94
- if (d < 0)
152
+ window.addEventListener("online", onlineHandler);
153
+ window.addEventListener("offline", offlineHandler);
154
+ const refresh = () => {
155
+ if (timeoutId !== null) {
156
+ window.clearTimeout(timeoutId);
157
+ timeoutId = null;
158
+ }
159
+ const sessionPayload = this.getSessionPayload();
160
+ if (!sessionPayload || isExpiredIn(sessionPayload.exp, 0)) return;
161
+ const timeoutDelayMS = calculateTimeoutDelay(sessionPayload.exp, SESSION_EXPIRATION_BUFFER);
162
+ if (timeoutDelayMS < 0) {
95
163
  return;
96
- const g = async () => {
97
- if (r = null, !s) {
98
- this.pendingRefresher = g;
164
+ }
165
+ const refresher = async () => {
166
+ timeoutId = null;
167
+ if (!isOnline) {
168
+ this.pendingRefresher = refresher;
99
169
  return;
100
170
  }
101
- const c = await this.refreshSession({ signal: e.signal });
102
- if ("error" in c) {
103
- if (c.error === "aborted")
171
+ const result = await this.refreshSession({ signal: abortController.signal });
172
+ if ("error" in result) {
173
+ if (result.error === "aborted") {
104
174
  return;
175
+ }
105
176
  this.store.setState({
106
177
  status: "error",
107
178
  user: null,
108
- error: c.error
179
+ error: result.error
109
180
  });
110
181
  return;
111
- } else
112
- a();
182
+ } else {
183
+ refresh();
184
+ }
113
185
  };
114
- r = window.setTimeout(g, d);
186
+ timeoutId = window.setTimeout(refresher, timeoutDelayMS);
115
187
  };
116
- return a(), () => {
117
- r && window.clearTimeout(r), e.abort(), window.removeEventListener("online", t), window.removeEventListener("offline", l);
188
+ refresh();
189
+ return () => {
190
+ if (timeoutId) {
191
+ window.clearTimeout(timeoutId);
192
+ }
193
+ abortController.abort();
194
+ window.removeEventListener("online", onlineHandler);
195
+ window.removeEventListener("offline", offlineHandler);
118
196
  };
119
197
  }
120
- async refreshSession({ signal: e } = {}) {
121
- if (e && (this.refreshingSignals.add(e), e.addEventListener("abort", () => {
122
- this.refreshingSignals.delete(e), this.refreshingSignals.size === 0 && this.refreshingSignalAbortController?.abort();
123
- })), this.refreshPromise)
198
+ async refreshSession({ signal } = {}) {
199
+ if (signal) {
200
+ this.refreshingSignals.add(signal);
201
+ signal.addEventListener("abort", () => {
202
+ this.refreshingSignals.delete(signal);
203
+ if (this.refreshingSignals.size === 0) {
204
+ this.refreshingSignalAbortController?.abort();
205
+ }
206
+ });
207
+ }
208
+ if (this.refreshPromise) {
124
209
  return this.refreshPromise;
125
- this.refreshingSignalAbortController = new AbortController(), this.refreshingSignalAbortController.signal.addEventListener("abort", () => {
126
- this.refreshPromise = null, this.refreshingSignalAbortController = null, this.refreshingSignals.clear();
210
+ }
211
+ this.refreshingSignalAbortController = new AbortController();
212
+ this.refreshingSignalAbortController.signal.addEventListener("abort", () => {
213
+ this.refreshPromise = null;
214
+ this.refreshingSignalAbortController = null;
215
+ this.refreshingSignals.clear();
127
216
  });
128
- const s = this.isLive ? void 0 : o.get(u), r = {};
129
- s && (r.__lh_jwt = s), this.refreshPromise = this.localClient.auth.refresh(r, {
217
+ const localhostJWT = !this.isLive ? api.get(LOCALHOST_JWT_COOKIE_NAME) : void 0;
218
+ const queryParams = {};
219
+ if (localhostJWT) {
220
+ queryParams.__lh_jwt = localhostJWT;
221
+ }
222
+ this.refreshPromise = this.localClient.auth.refresh(queryParams, {
130
223
  signal: this.refreshingSignalAbortController.signal
131
- }).then((t) => (this.isLive || this.setCookie(h, t.sessionToken, {
132
- maxAge: 720 * 60 * 60
133
- // 30 days
134
- }), t)).catch(this.handleRequestError);
224
+ }).then((response) => {
225
+ if (!this.isLive) {
226
+ this.setCookie(SESSION_COOKIE_NAME, response.sessionToken, {
227
+ maxAge: 30 * 24 * 60 * 60
228
+ // 30 days
229
+ });
230
+ }
231
+ return response;
232
+ }).catch(this.handleRequestError);
135
233
  try {
136
234
  return await this.refreshPromise;
137
235
  } finally {
138
- this.refreshPromise = null, this.refreshingSignalAbortController = null, this.refreshingSignals.clear();
236
+ this.refreshPromise = null;
237
+ this.refreshingSignalAbortController = null;
238
+ this.refreshingSignals.clear();
139
239
  }
140
240
  }
141
241
  }
142
242
  export {
143
- x as AuthSessionService,
144
- u as LOCALHOST_JWT_COOKIE_NAME,
145
- S as LOCALHOST_JWT_URL_PARAM_NAME,
146
- h as SESSION_COOKIE_NAME,
147
- m as SESSION_EXPIRATION_BUFFER,
148
- f as isExpiredIn
243
+ AuthSessionService,
244
+ LOCALHOST_JWT_COOKIE_NAME,
245
+ LOCALHOST_JWT_URL_PARAM_NAME,
246
+ SESSION_COOKIE_NAME,
247
+ SESSION_EXPIRATION_BUFFER,
248
+ isExpiredIn
149
249
  };
150
250
  //# sourceMappingURL=auth.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.service.js","sources":["../../src/client/auth.service.ts"],"sourcesContent":["import { Blimu, BlimuError } from '@blimu/client';\nimport type { RefreshResponse } from '@blimu/client/schema';\nimport Cookies from 'js-cookie';\nimport { jwtDecode } from 'jwt-decode';\n\nimport type { AuthState, User } from '../types';\nimport { ExternalStore } from './external-store';\n\nexport const SESSION_COOKIE_NAME = '__bli_session';\nexport const LOCALHOST_JWT_URL_PARAM_NAME = '__lh_jwt';\nexport const LOCALHOST_JWT_COOKIE_NAME = '__lh_jwt';\nexport const SESSION_EXPIRATION_BUFFER = 10;\n\n/**\n * Time conversion utilities\n * JWT tokens use seconds (Unix timestamp), JavaScript Date uses milliseconds\n */\nconst SECONDS_TO_MS = 1000;\n\n/**\n * Convert seconds to milliseconds\n */\nconst secondsToMilliseconds = (seconds: number): number => Math.floor(seconds * SECONDS_TO_MS);\n\n/**\n * Convert milliseconds to seconds\n */\nconst millisecondsToSeconds = (ms: number): number => Math.floor(ms / SECONDS_TO_MS);\n\n/**\n * Get current time in seconds (Unix timestamp)\n */\nconst nowInSeconds = (): number => millisecondsToSeconds(Date.now());\n\n/**\n * Convert JWT expiration time (seconds) to milliseconds\n */\nconst jwtExpToMilliseconds = (exp: number): number => secondsToMilliseconds(exp);\n\n/**\n * Calculate timeout delay in milliseconds for refreshing before expiration\n * @param expirationSeconds - JWT exp claim in seconds\n * @param bufferSeconds - Buffer time in seconds before expiration\n * @returns Timeout delay in milliseconds\n */\nconst calculateTimeoutDelay = (expirationSeconds: number, bufferSeconds: number): number => {\n const expirationMS = jwtExpToMilliseconds(expirationSeconds);\n const bufferMS = secondsToMilliseconds(bufferSeconds);\n const nowMS = Date.now();\n return Math.max(expirationMS - bufferMS - nowMS, 0);\n};\n\n/**\n * Check if a JWT expiration time (in seconds) is expired or will expire within the buffer\n * @param expiration - JWT exp claim in seconds (Unix timestamp)\n * @param buffer - Buffer time in seconds before expiration to consider it expired\n * @returns true if expired or will expire within buffer\n */\nexport const isExpiredIn = (expiration: number, buffer: number): boolean => {\n const now = nowInSeconds();\n return expiration - buffer < now;\n};\n\nexport class AuthSessionService {\n private pendingRefresher: (() => void) | null = null;\n private refreshPromise: Promise<RefreshResponse | { error: string; user: null }> | null = null;\n private refreshingSignals: Set<AbortSignal> = new Set();\n private refreshingSignalAbortController: AbortController | null = null;\n // A local client that doesn't call getSessionToken() which calls refreshSession().\n private localClient: Blimu;\n\n constructor(\n private readonly isLive: boolean,\n private readonly client: Blimu,\n private readonly store: ExternalStore<AuthState>,\n baseURL: string,\n publishableKey: string,\n ) {\n this.localClient = new Blimu({\n baseURL,\n credentials: 'include',\n headers: { 'x-blimu-publishable-key': publishableKey },\n });\n this.handleRequestError = this.handleRequestError.bind(this);\n }\n\n /**\n * Set cookie with appropriate security settings based on environment\n */\n private setCookie(name: string, value: string, options: { maxAge?: number } = {}): void {\n const cookieOptions: Cookies.CookieAttributes = {\n secure: this.isLive, // true for live environments, false for localhost\n sameSite: 'lax',\n path: '/',\n };\n\n if (options.maxAge !== undefined) {\n cookieOptions.expires = options.maxAge / (24 * 60 * 60); // Convert seconds to days\n }\n\n Cookies.set(name, value, cookieOptions);\n }\n\n getSessionPayload(): {\n sub: string;\n environmentId: string;\n type: string;\n iat: number;\n exp: number;\n } | null {\n const token = Cookies.get(SESSION_COOKIE_NAME);\n\n if (!token) {\n return null;\n }\n\n const decoded = jwtDecode<{\n sub: string;\n environmentId: string;\n type: string;\n iat: number;\n exp: number;\n }>(token);\n\n return decoded;\n }\n\n async getSessionToken(): Promise<string | undefined> {\n const sessionPayload = this.getSessionPayload();\n\n if (!sessionPayload) {\n return undefined;\n }\n\n // If a refresh is already in progress, wait for it to complete\n // This prevents infinite recursion when refreshSession() calls client.auth.refresh()\n // which triggers accessToken() which calls getSessionToken()\n if (this.refreshPromise) {\n await this.refreshPromise;\n // After refresh completes, return the updated token from cookie\n return Cookies.get(SESSION_COOKIE_NAME);\n }\n\n if (isExpiredIn(sessionPayload.exp, 0)) {\n await this.refreshSession();\n }\n\n return Cookies.get(SESSION_COOKIE_NAME);\n }\n\n async handleRequestError(error: unknown): Promise<{ error: string; user: null }> {\n if (error instanceof BlimuError && [401, 500].includes(error.status)) {\n Cookies.remove(SESSION_COOKIE_NAME);\n Cookies.remove(LOCALHOST_JWT_COOKIE_NAME);\n\n return {\n error: error.message,\n user: null,\n };\n }\n\n if (error instanceof DOMException)\n return {\n error: error.message,\n user: null,\n };\n\n if (error instanceof Error) {\n return {\n error: error.message,\n user: null,\n };\n }\n\n return {\n error: 'unknown error',\n user: null,\n };\n }\n\n async initialize({ signal }: { signal?: AbortSignal } = {}): Promise<{\n error: string | null;\n user: User | null;\n }> {\n const url = new URL(window.location.href);\n const localhostJWT = url.searchParams.get(LOCALHOST_JWT_URL_PARAM_NAME) ?? undefined;\n\n // Clean up URL parameters immediately to prevent re-processing on re-renders\n if (localhostJWT) {\n url.searchParams.delete(LOCALHOST_JWT_URL_PARAM_NAME);\n window.history.replaceState({}, '', url.toString());\n }\n\n // Handle localhost JWT from URL parameter\n if (localhostJWT) {\n // Set localhost JWT cookie on customer app domain\n this.setCookie(LOCALHOST_JWT_COOKIE_NAME, localhostJWT, {\n maxAge: 30 * 24 * 60 * 60, // 30 days\n });\n }\n\n const localhostJWTCookie = Cookies.get(LOCALHOST_JWT_COOKIE_NAME);\n\n if (localhostJWTCookie && !Cookies.get(SESSION_COOKIE_NAME)) {\n const result = await this.refreshSession({ signal }).catch(this.handleRequestError);\n if ('error' in result) return result;\n }\n\n const sessionPayload = this.getSessionPayload();\n\n if (!sessionPayload) {\n return {\n error: null,\n user: null,\n };\n }\n\n if (isExpiredIn(sessionPayload.exp, SESSION_EXPIRATION_BUFFER)) {\n const result = await this.refreshSession().catch(this.handleRequestError);\n if ('error' in result) return result;\n }\n\n const result = await this.client.auth.getSession().catch(this.handleRequestError);\n if ('error' in result) return result;\n\n return {\n error: null,\n user: result.user,\n };\n }\n\n scheduleRefresh() {\n const abortController = new AbortController();\n let isOnline = true;\n let timeoutId: number | null = null;\n\n const onlineHandler = () => {\n isOnline = true;\n if (this.pendingRefresher) {\n this.pendingRefresher();\n this.pendingRefresher = null;\n }\n };\n const offlineHandler = () => {\n isOnline = false;\n };\n\n window.addEventListener('online', onlineHandler);\n window.addEventListener('offline', offlineHandler);\n\n const refresh = () => {\n // Clear any existing timeout before scheduling a new one\n // This prevents infinite loops when refresh() is called recursively\n if (timeoutId !== null) {\n window.clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n const sessionPayload = this.getSessionPayload();\n\n if (!sessionPayload || isExpiredIn(sessionPayload.exp, 0)) return;\n\n // Calculate timeout delay: refresh SESSION_EXPIRATION_BUFFER seconds before expiration\n const timeoutDelayMS = calculateTimeoutDelay(sessionPayload.exp, SESSION_EXPIRATION_BUFFER);\n\n // Prevent scheduling if timeout is negative (token already expired)\n // Allow 0ms delays to handle edge cases where we're exactly at the refresh point\n // This prevents immediate re-scheduling that could cause infinite loops\n if (timeoutDelayMS < 0) {\n return;\n }\n\n // Having this function outside timeout, allows us to call refresh immediately when back online\n const refresher = async () => {\n // Clear timeoutId since we're executing now\n timeoutId = null;\n\n if (!isOnline) {\n // Keep closure of refresh function alive\n this.pendingRefresher = refresher;\n return;\n }\n\n const result = await this.refreshSession({ signal: abortController.signal });\n\n if ('error' in result) {\n // If the refresh was aborted (e.g., due to React strict mode unmounting),\n // don't treat it as an error - just return and let the component remount handle it\n if (result.error === 'aborted') {\n return;\n }\n // For real errors, update the store\n this.store.setState({\n status: 'error',\n user: null,\n error: result.error,\n });\n return;\n } else {\n // After successful refresh, schedule the next refresh with the new token\n refresh();\n }\n };\n\n timeoutId = window.setTimeout(refresher, timeoutDelayMS);\n };\n\n refresh();\n\n return () => {\n if (timeoutId) {\n window.clearTimeout(timeoutId);\n }\n abortController.abort();\n window.removeEventListener('online', onlineHandler);\n window.removeEventListener('offline', offlineHandler);\n };\n }\n\n private async refreshSession({ signal }: { signal?: AbortSignal } = {}) {\n if (signal) {\n // Add signal to tracking set (was using .has() instead of .add() - bug fix)\n this.refreshingSignals.add(signal);\n\n signal.addEventListener('abort', () => {\n this.refreshingSignals.delete(signal);\n\n if (this.refreshingSignals.size === 0) {\n this.refreshingSignalAbortController?.abort();\n }\n });\n }\n\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.refreshingSignalAbortController = new AbortController();\n\n this.refreshingSignalAbortController.signal.addEventListener('abort', () => {\n this.refreshPromise = null;\n this.refreshingSignalAbortController = null;\n this.refreshingSignals.clear();\n });\n\n // Get localhost_jwt from cookie to send as query parameter (only for non-live environments)\n const localhostJWT = !this.isLive ? Cookies.get(LOCALHOST_JWT_COOKIE_NAME) : undefined;\n\n // Build query parameters - only include __lh_jwt for non-live environments when cookie exists\n const queryParams: { __lh_jwt?: string } = {};\n if (localhostJWT) {\n queryParams.__lh_jwt = localhostJWT;\n }\n\n // Use local client to avoid infinite recursion. Regular client calls getSessionToken() which calls refreshSession().\n // There are hacks to avoid infinite recursion, but they are not reliable.\n // The localhost_jwt is sent as a query parameter only in non-live environments\n // Note: Type assertion needed because the generated SDK type doesn't include 'query' in RequestInit,\n // but the underlying CoreClient.request() method does support it\n this.refreshPromise = this.localClient.auth\n .refresh(queryParams, {\n signal: this.refreshingSignalAbortController.signal,\n })\n .then((response) => {\n // Update cookie with new session token from response body\n // Server also sets it via Set-Cookie header on auth domain, but we set it manually on customer domain\n if (!this.isLive) {\n this.setCookie(SESSION_COOKIE_NAME, response.sessionToken, {\n maxAge: 30 * 24 * 60 * 60, // 30 days\n });\n }\n return response;\n })\n .catch(this.handleRequestError);\n\n try {\n return await this.refreshPromise;\n } finally {\n this.refreshPromise = null;\n this.refreshingSignalAbortController = null;\n this.refreshingSignals.clear();\n }\n }\n}\n"],"names":["SESSION_COOKIE_NAME","LOCALHOST_JWT_URL_PARAM_NAME","LOCALHOST_JWT_COOKIE_NAME","SESSION_EXPIRATION_BUFFER","SECONDS_TO_MS","secondsToMilliseconds","seconds","millisecondsToSeconds","ms","nowInSeconds","jwtExpToMilliseconds","exp","calculateTimeoutDelay","expirationSeconds","bufferSeconds","expirationMS","bufferMS","nowMS","isExpiredIn","expiration","buffer","now","AuthSessionService","isLive","client","store","baseURL","publishableKey","Blimu","name","value","options","cookieOptions","Cookies","token","jwtDecode","sessionPayload","error","BlimuError","signal","url","localhostJWT","result","abortController","isOnline","timeoutId","onlineHandler","offlineHandler","refresh","timeoutDelayMS","refresher","queryParams","response"],"mappings":";;;AAQO,MAAMA,IAAsB,iBACtBC,IAA+B,YAC/BC,IAA4B,YAC5BC,IAA4B,IAMnCC,IAAgB,KAKhBC,IAAwB,CAACC,MAA4B,KAAK,MAAMA,IAAUF,CAAa,GAKvFG,IAAwB,CAACC,MAAuB,KAAK,MAAMA,IAAKJ,CAAa,GAK7EK,IAAe,MAAcF,EAAsB,KAAK,KAAK,GAK7DG,IAAuB,CAACC,MAAwBN,EAAsBM,CAAG,GAQzEC,IAAwB,CAACC,GAA2BC,MAAkC;AAC1F,QAAMC,IAAeL,EAAqBG,CAAiB,GACrDG,IAAWX,EAAsBS,CAAa,GAC9CG,IAAQ,KAAK,IAAA;AACnB,SAAO,KAAK,IAAIF,IAAeC,IAAWC,GAAO,CAAC;AACpD,GAQaC,IAAc,CAACC,GAAoBC,MAA4B;AAC1E,QAAMC,IAAMZ,EAAA;AACZ,SAAOU,IAAaC,IAASC;AAC/B;AAEO,MAAMC,EAAmB;AAAA,EAQ9B,YACmBC,GACAC,GACAC,GACjBC,GACAC,GACA;AALiB,SAAA,SAAAJ,GACA,KAAA,SAAAC,GACA,KAAA,QAAAC,GAVnB,KAAQ,mBAAwC,MAChD,KAAQ,iBAAkF,MAC1F,KAAQ,wCAA0C,IAAA,GACl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,KAClC,KAAK,iCAAiC,MAAA;AAAA,IAE1C,CAAC,IAGC,KAAK;AACP,aAAO,KAAK;AAGd,SAAK,kCAAkC,IAAI,gBAAA,GAE3C,KAAK,gCAAgC,OAAO,iBAAiB,SAAS,MAAM;AAC1E,WAAK,iBAAiB,MACtB,KAAK,kCAAkC,MACvC,KAAK,kBAAkB,MAAA;AAAA,IACzB,CAAC;AAGD,UAAME,IAAgB,KAAK,SAAkD,SAAzCR,EAAQ,IAAI/B,CAAyB,GAGnEiD,IAAqC,CAAA;AAC3C,IAAIV,MACFU,EAAY,WAAWV,IAQzB,KAAK,iBAAiB,KAAK,YAAY,KACpC,QAAQU,GAAa;AAAA,MACpB,QAAQ,KAAK,gCAAgC;AAAA,IAAA,CAC9C,EACA,KAAK,CAACC,OAGA,KAAK,UACR,KAAK,UAAUpD,GAAqBoD,EAAS,cAAc;AAAA,MACzD,QAAQ,MAAU,KAAK;AAAA;AAAA,IAAA,CACxB,GAEIA,EACR,EACA,MAAM,KAAK,kBAAkB;AAEhC,QAAI;AACF,aAAO,MAAM,KAAK;AAAA,IACpB,UAAA;AACE,WAAK,iBAAiB,MACtB,KAAK,kCAAkC,MACvC,KAAK,kBAAkB,MAAA;AAAA,IACzB;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"auth.service.js","sources":["../../src/client/auth.service.ts"],"sourcesContent":["import { Blimu, BlimuError } from '@blimu/client';\nimport type { RefreshResponse } from '@blimu/client/schema';\nimport Cookies from 'js-cookie';\nimport { jwtDecode } from 'jwt-decode';\n\nimport type { AuthState, User } from '../types';\nimport { ExternalStore } from './external-store';\n\nexport const SESSION_COOKIE_NAME = '__bli_session';\nexport const LOCALHOST_JWT_URL_PARAM_NAME = '__lh_jwt';\nexport const LOCALHOST_JWT_COOKIE_NAME = '__lh_jwt';\nexport const SESSION_EXPIRATION_BUFFER = 10;\n\n/**\n * Time conversion utilities\n * JWT tokens use seconds (Unix timestamp), JavaScript Date uses milliseconds\n */\nconst SECONDS_TO_MS = 1000;\n\n/**\n * Convert seconds to milliseconds\n */\nconst secondsToMilliseconds = (seconds: number): number => Math.floor(seconds * SECONDS_TO_MS);\n\n/**\n * Convert milliseconds to seconds\n */\nconst millisecondsToSeconds = (ms: number): number => Math.floor(ms / SECONDS_TO_MS);\n\n/**\n * Get current time in seconds (Unix timestamp)\n */\nconst nowInSeconds = (): number => millisecondsToSeconds(Date.now());\n\n/**\n * Convert JWT expiration time (seconds) to milliseconds\n */\nconst jwtExpToMilliseconds = (exp: number): number => secondsToMilliseconds(exp);\n\n/**\n * Calculate timeout delay in milliseconds for refreshing before expiration\n * @param expirationSeconds - JWT exp claim in seconds\n * @param bufferSeconds - Buffer time in seconds before expiration\n * @returns Timeout delay in milliseconds\n */\nconst calculateTimeoutDelay = (expirationSeconds: number, bufferSeconds: number): number => {\n const expirationMS = jwtExpToMilliseconds(expirationSeconds);\n const bufferMS = secondsToMilliseconds(bufferSeconds);\n const nowMS = Date.now();\n return Math.max(expirationMS - bufferMS - nowMS, 0);\n};\n\n/**\n * Check if a JWT expiration time (in seconds) is expired or will expire within the buffer\n * @param expiration - JWT exp claim in seconds (Unix timestamp)\n * @param buffer - Buffer time in seconds before expiration to consider it expired\n * @returns true if expired or will expire within buffer\n */\nexport const isExpiredIn = (expiration: number, buffer: number): boolean => {\n const now = nowInSeconds();\n return expiration - buffer < now;\n};\n\nexport class AuthSessionService {\n private pendingRefresher: (() => void) | null = null;\n private refreshPromise: Promise<RefreshResponse | { error: string; user: null }> | null = null;\n private refreshingSignals: Set<AbortSignal> = new Set();\n private refreshingSignalAbortController: AbortController | null = null;\n // A local client that doesn't call getSessionToken() which calls refreshSession().\n private localClient: Blimu;\n\n constructor(\n private readonly isLive: boolean,\n private readonly client: Blimu,\n private readonly store: ExternalStore<AuthState>,\n baseURL: string,\n publishableKey: string,\n ) {\n this.localClient = new Blimu({\n baseURL,\n credentials: 'include',\n headers: { 'x-blimu-publishable-key': publishableKey },\n });\n this.handleRequestError = this.handleRequestError.bind(this);\n }\n\n /**\n * Set cookie with appropriate security settings based on environment\n */\n private setCookie(name: string, value: string, options: { maxAge?: number } = {}): void {\n const cookieOptions: Cookies.CookieAttributes = {\n secure: this.isLive, // true for live environments, false for localhost\n sameSite: 'lax',\n path: '/',\n };\n\n if (options.maxAge !== undefined) {\n cookieOptions.expires = options.maxAge / (24 * 60 * 60); // Convert seconds to days\n }\n\n Cookies.set(name, value, cookieOptions);\n }\n\n getSessionPayload(): {\n sub: string;\n environmentId: string;\n type: string;\n iat: number;\n exp: number;\n } | null {\n const token = Cookies.get(SESSION_COOKIE_NAME);\n\n if (!token) {\n return null;\n }\n\n const decoded = jwtDecode<{\n sub: string;\n environmentId: string;\n type: string;\n iat: number;\n exp: number;\n }>(token);\n\n return decoded;\n }\n\n async getSessionToken(): Promise<string | undefined> {\n const sessionPayload = this.getSessionPayload();\n\n if (!sessionPayload) {\n return undefined;\n }\n\n // If a refresh is already in progress, wait for it to complete\n // This prevents infinite recursion when refreshSession() calls client.auth.refresh()\n // which triggers accessToken() which calls getSessionToken()\n if (this.refreshPromise) {\n await this.refreshPromise;\n // After refresh completes, return the updated token from cookie\n return Cookies.get(SESSION_COOKIE_NAME);\n }\n\n if (isExpiredIn(sessionPayload.exp, 0)) {\n await this.refreshSession();\n }\n\n return Cookies.get(SESSION_COOKIE_NAME);\n }\n\n async handleRequestError(error: unknown): Promise<{ error: string; user: null }> {\n if (error instanceof BlimuError && [401, 500].includes(error.status)) {\n Cookies.remove(SESSION_COOKIE_NAME);\n Cookies.remove(LOCALHOST_JWT_COOKIE_NAME);\n\n return {\n error: error.message,\n user: null,\n };\n }\n\n if (error instanceof DOMException)\n return {\n error: error.message,\n user: null,\n };\n\n if (error instanceof Error) {\n return {\n error: error.message,\n user: null,\n };\n }\n\n return {\n error: 'unknown error',\n user: null,\n };\n }\n\n async initialize({ signal }: { signal?: AbortSignal } = {}): Promise<{\n error: string | null;\n user: User | null;\n }> {\n const url = new URL(window.location.href);\n const localhostJWT = url.searchParams.get(LOCALHOST_JWT_URL_PARAM_NAME) ?? undefined;\n\n // Clean up URL parameters immediately to prevent re-processing on re-renders\n if (localhostJWT) {\n url.searchParams.delete(LOCALHOST_JWT_URL_PARAM_NAME);\n window.history.replaceState({}, '', url.toString());\n }\n\n // Handle localhost JWT from URL parameter\n if (localhostJWT) {\n // Set localhost JWT cookie on customer app domain\n this.setCookie(LOCALHOST_JWT_COOKIE_NAME, localhostJWT, {\n maxAge: 30 * 24 * 60 * 60, // 30 days\n });\n }\n\n const localhostJWTCookie = Cookies.get(LOCALHOST_JWT_COOKIE_NAME);\n\n console.log('localhostJWTCookie', localhostJWTCookie);\n\n if (localhostJWTCookie && !Cookies.get(SESSION_COOKIE_NAME)) {\n const result = await this.refreshSession({ signal }).catch(this.handleRequestError);\n if ('error' in result) return result;\n }\n\n const sessionPayload = this.getSessionPayload();\n\n if (!sessionPayload) {\n return {\n error: null,\n user: null,\n };\n }\n\n if (isExpiredIn(sessionPayload.exp, SESSION_EXPIRATION_BUFFER)) {\n const result = await this.refreshSession().catch(this.handleRequestError);\n if ('error' in result) return result;\n }\n\n const result = await this.client.auth.getSession().catch(this.handleRequestError);\n if ('error' in result) return result;\n\n return {\n error: null,\n user: result.user,\n };\n }\n\n scheduleRefresh() {\n const abortController = new AbortController();\n let isOnline = true;\n let timeoutId: number | null = null;\n\n const onlineHandler = () => {\n isOnline = true;\n if (this.pendingRefresher) {\n this.pendingRefresher();\n this.pendingRefresher = null;\n }\n };\n const offlineHandler = () => {\n isOnline = false;\n };\n\n window.addEventListener('online', onlineHandler);\n window.addEventListener('offline', offlineHandler);\n\n const refresh = () => {\n // Clear any existing timeout before scheduling a new one\n // This prevents infinite loops when refresh() is called recursively\n if (timeoutId !== null) {\n window.clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n const sessionPayload = this.getSessionPayload();\n\n if (!sessionPayload || isExpiredIn(sessionPayload.exp, 0)) return;\n\n // Calculate timeout delay: refresh SESSION_EXPIRATION_BUFFER seconds before expiration\n const timeoutDelayMS = calculateTimeoutDelay(sessionPayload.exp, SESSION_EXPIRATION_BUFFER);\n\n // Prevent scheduling if timeout is negative (token already expired)\n // Allow 0ms delays to handle edge cases where we're exactly at the refresh point\n // This prevents immediate re-scheduling that could cause infinite loops\n if (timeoutDelayMS < 0) {\n return;\n }\n\n // Having this function outside timeout, allows us to call refresh immediately when back online\n const refresher = async () => {\n // Clear timeoutId since we're executing now\n timeoutId = null;\n\n if (!isOnline) {\n // Keep closure of refresh function alive\n this.pendingRefresher = refresher;\n return;\n }\n\n const result = await this.refreshSession({ signal: abortController.signal });\n\n if ('error' in result) {\n // If the refresh was aborted (e.g., due to React strict mode unmounting),\n // don't treat it as an error - just return and let the component remount handle it\n if (result.error === 'aborted') {\n return;\n }\n // For real errors, update the store\n this.store.setState({\n status: 'error',\n user: null,\n error: result.error,\n });\n return;\n } else {\n // After successful refresh, schedule the next refresh with the new token\n refresh();\n }\n };\n\n timeoutId = window.setTimeout(refresher, timeoutDelayMS);\n };\n\n refresh();\n\n return () => {\n if (timeoutId) {\n window.clearTimeout(timeoutId);\n }\n abortController.abort();\n window.removeEventListener('online', onlineHandler);\n window.removeEventListener('offline', offlineHandler);\n };\n }\n\n private async refreshSession({ signal }: { signal?: AbortSignal } = {}) {\n if (signal) {\n // Add signal to tracking set (was using .has() instead of .add() - bug fix)\n this.refreshingSignals.add(signal);\n\n signal.addEventListener('abort', () => {\n this.refreshingSignals.delete(signal);\n\n if (this.refreshingSignals.size === 0) {\n this.refreshingSignalAbortController?.abort();\n }\n });\n }\n\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.refreshingSignalAbortController = new AbortController();\n\n this.refreshingSignalAbortController.signal.addEventListener('abort', () => {\n this.refreshPromise = null;\n this.refreshingSignalAbortController = null;\n this.refreshingSignals.clear();\n });\n\n // Get localhost_jwt from cookie to send as query parameter (only for non-live environments)\n const localhostJWT = !this.isLive ? Cookies.get(LOCALHOST_JWT_COOKIE_NAME) : undefined;\n\n // Build query parameters - only include __lh_jwt for non-live environments when cookie exists\n const queryParams: { __lh_jwt?: string } = {};\n if (localhostJWT) {\n queryParams.__lh_jwt = localhostJWT;\n }\n\n // Use local client to avoid infinite recursion. Regular client calls getSessionToken() which calls refreshSession().\n // There are hacks to avoid infinite recursion, but they are not reliable.\n // The localhost_jwt is sent as a query parameter only in non-live environments\n // Note: Type assertion needed because the generated SDK type doesn't include 'query' in RequestInit,\n // but the underlying CoreClient.request() method does support it\n this.refreshPromise = this.localClient.auth\n .refresh(queryParams, {\n signal: this.refreshingSignalAbortController.signal,\n })\n .then((response) => {\n // Update cookie with new session token from response body\n // Server also sets it via Set-Cookie header on auth domain, but we set it manually on customer domain\n if (!this.isLive) {\n this.setCookie(SESSION_COOKIE_NAME, response.sessionToken, {\n maxAge: 30 * 24 * 60 * 60, // 30 days\n });\n }\n return response;\n })\n .catch(this.handleRequestError);\n\n try {\n return await this.refreshPromise;\n } finally {\n this.refreshPromise = null;\n this.refreshingSignalAbortController = null;\n this.refreshingSignals.clear();\n }\n }\n}\n"],"names":["Cookies","result"],"mappings":";;;AAQO,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAMzC,MAAM,gBAAgB;AAKtB,MAAM,wBAAwB,CAAC,YAA4B,KAAK,MAAM,UAAU,aAAa;AAK7F,MAAM,wBAAwB,CAAC,OAAuB,KAAK,MAAM,KAAK,aAAa;AAKnF,MAAM,eAAe,MAAc,sBAAsB,KAAK,KAAK;AAKnE,MAAM,uBAAuB,CAAC,QAAwB,sBAAsB,GAAG;AAQ/E,MAAM,wBAAwB,CAAC,mBAA2B,kBAAkC;AAC1F,QAAM,eAAe,qBAAqB,iBAAiB;AAC3D,QAAM,WAAW,sBAAsB,aAAa;AACpD,QAAM,QAAQ,KAAK,IAAA;AACnB,SAAO,KAAK,IAAI,eAAe,WAAW,OAAO,CAAC;AACpD;AAQO,MAAM,cAAc,CAAC,YAAoB,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,UAAU,qBAAqB,SAAS,cAAc;AAAA,UACzD,QAAQ,KAAK,KAAK,KAAK;AAAA;AAAA,QAAA,CACxB;AAAA,MACH;AACA,aAAO;AAAA,IACT,CAAC,EACA,MAAM,KAAK,kBAAkB;AAEhC,QAAI;AACF,aAAO,MAAM,KAAK;AAAA,IACpB,UAAA;AACE,WAAK,iBAAiB;AACtB,WAAK,kCAAkC;AACvC,WAAK,kBAAkB,MAAA;AAAA,IACzB;AAAA,EACF;AACF;"}
@@ -1,2 +1,27 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class i{constructor(e){this.listeners=new Set,this.subscribe=t=>(this.listeners.add(t),()=>{this.listeners.delete(t)}),this.setState=t=>{typeof t=="function"?this.state=t(this.state):this.state=t,this.listeners.forEach(s=>s(this.state))},this.getSnapshot=()=>this.state,this.state=e}}exports.ExternalStore=i;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class ExternalStore {
4
+ constructor(initialState) {
5
+ this.listeners = /* @__PURE__ */ new Set();
6
+ this.subscribe = (listener) => {
7
+ this.listeners.add(listener);
8
+ return () => {
9
+ this.listeners.delete(listener);
10
+ };
11
+ };
12
+ this.setState = (state) => {
13
+ if (typeof state === "function") {
14
+ this.state = state(this.state);
15
+ } else {
16
+ this.state = state;
17
+ }
18
+ this.listeners.forEach((listener) => listener(this.state));
19
+ };
20
+ this.getSnapshot = () => {
21
+ return this.state;
22
+ };
23
+ this.state = initialState;
24
+ }
25
+ }
26
+ exports.ExternalStore = ExternalStore;
2
27
  //# sourceMappingURL=external-store.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-store.cjs","sources":["../../src/client/external-store.ts"],"sourcesContent":["export class ExternalStore<T> {\n private state: T;\n private listeners: Set<(state: T) => void> = new Set();\n\n constructor(initialState: T) {\n this.state = initialState;\n }\n\n /**\n * Subscribe to state changes\n * Returns an unsubscribe function\n */\n subscribe = (listener: (state: T) => void): (() => void) => {\n this.listeners.add(listener);\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n /**\n * Update state and notify all listeners\n * Accepts either a new state value or a function updater\n */\n setState = (state: T | ((state: T) => T)) => {\n if (typeof state === 'function') {\n this.state = (state as (prev: T) => T)(this.state);\n } else {\n this.state = state;\n }\n // Notify all listeners\n this.listeners.forEach((listener) => listener(this.state));\n };\n\n /**\n * Get current state without subscribing\n */\n getSnapshot = (): T => {\n return this.state;\n };\n}\n"],"names":["ExternalStore","initialState","listener","state"],"mappings":"gFAAO,MAAMA,CAAiB,CAI5B,YAAYC,EAAiB,CAF7B,KAAQ,cAAyC,IAUjD,KAAA,UAAaC,IACX,KAAK,UAAU,IAAIA,CAAQ,EAEpB,IAAM,CACX,KAAK,UAAU,OAAOA,CAAQ,CAChC,GAOF,KAAA,SAAYC,GAAiC,CACvC,OAAOA,GAAU,WACnB,KAAK,MAASA,EAAyB,KAAK,KAAK,EAEjD,KAAK,MAAQA,EAGf,KAAK,UAAU,QAASD,GAAaA,EAAS,KAAK,KAAK,CAAC,CAC3D,EAKA,KAAA,YAAc,IACL,KAAK,MAjCZ,KAAK,MAAQD,CACf,CAkCF"}
1
+ {"version":3,"file":"external-store.cjs","sources":["../../src/client/external-store.ts"],"sourcesContent":["export class ExternalStore<T> {\n private state: T;\n private listeners: Set<(state: T) => void> = new Set();\n\n constructor(initialState: T) {\n this.state = initialState;\n }\n\n /**\n * Subscribe to state changes\n * Returns an unsubscribe function\n */\n subscribe = (listener: (state: T) => void): (() => void) => {\n this.listeners.add(listener);\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n /**\n * Update state and notify all listeners\n * Accepts either a new state value or a function updater\n */\n setState = (state: T | ((state: T) => T)) => {\n if (typeof state === 'function') {\n this.state = (state as (prev: T) => T)(this.state);\n } else {\n this.state = state;\n }\n // Notify all listeners\n this.listeners.forEach((listener) => listener(this.state));\n };\n\n /**\n * Get current state without subscribing\n */\n getSnapshot = (): T => {\n return this.state;\n };\n}\n"],"names":[],"mappings":";;AAAO,MAAM,cAAiB;AAAA,EAI5B,YAAY,cAAiB;AAF7B,SAAQ,gCAAyC,IAAA;AAUjD,SAAA,YAAY,CAAC,aAA+C;AAC1D,WAAK,UAAU,IAAI,QAAQ;AAE3B,aAAO,MAAM;AACX,aAAK,UAAU,OAAO,QAAQ;AAAA,MAChC;AAAA,IACF;AAMA,SAAA,WAAW,CAAC,UAAiC;AAC3C,UAAI,OAAO,UAAU,YAAY;AAC/B,aAAK,QAAS,MAAyB,KAAK,KAAK;AAAA,MACnD,OAAO;AACL,aAAK,QAAQ;AAAA,MACf;AAEA,WAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,KAAK,KAAK,CAAC;AAAA,IAC3D;AAKA,SAAA,cAAc,MAAS;AACrB,aAAO,KAAK;AAAA,IACd;AAlCE,SAAK,QAAQ;AAAA,EACf;AAkCF;;"}
@@ -1,13 +1,27 @@
1
- class h {
2
- constructor(s) {
3
- this.listeners = /* @__PURE__ */ new Set(), this.subscribe = (t) => (this.listeners.add(t), () => {
4
- this.listeners.delete(t);
5
- }), this.setState = (t) => {
6
- typeof t == "function" ? this.state = t(this.state) : this.state = t, this.listeners.forEach((e) => e(this.state));
7
- }, this.getSnapshot = () => this.state, this.state = s;
1
+ class ExternalStore {
2
+ constructor(initialState) {
3
+ this.listeners = /* @__PURE__ */ new Set();
4
+ this.subscribe = (listener) => {
5
+ this.listeners.add(listener);
6
+ return () => {
7
+ this.listeners.delete(listener);
8
+ };
9
+ };
10
+ this.setState = (state) => {
11
+ if (typeof state === "function") {
12
+ this.state = state(this.state);
13
+ } else {
14
+ this.state = state;
15
+ }
16
+ this.listeners.forEach((listener) => listener(this.state));
17
+ };
18
+ this.getSnapshot = () => {
19
+ return this.state;
20
+ };
21
+ this.state = initialState;
8
22
  }
9
23
  }
10
24
  export {
11
- h as ExternalStore
25
+ ExternalStore
12
26
  };
13
27
  //# sourceMappingURL=external-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-store.js","sources":["../../src/client/external-store.ts"],"sourcesContent":["export class ExternalStore<T> {\n private state: T;\n private listeners: Set<(state: T) => void> = new Set();\n\n constructor(initialState: T) {\n this.state = initialState;\n }\n\n /**\n * Subscribe to state changes\n * Returns an unsubscribe function\n */\n subscribe = (listener: (state: T) => void): (() => void) => {\n this.listeners.add(listener);\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n /**\n * Update state and notify all listeners\n * Accepts either a new state value or a function updater\n */\n setState = (state: T | ((state: T) => T)) => {\n if (typeof state === 'function') {\n this.state = (state as (prev: T) => T)(this.state);\n } else {\n this.state = state;\n }\n // Notify all listeners\n this.listeners.forEach((listener) => listener(this.state));\n };\n\n /**\n * Get current state without subscribing\n */\n getSnapshot = (): T => {\n return this.state;\n };\n}\n"],"names":["ExternalStore","initialState","listener","state"],"mappings":"AAAO,MAAMA,EAAiB;AAAA,EAI5B,YAAYC,GAAiB;AAF7B,SAAQ,gCAAyC,IAAA,GAUjD,KAAA,YAAY,CAACC,OACX,KAAK,UAAU,IAAIA,CAAQ,GAEpB,MAAM;AACX,WAAK,UAAU,OAAOA,CAAQ;AAAA,IAChC,IAOF,KAAA,WAAW,CAACC,MAAiC;AAC3C,MAAI,OAAOA,KAAU,aACnB,KAAK,QAASA,EAAyB,KAAK,KAAK,IAEjD,KAAK,QAAQA,GAGf,KAAK,UAAU,QAAQ,CAACD,MAAaA,EAAS,KAAK,KAAK,CAAC;AAAA,IAC3D,GAKA,KAAA,cAAc,MACL,KAAK,OAjCZ,KAAK,QAAQD;AAAA,EACf;AAkCF;"}
1
+ {"version":3,"file":"external-store.js","sources":["../../src/client/external-store.ts"],"sourcesContent":["export class ExternalStore<T> {\n private state: T;\n private listeners: Set<(state: T) => void> = new Set();\n\n constructor(initialState: T) {\n this.state = initialState;\n }\n\n /**\n * Subscribe to state changes\n * Returns an unsubscribe function\n */\n subscribe = (listener: (state: T) => void): (() => void) => {\n this.listeners.add(listener);\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n /**\n * Update state and notify all listeners\n * Accepts either a new state value or a function updater\n */\n setState = (state: T | ((state: T) => T)) => {\n if (typeof state === 'function') {\n this.state = (state as (prev: T) => T)(this.state);\n } else {\n this.state = state;\n }\n // Notify all listeners\n this.listeners.forEach((listener) => listener(this.state));\n };\n\n /**\n * Get current state without subscribing\n */\n getSnapshot = (): T => {\n return this.state;\n };\n}\n"],"names":[],"mappings":"AAAO,MAAM,cAAiB;AAAA,EAI5B,YAAY,cAAiB;AAF7B,SAAQ,gCAAyC,IAAA;AAUjD,SAAA,YAAY,CAAC,aAA+C;AAC1D,WAAK,UAAU,IAAI,QAAQ;AAE3B,aAAO,MAAM;AACX,aAAK,UAAU,OAAO,QAAQ;AAAA,MAChC;AAAA,IACF;AAMA,SAAA,WAAW,CAAC,UAAiC;AAC3C,UAAI,OAAO,UAAU,YAAY;AAC/B,aAAK,QAAS,MAAyB,KAAK,KAAK;AAAA,MACnD,OAAO;AACL,aAAK,QAAQ;AAAA,MACf;AAEA,WAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,KAAK,KAAK,CAAC;AAAA,IAC3D;AAKA,SAAA,cAAc,MAAS;AACrB,aAAO,KAAK;AAAA,IACd;AAlCE,SAAK,QAAQ;AAAA,EACf;AAkCF;"}