@alexandregme/zljs 3.5.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,18 @@ A change that needs action in an app has a **Migration** note. When updating, re
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [3.7.0] - 2026-11-11
12
+
13
+ ### Added
14
+
15
+ - `Authorized`, the wall in front of an app: a signed-out user sees `Login`, a signed-in user without access to this app (`hasAccess` on `AuthUser`, set by the adapter, such as after an admin approves) sees `AccessPending`, and a user with access sees the app. `login` and `accessPending` take the props of the two screens. Roles are a separate check: with `roles`, the user also needs one of them in this app. The type `AuthorizedProps` types what an app passes to it
16
+
17
+ ## [3.6.0] - 2026-11-11
18
+
19
+ ### Added
20
+
21
+ - `AccessPending`, the screen of a user who signed in and has no access to the app yet. It shows the email of the account and a `SignOutButton`. Every text has an English default: `title`, `message`, `signOutLabel`, and the `confirmTitle`, `confirmLabel`, `cancelLabel` and `errorMessage` of the sign-out
22
+
11
23
  ## [3.5.0] - 2026-11-11
12
24
 
13
25
  ### Added
@@ -447,7 +459,9 @@ Replace the shade with the class of the `color` being tested, for example `/(^|\
447
459
 
448
460
  The message of `Error` is `text-zl-danger`. `none` and `ghost` didn't change.
449
461
 
450
- [Unreleased]: https://github.com/alexandregme/zljs/compare/v3.5.0...HEAD
462
+ [Unreleased]: https://github.com/alexandregme/zljs/compare/v3.7.0...HEAD
463
+ [3.7.0]: https://github.com/alexandregme/zljs/compare/v3.6.0...v3.7.0
464
+ [3.6.0]: https://github.com/alexandregme/zljs/compare/v3.5.0...v3.6.0
451
465
  [3.5.0]: https://github.com/alexandregme/zljs/compare/v3.3.0...v3.5.0
452
466
  [3.3.0]: https://github.com/alexandregme/zljs/compare/v3.2.0...v3.3.0
453
467
  [3.2.0]: https://github.com/alexandregme/zljs/compare/v3.1.0...v3.2.0
@@ -602,63 +602,115 @@ var Loader = ({ label = "Loading" }) => {
602
602
  return /* @__PURE__ */ jsx9("div", { className: loader(), children: /* @__PURE__ */ jsx9(Spinner, { size: "lg", label }) });
603
603
  };
604
604
 
605
- // features/auth/state/auth.store.ts
605
+ // core/state/redux/redux-provider/redux-provider.tsx
606
+ import { useState } from "react";
607
+ import { Provider } from "react-redux";
608
+
609
+ // core/state/redux/store/store.ts
610
+ import {
611
+ combineReducers,
612
+ configureStore
613
+ } from "@reduxjs/toolkit";
614
+ var emptyReducer = (state = {}) => state;
615
+ var createReduxStore = ({
616
+ reducers,
617
+ middlewares,
618
+ preloadedState,
619
+ coreReducers
620
+ }) => {
621
+ let dynamicReducers = {};
622
+ const createReducer = () => {
623
+ const all = { ...dynamicReducers, ...reducers, ...coreReducers };
624
+ return Object.keys(all).length ? combineReducers(all) : emptyReducer;
625
+ };
626
+ const store = configureStore({
627
+ reducer: createReducer(),
628
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(middlewares),
629
+ preloadedState
630
+ });
631
+ store.setDynamicReducers = (newDynamicReducers = {}) => {
632
+ dynamicReducers = newDynamicReducers;
633
+ store.replaceReducer(createReducer());
634
+ };
635
+ return store;
636
+ };
637
+
638
+ // core/state/redux/redux-provider/redux-provider.tsx
639
+ import { jsx as jsx10 } from "react/jsx-runtime";
640
+ var ReduxProvider = ({
641
+ children,
642
+ reducers = {},
643
+ middlewares = [],
644
+ preloadedState = {},
645
+ coreReducers = {}
646
+ }) => {
647
+ const [store] = useState(
648
+ () => createReduxStore({
649
+ reducers,
650
+ middlewares,
651
+ preloadedState,
652
+ coreReducers
653
+ })
654
+ );
655
+ return /* @__PURE__ */ jsx10(Provider, { store, children });
656
+ };
657
+
658
+ // core/state/zustand/router/router.utils.ts
659
+ var splitURLasPath = (urlAsPath) => {
660
+ const [pathAndQuery = ""] = urlAsPath?.split("#") ?? [];
661
+ const [, query = ""] = pathAndQuery.split("?");
662
+ const parametersAsObject = {};
663
+ query.split("&").forEach((p) => {
664
+ const [parameter, value] = p.split("=");
665
+ if (parameter) {
666
+ parametersAsObject[parameter] = value ?? "";
667
+ }
668
+ });
669
+ return parametersAsObject;
670
+ };
671
+
672
+ // core/state/zustand/router/router.store.ts
606
673
  import { create as create3 } from "zustand";
607
674
  import { devtools as devtools3 } from "zustand/middleware";
608
675
 
609
- // features/auth/state/auth.const.ts
610
- var authInitialState = {
611
- status: "loading",
612
- session: null,
613
- adapter: null,
614
- appId: null
676
+ // core/state/zustand/router/router.const.ts
677
+ var routerInitialState = {
678
+ urlAsPath: "/",
679
+ query: {}
615
680
  };
616
- var authDevtools = { name: "zljs", store: "auth" };
681
+ var routerDevtools = { name: "zljs", store: "router" };
617
682
 
618
- // features/auth/state/auth.store.ts
619
- var useAuthStore = create3()(
683
+ // core/state/zustand/router/router.store.ts
684
+ var useRouterStore = create3()(
620
685
  devtools3(
621
686
  (set) => ({
622
- ...authInitialState,
623
- setSession: (session) => set(
624
- {
625
- session,
626
- status: session ? "authenticated" : "unauthenticated"
627
- },
628
- false,
629
- "setSession"
630
- ),
631
- configure: (adapter, appId) => set({ adapter, appId }, false, "configure"),
632
- reset: () => set(authInitialState, false, "reset")
687
+ ...routerInitialState,
688
+ setRoute: (urlAsPath) => set({ urlAsPath, query: splitURLasPath(urlAsPath) }, false, "setRoute")
633
689
  }),
634
- authDevtools
690
+ routerDevtools
635
691
  )
636
692
  );
637
693
 
638
- // features/auth/state/get-auth-session/get-auth-session.ts
639
- var getAuthSession = () => useAuthStore.getState().session;
694
+ // core/state/zustand/page/page.store.ts
695
+ import { create as create4 } from "zustand";
696
+ import { devtools as devtools4 } from "zustand/middleware";
640
697
 
641
- // features/auth/components/auth-provider/auth-provider.tsx
642
- import { useEffect as useEffect2 } from "react";
643
- import { Fragment as Fragment3, jsx as jsx10 } from "react/jsx-runtime";
644
- var AuthProvider = ({
645
- adapter,
646
- appId,
647
- children
648
- }) => {
649
- const configure = useAuthStore((s) => s.configure);
650
- const setSession = useAuthStore((s) => s.setSession);
651
- const reset = useAuthStore((s) => s.reset);
652
- useEffect2(() => {
653
- configure(adapter, appId);
654
- const unsubscribe = adapter.onSessionChange(setSession);
655
- return () => {
656
- unsubscribe();
657
- reset();
658
- };
659
- }, [adapter, appId, configure, setSession, reset]);
660
- return /* @__PURE__ */ jsx10(Fragment3, { children });
698
+ // core/state/zustand/page/page.const.ts
699
+ var pageInitialState = {
700
+ title: ""
661
701
  };
702
+ var pageDevtools = { name: "zljs", store: "page" };
703
+
704
+ // core/state/zustand/page/page.store.ts
705
+ var usePageStore = create4()(
706
+ devtools4(
707
+ (set) => ({
708
+ ...pageInitialState,
709
+ setTitle: (title2) => set({ title: title2 }, false, "setTitle")
710
+ }),
711
+ pageDevtools
712
+ )
713
+ );
662
714
 
663
715
  // core/card/card.styles.ts
664
716
  import { tv as tv9 } from "tailwind-variants";
@@ -711,6 +763,42 @@ var Card = ({
711
763
  ] });
712
764
  };
713
765
 
766
+ // features/auth/state/auth.store.ts
767
+ import { create as create5 } from "zustand";
768
+ import { devtools as devtools5 } from "zustand/middleware";
769
+
770
+ // features/auth/state/auth.const.ts
771
+ var authInitialState = {
772
+ status: "loading",
773
+ session: null,
774
+ adapter: null,
775
+ appId: null
776
+ };
777
+ var authDevtools = { name: "zljs", store: "auth" };
778
+
779
+ // features/auth/state/auth.store.ts
780
+ var useAuthStore = create5()(
781
+ devtools5(
782
+ (set) => ({
783
+ ...authInitialState,
784
+ setSession: (session) => set(
785
+ {
786
+ session,
787
+ status: session ? "authenticated" : "unauthenticated"
788
+ },
789
+ false,
790
+ "setSession"
791
+ ),
792
+ configure: (adapter, appId) => set({ adapter, appId }, false, "configure"),
793
+ reset: () => set(authInitialState, false, "reset")
794
+ }),
795
+ authDevtools
796
+ )
797
+ );
798
+
799
+ // features/auth/state/get-auth-session/get-auth-session.ts
800
+ var getAuthSession = () => useAuthStore.getState().session;
801
+
714
802
  // features/auth/hooks/use-auth/use-auth.ts
715
803
  var requireAdapter = () => {
716
804
  const { adapter } = useAuthStore.getState();
@@ -735,79 +823,19 @@ var useAuth = () => {
735
823
  };
736
824
  };
737
825
 
738
- // features/auth/components/login/login.const.ts
739
- var loginVendors = {
740
- supabase: {
741
- google: "Google",
742
- apple: "Apple",
743
- github: "GitHub",
744
- facebook: "Facebook"
745
- }
746
- };
747
-
748
- // features/auth/components/login/login.styles.ts
749
- import { tv as tv10 } from "tailwind-variants";
750
- var login = tv10({
751
- slots: {
752
- options: "flex flex-col gap-3"
753
- }
754
- });
755
-
756
- // features/auth/components/login/login.tsx
757
- import { jsx as jsx12 } from "react/jsx-runtime";
758
- var LoginProviderButton = ({
759
- id,
760
- label,
761
- onSignIn
762
- }) => {
763
- const signIn = () => {
764
- onSignIn(id);
765
- };
766
- return /* @__PURE__ */ jsx12(Button, { size: "lg", fullWidth: true, onClick: signIn, children: label });
767
- };
768
- var Login = ({
769
- vendor,
770
- providers,
771
- title: title2 = "Sign in",
772
- message = "Choose how to sign in",
773
- providerLabel = "Continue with",
774
- errorMessage = "Could not sign in. Try again."
775
- }) => {
776
- const { signInWithOAuth } = useAuth();
777
- const { options } = login();
778
- const names = loginVendors[vendor];
779
- const signIn = (id) => {
780
- signInWithOAuth(id).catch(() => {
781
- useToastStore.getState().error(errorMessage);
782
- });
783
- };
784
- return /* @__PURE__ */ jsx12(Card, { title: title2, titleLevel: 1, message, children: /* @__PURE__ */ jsx12("div", { className: options(), children: providers.map((provider) => {
785
- const id = String(provider);
786
- return /* @__PURE__ */ jsx12(
787
- LoginProviderButton,
788
- {
789
- id,
790
- label: `${providerLabel} ${names[id]}`,
791
- onSignIn: signIn
792
- },
793
- id
794
- );
795
- }) }) });
796
- };
797
-
798
826
  // features/auth/components/sign-out/sign-out-modal.const.ts
799
827
  var SIGN_OUT_MODAL_ID = "zljs-sign-out";
800
828
 
801
829
  // features/auth/components/sign-out/sign-out-modal.styles.ts
802
- import { tv as tv11 } from "tailwind-variants";
803
- var signOutModal = tv11({
830
+ import { tv as tv10 } from "tailwind-variants";
831
+ var signOutModal = tv10({
804
832
  slots: {
805
833
  actions: "flex justify-end gap-2"
806
834
  }
807
835
  });
808
836
 
809
837
  // features/auth/components/sign-out/sign-out-modal.tsx
810
- import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
838
+ import { jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
811
839
  var SignOutModal = ({
812
840
  title: title2 = "Sign out?",
813
841
  confirmLabel = "Sign out",
@@ -826,7 +854,7 @@ var SignOutModal = ({
826
854
  useToastStore.getState().error(errorMessage);
827
855
  });
828
856
  };
829
- return /* @__PURE__ */ jsx13(
857
+ return /* @__PURE__ */ jsx12(
830
858
  ConnectedModal,
831
859
  {
832
860
  modalId: SIGN_OUT_MODAL_ID,
@@ -834,15 +862,15 @@ var SignOutModal = ({
834
862
  size: "xs",
835
863
  color: "danger",
836
864
  children: /* @__PURE__ */ jsxs4("div", { className: actions(), children: [
837
- /* @__PURE__ */ jsx13(Button, { color: "ghost", onClick: stay, children: cancelLabel }),
838
- /* @__PURE__ */ jsx13(Button, { color: "danger", onClick: leave, children: confirmLabel })
865
+ /* @__PURE__ */ jsx12(Button, { color: "ghost", onClick: stay, children: cancelLabel }),
866
+ /* @__PURE__ */ jsx12(Button, { color: "danger", onClick: leave, children: confirmLabel })
839
867
  ] })
840
868
  }
841
869
  );
842
870
  };
843
871
 
844
872
  // features/auth/components/sign-out/sign-out-button.tsx
845
- import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs5 } from "react/jsx-runtime";
873
+ import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
846
874
  var SignOutButton = ({
847
875
  label = "Sign out",
848
876
  confirmTitle,
@@ -854,8 +882,8 @@ var SignOutButton = ({
854
882
  const ask = () => {
855
883
  openModal(SIGN_OUT_MODAL_ID);
856
884
  };
857
- return /* @__PURE__ */ jsxs5(Fragment4, { children: [
858
- /* @__PURE__ */ jsx14(
885
+ return /* @__PURE__ */ jsxs5(Fragment3, { children: [
886
+ /* @__PURE__ */ jsx13(
859
887
  Button,
860
888
  {
861
889
  variant: "icon",
@@ -865,7 +893,7 @@ var SignOutButton = ({
865
893
  onClick: ask
866
894
  }
867
895
  ),
868
- /* @__PURE__ */ jsx14(
896
+ /* @__PURE__ */ jsx13(
869
897
  SignOutModal,
870
898
  {
871
899
  title: confirmTitle,
@@ -877,123 +905,150 @@ var SignOutButton = ({
877
905
  ] });
878
906
  };
879
907
 
880
- // features/providers/components/zustand-providers/zustand-providers.tsx
881
- import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs6 } from "react/jsx-runtime";
882
- var ZustandProviders = ({ children, auth }) => /* @__PURE__ */ jsxs6(Fragment5, { children: [
883
- /* @__PURE__ */ jsx15(Loader, {}),
884
- /* @__PURE__ */ jsx15(Toaster, {}),
885
- auth ? /* @__PURE__ */ jsx15(AuthProvider, { adapter: auth.adapter, appId: auth.appId, children }) : children
886
- ] });
887
-
888
- // core/state/redux/redux-provider/redux-provider.tsx
889
- import { useState } from "react";
890
- import { Provider } from "react-redux";
908
+ // features/auth/components/access-pending/access-pending.styles.ts
909
+ import { tv as tv11 } from "tailwind-variants";
910
+ var accessPending = tv11({
911
+ slots: {
912
+ account: "flex items-center justify-between gap-3"
913
+ }
914
+ });
891
915
 
892
- // core/state/redux/store/store.ts
893
- import {
894
- combineReducers,
895
- configureStore
896
- } from "@reduxjs/toolkit";
897
- var emptyReducer = (state = {}) => state;
898
- var createReduxStore = ({
899
- reducers,
900
- middlewares,
901
- preloadedState,
902
- coreReducers
916
+ // features/auth/components/access-pending/access-pending.tsx
917
+ import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
918
+ var AccessPending = ({
919
+ title: title2 = "Waiting for approval",
920
+ message = "Your access to this app has not been approved yet.",
921
+ signOutLabel,
922
+ confirmTitle,
923
+ confirmLabel,
924
+ cancelLabel,
925
+ errorMessage
903
926
  }) => {
904
- let dynamicReducers = {};
905
- const createReducer = () => {
906
- const all = { ...dynamicReducers, ...reducers, ...coreReducers };
907
- return Object.keys(all).length ? combineReducers(all) : emptyReducer;
908
- };
909
- const store = configureStore({
910
- reducer: createReducer(),
911
- middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(middlewares),
912
- preloadedState
913
- });
914
- store.setDynamicReducers = (newDynamicReducers = {}) => {
915
- dynamicReducers = newDynamicReducers;
916
- store.replaceReducer(createReducer());
917
- };
918
- return store;
927
+ const { user } = useAuth();
928
+ const { account } = accessPending();
929
+ if (!user) {
930
+ return null;
931
+ }
932
+ return /* @__PURE__ */ jsx14(Card, { title: title2, titleLevel: 1, message, children: /* @__PURE__ */ jsxs6("div", { className: account(), children: [
933
+ /* @__PURE__ */ jsx14(Text, { variant: "caption", color: "muted", children: user.email }),
934
+ /* @__PURE__ */ jsx14(
935
+ SignOutButton,
936
+ {
937
+ label: signOutLabel,
938
+ confirmTitle,
939
+ confirmLabel,
940
+ cancelLabel,
941
+ errorMessage
942
+ }
943
+ )
944
+ ] }) });
919
945
  };
920
946
 
921
- // core/state/redux/redux-provider/redux-provider.tsx
922
- import { jsx as jsx16 } from "react/jsx-runtime";
923
- var ReduxProvider = ({
924
- children,
925
- reducers = {},
926
- middlewares = [],
927
- preloadedState = {},
928
- coreReducers = {}
947
+ // features/auth/components/auth-provider/auth-provider.tsx
948
+ import { useEffect as useEffect2 } from "react";
949
+ import { Fragment as Fragment4, jsx as jsx15 } from "react/jsx-runtime";
950
+ var AuthProvider = ({
951
+ adapter,
952
+ appId,
953
+ children
929
954
  }) => {
930
- const [store] = useState(
931
- () => createReduxStore({
932
- reducers,
933
- middlewares,
934
- preloadedState,
935
- coreReducers
936
- })
937
- );
938
- return /* @__PURE__ */ jsx16(Provider, { store, children });
955
+ const configure = useAuthStore((s) => s.configure);
956
+ const setSession = useAuthStore((s) => s.setSession);
957
+ const reset = useAuthStore((s) => s.reset);
958
+ useEffect2(() => {
959
+ configure(adapter, appId);
960
+ const unsubscribe = adapter.onSessionChange(setSession);
961
+ return () => {
962
+ unsubscribe();
963
+ reset();
964
+ };
965
+ }, [adapter, appId, configure, setSession, reset]);
966
+ return /* @__PURE__ */ jsx15(Fragment4, { children });
939
967
  };
940
968
 
941
- // core/state/zustand/router/router.utils.ts
942
- var splitURLasPath = (urlAsPath) => {
943
- const [pathAndQuery = ""] = urlAsPath?.split("#") ?? [];
944
- const [, query = ""] = pathAndQuery.split("?");
945
- const parametersAsObject = {};
946
- query.split("&").forEach((p) => {
947
- const [parameter, value] = p.split("=");
948
- if (parameter) {
949
- parametersAsObject[parameter] = value ?? "";
950
- }
951
- });
952
- return parametersAsObject;
969
+ // features/auth/components/login/login.const.ts
970
+ var loginVendors = {
971
+ supabase: {
972
+ google: "Google",
973
+ apple: "Apple",
974
+ github: "GitHub",
975
+ facebook: "Facebook"
976
+ }
953
977
  };
954
978
 
955
- // core/state/zustand/router/router.store.ts
956
- import { create as create4 } from "zustand";
957
- import { devtools as devtools4 } from "zustand/middleware";
979
+ // features/auth/components/login/login.styles.ts
980
+ import { tv as tv12 } from "tailwind-variants";
981
+ var login = tv12({
982
+ slots: {
983
+ options: "flex flex-col gap-3"
984
+ }
985
+ });
958
986
 
959
- // core/state/zustand/router/router.const.ts
960
- var routerInitialState = {
961
- urlAsPath: "/",
962
- query: {}
987
+ // features/auth/components/login/login.tsx
988
+ import { jsx as jsx16 } from "react/jsx-runtime";
989
+ var LoginProviderButton = ({
990
+ id,
991
+ label,
992
+ onSignIn
993
+ }) => {
994
+ const signIn = () => {
995
+ onSignIn(id);
996
+ };
997
+ return /* @__PURE__ */ jsx16(Button, { size: "lg", fullWidth: true, onClick: signIn, children: label });
998
+ };
999
+ var Login = ({
1000
+ vendor,
1001
+ providers,
1002
+ title: title2 = "Sign in",
1003
+ message = "Choose how to sign in",
1004
+ providerLabel = "Continue with",
1005
+ errorMessage = "Could not sign in. Try again."
1006
+ }) => {
1007
+ const { signInWithOAuth } = useAuth();
1008
+ const { options } = login();
1009
+ const names = loginVendors[vendor];
1010
+ const signIn = (id) => {
1011
+ signInWithOAuth(id).catch(() => {
1012
+ useToastStore.getState().error(errorMessage);
1013
+ });
1014
+ };
1015
+ return /* @__PURE__ */ jsx16(Card, { title: title2, titleLevel: 1, message, children: /* @__PURE__ */ jsx16("div", { className: options(), children: providers.map((provider) => {
1016
+ const id = String(provider);
1017
+ return /* @__PURE__ */ jsx16(
1018
+ LoginProviderButton,
1019
+ {
1020
+ id,
1021
+ label: `${providerLabel} ${names[id]}`,
1022
+ onSignIn: signIn
1023
+ },
1024
+ id
1025
+ );
1026
+ }) }) });
963
1027
  };
964
- var routerDevtools = { name: "zljs", store: "router" };
965
-
966
- // core/state/zustand/router/router.store.ts
967
- var useRouterStore = create4()(
968
- devtools4(
969
- (set) => ({
970
- ...routerInitialState,
971
- setRoute: (urlAsPath) => set({ urlAsPath, query: splitURLasPath(urlAsPath) }, false, "setRoute")
972
- }),
973
- routerDevtools
974
- )
975
- );
976
-
977
- // core/state/zustand/page/page.store.ts
978
- import { create as create5 } from "zustand";
979
- import { devtools as devtools5 } from "zustand/middleware";
980
1028
 
981
- // core/state/zustand/page/page.const.ts
982
- var pageInitialState = {
983
- title: ""
1029
+ // features/auth/components/authorized/authorized.tsx
1030
+ import { Fragment as Fragment5, jsx as jsx17 } from "react/jsx-runtime";
1031
+ var Authorized = ({
1032
+ children,
1033
+ roles,
1034
+ login: login2,
1035
+ accessPending: accessPending2
1036
+ }) => {
1037
+ const { status, user, role } = useAuth();
1038
+ if (status === "loading") return null;
1039
+ if (!user) return /* @__PURE__ */ jsx17(Login, { ...login2 });
1040
+ const hasRole = !roles || role !== null && roles.includes(role);
1041
+ if (!user.hasAccess || !hasRole) return /* @__PURE__ */ jsx17(AccessPending, { ...accessPending2 });
1042
+ return /* @__PURE__ */ jsx17(Fragment5, { children });
984
1043
  };
985
- var pageDevtools = { name: "zljs", store: "page" };
986
1044
 
987
- // core/state/zustand/page/page.store.ts
988
- var usePageStore = create5()(
989
- devtools5(
990
- (set) => ({
991
- ...pageInitialState,
992
- setTitle: (title2) => set({ title: title2 }, false, "setTitle")
993
- }),
994
- pageDevtools
995
- )
996
- );
1045
+ // features/providers/components/zustand-providers/zustand-providers.tsx
1046
+ import { Fragment as Fragment6, jsx as jsx18, jsxs as jsxs7 } from "react/jsx-runtime";
1047
+ var ZustandProviders = ({ children, auth }) => /* @__PURE__ */ jsxs7(Fragment6, { children: [
1048
+ /* @__PURE__ */ jsx18(Loader, {}),
1049
+ /* @__PURE__ */ jsx18(Toaster, {}),
1050
+ auth ? /* @__PURE__ */ jsx18(AuthProvider, { adapter: auth.adapter, appId: auth.appId, children }) : children
1051
+ ] });
997
1052
 
998
1053
  export {
999
1054
  Icon,
@@ -1009,15 +1064,17 @@ export {
1009
1064
  ConnectedModal,
1010
1065
  Spinner,
1011
1066
  Loader,
1012
- getAuthSession,
1013
- AuthProvider,
1014
- Card,
1015
- useAuth,
1016
- Login,
1017
- SignOutButton,
1018
- ZustandProviders,
1019
1067
  ReduxProvider,
1020
1068
  splitURLasPath,
1021
1069
  useRouterStore,
1022
- usePageStore
1070
+ usePageStore,
1071
+ Card,
1072
+ getAuthSession,
1073
+ useAuth,
1074
+ SignOutButton,
1075
+ AccessPending,
1076
+ AuthProvider,
1077
+ Login,
1078
+ Authorized,
1079
+ ZustandProviders
1023
1080
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, ChangeEvent, FormEvent, HTMLInputAutoCompleteAttribute, FocusEvent, KeyboardEvent, Ref } from 'react';
3
- import { S as SemanticColor, D as DataColor, A as AuxiliaryColor, a as AuthSession, b as AuthConfig, c as AuthAdapter, d as AuthStatus, e as AuthUser, Z as ZustandProvidersProps, R as ReduxProviderProps } from './redux-provider.interface-D6qhg7ND.js';
3
+ import { S as SemanticColor, D as DataColor, A as AuxiliaryColor, R as ReduxProviderProps, a as AuthSession, b as AuthConfig, c as AuthAdapter, d as AuthStatus, e as AuthUser, Z as ZustandProvidersProps } from './zustand-providers.interface-CeC8U2hM.js';
4
4
  export { FormInput, FormInputProps, FormProvider, FormProviderProps } from './rhf/index.js';
5
5
  export { toast } from 'sonner';
6
6
  import * as zustand from 'zustand';
@@ -368,76 +368,6 @@ declare const useAppStore: zustand.UseBoundStore<Omit<zustand.StoreApi<AppState>
368
368
  };
369
369
  }>;
370
370
 
371
- /** The current session, for code outside React, such as a thunk. */
372
- declare const getAuthSession: () => AuthSession | null;
373
-
374
- interface AuthProviderProps extends AuthConfig {
375
- children: ReactNode;
376
- }
377
-
378
- /**
379
- * Keeps the adapter, the appId and the session in `useAuthStore`, the one
380
- * place `useAuth` and `getAuthSession` read from. It runs in an effect, so on
381
- * the first render the status is still `loading`.
382
- */
383
- declare const AuthProvider: ({ adapter, appId, children, }: AuthProviderProps) => react.JSX.Element;
384
-
385
- /**
386
- * The OAuth providers of each auth vendor, by the id the vendor knows, with
387
- * the name each one shows on its button. A new vendor is a new key here.
388
- */
389
- declare const loginVendors: {
390
- readonly supabase: {
391
- readonly google: "Google";
392
- readonly apple: "Apple";
393
- readonly github: "GitHub";
394
- readonly facebook: "Facebook";
395
- };
396
- };
397
-
398
- type LoginVendor = keyof typeof loginVendors;
399
- type LoginProvider<V extends LoginVendor = LoginVendor> = keyof (typeof loginVendors)[V];
400
- interface LoginProps<V extends LoginVendor = LoginVendor> {
401
- /** The auth vendor behind the app's `AuthAdapter`. It sets which providers exist. */
402
- vendor: V;
403
- /** One button per provider, in this order. */
404
- providers: LoginProvider<V>[];
405
- title?: string;
406
- message?: string;
407
- /** Comes before the name of each provider, on its button. */
408
- providerLabel?: string;
409
- /** The toast when a sign-in fails. */
410
- errorMessage?: string;
411
- }
412
-
413
- declare const Login: <V extends LoginVendor>({ vendor, providers, title, message, providerLabel, errorMessage, }: LoginProps<V>) => react.JSX.Element;
414
-
415
- interface SignOutButtonProps {
416
- /** The accessible name of the icon button. */
417
- label?: string;
418
- /** The question of the modal a click opens. */
419
- confirmTitle?: string;
420
- /** The button of the modal that signs out. */
421
- confirmLabel?: string;
422
- /** The button of the modal that keeps the user signed in. */
423
- cancelLabel?: string;
424
- /** The toast when signing out fails. */
425
- errorMessage?: string;
426
- }
427
-
428
- declare const SignOutButton: ({ label, confirmTitle, confirmLabel, cancelLabel, errorMessage, }: SignOutButtonProps) => react.JSX.Element;
429
-
430
- interface UseAuthResult extends Omit<AuthAdapter, "onSessionChange"> {
431
- status: AuthStatus;
432
- user: AuthUser | null;
433
- /** The user's role in this app, or `null` when they have none. */
434
- role: string | null;
435
- }
436
-
437
- declare const useAuth: () => UseAuthResult;
438
-
439
- declare const ZustandProviders: ({ children, auth }: ZustandProvidersProps) => react.JSX.Element;
440
-
441
371
  declare const ReduxProvider: ({ children, reducers, middlewares, preloadedState, coreReducers, }: ReduxProviderProps) => react.JSX.Element;
442
372
 
443
373
  interface ReduxStore extends Store {
@@ -539,5 +469,108 @@ declare class HTTPClient {
539
469
  patch<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T | undefined>;
540
470
  }
541
471
 
542
- export { AuthAdapter, AuthProvider, AuthSession, AuxiliaryColor, Button, Card, Checkbox, ConnectedModal, DataColor, DataGrid, Error, Form, HTTPClient, Heading, Icon, Input, Loader, Login, Modal, Radio, ReduxProvider, ReduxProviderProps, Select, SemanticColor, Sidebar, SignOutButton, Spinner, StatsCard, Tag, Text, TextArea, Toaster, WhatsAppButton, ZustandProviders, ZustandProvidersProps, appInitialState, getAuthSession, splitURLasPath, useAppStore, useAuth, usePageStore, useRouterStore, useToastStore };
543
- export type { AppState, ButtonColor, ButtonProps, ButtonVariant, CardProps, CheckboxProps, CheckboxVariant, ConnectedModalProps, DataGridColumn, DataGridProps, ErrorProps, FormProps, HeadingProps, HttpClientConfig, HttpRequestConfig, IconName, IconProps, InputProps, LoaderProps, LoginProvider, LoginVendor, ModalProps, PageState, RadioProps, ReduxStore, RouterState, SelectOption, SelectProps, SidebarItem, SidebarProps, SidebarSection, SidebarUser, Size, SpinnerProps, SpinnerVariant, StatsCardProps, TagColor, TagProps, TextAreaProps, TextProps, TextVariant, Toast, ToastState, ToastType, WhatsAppButtonProps };
472
+ interface AccessPendingProps {
473
+ title?: string;
474
+ message?: string;
475
+ /** The accessible name of the sign-out button. */
476
+ signOutLabel?: string;
477
+ /** The question of the modal the button opens. */
478
+ confirmTitle?: string;
479
+ /** The button of the modal that signs out. */
480
+ confirmLabel?: string;
481
+ /** The button of the modal that keeps the user signed in. */
482
+ cancelLabel?: string;
483
+ /** The toast when signing out fails. */
484
+ errorMessage?: string;
485
+ }
486
+
487
+ declare const AccessPending: ({ title, message, signOutLabel, confirmTitle, confirmLabel, cancelLabel, errorMessage, }: AccessPendingProps) => react.JSX.Element | null;
488
+
489
+ /** The current session, for code outside React, such as a thunk. */
490
+ declare const getAuthSession: () => AuthSession | null;
491
+
492
+ interface AuthProviderProps extends AuthConfig {
493
+ children: ReactNode;
494
+ }
495
+
496
+ /**
497
+ * Keeps the adapter, the appId and the session in `useAuthStore`, the one
498
+ * place `useAuth` and `getAuthSession` read from. It runs in an effect, so on
499
+ * the first render the status is still `loading`.
500
+ */
501
+ declare const AuthProvider: ({ adapter, appId, children, }: AuthProviderProps) => react.JSX.Element;
502
+
503
+ /**
504
+ * The OAuth providers of each auth vendor, by the id the vendor knows, with
505
+ * the name each one shows on its button. A new vendor is a new key here.
506
+ */
507
+ declare const loginVendors: {
508
+ readonly supabase: {
509
+ readonly google: "Google";
510
+ readonly apple: "Apple";
511
+ readonly github: "GitHub";
512
+ readonly facebook: "Facebook";
513
+ };
514
+ };
515
+
516
+ type LoginVendor = keyof typeof loginVendors;
517
+ type LoginProvider<V extends LoginVendor = LoginVendor> = keyof (typeof loginVendors)[V];
518
+ interface LoginProps<V extends LoginVendor = LoginVendor> {
519
+ /** The auth vendor behind the app's `AuthAdapter`. It sets which providers exist. */
520
+ vendor: V;
521
+ /** One button per provider, in this order. */
522
+ providers: LoginProvider<V>[];
523
+ title?: string;
524
+ message?: string;
525
+ /** Comes before the name of each provider, on its button. */
526
+ providerLabel?: string;
527
+ /** The toast when a sign-in fails. */
528
+ errorMessage?: string;
529
+ }
530
+
531
+ declare const Login: <V extends LoginVendor>({ vendor, providers, title, message, providerLabel, errorMessage, }: LoginProps<V>) => react.JSX.Element;
532
+
533
+ interface AuthorizedProps<V extends LoginVendor = LoginVendor> {
534
+ /** The app, shown only to a signed-in user with access to it. */
535
+ children: ReactNode;
536
+ /**
537
+ * Roles that may see `children`, on top of access. Without it, access is
538
+ * enough, with or without a role.
539
+ */
540
+ roles?: string[];
541
+ /** The props of the `Login` a signed-out user sees. */
542
+ login: LoginProps<V>;
543
+ /** The props of the `AccessPending` a user who can't see `children` sees. */
544
+ accessPending?: AccessPendingProps;
545
+ }
546
+
547
+ declare const Authorized: <V extends LoginVendor>({ children, roles, login, accessPending, }: AuthorizedProps<V>) => react.JSX.Element | null;
548
+
549
+ interface SignOutButtonProps {
550
+ /** The accessible name of the icon button. */
551
+ label?: string;
552
+ /** The question of the modal a click opens. */
553
+ confirmTitle?: string;
554
+ /** The button of the modal that signs out. */
555
+ confirmLabel?: string;
556
+ /** The button of the modal that keeps the user signed in. */
557
+ cancelLabel?: string;
558
+ /** The toast when signing out fails. */
559
+ errorMessage?: string;
560
+ }
561
+
562
+ declare const SignOutButton: ({ label, confirmTitle, confirmLabel, cancelLabel, errorMessage, }: SignOutButtonProps) => react.JSX.Element;
563
+
564
+ interface UseAuthResult extends Omit<AuthAdapter, "onSessionChange"> {
565
+ status: AuthStatus;
566
+ user: AuthUser | null;
567
+ /** The user's role in this app, or `null` when they have none. */
568
+ role: string | null;
569
+ }
570
+
571
+ declare const useAuth: () => UseAuthResult;
572
+
573
+ declare const ZustandProviders: ({ children, auth }: ZustandProvidersProps) => react.JSX.Element;
574
+
575
+ export { AccessPending, AuthAdapter, AuthProvider, AuthSession, Authorized, AuxiliaryColor, Button, Card, Checkbox, ConnectedModal, DataColor, DataGrid, Error, Form, HTTPClient, Heading, Icon, Input, Loader, Login, Modal, Radio, ReduxProvider, ReduxProviderProps, Select, SemanticColor, Sidebar, SignOutButton, Spinner, StatsCard, Tag, Text, TextArea, Toaster, WhatsAppButton, ZustandProviders, ZustandProvidersProps, appInitialState, getAuthSession, splitURLasPath, useAppStore, useAuth, usePageStore, useRouterStore, useToastStore };
576
+ export type { AppState, AuthorizedProps, ButtonColor, ButtonProps, ButtonVariant, CardProps, CheckboxProps, CheckboxVariant, ConnectedModalProps, DataGridColumn, DataGridProps, ErrorProps, FormProps, HeadingProps, HttpClientConfig, HttpRequestConfig, IconName, IconProps, InputProps, LoaderProps, LoginProvider, LoginVendor, ModalProps, PageState, RadioProps, ReduxStore, RouterState, SelectOption, SelectProps, SidebarItem, SidebarProps, SidebarSection, SidebarUser, Size, SpinnerProps, SpinnerVariant, StatsCardProps, TagColor, TagProps, TextAreaProps, TextProps, TextVariant, Toast, ToastState, ToastType, WhatsAppButtonProps };
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import {
3
+ AccessPending,
3
4
  AuthProvider,
5
+ Authorized,
4
6
  Button,
5
7
  Card,
6
8
  ConnectedModal,
@@ -24,7 +26,7 @@ import {
24
26
  usePageStore,
25
27
  useRouterStore,
26
28
  useToastStore
27
- } from "./chunk-Y453WAGC.js";
29
+ } from "./chunk-JMEGXQKC.js";
28
30
  import {
29
31
  Error,
30
32
  FormInput,
@@ -845,7 +847,9 @@ var HTTPClient = class {
845
847
  }
846
848
  };
847
849
  export {
850
+ AccessPending,
848
851
  AuthProvider,
852
+ Authorized,
849
853
  Button,
850
854
  Card,
851
855
  Checkbox,
@@ -6,7 +6,7 @@ import {
6
6
  ZustandProviders,
7
7
  usePageStore,
8
8
  useRouterStore
9
- } from "../chunk-Y453WAGC.js";
9
+ } from "../chunk-JMEGXQKC.js";
10
10
 
11
11
  // core/next/root-layout/root-layout.styles.ts
12
12
  import { tv } from "tailwind-variants";
@@ -14,6 +14,14 @@ type DataColor = "blue" | "red" | "yellow" | "green" | "gray" | "orange";
14
14
  */
15
15
  type AuxiliaryColor = "orange" | "pink" | "purple";
16
16
 
17
+ interface ReduxProviderProps {
18
+ children: ReactNode;
19
+ reducers?: Record<string, Reducer>;
20
+ middlewares?: Middleware[];
21
+ preloadedState?: Record<string, unknown>;
22
+ coreReducers?: Record<string, Reducer>;
23
+ }
24
+
17
25
  type AuthStatus = "loading" | "authenticated" | "unauthenticated";
18
26
  interface AuthUser {
19
27
  id: string;
@@ -22,7 +30,7 @@ interface AuthUser {
22
30
  avatarUrl?: string;
23
31
  /**
24
32
  * Whether the user may use this app, such as approved by an admin. It is
25
- * separate from the role: a user can have access and no role.
33
+ * the only thing `Authorized` checks unless it gets `roles`.
26
34
  */
27
35
  hasAccess: boolean;
28
36
  /** The user's role in each app, by app id: `{ entregas: "admin" }`. */
@@ -66,12 +74,4 @@ interface ZustandProvidersProps {
66
74
  auth?: AuthConfig;
67
75
  }
68
76
 
69
- interface ReduxProviderProps {
70
- children: ReactNode;
71
- reducers?: Record<string, Reducer>;
72
- middlewares?: Middleware[];
73
- preloadedState?: Record<string, unknown>;
74
- coreReducers?: Record<string, Reducer>;
75
- }
76
-
77
77
  export type { AuxiliaryColor as A, DataColor as D, ReduxProviderProps as R, SemanticColor as S, ZustandProvidersProps as Z, AuthSession as a, AuthConfig as b, AuthAdapter as c, AuthStatus as d, AuthUser as e };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexandregme/zljs",
3
- "version": "3.5.0",
3
+ "version": "3.7.0",
4
4
  "description": "Opinionated, accessible React component library for enterprise apps (Next.js, Tailwind CSS v4).",
5
5
  "keywords": [
6
6
  "react",