@blimu/react 1.1.0 → 1.1.4

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 (489) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/index.cjs +5 -1
  3. package/dist/_virtual/index.cjs.map +1 -1
  4. package/dist/_virtual/index.js +3 -3
  5. package/dist/_virtual/index2.cjs +4 -1
  6. package/dist/_virtual/index2.cjs.map +1 -1
  7. package/dist/_virtual/index2.js +2 -2
  8. package/dist/_virtual/use-sync-external-store-shim.development.cjs +4 -1
  9. package/dist/_virtual/use-sync-external-store-shim.development.cjs.map +1 -1
  10. package/dist/_virtual/use-sync-external-store-shim.development.js +2 -2
  11. package/dist/_virtual/use-sync-external-store-shim.production.cjs +4 -1
  12. package/dist/_virtual/use-sync-external-store-shim.production.cjs.map +1 -1
  13. package/dist/_virtual/use-sync-external-store-shim.production.js +2 -2
  14. package/dist/client/auth.service.cjs +248 -1
  15. package/dist/client/auth.service.cjs.map +1 -1
  16. package/dist/client/auth.service.d.ts.map +1 -1
  17. package/dist/client/auth.service.js +193 -96
  18. package/dist/client/auth.service.js.map +1 -1
  19. package/dist/client/external-store.cjs +26 -1
  20. package/dist/client/external-store.cjs.map +1 -1
  21. package/dist/client/external-store.js +22 -8
  22. package/dist/client/external-store.js.map +1 -1
  23. package/dist/client/runtime-client.cjs +136 -1
  24. package/dist/client/runtime-client.cjs.map +1 -1
  25. package/dist/client/runtime-client.d.ts +1 -1
  26. package/dist/client/runtime-client.d.ts.map +1 -1
  27. package/dist/client/runtime-client.js +85 -51
  28. package/dist/client/runtime-client.js.map +1 -1
  29. package/dist/components/index.cjs +13 -0
  30. package/dist/components/index.cjs.map +1 -0
  31. package/dist/components/index.d.ts +6 -6
  32. package/dist/components/index.d.ts.map +1 -1
  33. package/dist/components/index.js +13 -0
  34. package/dist/components/index.js.map +1 -0
  35. package/dist/components/members-list.cjs +132 -1
  36. package/dist/components/members-list.cjs.map +1 -1
  37. package/dist/components/members-list.d.ts.map +1 -1
  38. package/dist/components/members-list.js +69 -64
  39. package/dist/components/members-list.js.map +1 -1
  40. package/dist/components/redirect-to-sign-in.cjs +34 -1
  41. package/dist/components/redirect-to-sign-in.cjs.map +1 -1
  42. package/dist/components/redirect-to-sign-in.js +28 -20
  43. package/dist/components/redirect-to-sign-in.js.map +1 -1
  44. package/dist/components/sign-in-button.cjs +36 -1
  45. package/dist/components/sign-in-button.cjs.map +1 -1
  46. package/dist/components/sign-in-button.d.ts.map +1 -1
  47. package/dist/components/sign-in-button.js +25 -21
  48. package/dist/components/sign-in-button.js.map +1 -1
  49. package/dist/components/ui/avatar.cjs +42 -1
  50. package/dist/components/ui/avatar.cjs.map +1 -1
  51. package/dist/components/ui/avatar.d.ts +2 -2
  52. package/dist/components/ui/avatar.d.ts.map +1 -1
  53. package/dist/components/ui/avatar.js +23 -23
  54. package/dist/components/ui/avatar.js.map +1 -1
  55. package/dist/components/ui/badge.d.ts +2 -2
  56. package/dist/components/ui/badge.d.ts.map +1 -1
  57. package/dist/components/ui/dropdown-menu.cjs +148 -1
  58. package/dist/components/ui/dropdown-menu.cjs.map +1 -1
  59. package/dist/components/ui/dropdown-menu.d.ts +2 -2
  60. package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
  61. package/dist/components/ui/dropdown-menu.js +83 -81
  62. package/dist/components/ui/dropdown-menu.js.map +1 -1
  63. package/dist/components/ui/popover.d.ts +2 -2
  64. package/dist/components/ui/popover.d.ts.map +1 -1
  65. package/dist/components/ui/separator.d.ts +1 -1
  66. package/dist/components/ui/separator.d.ts.map +1 -1
  67. package/dist/components/user-avatar.cjs +22 -1
  68. package/dist/components/user-avatar.cjs.map +1 -1
  69. package/dist/components/user-avatar.d.ts +5 -5
  70. package/dist/components/user-avatar.d.ts.map +1 -1
  71. package/dist/components/user-avatar.js +16 -16
  72. package/dist/components/user-avatar.js.map +1 -1
  73. package/dist/components/user-button/styles.cjs +39 -1
  74. package/dist/components/user-button/styles.cjs.map +1 -1
  75. package/dist/components/user-button/styles.js +6 -5
  76. package/dist/components/user-button/styles.js.map +1 -1
  77. package/dist/components/user-button/user-button.cjs +98 -1
  78. package/dist/components/user-button/user-button.cjs.map +1 -1
  79. package/dist/components/user-button/user-button.d.ts +1 -1
  80. package/dist/components/user-button/user-button.d.ts.map +1 -1
  81. package/dist/components/user-button/user-button.js +64 -58
  82. package/dist/components/user-button/user-button.js.map +1 -1
  83. package/dist/hooks/index.cjs +14 -0
  84. package/dist/hooks/index.cjs.map +1 -0
  85. package/dist/hooks/index.d.ts +3 -2
  86. package/dist/hooks/index.d.ts.map +1 -1
  87. package/dist/hooks/index.js +14 -0
  88. package/dist/hooks/index.js.map +1 -0
  89. package/dist/hooks/use-auth.cjs +44 -1
  90. package/dist/hooks/use-auth.cjs.map +1 -1
  91. package/dist/hooks/use-auth.d.ts +13 -15
  92. package/dist/hooks/use-auth.d.ts.map +1 -1
  93. package/dist/hooks/use-auth.js +30 -26
  94. package/dist/hooks/use-auth.js.map +1 -1
  95. package/dist/hooks/use-client.cjs +9 -1
  96. package/dist/hooks/use-client.cjs.map +1 -1
  97. package/dist/hooks/use-client.d.ts +1 -1
  98. package/dist/hooks/use-client.d.ts.map +1 -1
  99. package/dist/hooks/use-client.js +6 -5
  100. package/dist/hooks/use-client.js.map +1 -1
  101. package/dist/hooks/use-members.cjs +60 -1
  102. package/dist/hooks/use-members.cjs.map +1 -1
  103. package/dist/hooks/use-members.d.ts +5 -5
  104. package/dist/hooks/use-members.d.ts.map +1 -1
  105. package/dist/hooks/use-members.js +53 -41
  106. package/dist/hooks/use-members.js.map +1 -1
  107. package/dist/hooks/use-store.cjs +17 -1
  108. package/dist/hooks/use-store.cjs.map +1 -1
  109. package/dist/hooks/use-store.js +7 -7
  110. package/dist/hooks/use-store.js.map +1 -1
  111. package/dist/index.cjs +37 -1
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.d.ts +5 -5
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +35 -35
  116. package/dist/lib/utils.cjs +8 -1
  117. package/dist/lib/utils.cjs.map +1 -1
  118. package/dist/lib/utils.js +5 -5
  119. package/dist/lib/utils.js.map +1 -1
  120. package/dist/lib/variants.cjs +46 -1
  121. package/dist/lib/variants.cjs.map +1 -1
  122. package/dist/lib/variants.d.ts +1 -1
  123. package/dist/lib/variants.js +6 -5
  124. package/dist/lib/variants.js.map +1 -1
  125. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.cjs +721 -1
  126. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.cjs.map +1 -1
  127. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +571 -377
  128. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js.map +1 -1
  129. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs +625 -1
  130. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs.map +1 -1
  131. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +539 -316
  132. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js.map +1 -1
  133. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs +313 -1
  134. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs.map +1 -1
  135. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +261 -172
  136. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js.map +1 -1
  137. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs +154 -1
  138. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs.map +1 -1
  139. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs +173 -1
  140. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs.map +1 -1
  141. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +144 -107
  142. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -1
  143. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +111 -87
  144. package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js.map +1 -1
  145. package/dist/node_modules/@radix-ui/primitive/dist/index.cjs +11 -1
  146. package/dist/node_modules/@radix-ui/primitive/dist/index.cjs.map +1 -1
  147. package/dist/node_modules/@radix-ui/primitive/dist/index.js +7 -5
  148. package/dist/node_modules/@radix-ui/primitive/dist/index.js.map +1 -1
  149. package/dist/node_modules/@radix-ui/react-arrow/dist/index.cjs +42 -1
  150. package/dist/node_modules/@radix-ui/react-arrow/dist/index.cjs.map +1 -1
  151. package/dist/node_modules/@radix-ui/react-arrow/dist/index.js +17 -16
  152. package/dist/node_modules/@radix-ui/react-arrow/dist/index.js.map +1 -1
  153. package/dist/node_modules/@radix-ui/react-avatar/dist/index.cjs +140 -1
  154. package/dist/node_modules/@radix-ui/react-avatar/dist/index.cjs.map +1 -1
  155. package/dist/node_modules/@radix-ui/react-avatar/dist/index.js +105 -57
  156. package/dist/node_modules/@radix-ui/react-avatar/dist/index.js.map +1 -1
  157. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.cjs +80 -1
  158. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
  159. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.js +49 -41
  160. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.js.map +1 -1
  161. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.cjs +56 -1
  162. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
  163. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js +17 -10
  164. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -1
  165. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.cjs +119 -1
  166. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
  167. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.js +86 -42
  168. package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -1
  169. package/dist/node_modules/@radix-ui/react-collection/dist/index.cjs +70 -1
  170. package/dist/node_modules/@radix-ui/react-collection/dist/index.cjs.map +1 -1
  171. package/dist/node_modules/@radix-ui/react-collection/dist/index.js +57 -37
  172. package/dist/node_modules/@radix-ui/react-collection/dist/index.js.map +1 -1
  173. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +56 -1
  174. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.map +1 -1
  175. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js +29 -19
  176. package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js.map +1 -1
  177. package/dist/node_modules/@radix-ui/react-context/dist/index.cjs +79 -1
  178. package/dist/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
  179. package/dist/node_modules/@radix-ui/react-context/dist/index.js +48 -39
  180. package/dist/node_modules/@radix-ui/react-context/dist/index.js.map +1 -1
  181. package/dist/node_modules/@radix-ui/react-direction/dist/index.cjs +27 -1
  182. package/dist/node_modules/@radix-ui/react-direction/dist/index.cjs.map +1 -1
  183. package/dist/node_modules/@radix-ui/react-direction/dist/index.js +6 -6
  184. package/dist/node_modules/@radix-ui/react-direction/dist/index.js.map +1 -1
  185. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs +229 -1
  186. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs.map +1 -1
  187. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +182 -97
  188. package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js.map +1 -1
  189. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs +296 -1
  190. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs.map +1 -1
  191. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js +232 -167
  192. package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js.map +1 -1
  193. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs +46 -1
  194. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs.map +1 -1
  195. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js +23 -11
  196. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js.map +1 -1
  197. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs +224 -1
  198. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs.map +1 -1
  199. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js +169 -98
  200. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js.map +1 -1
  201. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs +31 -1
  202. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs.map +1 -1
  203. package/dist/node_modules/@radix-ui/react-id/dist/index.js +11 -10
  204. package/dist/node_modules/@radix-ui/react-id/dist/index.js.map +1 -1
  205. package/dist/node_modules/@radix-ui/react-menu/dist/index.cjs +845 -1
  206. package/dist/node_modules/@radix-ui/react-menu/dist/index.cjs.map +1 -1
  207. package/dist/node_modules/@radix-ui/react-menu/dist/index.js +662 -442
  208. package/dist/node_modules/@radix-ui/react-menu/dist/index.js.map +1 -1
  209. package/dist/node_modules/@radix-ui/react-popper/dist/index.cjs +308 -1
  210. package/dist/node_modules/@radix-ui/react-popper/dist/index.cjs.map +1 -1
  211. package/dist/node_modules/@radix-ui/react-popper/dist/index.js +209 -137
  212. package/dist/node_modules/@radix-ui/react-popper/dist/index.js.map +1 -1
  213. package/dist/node_modules/@radix-ui/react-portal/dist/index.cjs +34 -1
  214. package/dist/node_modules/@radix-ui/react-portal/dist/index.cjs.map +1 -1
  215. package/dist/node_modules/@radix-ui/react-portal/dist/index.js +14 -12
  216. package/dist/node_modules/@radix-ui/react-portal/dist/index.js.map +1 -1
  217. package/dist/node_modules/@radix-ui/react-presence/dist/index.cjs +145 -1
  218. package/dist/node_modules/@radix-ui/react-presence/dist/index.cjs.map +1 -1
  219. package/dist/node_modules/@radix-ui/react-presence/dist/index.js +103 -45
  220. package/dist/node_modules/@radix-ui/react-presence/dist/index.js.map +1 -1
  221. package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs +61 -1
  222. package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
  223. package/dist/node_modules/@radix-ui/react-primitive/dist/index.js +21 -14
  224. package/dist/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -1
  225. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.cjs +244 -1
  226. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.cjs.map +1 -1
  227. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js +179 -135
  228. package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js.map +1 -1
  229. package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs +105 -1
  230. package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
  231. package/dist/node_modules/@radix-ui/react-slot/dist/index.js +74 -35
  232. package/dist/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -1
  233. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs +28 -1
  234. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs.map +1 -1
  235. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js +8 -7
  236. package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js.map +1 -1
  237. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs +86 -1
  238. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs.map +1 -1
  239. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js +57 -40
  240. package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js.map +1 -1
  241. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs +34 -1
  242. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs.map +1 -1
  243. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +13 -10
  244. package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js.map +1 -1
  245. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.cjs +15 -1
  246. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.cjs.map +1 -1
  247. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +8 -8
  248. package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js.map +1 -1
  249. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs +23 -1
  250. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs.map +1 -1
  251. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js +3 -3
  252. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js.map +1 -1
  253. package/dist/node_modules/@radix-ui/react-use-size/dist/index.cjs +56 -1
  254. package/dist/node_modules/@radix-ui/react-use-size/dist/index.cjs.map +1 -1
  255. package/dist/node_modules/@radix-ui/react-use-size/dist/index.js +34 -22
  256. package/dist/node_modules/@radix-ui/react-use-size/dist/index.js.map +1 -1
  257. package/dist/node_modules/aria-hidden/dist/es2015/index.cjs +122 -1
  258. package/dist/node_modules/aria-hidden/dist/es2015/index.cjs.map +1 -1
  259. package/dist/node_modules/aria-hidden/dist/es2015/index.js +111 -41
  260. package/dist/node_modules/aria-hidden/dist/es2015/index.js.map +1 -1
  261. package/dist/node_modules/class-variance-authority/dist/index.cjs +45 -1
  262. package/dist/node_modules/class-variance-authority/dist/index.cjs.map +1 -1
  263. package/dist/node_modules/class-variance-authority/dist/index.js +40 -30
  264. package/dist/node_modules/class-variance-authority/dist/index.js.map +1 -1
  265. package/dist/node_modules/clsx/dist/clsx.cjs +17 -1
  266. package/dist/node_modules/clsx/dist/clsx.cjs.map +1 -1
  267. package/dist/node_modules/clsx/dist/clsx.js +13 -13
  268. package/dist/node_modules/clsx/dist/clsx.js.map +1 -1
  269. package/dist/node_modules/get-nonce/dist/es2015/index.cjs +9 -1
  270. package/dist/node_modules/get-nonce/dist/es2015/index.cjs.map +1 -1
  271. package/dist/node_modules/get-nonce/dist/es2015/index.js +5 -3
  272. package/dist/node_modules/get-nonce/dist/es2015/index.js.map +1 -1
  273. package/dist/node_modules/js-cookie/dist/js.cookie.cjs +99 -1
  274. package/dist/node_modules/js-cookie/dist/js.cookie.cjs.map +1 -1
  275. package/dist/node_modules/js-cookie/dist/js.cookie.js +69 -43
  276. package/dist/node_modules/js-cookie/dist/js.cookie.js.map +1 -1
  277. package/dist/node_modules/jwt-decode/build/esm/index.cjs +58 -1
  278. package/dist/node_modules/jwt-decode/build/esm/index.cjs.map +1 -1
  279. package/dist/node_modules/jwt-decode/build/esm/index.js +36 -30
  280. package/dist/node_modules/jwt-decode/build/esm/index.js.map +1 -1
  281. package/dist/node_modules/lucide-react/dist/esm/Icon.cjs +35 -1
  282. package/dist/node_modules/lucide-react/dist/esm/Icon.cjs.map +1 -1
  283. package/dist/node_modules/lucide-react/dist/esm/Icon.js +25 -25
  284. package/dist/node_modules/lucide-react/dist/esm/Icon.js.map +1 -1
  285. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.cjs +22 -1
  286. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.cjs.map +1 -1
  287. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.js +16 -15
  288. package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.js.map +1 -1
  289. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.cjs +14 -1
  290. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.cjs.map +1 -1
  291. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.js +2 -2
  292. package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.js.map +1 -1
  293. package/dist/node_modules/lucide-react/dist/esm/icons/check.cjs +7 -1
  294. package/dist/node_modules/lucide-react/dist/esm/icons/check.cjs.map +1 -1
  295. package/dist/node_modules/lucide-react/dist/esm/icons/check.js +5 -4
  296. package/dist/node_modules/lucide-react/dist/esm/icons/check.js.map +1 -1
  297. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.cjs +7 -1
  298. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.cjs.map +1 -1
  299. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.js +5 -4
  300. package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.js.map +1 -1
  301. package/dist/node_modules/lucide-react/dist/esm/icons/circle.cjs +7 -1
  302. package/dist/node_modules/lucide-react/dist/esm/icons/circle.cjs.map +1 -1
  303. package/dist/node_modules/lucide-react/dist/esm/icons/circle.js +5 -4
  304. package/dist/node_modules/lucide-react/dist/esm/icons/circle.js.map +1 -1
  305. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.cjs +11 -1
  306. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.cjs.map +1 -1
  307. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.js +6 -5
  308. package/dist/node_modules/lucide-react/dist/esm/icons/log-out.js.map +1 -1
  309. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.cjs +26 -1
  310. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.cjs.map +1 -1
  311. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.js +22 -14
  312. package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.js.map +1 -1
  313. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.cjs +28 -1
  314. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.cjs.map +1 -1
  315. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js +8 -8
  316. package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js.map +1 -1
  317. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs +197 -4
  318. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs.map +1 -1
  319. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js +163 -98
  320. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js.map +1 -1
  321. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.cjs +55 -1
  322. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.cjs.map +1 -1
  323. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js +31 -24
  324. package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js.map +1 -1
  325. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs +19 -1
  326. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs.map +1 -1
  327. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +12 -9
  328. package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js.map +1 -1
  329. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs +102 -1
  330. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs.map +1 -1
  331. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js +85 -51
  332. package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js.map +1 -1
  333. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.cjs +5 -1
  334. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.cjs.map +1 -1
  335. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js +3 -3
  336. package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js.map +1 -1
  337. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs +7 -1
  338. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs.map +1 -1
  339. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js +5 -5
  340. package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js.map +1 -1
  341. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs +62 -36
  342. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs.map +1 -1
  343. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js +41 -65
  344. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js.map +1 -1
  345. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs +10 -1
  346. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs.map +1 -1
  347. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js +8 -5
  348. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js.map +1 -1
  349. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs +37 -1
  350. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs.map +1 -1
  351. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js +28 -16
  352. package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js.map +1 -1
  353. package/dist/node_modules/react-style-singleton/dist/es2015/component.cjs +13 -1
  354. package/dist/node_modules/react-style-singleton/dist/es2015/component.cjs.map +1 -1
  355. package/dist/node_modules/react-style-singleton/dist/es2015/component.js +9 -7
  356. package/dist/node_modules/react-style-singleton/dist/es2015/component.js.map +1 -1
  357. package/dist/node_modules/react-style-singleton/dist/es2015/hook.cjs +33 -1
  358. package/dist/node_modules/react-style-singleton/dist/es2015/hook.cjs.map +1 -1
  359. package/dist/node_modules/react-style-singleton/dist/es2015/hook.js +11 -10
  360. package/dist/node_modules/react-style-singleton/dist/es2015/hook.js.map +1 -1
  361. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.cjs +48 -1
  362. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.cjs.map +1 -1
  363. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js +35 -17
  364. package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js.map +1 -1
  365. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.cjs +3014 -1
  366. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.cjs.map +1 -1
  367. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +804 -555
  368. package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -1
  369. package/dist/node_modules/tailwindcss/dist/plugin.cjs +13 -1
  370. package/dist/node_modules/tailwindcss/dist/plugin.cjs.map +1 -1
  371. package/dist/node_modules/tailwindcss/dist/plugin.js +8 -8
  372. package/dist/node_modules/tailwindcss/dist/plugin.js.map +1 -1
  373. package/dist/node_modules/tslib/tslib.es6.cjs +38 -1
  374. package/dist/node_modules/tslib/tslib.es6.cjs.map +1 -1
  375. package/dist/node_modules/tslib/tslib.es6.js +33 -21
  376. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  377. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.cjs +11 -1
  378. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.cjs.map +1 -1
  379. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js +8 -3
  380. package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js.map +1 -1
  381. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs +52 -1
  382. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs.map +1 -1
  383. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js +28 -19
  384. package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js.map +1 -1
  385. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.cjs +29 -1
  386. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.cjs.map +1 -1
  387. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js +15 -11
  388. package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js.map +1 -1
  389. package/dist/node_modules/use-sidecar/dist/es2015/exports.cjs +38 -1
  390. package/dist/node_modules/use-sidecar/dist/es2015/exports.cjs.map +1 -1
  391. package/dist/node_modules/use-sidecar/dist/es2015/exports.js +15 -12
  392. package/dist/node_modules/use-sidecar/dist/es2015/exports.js.map +1 -1
  393. package/dist/node_modules/use-sidecar/dist/es2015/medium.cjs +88 -1
  394. package/dist/node_modules/use-sidecar/dist/es2015/medium.cjs.map +1 -1
  395. package/dist/node_modules/use-sidecar/dist/es2015/medium.js +64 -43
  396. package/dist/node_modules/use-sidecar/dist/es2015/medium.js.map +1 -1
  397. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +68 -1
  398. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -1
  399. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +49 -39
  400. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
  401. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs +53 -1
  402. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs.map +1 -1
  403. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +39 -32
  404. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js.map +1 -1
  405. package/dist/node_modules/use-sync-external-store/shim/index.cjs +17 -1
  406. package/dist/node_modules/use-sync-external-store/shim/index.cjs.map +1 -1
  407. package/dist/node_modules/use-sync-external-store/shim/index.js +14 -7
  408. package/dist/node_modules/use-sync-external-store/shim/index.js.map +1 -1
  409. package/dist/providers/auth/auth.context.cjs +5 -1
  410. package/dist/providers/auth/auth.context.cjs.map +1 -1
  411. package/dist/providers/auth/auth.context.js +3 -3
  412. package/dist/providers/auth/auth.context.js.map +1 -1
  413. package/dist/providers/auth/auth.hook.cjs +12 -1
  414. package/dist/providers/auth/auth.hook.cjs.map +1 -1
  415. package/dist/providers/auth/auth.hook.js +8 -7
  416. package/dist/providers/auth/auth.hook.js.map +1 -1
  417. package/dist/providers/auth/auth.provider.cjs +37 -1
  418. package/dist/providers/auth/auth.provider.cjs.map +1 -1
  419. package/dist/providers/auth/auth.provider.js +31 -22
  420. package/dist/providers/auth/auth.provider.js.map +1 -1
  421. package/dist/providers/blimu/blimu.context.cjs +5 -1
  422. package/dist/providers/blimu/blimu.context.cjs.map +1 -1
  423. package/dist/providers/blimu/blimu.context.d.ts +4 -4
  424. package/dist/providers/blimu/blimu.context.d.ts.map +1 -1
  425. package/dist/providers/blimu/blimu.context.js +3 -3
  426. package/dist/providers/blimu/blimu.context.js.map +1 -1
  427. package/dist/providers/blimu/blimu.hook.cjs +12 -1
  428. package/dist/providers/blimu/blimu.hook.cjs.map +1 -1
  429. package/dist/providers/blimu/blimu.hook.js +8 -7
  430. package/dist/providers/blimu/blimu.hook.js.map +1 -1
  431. package/dist/providers/blimu/blimu.provider.cjs +71 -1
  432. package/dist/providers/blimu/blimu.provider.cjs.map +1 -1
  433. package/dist/providers/blimu/blimu.provider.d.ts +1 -1
  434. package/dist/providers/blimu/blimu.provider.d.ts.map +1 -1
  435. package/dist/providers/blimu/blimu.provider.js +32 -27
  436. package/dist/providers/blimu/blimu.provider.js.map +1 -1
  437. package/dist/providers/index.cjs +13 -0
  438. package/dist/providers/index.cjs.map +1 -0
  439. package/dist/providers/index.d.ts +3 -3
  440. package/dist/providers/index.d.ts.map +1 -1
  441. package/dist/providers/index.js +13 -0
  442. package/dist/providers/index.js.map +1 -0
  443. package/dist/providers/theme/index.d.ts +2 -2
  444. package/dist/providers/theme/index.d.ts.map +1 -1
  445. package/dist/providers/theme/theme.context.cjs +5 -1
  446. package/dist/providers/theme/theme.context.cjs.map +1 -1
  447. package/dist/providers/theme/theme.context.js +3 -3
  448. package/dist/providers/theme/theme.context.js.map +1 -1
  449. package/dist/providers/theme/theme.hook.cjs +12 -1
  450. package/dist/providers/theme/theme.hook.cjs.map +1 -1
  451. package/dist/providers/theme/theme.hook.js +8 -7
  452. package/dist/providers/theme/theme.hook.js.map +1 -1
  453. package/dist/providers/theme/theme.provider.cjs +104 -1
  454. package/dist/providers/theme/theme.provider.cjs.map +1 -1
  455. package/dist/providers/theme/theme.provider.d.ts.map +1 -1
  456. package/dist/providers/theme/theme.provider.js +85 -48
  457. package/dist/providers/theme/theme.provider.js.map +1 -1
  458. package/dist/styles/styles.css +34 -40
  459. package/dist/styles/tw-styles.css +34 -40
  460. package/dist/tailwind.cjs +200 -0
  461. package/dist/tailwind.cjs.map +1 -0
  462. package/dist/{tailwind.plugin.js → tailwind.js} +43 -43
  463. package/dist/tailwind.js.map +1 -0
  464. package/dist/types/index.cjs +11 -1
  465. package/dist/types/index.cjs.map +1 -1
  466. package/dist/types/index.d.ts +22 -8
  467. package/dist/types/index.d.ts.map +1 -1
  468. package/dist/types/index.js +8 -8
  469. package/dist/types/index.js.map +1 -1
  470. package/dist/utils/publishable-key.cjs +62 -1
  471. package/dist/utils/publishable-key.cjs.map +1 -1
  472. package/dist/utils/publishable-key.js +52 -27
  473. package/dist/utils/publishable-key.js.map +1 -1
  474. package/package.json +68 -53
  475. package/dist/components.cjs +0 -2
  476. package/dist/components.cjs.map +0 -1
  477. package/dist/components.js +0 -13
  478. package/dist/components.js.map +0 -1
  479. package/dist/hooks.cjs +0 -2
  480. package/dist/hooks.cjs.map +0 -1
  481. package/dist/hooks.js +0 -14
  482. package/dist/hooks.js.map +0 -1
  483. package/dist/providers.cjs +0 -2
  484. package/dist/providers.cjs.map +0 -1
  485. package/dist/providers.js +0 -13
  486. package/dist/providers.js.map +0 -1
  487. package/dist/tailwind.plugin.cjs +0 -2
  488. package/dist/tailwind.plugin.cjs.map +0 -1
  489. package/dist/tailwind.plugin.js.map +0 -1
@@ -1,152 +1,249 @@
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 = (n) => Math.floor(n * w), b = (n) => Math.floor(n / w), p = () => b(Date.now()), P = (n) => E(n), v = (n, e) => {
5
- const s = P(n), r = E(e), t = Date.now();
6
- return Math.max(s - r - t, 0);
7
- }, f = (n, e) => {
8
- const s = p();
9
- return n - 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
- r && (s.searchParams.delete(S), window.history.replaceState({}, "", s.toString())), r && this.setCookie(u, r, {
58
- maxAge: 720 * 60 * 60
59
- // 30 days
60
- });
61
- const t = o.get(u);
62
- if (console.log("localhostJWTCookie", t), t && !o.get(h)) {
63
- const i = await this.refreshSession({ signal: e }).catch(this.handleRequestError);
64
- if ("error" in i) return i;
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
+ if (localhostJWTCookie && !api.get(SESSION_COOKIE_NAME)) {
116
+ const result2 = await this.refreshSession({ signal }).catch(this.handleRequestError);
117
+ if ("error" in result2) return result2;
65
118
  }
66
- const l = this.getSessionPayload();
67
- if (!l)
119
+ const sessionPayload = this.getSessionPayload();
120
+ if (!sessionPayload) {
68
121
  return {
69
122
  error: null,
70
123
  user: null
71
124
  };
72
- if (f(l.exp, m)) {
73
- const i = await this.refreshSession().catch(this.handleRequestError);
74
- if ("error" in i) return i;
75
125
  }
76
- const a = await this.client.auth.getSession().catch(this.handleRequestError);
77
- return "error" in a ? a : {
126
+ if (isExpiredIn(sessionPayload.exp, SESSION_EXPIRATION_BUFFER)) {
127
+ const result2 = await this.refreshSession().catch(this.handleRequestError);
128
+ if ("error" in result2) return result2;
129
+ }
130
+ const result = await this.client.auth.getSession().catch(this.handleRequestError);
131
+ if ("error" in result) return result;
132
+ return {
78
133
  error: null,
79
- user: a.user
134
+ user: result.user
80
135
  };
81
136
  }
82
137
  scheduleRefresh() {
83
- const e = new AbortController();
84
- let s = !0, r = null;
85
- const t = () => {
86
- s = !0, this.pendingRefresher && (this.pendingRefresher(), this.pendingRefresher = null);
87
- }, l = () => {
88
- s = !1;
138
+ const abortController = new AbortController();
139
+ let isOnline = true;
140
+ let timeoutId = null;
141
+ const onlineHandler = () => {
142
+ isOnline = true;
143
+ if (this.pendingRefresher) {
144
+ this.pendingRefresher();
145
+ this.pendingRefresher = null;
146
+ }
147
+ };
148
+ const offlineHandler = () => {
149
+ isOnline = false;
89
150
  };
90
- window.addEventListener("online", t), window.addEventListener("offline", l);
91
- const a = () => {
92
- r !== null && (window.clearTimeout(r), r = null);
93
- const i = this.getSessionPayload();
94
- if (!i || f(i.exp, 0)) return;
95
- const d = v(i.exp, m);
96
- if (d < 0)
151
+ window.addEventListener("online", onlineHandler);
152
+ window.addEventListener("offline", offlineHandler);
153
+ const refresh = () => {
154
+ if (timeoutId !== null) {
155
+ window.clearTimeout(timeoutId);
156
+ timeoutId = null;
157
+ }
158
+ const sessionPayload = this.getSessionPayload();
159
+ if (!sessionPayload || isExpiredIn(sessionPayload.exp, 0)) return;
160
+ const timeoutDelayMS = calculateTimeoutDelay(sessionPayload.exp, SESSION_EXPIRATION_BUFFER);
161
+ if (timeoutDelayMS < 0) {
97
162
  return;
98
- const g = async () => {
99
- if (r = null, !s) {
100
- this.pendingRefresher = g;
163
+ }
164
+ const refresher = async () => {
165
+ timeoutId = null;
166
+ if (!isOnline) {
167
+ this.pendingRefresher = refresher;
101
168
  return;
102
169
  }
103
- const c = await this.refreshSession({ signal: e.signal });
104
- if ("error" in c) {
105
- if (c.error === "aborted")
170
+ const result = await this.refreshSession({ signal: abortController.signal });
171
+ if ("error" in result) {
172
+ if (result.error === "aborted") {
106
173
  return;
174
+ }
107
175
  this.store.setState({
108
176
  status: "error",
109
177
  user: null,
110
- error: c.error
178
+ error: result.error
111
179
  });
112
180
  return;
113
- } else
114
- a();
181
+ } else {
182
+ refresh();
183
+ }
115
184
  };
116
- r = window.setTimeout(g, d);
185
+ timeoutId = window.setTimeout(refresher, timeoutDelayMS);
117
186
  };
118
- return a(), () => {
119
- r && window.clearTimeout(r), e.abort(), window.removeEventListener("online", t), window.removeEventListener("offline", l);
187
+ refresh();
188
+ return () => {
189
+ if (timeoutId) {
190
+ window.clearTimeout(timeoutId);
191
+ }
192
+ abortController.abort();
193
+ window.removeEventListener("online", onlineHandler);
194
+ window.removeEventListener("offline", offlineHandler);
120
195
  };
121
196
  }
122
- async refreshSession({ signal: e } = {}) {
123
- if (e && (this.refreshingSignals.add(e), e.addEventListener("abort", () => {
124
- this.refreshingSignals.delete(e), this.refreshingSignals.size === 0 && this.refreshingSignalAbortController?.abort();
125
- })), this.refreshPromise)
197
+ async refreshSession({ signal } = {}) {
198
+ if (signal) {
199
+ this.refreshingSignals.add(signal);
200
+ signal.addEventListener("abort", () => {
201
+ this.refreshingSignals.delete(signal);
202
+ if (this.refreshingSignals.size === 0) {
203
+ this.refreshingSignalAbortController?.abort();
204
+ }
205
+ });
206
+ }
207
+ if (this.refreshPromise) {
126
208
  return this.refreshPromise;
127
- this.refreshingSignalAbortController = new AbortController(), this.refreshingSignalAbortController.signal.addEventListener("abort", () => {
128
- this.refreshPromise = null, this.refreshingSignalAbortController = null, this.refreshingSignals.clear();
209
+ }
210
+ this.refreshingSignalAbortController = new AbortController();
211
+ this.refreshingSignalAbortController.signal.addEventListener("abort", () => {
212
+ this.refreshPromise = null;
213
+ this.refreshingSignalAbortController = null;
214
+ this.refreshingSignals.clear();
129
215
  });
130
- const s = this.isLive ? void 0 : o.get(u), r = {};
131
- s && (r.__lh_jwt = s), this.refreshPromise = this.localClient.auth.refresh(r, {
216
+ const localhostJWT = !this.isLive ? api.get(LOCALHOST_JWT_COOKIE_NAME) : void 0;
217
+ const queryParams = {};
218
+ if (localhostJWT) {
219
+ queryParams.__lh_jwt = localhostJWT;
220
+ }
221
+ this.refreshPromise = this.localClient.auth.refresh(queryParams, {
132
222
  signal: this.refreshingSignalAbortController.signal
133
- }).then((t) => (this.isLive || this.setCookie(h, t.sessionToken, {
134
- maxAge: 720 * 60 * 60
135
- // 30 days
136
- }), t)).catch(this.handleRequestError);
223
+ }).then((response) => {
224
+ if (!this.isLive) {
225
+ this.setCookie(SESSION_COOKIE_NAME, response.sessionToken, {
226
+ maxAge: 30 * 24 * 60 * 60
227
+ // 30 days
228
+ });
229
+ }
230
+ return response;
231
+ }).catch(this.handleRequestError);
137
232
  try {
138
233
  return await this.refreshPromise;
139
234
  } finally {
140
- this.refreshPromise = null, this.refreshingSignalAbortController = null, this.refreshingSignals.clear();
235
+ this.refreshPromise = null;
236
+ this.refreshingSignalAbortController = null;
237
+ this.refreshingSignals.clear();
141
238
  }
142
239
  }
143
240
  }
144
241
  export {
145
- x as AuthSessionService,
146
- u as LOCALHOST_JWT_COOKIE_NAME,
147
- S as LOCALHOST_JWT_URL_PARAM_NAME,
148
- h as SESSION_COOKIE_NAME,
149
- m as SESSION_EXPIRATION_BUFFER,
150
- f as isExpiredIn
242
+ AuthSessionService,
243
+ LOCALHOST_JWT_COOKIE_NAME,
244
+ LOCALHOST_JWT_URL_PARAM_NAME,
245
+ SESSION_COOKIE_NAME,
246
+ SESSION_EXPIRATION_BUFFER,
247
+ isExpiredIn
151
248
  };
152
249
  //# 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 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":["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","localhostJWTCookie","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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S,MAAM;AACrC,WAAK,kBAAkB,OAAOA,CAAM,GAEhC,KAAK,kBAAkB,SAAS,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,GAGnEkD,IAAqC,CAAA;AAC3C,IAAIX,MACFW,EAAY,WAAWX,IAQzB,KAAK,iBAAiB,KAAK,YAAY,KACpC,QAAQW,GAAa;AAAA,MACpB,QAAQ,KAAK,gCAAgC;AAAA,IAAA,CAC9C,EACA,KAAK,CAACC,OAGA,KAAK,UACR,KAAK,UAAUrD,GAAqBqD,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 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 | undefined } = {}) {\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,CAA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AK,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;"}