@alexandregme/zljs 3.2.0 → 3.4.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.3.0] - 2026-11-10
12
+
13
+ ### Added
14
+
15
+ - Authentication that doesn't depend on a provider. `AuthProvider` takes an `adapter` (`AuthAdapter`), which connects to the app's auth provider, and an `appId`, the key of the app in each user's `roles`, so the same users sign in to several apps with a role in each
16
+ - `useAuth`, which returns `status` (`loading`, `authenticated` or `unauthenticated`), `user`, `role` in this app, and the sign-in methods: `signInWithOAuth`, `signInWithPassword`, `signInWithMagicLink` and `signOut`
17
+ - `getAuthSession`, which returns the session to code outside React, such as a thunk
18
+ - The types `AuthAdapter` and `AuthSession`, the contract an app implements to connect its provider
19
+ - `auth` on `ZustandProviders` and `AppProviders`, with the `adapter` and `appId` of `AuthProvider`, which mounts `AuthProvider` so the app doesn't. Without `auth`, nothing of auth is mounted
20
+ - `color` on `Modal` and `ConnectedModal`, a semantic color for the title and a light background in that color, such as `danger` for a question that can't be undone. `none`, the default, keeps the modal as it was
21
+ - `SignOutButton`, an icon button that signs the user out through the adapter. A click opens a `danger` modal that asks first, with the texts the button gets: `confirmTitle`, `confirmLabel` and `cancelLabel`. A failed sign-out fires an error toast with `errorMessage`
22
+
11
23
  ## [3.2.0] - 2026-11-10
12
24
 
13
25
  ### Added
@@ -423,7 +435,8 @@ Replace the shade with the class of the `color` being tested, for example `/(^|\
423
435
 
424
436
  The message of `Error` is `text-zl-danger`. `none` and `ghost` didn't change.
425
437
 
426
- [Unreleased]: https://github.com/alexandregme/zljs/compare/v3.2.0...HEAD
438
+ [Unreleased]: https://github.com/alexandregme/zljs/compare/v3.3.0...HEAD
439
+ [3.3.0]: https://github.com/alexandregme/zljs/compare/v3.2.0...v3.3.0
427
440
  [3.2.0]: https://github.com/alexandregme/zljs/compare/v3.1.0...v3.2.0
428
441
  [3.1.0]: https://github.com/alexandregme/zljs/compare/v3.0.0...v3.1.0
429
442
  [3.0.0]: https://github.com/alexandregme/zljs/compare/v2.3.0...v3.0.0
@@ -252,7 +252,7 @@ var overlay = tv4({
252
252
  base: "fixed inset-0 bg-black/50"
253
253
  });
254
254
  var content = tv4({
255
- base: "fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white rounded-lg shadow-lg p-6 w-full focus:outline-none max-h-[90vh] overflow-y-auto",
255
+ base: "fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-lg shadow-lg p-6 w-full focus:outline-none max-h-[90vh] overflow-y-auto",
256
256
  variants: {
257
257
  size: {
258
258
  xs: "max-w-xs",
@@ -261,17 +261,43 @@ var content = tv4({
261
261
  lg: "max-w-2xl",
262
262
  xl: "max-w-4xl",
263
263
  full: "max-w-6xl"
264
+ },
265
+ // An opaque tint: a translucent one, as Card has, would show the dark overlay behind the modal.
266
+ color: {
267
+ primary: "bg-[color-mix(in_srgb,var(--color-zl-primary)_15%,white)]",
268
+ success: "bg-[color-mix(in_srgb,var(--color-zl-success)_15%,white)]",
269
+ danger: "bg-[color-mix(in_srgb,var(--color-zl-danger)_15%,white)]",
270
+ warning: "bg-[color-mix(in_srgb,var(--color-zl-warning)_15%,white)]",
271
+ info: "bg-[color-mix(in_srgb,var(--color-zl-info)_15%,white)]",
272
+ muted: "bg-[color-mix(in_srgb,var(--color-zl-muted)_15%,white)]",
273
+ none: "bg-white"
264
274
  }
265
275
  },
266
276
  defaultVariants: {
267
- size: "md"
277
+ size: "md",
278
+ color: "none"
268
279
  }
269
280
  });
270
281
  var header = tv4({
271
282
  base: "flex items-start justify-between"
272
283
  });
273
284
  var title = tv4({
274
- base: "text-lg font-semibold text-gray-900 m-0"
285
+ base: "text-lg font-semibold m-0",
286
+ variants: {
287
+ // The strong value, as the colored toasts use: the plain one is too light on the tint.
288
+ color: {
289
+ primary: "text-zl-primary-strong",
290
+ success: "text-zl-success-strong",
291
+ danger: "text-zl-danger-strong",
292
+ warning: "text-zl-warning-strong",
293
+ info: "text-zl-info-strong",
294
+ muted: "text-zl-muted-strong",
295
+ none: "text-gray-900"
296
+ }
297
+ },
298
+ defaultVariants: {
299
+ color: "none"
300
+ }
275
301
  });
276
302
  var description = tv4({
277
303
  base: "text-sm text-gray-600 mt-2"
@@ -288,18 +314,19 @@ var Modal = ({
288
314
  title: title2,
289
315
  description: description2,
290
316
  children,
291
- size = "md"
317
+ size = "md",
318
+ color = "none"
292
319
  }) => {
293
320
  return /* @__PURE__ */ jsx4(Dialog.Root, { open, onOpenChange: (isOpen) => !isOpen && onClose(), children: /* @__PURE__ */ jsxs2(Dialog.Portal, { children: [
294
321
  /* @__PURE__ */ jsx4(Dialog.Overlay, { className: overlay() }),
295
322
  /* @__PURE__ */ jsxs2(
296
323
  Dialog.Content,
297
324
  {
298
- className: content({ size }),
325
+ className: content({ size, color }),
299
326
  ...!description2 && { "aria-describedby": void 0 },
300
327
  children: [
301
328
  /* @__PURE__ */ jsxs2("div", { className: header(), children: [
302
- /* @__PURE__ */ jsx4(Dialog.Title, { className: title(), children: title2 }),
329
+ /* @__PURE__ */ jsx4(Dialog.Title, { className: title({ color }), children: title2 }),
303
330
  /* @__PURE__ */ jsx4(Button, { icon: "X", "aria-label": "Close", onClick: onClose })
304
331
  ] }),
305
332
  description2 && /* @__PURE__ */ jsx4(Dialog.Description, { className: description(), children: description2 }),
@@ -509,6 +536,7 @@ var ConnectedModal = ({
509
536
  title: title2,
510
537
  description: description2,
511
538
  size,
539
+ color,
512
540
  children
513
541
  }) => {
514
542
  const open = useAppStore((s) => s.isModalOpen(modalId));
@@ -524,6 +552,7 @@ var ConnectedModal = ({
524
552
  title: title2,
525
553
  description: description2,
526
554
  size,
555
+ color,
527
556
  children
528
557
  }
529
558
  );
@@ -573,12 +602,176 @@ var Loader = ({ label = "Loading" }) => {
573
602
  return /* @__PURE__ */ jsx9("div", { className: loader(), children: /* @__PURE__ */ jsx9(Spinner, { size: "lg", label }) });
574
603
  };
575
604
 
576
- // features/providers/components/zustand-providers/zustand-providers.tsx
577
- import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
578
- var ZustandProviders = ({ children }) => /* @__PURE__ */ jsxs3(Fragment3, { children: [
579
- /* @__PURE__ */ jsx10(Loader, {}),
580
- /* @__PURE__ */ jsx10(Toaster, {}),
605
+ // features/auth/state/auth.store.ts
606
+ import { create as create3 } from "zustand";
607
+ import { devtools as devtools3 } from "zustand/middleware";
608
+
609
+ // features/auth/state/auth.const.ts
610
+ var authInitialState = {
611
+ status: "loading",
612
+ session: null,
613
+ adapter: null,
614
+ appId: null
615
+ };
616
+ var authDevtools = { name: "zljs", store: "auth" };
617
+
618
+ // features/auth/state/auth.store.ts
619
+ var useAuthStore = create3()(
620
+ devtools3(
621
+ (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")
633
+ }),
634
+ authDevtools
635
+ )
636
+ );
637
+
638
+ // features/auth/state/get-auth-session/get-auth-session.ts
639
+ var getAuthSession = () => useAuthStore.getState().session;
640
+
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,
581
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 });
661
+ };
662
+
663
+ // features/auth/hooks/use-auth/use-auth.ts
664
+ var requireAdapter = () => {
665
+ const { adapter } = useAuthStore.getState();
666
+ if (!adapter) {
667
+ throw new Error("useAuth must be used inside <AuthProvider>");
668
+ }
669
+ return adapter;
670
+ };
671
+ var useAuth = () => {
672
+ const status = useAuthStore((s) => s.status);
673
+ const session = useAuthStore((s) => s.session);
674
+ const appId = useAuthStore((s) => s.appId);
675
+ const user = session?.user ?? null;
676
+ return {
677
+ status,
678
+ user,
679
+ role: (appId && user?.roles[appId]) ?? null,
680
+ signInWithOAuth: (provider) => requireAdapter().signInWithOAuth(provider),
681
+ signInWithPassword: (credentials) => requireAdapter().signInWithPassword(credentials),
682
+ signInWithMagicLink: (email) => requireAdapter().signInWithMagicLink(email),
683
+ signOut: () => requireAdapter().signOut()
684
+ };
685
+ };
686
+
687
+ // features/auth/components/sign-out/sign-out-modal.const.ts
688
+ var SIGN_OUT_MODAL_ID = "zljs-sign-out";
689
+
690
+ // features/auth/components/sign-out/sign-out-modal.styles.ts
691
+ import { tv as tv9 } from "tailwind-variants";
692
+ var signOutModal = tv9({
693
+ slots: {
694
+ actions: "flex justify-end gap-2"
695
+ }
696
+ });
697
+
698
+ // features/auth/components/sign-out/sign-out-modal.tsx
699
+ import { jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
700
+ var SignOutModal = ({
701
+ title: title2 = "Sign out?",
702
+ confirmLabel = "Sign out",
703
+ cancelLabel = "Cancel",
704
+ errorMessage = "Could not sign out. Try again."
705
+ }) => {
706
+ const { signOut } = useAuth();
707
+ const closeModal = useAppStore((s) => s.closeModal);
708
+ const { actions } = signOutModal();
709
+ const stay = () => {
710
+ closeModal(SIGN_OUT_MODAL_ID);
711
+ };
712
+ const leave = () => {
713
+ closeModal(SIGN_OUT_MODAL_ID);
714
+ signOut().catch(() => {
715
+ useToastStore.getState().error(errorMessage);
716
+ });
717
+ };
718
+ return /* @__PURE__ */ jsx11(
719
+ ConnectedModal,
720
+ {
721
+ modalId: SIGN_OUT_MODAL_ID,
722
+ title: title2,
723
+ size: "xs",
724
+ color: "danger",
725
+ children: /* @__PURE__ */ jsxs3("div", { className: actions(), children: [
726
+ /* @__PURE__ */ jsx11(Button, { color: "ghost", onClick: stay, children: cancelLabel }),
727
+ /* @__PURE__ */ jsx11(Button, { color: "danger", onClick: leave, children: confirmLabel })
728
+ ] })
729
+ }
730
+ );
731
+ };
732
+
733
+ // features/auth/components/sign-out/sign-out-button.tsx
734
+ import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
735
+ var SignOutButton = ({
736
+ label = "Sign out",
737
+ confirmTitle,
738
+ confirmLabel,
739
+ cancelLabel,
740
+ errorMessage
741
+ }) => {
742
+ const openModal = useAppStore((s) => s.openModal);
743
+ const ask = () => {
744
+ openModal(SIGN_OUT_MODAL_ID);
745
+ };
746
+ return /* @__PURE__ */ jsxs4(Fragment4, { children: [
747
+ /* @__PURE__ */ jsx12(
748
+ Button,
749
+ {
750
+ variant: "icon",
751
+ color: "none",
752
+ icon: "LogOut",
753
+ "aria-label": label,
754
+ onClick: ask
755
+ }
756
+ ),
757
+ /* @__PURE__ */ jsx12(
758
+ SignOutModal,
759
+ {
760
+ title: confirmTitle,
761
+ confirmLabel,
762
+ cancelLabel,
763
+ errorMessage
764
+ }
765
+ )
766
+ ] });
767
+ };
768
+
769
+ // features/providers/components/zustand-providers/zustand-providers.tsx
770
+ import { Fragment as Fragment5, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
771
+ var ZustandProviders = ({ children, auth }) => /* @__PURE__ */ jsxs5(Fragment5, { children: [
772
+ /* @__PURE__ */ jsx13(Loader, {}),
773
+ /* @__PURE__ */ jsx13(Toaster, {}),
774
+ auth ? /* @__PURE__ */ jsx13(AuthProvider, { adapter: auth.adapter, appId: auth.appId, children }) : children
582
775
  ] });
583
776
 
584
777
  // core/state/redux/redux-provider/redux-provider.tsx
@@ -615,7 +808,7 @@ var createReduxStore = ({
615
808
  };
616
809
 
617
810
  // core/state/redux/redux-provider/redux-provider.tsx
618
- import { jsx as jsx11 } from "react/jsx-runtime";
811
+ import { jsx as jsx14 } from "react/jsx-runtime";
619
812
  var ReduxProvider = ({
620
813
  children,
621
814
  reducers = {},
@@ -631,7 +824,7 @@ var ReduxProvider = ({
631
824
  coreReducers
632
825
  })
633
826
  );
634
- return /* @__PURE__ */ jsx11(Provider, { store, children });
827
+ return /* @__PURE__ */ jsx14(Provider, { store, children });
635
828
  };
636
829
 
637
830
  // core/state/zustand/router/router.utils.ts
@@ -649,8 +842,8 @@ var splitURLasPath = (urlAsPath) => {
649
842
  };
650
843
 
651
844
  // core/state/zustand/router/router.store.ts
652
- import { create as create3 } from "zustand";
653
- import { devtools as devtools3 } from "zustand/middleware";
845
+ import { create as create4 } from "zustand";
846
+ import { devtools as devtools4 } from "zustand/middleware";
654
847
 
655
848
  // core/state/zustand/router/router.const.ts
656
849
  var routerInitialState = {
@@ -660,8 +853,8 @@ var routerInitialState = {
660
853
  var routerDevtools = { name: "zljs", store: "router" };
661
854
 
662
855
  // core/state/zustand/router/router.store.ts
663
- var useRouterStore = create3()(
664
- devtools3(
856
+ var useRouterStore = create4()(
857
+ devtools4(
665
858
  (set) => ({
666
859
  ...routerInitialState,
667
860
  setRoute: (urlAsPath) => set({ urlAsPath, query: splitURLasPath(urlAsPath) }, false, "setRoute")
@@ -671,8 +864,8 @@ var useRouterStore = create3()(
671
864
  );
672
865
 
673
866
  // core/state/zustand/page/page.store.ts
674
- import { create as create4 } from "zustand";
675
- import { devtools as devtools4 } from "zustand/middleware";
867
+ import { create as create5 } from "zustand";
868
+ import { devtools as devtools5 } from "zustand/middleware";
676
869
 
677
870
  // core/state/zustand/page/page.const.ts
678
871
  var pageInitialState = {
@@ -681,8 +874,8 @@ var pageInitialState = {
681
874
  var pageDevtools = { name: "zljs", store: "page" };
682
875
 
683
876
  // core/state/zustand/page/page.store.ts
684
- var usePageStore = create4()(
685
- devtools4(
877
+ var usePageStore = create5()(
878
+ devtools5(
686
879
  (set) => ({
687
880
  ...pageInitialState,
688
881
  setTitle: (title2) => set({ title: title2 }, false, "setTitle")
@@ -705,6 +898,10 @@ export {
705
898
  ConnectedModal,
706
899
  Spinner,
707
900
  Loader,
901
+ getAuthSession,
902
+ AuthProvider,
903
+ useAuth,
904
+ SignOutButton,
708
905
  ZustandProviders,
709
906
  ReduxProvider,
710
907
  splitURLasPath,
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, R as ReduxProviderProps } from './redux-provider.interface-DXOZKAMA.js';
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';
4
4
  export { FormInput, FormInputProps, FormProvider, FormProviderProps } from './rhf/index.js';
5
5
  export { toast } from 'sonner';
6
6
  import * as zustand from 'zustand';
@@ -208,9 +208,11 @@ interface ModalProps {
208
208
  children?: ReactNode;
209
209
  /** The width. `xs` is the smallest, for a short question and its buttons. */
210
210
  size?: ModalSize;
211
+ /** The color of the title and a light background in that color. `none`, the default, is white. */
212
+ color?: SemanticColor;
211
213
  }
212
214
 
213
- declare const Modal: ({ open, onClose, title, description, children, size, }: ModalProps) => react.JSX.Element;
215
+ declare const Modal: ({ open, onClose, title, description, children, size, color, }: ModalProps) => react.JSX.Element;
214
216
 
215
217
  interface WhatsAppButtonProps {
216
218
  phone: string;
@@ -315,11 +317,12 @@ interface ConnectedModalProps {
315
317
  modalId: string;
316
318
  title: string;
317
319
  description?: string;
318
- size?: ModalSize;
320
+ size?: ModalProps["size"];
321
+ color?: ModalProps["color"];
319
322
  children?: ReactNode;
320
323
  }
321
324
 
322
- declare const ConnectedModal: ({ modalId, title, description, size, children, }: ConnectedModalProps) => react.JSX.Element;
325
+ declare const ConnectedModal: ({ modalId, title, description, size, color, children, }: ConnectedModalProps) => react.JSX.Element;
323
326
 
324
327
  interface LoaderProps {
325
328
  label?: string;
@@ -365,11 +368,45 @@ declare const useAppStore: zustand.UseBoundStore<Omit<zustand.StoreApi<AppState>
365
368
  };
366
369
  }>;
367
370
 
368
- interface ZustandProvidersProps {
371
+ /** The current session, for code outside React, such as a thunk. */
372
+ declare const getAuthSession: () => AuthSession | null;
373
+
374
+ interface AuthProviderProps extends AuthConfig {
369
375
  children: ReactNode;
370
376
  }
371
377
 
372
- declare const ZustandProviders: ({ children }: ZustandProvidersProps) => react.JSX.Element;
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
+ interface SignOutButtonProps {
386
+ /** The accessible name of the icon button. */
387
+ label?: string;
388
+ /** The question of the modal a click opens. */
389
+ confirmTitle?: string;
390
+ /** The button of the modal that signs out. */
391
+ confirmLabel?: string;
392
+ /** The button of the modal that keeps the user signed in. */
393
+ cancelLabel?: string;
394
+ /** The toast when signing out fails. */
395
+ errorMessage?: string;
396
+ }
397
+
398
+ declare const SignOutButton: ({ label, confirmTitle, confirmLabel, cancelLabel, errorMessage, }: SignOutButtonProps) => react.JSX.Element;
399
+
400
+ interface UseAuthResult extends Omit<AuthAdapter, "onSessionChange"> {
401
+ status: AuthStatus;
402
+ user: AuthUser | null;
403
+ /** The user's role in this app, or `null` when they have none. */
404
+ role: string | null;
405
+ }
406
+
407
+ declare const useAuth: () => UseAuthResult;
408
+
409
+ declare const ZustandProviders: ({ children, auth }: ZustandProvidersProps) => react.JSX.Element;
373
410
 
374
411
  declare const ReduxProvider: ({ children, reducers, middlewares, preloadedState, coreReducers, }: ReduxProviderProps) => react.JSX.Element;
375
412
 
@@ -472,5 +509,5 @@ declare class HTTPClient {
472
509
  patch<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T | undefined>;
473
510
  }
474
511
 
475
- export { AuxiliaryColor, Button, Card, Checkbox, ConnectedModal, DataColor, DataGrid, Error, Form, HTTPClient, Heading, Icon, Input, Loader, Modal, Radio, ReduxProvider, ReduxProviderProps, Select, SemanticColor, Sidebar, Spinner, StatsCard, Tag, Text, TextArea, Toaster, WhatsAppButton, ZustandProviders, appInitialState, splitURLasPath, useAppStore, usePageStore, useRouterStore, useToastStore };
476
- export type { AppState, ButtonColor, ButtonProps, ButtonVariant, CardProps, CheckboxProps, CheckboxVariant, ConnectedModalProps, DataGridColumn, DataGridProps, ErrorProps, FormProps, HeadingProps, HttpClientConfig, HttpRequestConfig, IconName, IconProps, InputProps, LoaderProps, ModalProps, PageState, RadioProps, ReduxStore, RouterState, SelectOption, SelectProps, SidebarItem, SidebarProps, SidebarSection, SidebarUser, Size, SpinnerProps, SpinnerVariant, StatsCardProps, TagColor, TagProps, TextAreaProps, TextProps, TextVariant, Toast, ToastState, ToastType, WhatsAppButtonProps, ZustandProvidersProps };
512
+ export { AuthAdapter, AuthProvider, AuthSession, AuxiliaryColor, Button, Card, Checkbox, ConnectedModal, DataColor, DataGrid, Error, Form, HTTPClient, Heading, Icon, Input, Loader, 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 };
513
+ export type { AppState, ButtonColor, ButtonProps, ButtonVariant, CardProps, CheckboxProps, CheckboxVariant, ConnectedModalProps, DataGridColumn, DataGridProps, ErrorProps, FormProps, HeadingProps, HttpClientConfig, HttpRequestConfig, IconName, IconProps, InputProps, LoaderProps, 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,5 +1,6 @@
1
1
  "use client";
2
2
  import {
3
+ AuthProvider,
3
4
  Button,
4
5
  ConnectedModal,
5
6
  Heading,
@@ -7,18 +8,21 @@ import {
7
8
  Loader,
8
9
  Modal,
9
10
  ReduxProvider,
11
+ SignOutButton,
10
12
  Spinner,
11
13
  Text,
12
14
  Toaster,
13
15
  ZustandProviders,
14
16
  appInitialState,
17
+ getAuthSession,
15
18
  splitURLasPath,
16
19
  toast,
17
20
  useAppStore,
21
+ useAuth,
18
22
  usePageStore,
19
23
  useRouterStore,
20
24
  useToastStore
21
- } from "./chunk-ZIY5NUGA.js";
25
+ } from "./chunk-TYN56WKD.js";
22
26
  import {
23
27
  Error,
24
28
  FormInput,
@@ -890,6 +894,7 @@ var HTTPClient = class {
890
894
  }
891
895
  };
892
896
  export {
897
+ AuthProvider,
893
898
  Button,
894
899
  Card,
895
900
  Checkbox,
@@ -909,6 +914,7 @@ export {
909
914
  ReduxProvider,
910
915
  Select,
911
916
  Sidebar,
917
+ SignOutButton,
912
918
  Spinner,
913
919
  StatsCard,
914
920
  Tag,
@@ -918,9 +924,11 @@ export {
918
924
  WhatsAppButton,
919
925
  ZustandProviders,
920
926
  appInitialState,
927
+ getAuthSession,
921
928
  splitURLasPath,
922
929
  toast,
923
930
  useAppStore,
931
+ useAuth,
924
932
  usePageStore,
925
933
  useRouterStore,
926
934
  useToastStore
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { SemanticColor, ReduxProviderProps } from '../index.js';
3
+ import { SemanticColor, ReduxProviderProps, ZustandProvidersProps } from '../index.js';
4
4
  import { ThunkDispatch, UnknownAction, Reducer } from '@reduxjs/toolkit';
5
5
 
6
6
  interface RootLayoutProps {
@@ -33,9 +33,9 @@ interface LinkProps {
33
33
 
34
34
  declare const Link: ({ children, href, color }: LinkProps) => react.JSX.Element;
35
35
 
36
- type AppProvidersProps = ReduxProviderProps;
36
+ type AppProvidersProps = ReduxProviderProps & Pick<ZustandProvidersProps, "auth">;
37
37
 
38
- declare const AppProviders: ({ children, ...store }: AppProvidersProps) => react.JSX.Element;
38
+ declare const AppProviders: ({ children, auth, ...store }: AppProvidersProps) => react.JSX.Element;
39
39
 
40
40
  type InitPageFunction = (dispatch: ThunkDispatch<any, undefined, UnknownAction>) => void;
41
41
  interface PageConfigProps {
@@ -6,7 +6,7 @@ import {
6
6
  ZustandProviders,
7
7
  usePageStore,
8
8
  useRouterStore
9
- } from "../chunk-ZIY5NUGA.js";
9
+ } from "../chunk-TYN56WKD.js";
10
10
 
11
11
  // core/next/root-layout/root-layout.styles.ts
12
12
  import { tv } from "tailwind-variants";
@@ -109,9 +109,13 @@ var RouteSync = () => {
109
109
  }, [pathname, setRoute]);
110
110
  return null;
111
111
  };
112
- var AppProviders = ({ children, ...store }) => /* @__PURE__ */ jsxs2(ReduxProvider, { ...store, children: [
112
+ var AppProviders = ({
113
+ children,
114
+ auth,
115
+ ...store
116
+ }) => /* @__PURE__ */ jsxs2(ReduxProvider, { ...store, children: [
113
117
  /* @__PURE__ */ jsx5(RouteSync, {}),
114
- /* @__PURE__ */ jsx5(ZustandProviders, { children })
118
+ /* @__PURE__ */ jsx5(ZustandProviders, { auth, children })
115
119
  ] });
116
120
 
117
121
  // core/next/page-config/page-config.tsx
@@ -0,0 +1,77 @@
1
+ import { ReactNode } from 'react';
2
+ import { Reducer, Middleware } from '@reduxjs/toolkit';
3
+
4
+ /**
5
+ * Semantic colors for action-oriented components (Button, Heading, etc.)
6
+ */
7
+ type SemanticColor = "primary" | "success" | "danger" | "warning" | "info" | "muted" | "none";
8
+ /**
9
+ * Literal colors for data visualization components (StatsCard, etc.)
10
+ */
11
+ type DataColor = "blue" | "red" | "yellow" | "green" | "gray" | "orange";
12
+ /**
13
+ * Extra colors with no meaning of their own, to tell categories apart (Tag)
14
+ */
15
+ type AuxiliaryColor = "orange" | "pink" | "purple";
16
+
17
+ type AuthStatus = "loading" | "authenticated" | "unauthenticated";
18
+ interface AuthUser {
19
+ id: string;
20
+ email: string;
21
+ name?: string;
22
+ avatarUrl?: string;
23
+ /**
24
+ * 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.
26
+ */
27
+ hasAccess: boolean;
28
+ /** The user's role in each app, by app id: `{ entregas: "admin" }`. */
29
+ roles: Record<string, string>;
30
+ }
31
+ interface AuthSession {
32
+ accessToken: string;
33
+ user: AuthUser;
34
+ }
35
+ interface AuthCredentials {
36
+ email: string;
37
+ password: string;
38
+ }
39
+ /**
40
+ * What an auth provider must do for zljs. Each sign-in rejects
41
+ * on failure, so the caller can show the error.
42
+ */
43
+ interface AuthAdapter {
44
+ /**
45
+ * Calls `listener` right away with the current session, then on every
46
+ * change (sign in, sign out, token refresh). Returns the unsubscribe.
47
+ */
48
+ onSessionChange: (listener: (session: AuthSession | null) => void) => () => void;
49
+ signInWithOAuth: (provider: string) => Promise<void>;
50
+ signInWithPassword: (credentials: AuthCredentials) => Promise<void>;
51
+ /** Sends a sign-in link by email. The session comes when the link is opened. */
52
+ signInWithMagicLink: (email: string) => Promise<void>;
53
+ signOut: () => Promise<void>;
54
+ }
55
+ /** What an app gives zljs to turn auth on. */
56
+ interface AuthConfig {
57
+ /** Connects zljs to the app's auth provider. */
58
+ adapter: AuthAdapter;
59
+ /** The key of this app in each user's `roles`. */
60
+ appId: string;
61
+ }
62
+
63
+ interface ZustandProvidersProps {
64
+ children: ReactNode;
65
+ /** Turns on `AuthProvider`. Without it, nothing of auth is mounted. */
66
+ auth?: AuthConfig;
67
+ }
68
+
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
+ 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.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Opinionated, accessible React component library for enterprise apps (Next.js, Tailwind CSS v4).",
5
5
  "keywords": [
6
6
  "react",
@@ -1,25 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { Reducer, Middleware } from '@reduxjs/toolkit';
3
-
4
- /**
5
- * Semantic colors for action-oriented components (Button, Heading, etc.)
6
- */
7
- type SemanticColor = "primary" | "success" | "danger" | "warning" | "info" | "muted" | "none";
8
- /**
9
- * Literal colors for data visualization components (StatsCard, etc.)
10
- */
11
- type DataColor = "blue" | "red" | "yellow" | "green" | "gray" | "orange";
12
- /**
13
- * Extra colors with no meaning of their own, to tell categories apart (Tag)
14
- */
15
- type AuxiliaryColor = "orange" | "pink" | "purple";
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
-
25
- export type { AuxiliaryColor as A, DataColor as D, ReduxProviderProps as R, SemanticColor as S };