@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.
- package/README.md +1 -1
- package/dist/_virtual/index.cjs +5 -1
- package/dist/_virtual/index.cjs.map +1 -1
- package/dist/_virtual/index.js +3 -3
- package/dist/_virtual/index2.cjs +4 -1
- package/dist/_virtual/index2.cjs.map +1 -1
- package/dist/_virtual/index2.js +2 -2
- package/dist/_virtual/use-sync-external-store-shim.development.cjs +4 -1
- package/dist/_virtual/use-sync-external-store-shim.development.cjs.map +1 -1
- package/dist/_virtual/use-sync-external-store-shim.development.js +2 -2
- package/dist/_virtual/use-sync-external-store-shim.production.cjs +4 -1
- package/dist/_virtual/use-sync-external-store-shim.production.cjs.map +1 -1
- package/dist/_virtual/use-sync-external-store-shim.production.js +2 -2
- package/dist/client/auth.service.cjs +248 -1
- package/dist/client/auth.service.cjs.map +1 -1
- package/dist/client/auth.service.d.ts.map +1 -1
- package/dist/client/auth.service.js +193 -96
- package/dist/client/auth.service.js.map +1 -1
- package/dist/client/external-store.cjs +26 -1
- package/dist/client/external-store.cjs.map +1 -1
- package/dist/client/external-store.js +22 -8
- package/dist/client/external-store.js.map +1 -1
- package/dist/client/runtime-client.cjs +136 -1
- package/dist/client/runtime-client.cjs.map +1 -1
- package/dist/client/runtime-client.d.ts +1 -1
- package/dist/client/runtime-client.d.ts.map +1 -1
- package/dist/client/runtime-client.js +85 -51
- package/dist/client/runtime-client.js.map +1 -1
- package/dist/components/index.cjs +13 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.ts +6 -6
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +13 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/members-list.cjs +132 -1
- package/dist/components/members-list.cjs.map +1 -1
- package/dist/components/members-list.d.ts.map +1 -1
- package/dist/components/members-list.js +69 -64
- package/dist/components/members-list.js.map +1 -1
- package/dist/components/redirect-to-sign-in.cjs +34 -1
- package/dist/components/redirect-to-sign-in.cjs.map +1 -1
- package/dist/components/redirect-to-sign-in.js +28 -20
- package/dist/components/redirect-to-sign-in.js.map +1 -1
- package/dist/components/sign-in-button.cjs +36 -1
- package/dist/components/sign-in-button.cjs.map +1 -1
- package/dist/components/sign-in-button.d.ts.map +1 -1
- package/dist/components/sign-in-button.js +25 -21
- package/dist/components/sign-in-button.js.map +1 -1
- package/dist/components/ui/avatar.cjs +42 -1
- package/dist/components/ui/avatar.cjs.map +1 -1
- package/dist/components/ui/avatar.d.ts +2 -2
- package/dist/components/ui/avatar.d.ts.map +1 -1
- package/dist/components/ui/avatar.js +23 -23
- package/dist/components/ui/avatar.js.map +1 -1
- package/dist/components/ui/badge.d.ts +2 -2
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.cjs +148 -1
- package/dist/components/ui/dropdown-menu.cjs.map +1 -1
- package/dist/components/ui/dropdown-menu.d.ts +2 -2
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.js +83 -81
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/popover.d.ts.map +1 -1
- package/dist/components/ui/separator.d.ts +1 -1
- package/dist/components/ui/separator.d.ts.map +1 -1
- package/dist/components/user-avatar.cjs +22 -1
- package/dist/components/user-avatar.cjs.map +1 -1
- package/dist/components/user-avatar.d.ts +5 -5
- package/dist/components/user-avatar.d.ts.map +1 -1
- package/dist/components/user-avatar.js +16 -16
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/components/user-button/styles.cjs +39 -1
- package/dist/components/user-button/styles.cjs.map +1 -1
- package/dist/components/user-button/styles.js +6 -5
- package/dist/components/user-button/styles.js.map +1 -1
- package/dist/components/user-button/user-button.cjs +98 -1
- package/dist/components/user-button/user-button.cjs.map +1 -1
- package/dist/components/user-button/user-button.d.ts +1 -1
- package/dist/components/user-button/user-button.d.ts.map +1 -1
- package/dist/components/user-button/user-button.js +64 -58
- package/dist/components/user-button/user-button.js.map +1 -1
- package/dist/hooks/index.cjs +14 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.ts +3 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +14 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-auth.cjs +44 -1
- package/dist/hooks/use-auth.cjs.map +1 -1
- package/dist/hooks/use-auth.d.ts +13 -15
- package/dist/hooks/use-auth.d.ts.map +1 -1
- package/dist/hooks/use-auth.js +30 -26
- package/dist/hooks/use-auth.js.map +1 -1
- package/dist/hooks/use-client.cjs +9 -1
- package/dist/hooks/use-client.cjs.map +1 -1
- package/dist/hooks/use-client.d.ts +1 -1
- package/dist/hooks/use-client.d.ts.map +1 -1
- package/dist/hooks/use-client.js +6 -5
- package/dist/hooks/use-client.js.map +1 -1
- package/dist/hooks/use-members.cjs +60 -1
- package/dist/hooks/use-members.cjs.map +1 -1
- package/dist/hooks/use-members.d.ts +5 -5
- package/dist/hooks/use-members.d.ts.map +1 -1
- package/dist/hooks/use-members.js +53 -41
- package/dist/hooks/use-members.js.map +1 -1
- package/dist/hooks/use-store.cjs +17 -1
- package/dist/hooks/use-store.cjs.map +1 -1
- package/dist/hooks/use-store.js +7 -7
- package/dist/hooks/use-store.js.map +1 -1
- package/dist/index.cjs +37 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -35
- package/dist/lib/utils.cjs +8 -1
- package/dist/lib/utils.cjs.map +1 -1
- package/dist/lib/utils.js +5 -5
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/variants.cjs +46 -1
- package/dist/lib/variants.cjs.map +1 -1
- package/dist/lib/variants.d.ts +1 -1
- package/dist/lib/variants.js +6 -5
- package/dist/lib/variants.js.map +1 -1
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.cjs +721 -1
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.cjs.map +1 -1
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +571 -377
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js.map +1 -1
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs +625 -1
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.cjs.map +1 -1
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +539 -316
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js.map +1 -1
- package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs +313 -1
- package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.cjs.map +1 -1
- package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +261 -172
- package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js.map +1 -1
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs +154 -1
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.cjs.map +1 -1
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs +173 -1
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.cjs.map +1 -1
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +144 -107
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -1
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +111 -87
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js.map +1 -1
- package/dist/node_modules/@radix-ui/primitive/dist/index.cjs +11 -1
- package/dist/node_modules/@radix-ui/primitive/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/primitive/dist/index.js +7 -5
- package/dist/node_modules/@radix-ui/primitive/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-arrow/dist/index.cjs +42 -1
- package/dist/node_modules/@radix-ui/react-arrow/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-arrow/dist/index.js +17 -16
- package/dist/node_modules/@radix-ui/react-arrow/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/dist/index.cjs +140 -1
- package/dist/node_modules/@radix-ui/react-avatar/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/dist/index.js +105 -57
- package/dist/node_modules/@radix-ui/react-avatar/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.cjs +80 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.js +49 -41
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-context/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.cjs +56 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js +17 -10
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.cjs +119 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.js +86 -42
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-collection/dist/index.cjs +70 -1
- package/dist/node_modules/@radix-ui/react-collection/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-collection/dist/index.js +57 -37
- package/dist/node_modules/@radix-ui/react-collection/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +56 -1
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js +29 -19
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-context/dist/index.cjs +79 -1
- package/dist/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-context/dist/index.js +48 -39
- package/dist/node_modules/@radix-ui/react-context/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-direction/dist/index.cjs +27 -1
- package/dist/node_modules/@radix-ui/react-direction/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-direction/dist/index.js +6 -6
- package/dist/node_modules/@radix-ui/react-direction/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs +229 -1
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +182 -97
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs +296 -1
- package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js +232 -167
- package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs +46 -1
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js +23 -11
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs +224 -1
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js +169 -98
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-id/dist/index.cjs +31 -1
- package/dist/node_modules/@radix-ui/react-id/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-id/dist/index.js +11 -10
- package/dist/node_modules/@radix-ui/react-id/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-menu/dist/index.cjs +845 -1
- package/dist/node_modules/@radix-ui/react-menu/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-menu/dist/index.js +662 -442
- package/dist/node_modules/@radix-ui/react-menu/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-popper/dist/index.cjs +308 -1
- package/dist/node_modules/@radix-ui/react-popper/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-popper/dist/index.js +209 -137
- package/dist/node_modules/@radix-ui/react-popper/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-portal/dist/index.cjs +34 -1
- package/dist/node_modules/@radix-ui/react-portal/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-portal/dist/index.js +14 -12
- package/dist/node_modules/@radix-ui/react-portal/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-presence/dist/index.cjs +145 -1
- package/dist/node_modules/@radix-ui/react-presence/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-presence/dist/index.js +103 -45
- package/dist/node_modules/@radix-ui/react-presence/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs +61 -1
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.js +21 -14
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.cjs +244 -1
- package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js +179 -135
- package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs +105 -1
- package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-slot/dist/index.js +74 -35
- package/dist/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs +28 -1
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js +8 -7
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs +86 -1
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js +57 -40
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs +34 -1
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +13 -10
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.cjs +15 -1
- package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +8 -8
- package/dist/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs +23 -1
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js +3 -3
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-size/dist/index.cjs +56 -1
- package/dist/node_modules/@radix-ui/react-use-size/dist/index.cjs.map +1 -1
- package/dist/node_modules/@radix-ui/react-use-size/dist/index.js +34 -22
- package/dist/node_modules/@radix-ui/react-use-size/dist/index.js.map +1 -1
- package/dist/node_modules/aria-hidden/dist/es2015/index.cjs +122 -1
- package/dist/node_modules/aria-hidden/dist/es2015/index.cjs.map +1 -1
- package/dist/node_modules/aria-hidden/dist/es2015/index.js +111 -41
- package/dist/node_modules/aria-hidden/dist/es2015/index.js.map +1 -1
- package/dist/node_modules/class-variance-authority/dist/index.cjs +45 -1
- package/dist/node_modules/class-variance-authority/dist/index.cjs.map +1 -1
- package/dist/node_modules/class-variance-authority/dist/index.js +40 -30
- package/dist/node_modules/class-variance-authority/dist/index.js.map +1 -1
- package/dist/node_modules/clsx/dist/clsx.cjs +17 -1
- package/dist/node_modules/clsx/dist/clsx.cjs.map +1 -1
- package/dist/node_modules/clsx/dist/clsx.js +13 -13
- package/dist/node_modules/clsx/dist/clsx.js.map +1 -1
- package/dist/node_modules/get-nonce/dist/es2015/index.cjs +9 -1
- package/dist/node_modules/get-nonce/dist/es2015/index.cjs.map +1 -1
- package/dist/node_modules/get-nonce/dist/es2015/index.js +5 -3
- package/dist/node_modules/get-nonce/dist/es2015/index.js.map +1 -1
- package/dist/node_modules/js-cookie/dist/js.cookie.cjs +99 -1
- package/dist/node_modules/js-cookie/dist/js.cookie.cjs.map +1 -1
- package/dist/node_modules/js-cookie/dist/js.cookie.js +69 -43
- package/dist/node_modules/js-cookie/dist/js.cookie.js.map +1 -1
- package/dist/node_modules/jwt-decode/build/esm/index.cjs +58 -1
- package/dist/node_modules/jwt-decode/build/esm/index.cjs.map +1 -1
- package/dist/node_modules/jwt-decode/build/esm/index.js +36 -30
- package/dist/node_modules/jwt-decode/build/esm/index.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/Icon.cjs +35 -1
- package/dist/node_modules/lucide-react/dist/esm/Icon.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/Icon.js +25 -25
- package/dist/node_modules/lucide-react/dist/esm/Icon.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.cjs +22 -1
- package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.js +16 -15
- package/dist/node_modules/lucide-react/dist/esm/createLucideIcon.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.cjs +14 -1
- package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.js +2 -2
- package/dist/node_modules/lucide-react/dist/esm/defaultAttributes.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/check.cjs +7 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/check.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/check.js +5 -4
- package/dist/node_modules/lucide-react/dist/esm/icons/check.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.cjs +7 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.js +5 -4
- package/dist/node_modules/lucide-react/dist/esm/icons/chevron-right.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/circle.cjs +7 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/circle.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/circle.js +5 -4
- package/dist/node_modules/lucide-react/dist/esm/icons/circle.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/log-out.cjs +11 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/log-out.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/icons/log-out.js +6 -5
- package/dist/node_modules/lucide-react/dist/esm/icons/log-out.js.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.cjs +26 -1
- package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.cjs.map +1 -1
- package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.js +22 -14
- package/dist/node_modules/lucide-react/dist/esm/shared/src/utils.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.cjs +28 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js +8 -8
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs +197 -4
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js +163 -98
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.cjs +55 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js +31 -24
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs +19 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +12 -9
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs +102 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js +85 -51
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.cjs +5 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js +3 -3
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs +7 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js +5 -5
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js.map +1 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs +62 -36
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js +41 -65
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js.map +1 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs +10 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js +8 -5
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js.map +1 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs +37 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs.map +1 -1
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js +28 -16
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js.map +1 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/component.cjs +13 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/component.cjs.map +1 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/component.js +9 -7
- package/dist/node_modules/react-style-singleton/dist/es2015/component.js.map +1 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.cjs +33 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.cjs.map +1 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.js +11 -10
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.js.map +1 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.cjs +48 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.cjs.map +1 -1
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js +35 -17
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js.map +1 -1
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.cjs +3014 -1
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.cjs.map +1 -1
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +804 -555
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -1
- package/dist/node_modules/tailwindcss/dist/plugin.cjs +13 -1
- package/dist/node_modules/tailwindcss/dist/plugin.cjs.map +1 -1
- package/dist/node_modules/tailwindcss/dist/plugin.js +8 -8
- package/dist/node_modules/tailwindcss/dist/plugin.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.cjs +38 -1
- package/dist/node_modules/tslib/tslib.es6.cjs.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +33 -21
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.cjs +11 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.cjs.map +1 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js +8 -3
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js.map +1 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs +52 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs.map +1 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js +28 -19
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js.map +1 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.cjs +29 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.cjs.map +1 -1
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js +15 -11
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js.map +1 -1
- package/dist/node_modules/use-sidecar/dist/es2015/exports.cjs +38 -1
- package/dist/node_modules/use-sidecar/dist/es2015/exports.cjs.map +1 -1
- package/dist/node_modules/use-sidecar/dist/es2015/exports.js +15 -12
- package/dist/node_modules/use-sidecar/dist/es2015/exports.js.map +1 -1
- package/dist/node_modules/use-sidecar/dist/es2015/medium.cjs +88 -1
- package/dist/node_modules/use-sidecar/dist/es2015/medium.cjs.map +1 -1
- package/dist/node_modules/use-sidecar/dist/es2015/medium.js +64 -43
- package/dist/node_modules/use-sidecar/dist/es2015/medium.js.map +1 -1
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +68 -1
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -1
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +49 -39
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs +53 -1
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs.map +1 -1
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +39 -32
- package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js.map +1 -1
- package/dist/node_modules/use-sync-external-store/shim/index.cjs +17 -1
- package/dist/node_modules/use-sync-external-store/shim/index.cjs.map +1 -1
- package/dist/node_modules/use-sync-external-store/shim/index.js +14 -7
- package/dist/node_modules/use-sync-external-store/shim/index.js.map +1 -1
- package/dist/providers/auth/auth.context.cjs +5 -1
- package/dist/providers/auth/auth.context.cjs.map +1 -1
- package/dist/providers/auth/auth.context.js +3 -3
- package/dist/providers/auth/auth.context.js.map +1 -1
- package/dist/providers/auth/auth.hook.cjs +12 -1
- package/dist/providers/auth/auth.hook.cjs.map +1 -1
- package/dist/providers/auth/auth.hook.js +8 -7
- package/dist/providers/auth/auth.hook.js.map +1 -1
- package/dist/providers/auth/auth.provider.cjs +37 -1
- package/dist/providers/auth/auth.provider.cjs.map +1 -1
- package/dist/providers/auth/auth.provider.js +31 -22
- package/dist/providers/auth/auth.provider.js.map +1 -1
- package/dist/providers/blimu/blimu.context.cjs +5 -1
- package/dist/providers/blimu/blimu.context.cjs.map +1 -1
- package/dist/providers/blimu/blimu.context.d.ts +4 -4
- package/dist/providers/blimu/blimu.context.d.ts.map +1 -1
- package/dist/providers/blimu/blimu.context.js +3 -3
- package/dist/providers/blimu/blimu.context.js.map +1 -1
- package/dist/providers/blimu/blimu.hook.cjs +12 -1
- package/dist/providers/blimu/blimu.hook.cjs.map +1 -1
- package/dist/providers/blimu/blimu.hook.js +8 -7
- package/dist/providers/blimu/blimu.hook.js.map +1 -1
- package/dist/providers/blimu/blimu.provider.cjs +71 -1
- package/dist/providers/blimu/blimu.provider.cjs.map +1 -1
- package/dist/providers/blimu/blimu.provider.d.ts +1 -1
- package/dist/providers/blimu/blimu.provider.d.ts.map +1 -1
- package/dist/providers/blimu/blimu.provider.js +32 -27
- package/dist/providers/blimu/blimu.provider.js.map +1 -1
- package/dist/providers/index.cjs +13 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.ts +3 -3
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +13 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/theme/index.d.ts +2 -2
- package/dist/providers/theme/index.d.ts.map +1 -1
- package/dist/providers/theme/theme.context.cjs +5 -1
- package/dist/providers/theme/theme.context.cjs.map +1 -1
- package/dist/providers/theme/theme.context.js +3 -3
- package/dist/providers/theme/theme.context.js.map +1 -1
- package/dist/providers/theme/theme.hook.cjs +12 -1
- package/dist/providers/theme/theme.hook.cjs.map +1 -1
- package/dist/providers/theme/theme.hook.js +8 -7
- package/dist/providers/theme/theme.hook.js.map +1 -1
- package/dist/providers/theme/theme.provider.cjs +104 -1
- package/dist/providers/theme/theme.provider.cjs.map +1 -1
- package/dist/providers/theme/theme.provider.d.ts.map +1 -1
- package/dist/providers/theme/theme.provider.js +85 -48
- package/dist/providers/theme/theme.provider.js.map +1 -1
- package/dist/styles/styles.css +34 -40
- package/dist/styles/tw-styles.css +34 -40
- package/dist/tailwind.cjs +200 -0
- package/dist/tailwind.cjs.map +1 -0
- package/dist/{tailwind.plugin.js → tailwind.js} +43 -43
- package/dist/tailwind.js.map +1 -0
- package/dist/types/index.cjs +11 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +22 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +8 -8
- package/dist/types/index.js.map +1 -1
- package/dist/utils/publishable-key.cjs +62 -1
- package/dist/utils/publishable-key.cjs.map +1 -1
- package/dist/utils/publishable-key.js +52 -27
- package/dist/utils/publishable-key.js.map +1 -1
- package/package.json +68 -53
- package/dist/components.cjs +0 -2
- package/dist/components.cjs.map +0 -1
- package/dist/components.js +0 -13
- package/dist/components.js.map +0 -1
- package/dist/hooks.cjs +0 -2
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.js +0 -14
- package/dist/hooks.js.map +0 -1
- package/dist/providers.cjs +0 -2
- package/dist/providers.cjs.map +0 -1
- package/dist/providers.js +0 -13
- package/dist/providers.js.map +0 -1
- package/dist/tailwind.plugin.cjs +0 -2
- package/dist/tailwind.plugin.cjs.map +0 -1
- package/dist/tailwind.plugin.js.map +0 -1
|
@@ -1,152 +1,249 @@
|
|
|
1
|
-
import { Blimu
|
|
2
|
-
import
|
|
3
|
-
import { jwtDecode
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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":
|
|
17
|
-
})
|
|
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(
|
|
23
|
-
const
|
|
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
|
-
|
|
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
|
|
33
|
-
|
|
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
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
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(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
67
|
-
if (!
|
|
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
|
-
|
|
77
|
-
|
|
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:
|
|
134
|
+
user: result.user
|
|
80
135
|
};
|
|
81
136
|
}
|
|
82
137
|
scheduleRefresh() {
|
|
83
|
-
const
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
163
|
+
}
|
|
164
|
+
const refresher = async () => {
|
|
165
|
+
timeoutId = null;
|
|
166
|
+
if (!isOnline) {
|
|
167
|
+
this.pendingRefresher = refresher;
|
|
101
168
|
return;
|
|
102
169
|
}
|
|
103
|
-
const
|
|
104
|
-
if ("error" in
|
|
105
|
-
if (
|
|
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:
|
|
178
|
+
error: result.error
|
|
111
179
|
});
|
|
112
180
|
return;
|
|
113
|
-
} else
|
|
114
|
-
|
|
181
|
+
} else {
|
|
182
|
+
refresh();
|
|
183
|
+
}
|
|
115
184
|
};
|
|
116
|
-
|
|
185
|
+
timeoutId = window.setTimeout(refresher, timeoutDelayMS);
|
|
117
186
|
};
|
|
118
|
-
|
|
119
|
-
|
|
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
|
|
123
|
-
if (
|
|
124
|
-
this.refreshingSignals.
|
|
125
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
|
131
|
-
|
|
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((
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
235
|
+
this.refreshPromise = null;
|
|
236
|
+
this.refreshingSignalAbortController = null;
|
|
237
|
+
this.refreshingSignals.clear();
|
|
141
238
|
}
|
|
142
239
|
}
|
|
143
240
|
}
|
|
144
241
|
export {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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,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;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.refreshProm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,eAAK,iCAAiC,MAAA;AAAA,QACxC;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,KAAK,gBAAgB;AACvB,aAAO,KAAK;AAAA,IACd;AAEA,SAAK,kCAAkC,IAAI,gBAAA;AAE3C,SAAK,gCAAgC,OAAO,iBAAiB,SAAS,MAAM;AAC1E,WAAK,iBAAiB;AACtB,WAAK,kCAAkC;AACvC,WAAK,kBAAkB,MAAA;AAAA,IACzB,CAAC;AAGD,UAAM,eAAe,CAAC,KAAK,SAASD,IAAQ,IAAI,yBAAyB,IAAI;AAG7E,UAAM,cAAqC,CAAA;AAC3C,QAAI,cAAc;AAChB,kBAAY,WAAW;AAAA,IACzB;AAOA,SAAK,iBAAiB,KAAK,YAAY,KACpC,QAAQ,aAAa;AAAA,MACpB,QAAQ,KAAK,gCAAgC;AAAA,IAAA,CAC9C,EACA,KAAK,CAAC,aAAa;AAGlB,UAAI,CAAC,KAAK,QAAQ;AAChB,aAAK,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";
|
|
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":[
|
|
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
|
|
2
|
-
constructor(
|
|
3
|
-
this.listeners = /* @__PURE__ */ new Set()
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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":[
|
|
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;"}
|