@invect/user-auth 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -0
  3. package/dist/backend/index.cjs +1166 -0
  4. package/dist/backend/index.cjs.map +1 -0
  5. package/dist/backend/index.d.ts +42 -0
  6. package/dist/backend/index.d.ts.map +1 -0
  7. package/dist/backend/index.mjs +1164 -0
  8. package/dist/backend/index.mjs.map +1 -0
  9. package/dist/backend/plugin.d.ts +62 -0
  10. package/dist/backend/plugin.d.ts.map +1 -0
  11. package/dist/backend/types.d.ts +299 -0
  12. package/dist/backend/types.d.ts.map +1 -0
  13. package/dist/frontend/components/AuthGate.d.ts +17 -0
  14. package/dist/frontend/components/AuthGate.d.ts.map +1 -0
  15. package/dist/frontend/components/AuthenticatedInvect.d.ts +129 -0
  16. package/dist/frontend/components/AuthenticatedInvect.d.ts.map +1 -0
  17. package/dist/frontend/components/ProfilePage.d.ts +10 -0
  18. package/dist/frontend/components/ProfilePage.d.ts.map +1 -0
  19. package/dist/frontend/components/SidebarUserMenu.d.ts +12 -0
  20. package/dist/frontend/components/SidebarUserMenu.d.ts.map +1 -0
  21. package/dist/frontend/components/SignInForm.d.ts +14 -0
  22. package/dist/frontend/components/SignInForm.d.ts.map +1 -0
  23. package/dist/frontend/components/SignInPage.d.ts +19 -0
  24. package/dist/frontend/components/SignInPage.d.ts.map +1 -0
  25. package/dist/frontend/components/UserButton.d.ts +15 -0
  26. package/dist/frontend/components/UserButton.d.ts.map +1 -0
  27. package/dist/frontend/components/UserManagement.d.ts +19 -0
  28. package/dist/frontend/components/UserManagement.d.ts.map +1 -0
  29. package/dist/frontend/components/UserManagementPage.d.ts +9 -0
  30. package/dist/frontend/components/UserManagementPage.d.ts.map +1 -0
  31. package/dist/frontend/index.cjs +1262 -0
  32. package/dist/frontend/index.cjs.map +1 -0
  33. package/dist/frontend/index.d.ts +29 -0
  34. package/dist/frontend/index.d.ts.map +1 -0
  35. package/dist/frontend/index.mjs +1250 -0
  36. package/dist/frontend/index.mjs.map +1 -0
  37. package/dist/frontend/plugins/authFrontendPlugin.d.ts +14 -0
  38. package/dist/frontend/plugins/authFrontendPlugin.d.ts.map +1 -0
  39. package/dist/frontend/providers/AuthProvider.d.ts +46 -0
  40. package/dist/frontend/providers/AuthProvider.d.ts.map +1 -0
  41. package/dist/roles-BOY5N82v.cjs +74 -0
  42. package/dist/roles-BOY5N82v.cjs.map +1 -0
  43. package/dist/roles-CZuKFEpJ.mjs +33 -0
  44. package/dist/roles-CZuKFEpJ.mjs.map +1 -0
  45. package/dist/shared/roles.d.ts +11 -0
  46. package/dist/shared/roles.d.ts.map +1 -0
  47. package/dist/shared/types.cjs +0 -0
  48. package/dist/shared/types.d.ts +46 -0
  49. package/dist/shared/types.d.ts.map +1 -0
  50. package/dist/shared/types.mjs +1 -0
  51. package/package.json +116 -0
@@ -0,0 +1,129 @@
1
+ /**
2
+ * AuthenticatedInvect — Wraps the Invect component with auth gating.
3
+ *
4
+ * Renders InvectShell → AuthProvider → AuthGate around Invect.
5
+ * The shell establishes the `.invect` CSS scope so all theme tokens
6
+ * work for both the sign-in page and the Invect editor.
7
+ *
8
+ * When the user is not authenticated, shows the sign-in page.
9
+ * When authenticated, renders the full Invect UI.
10
+ *
11
+ * Sign-up is disabled — initial admin users are configured explicitly via
12
+ * `betterAuthPlugin({ globalAdmins: [...] })`, and subsequent users are
13
+ * created by the admin through the User Management panel.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * import { AuthenticatedInvect } from '@invect/user-auth/ui';
18
+ * import { Invect, InvectShell } from '@invect/frontend';
19
+ * import '@invect/frontend/styles';
20
+ *
21
+ * export default function Page() {
22
+ * return (
23
+ * <AuthenticatedInvect
24
+ * apiBaseUrl="/api/invect"
25
+ * basePath="/invect"
26
+ * InvectComponent={Invect}
27
+ * ShellComponent={InvectShell}
28
+ * />
29
+ * );
30
+ * }
31
+ * ```
32
+ */
33
+ import { type ReactNode, type ComponentType, type MemoExoticComponent } from 'react';
34
+ import { QueryClient } from '@tanstack/react-query';
35
+ /**
36
+ * Accepts both a plain component and a React.memo-wrapped component.
37
+ * React.memo returns MemoExoticComponent which isn't directly assignable
38
+ * to ComponentType in TypeScript, but is valid in JSX.
39
+ */
40
+ type ComponentOrMemo<P> = ComponentType<P> | MemoExoticComponent<ComponentType<P>>;
41
+ /**
42
+ * Generic over TPlugin so that passing a typed InvectComponent (e.g. one that
43
+ * expects `plugins?: InvectFrontendPlugin[]`) causes TypeScript to infer the
44
+ * correct element type for the `plugins` prop on AuthenticatedInvect itself.
45
+ * Defaults to `unknown` for the no-plugins case.
46
+ */
47
+ export interface AuthenticatedInvectProps<TPlugin = unknown> {
48
+ /**
49
+ * Base URL for the Invect API.
50
+ * Used for both auth endpoints and the Invect component.
51
+ * @example '/api/invect' or 'http://localhost:3000/invect'
52
+ */
53
+ apiBaseUrl?: string;
54
+ /**
55
+ * Base path where Invect is mounted in the browser.
56
+ * @default '/invect'
57
+ */
58
+ basePath?: string;
59
+ /**
60
+ * The Invect component to render when authenticated.
61
+ * Pass this to avoid a direct dependency on @invect/frontend.
62
+ * Accepts both plain and React.memo-wrapped components.
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * import { Invect } from '@invect/frontend';
67
+ * <AuthenticatedInvect InvectComponent={Invect} />
68
+ * ```
69
+ */
70
+ InvectComponent: ComponentOrMemo<{
71
+ apiBaseUrl?: string;
72
+ basePath?: string;
73
+ reactQueryClient?: QueryClient;
74
+ plugins?: TPlugin[];
75
+ }>;
76
+ /**
77
+ * The InvectShell component that provides the `.invect` CSS scope.
78
+ * This ensures theme tokens work for both the sign-in page and the
79
+ * Invect editor. Import from `@invect/frontend`.
80
+ *
81
+ * `children` is typed as `unknown` rather than `ReactNode` to avoid a
82
+ * structural incompatibility between `@types/react@18` (used here) and
83
+ * `@types/react@19` (used by `@invect/frontend`) where `ReactPortal`
84
+ * changed between versions.
85
+ *
86
+ * If not provided, the auth UI renders without the Invect CSS scope
87
+ * and must rely on the host app's styling.
88
+ *
89
+ * @example
90
+ * ```tsx
91
+ * import { InvectShell } from '@invect/frontend';
92
+ * <AuthenticatedInvect ShellComponent={InvectShell} />
93
+ * ```
94
+ */
95
+ ShellComponent?: ComponentOrMemo<{
96
+ children: ReactNode;
97
+ theme?: 'light' | 'dark' | 'system';
98
+ className?: string;
99
+ }>;
100
+ /**
101
+ * Optional React Query client. If provided, it's shared between
102
+ * the auth provider and the Invect component.
103
+ */
104
+ reactQueryClient?: QueryClient;
105
+ /**
106
+ * Content to display while checking session status.
107
+ */
108
+ loading?: ReactNode;
109
+ /**
110
+ * Theme for the shell wrapper.
111
+ * @default 'system'
112
+ */
113
+ theme?: 'light' | 'dark' | 'system';
114
+ /**
115
+ * Frontend plugins forwarded to InvectComponent.
116
+ * The element type is inferred from InvectComponent's `plugins` prop type,
117
+ * so this stays consistent with whatever component you pass.
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * import { rbacFrontendPlugin } from '@invect/rbac/ui';
122
+ * <AuthenticatedInvect plugins={[rbacFrontendPlugin]} />
123
+ * ```
124
+ */
125
+ plugins?: TPlugin[];
126
+ }
127
+ export declare function AuthenticatedInvect<TPlugin = unknown>({ apiBaseUrl, basePath, InvectComponent, ShellComponent, reactQueryClient, loading, theme, plugins, }: AuthenticatedInvectProps<TPlugin>): import("react/jsx-runtime").JSX.Element;
128
+ export {};
129
+ //# sourceMappingURL=AuthenticatedInvect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticatedInvect.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/AuthenticatedInvect.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,EAAE,WAAW,EAAuB,MA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2
+ * ProfilePage — Standalone page for the current authenticated user.
3
+ *
4
+ * Shows basic account information and provides a sign-out action.
5
+ */
6
+ export interface ProfilePageProps {
7
+ basePath: string;
8
+ }
9
+ export declare function ProfilePage({ basePath }: ProfilePageProps): import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=ProfilePage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProfilePage.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/ProfilePage.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,EAAE,gBAAgB,2CA6FzD"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SidebarUserMenu — User avatar link in the sidebar footer.
3
+ *
4
+ * Clicking navigates directly to the profile page.
5
+ * Sign-out is available on the profile page itself.
6
+ */
7
+ export interface SidebarUserMenuProps {
8
+ collapsed?: boolean;
9
+ basePath?: string;
10
+ }
11
+ export declare function SidebarUserMenu({ collapsed, basePath }: SidebarUserMenuProps): import("react/jsx-runtime").JSX.Element | null;
12
+ //# sourceMappingURL=SidebarUserMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SidebarUserMenu.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/SidebarUserMenu.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,EAAE,SAAiB,EAAE,QAAa,EAAE,EAAE,oBAAoB,kDA8CzF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * SignInForm — Email/password sign-in form component.
3
+ *
4
+ * Uses the AuthProvider's signIn action. Styled to match the Invect
5
+ * design system with grouped fields, clean labels, and themed inputs.
6
+ */
7
+ export interface SignInFormProps {
8
+ /** Called after successful sign-in */
9
+ onSuccess?: () => void;
10
+ /** Additional CSS class names */
11
+ className?: string;
12
+ }
13
+ export declare function SignInForm({ onSuccess, className }: SignInFormProps): import("react/jsx-runtime").JSX.Element;
14
+ //# sourceMappingURL=SignInForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignInForm.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/SignInForm.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,UAAU,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,eAAe,2CAgFnE"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * SignInPage — Full-page sign-in component with layout.
3
+ *
4
+ * Renders the SignInForm centered on the page with a logo, title,
5
+ * and grouped fields matching the Invect design system.
6
+ * Sign-up is not offered — new users are created by admins.
7
+ */
8
+ export interface SignInPageProps {
9
+ /** Called after successful sign-in */
10
+ onSuccess?: () => void;
11
+ /** Called when user clicks "Sign Up" link (optional — hidden if omitted) */
12
+ onNavigateToSignUp?: () => void;
13
+ /** Page title */
14
+ title?: string;
15
+ /** Page subtitle */
16
+ subtitle?: string;
17
+ }
18
+ export declare function SignInPage({ onSuccess, onNavigateToSignUp, title, subtitle, }: SignInPageProps): import("react/jsx-runtime").JSX.Element;
19
+ //# sourceMappingURL=SignInPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignInPage.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/SignInPage.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,UAAU,CAAC,EACzB,SAAS,EACT,kBAAkB,EAClB,KAAsB,EACtB,QAAgD,GACjD,EAAE,eAAe,2CAwCjB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * UserButton — Compact user avatar + dropdown for the authenticated user.
3
+ *
4
+ * Shows the user's avatar/initials when signed in, with a dropdown
5
+ * containing their name, email, and sign-out button.
6
+ * Shows a "Sign In" button when not authenticated.
7
+ */
8
+ export interface UserButtonProps {
9
+ /** Called when the sign-in button is clicked (unauthenticated state) */
10
+ onSignInClick?: () => void;
11
+ /** Additional CSS class names */
12
+ className?: string;
13
+ }
14
+ export declare function UserButton({ onSignInClick, className }: UserButtonProps): import("react/jsx-runtime").JSX.Element;
15
+ //# sourceMappingURL=UserButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserButton.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/UserButton.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,UAAU,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,eAAe,2CAwFvE"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * UserManagement — Admin panel for managing users.
3
+ *
4
+ * Displays a list of users with the ability to:
5
+ * - Create new users (email/password/role)
6
+ * - Change user roles
7
+ * - Delete users
8
+ *
9
+ * Only visible to admin users. Uses the auth plugin's
10
+ * `/plugins/auth/users` endpoints.
11
+ */
12
+ export interface UserManagementProps {
13
+ /** Base URL for the Invect API (same as AuthProvider's baseUrl) */
14
+ apiBaseUrl: string;
15
+ /** Additional CSS class names */
16
+ className?: string;
17
+ }
18
+ export declare function UserManagement({ apiBaseUrl, className }: UserManagementProps): import("react/jsx-runtime").JSX.Element | null;
19
+ //# sourceMappingURL=UserManagement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserManagement.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/UserManagement.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA8CH,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA8HD,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,mBAAmB,kDA2W5E"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * UserManagementPage — Standalone page for user management.
3
+ *
4
+ * Wraps the existing UserManagement component in a page layout
5
+ * consistent with the Access Control page style. Registered as a
6
+ * plugin route contribution at '/users'.
7
+ */
8
+ export declare function UserManagementPage(): import("react/jsx-runtime").JSX.Element;
9
+ //# sourceMappingURL=UserManagementPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserManagementPage.d.ts","sourceRoot":"","sources":["../../../src/frontend/components/UserManagementPage.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,wBAAgB,kBAAkB,4CAoCjC"}