@cortejojicoy/admin-kit 0.1.8
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/LICENSE +21 -0
- package/README.md +347 -0
- package/dist/client.cjs +950 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +334 -0
- package/dist/client.d.ts +334 -0
- package/dist/client.js +900 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.cjs +117 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +28 -0
- package/dist/middleware.d.ts +28 -0
- package/dist/middleware.js +115 -0
- package/dist/middleware.js.map +1 -0
- package/dist/server.cjs +128 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +56 -0
- package/dist/server.d.ts +56 -0
- package/dist/server.js +122 -0
- package/dist/server.js.map +1 -0
- package/dist/types-N0f4k4Ie.d.cts +210 -0
- package/dist/types-N0f4k4Ie.d.ts +210 -0
- package/package.json +106 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
import { A as AdminConfig, g as AuthSession, e as AuthContextValue, d as AuthConfig, m as LoginPageProps, l as LoginPageConfig, J as JWTAuthConfig, f as AuthProvider, O as OAuthConfig, n as NavSection, N as NavItem, a as AdminModule, j as AuthUser, R as ResolvedAdminConfig, T as ThemeConfig } from './types-N0f4k4Ie.js';
|
|
4
|
+
|
|
5
|
+
interface AdminProviderProps {
|
|
6
|
+
config: AdminConfig;
|
|
7
|
+
initialSession?: AuthSession | null;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Top-level provider. Wraps everything in:
|
|
12
|
+
* ThemeProvider → AuthContextProvider → ModuleProvider → children
|
|
13
|
+
*
|
|
14
|
+
* The user prop is read from auth context inside ModuleBridge so modules
|
|
15
|
+
* can apply `enabled({ user })` predicates without prop drilling.
|
|
16
|
+
*/
|
|
17
|
+
declare function AdminProvider({ config, initialSession, children }: AdminProviderProps): react.JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare const AuthContext: react.Context<AuthContextValue | null>;
|
|
20
|
+
interface AuthContextProviderProps {
|
|
21
|
+
config: AuthConfig;
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
initialSession?: AuthSession | null;
|
|
24
|
+
}
|
|
25
|
+
declare function AuthContextProvider({ config, children, initialSession }: AuthContextProviderProps): react.JSX.Element;
|
|
26
|
+
|
|
27
|
+
declare function useAuth(): AuthContextValue;
|
|
28
|
+
|
|
29
|
+
interface AdminLoginPageProps extends LoginPageProps {
|
|
30
|
+
config?: LoginPageConfig;
|
|
31
|
+
/** OAuth provider buttons to render alongside the form. */
|
|
32
|
+
oauthProviders?: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
icon?: React.ReactNode;
|
|
36
|
+
}>;
|
|
37
|
+
/** Called when an OAuth button is clicked. */
|
|
38
|
+
onOAuthClick?: (providerId: string) => void;
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Default login page. Consumers can replace it entirely via
|
|
43
|
+
* `config.auth.loginPage.component`, or keep this shell and just override
|
|
44
|
+
* the logo/title via `config.auth.loginPage`.
|
|
45
|
+
*/
|
|
46
|
+
declare function LoginPage({ config, oauthProviders, onOAuthClick, className }: AdminLoginPageProps): react.JSX.Element;
|
|
47
|
+
|
|
48
|
+
interface AppRouterGuardProps {
|
|
49
|
+
loginPath?: string;
|
|
50
|
+
publicRoutes?: string[];
|
|
51
|
+
fallback?: ReactNode;
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
}
|
|
54
|
+
declare function AppRouterGuard({ loginPath, publicRoutes, fallback, children, }: AppRouterGuardProps): react.JSX.Element;
|
|
55
|
+
|
|
56
|
+
interface PagesRouterGuardProps {
|
|
57
|
+
loginPath?: string;
|
|
58
|
+
publicRoutes?: string[];
|
|
59
|
+
fallback?: ReactNode;
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
}
|
|
62
|
+
declare function PagesRouterGuard({ loginPath, publicRoutes, fallback, children, }: PagesRouterGuardProps): react.JSX.Element;
|
|
63
|
+
|
|
64
|
+
declare function createJWTProvider(cfg: JWTAuthConfig): AuthProvider;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Client-side OAuth provider. Performs the redirect dance; the actual
|
|
68
|
+
* token exchange must happen in a server route handler that the consumer
|
|
69
|
+
* mounts (see `auth/server/oauth.ts` if implemented).
|
|
70
|
+
*
|
|
71
|
+
* After the server completes the callback and sets a session cookie,
|
|
72
|
+
* `getSession()` reads it via the consumer-provided `/api/auth/session` endpoint.
|
|
73
|
+
*/
|
|
74
|
+
declare function createOAuthProvider(cfg: OAuthConfig): AuthProvider;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Pass-through factory for consumers supplying their own AuthProvider.
|
|
78
|
+
* Exists so `config.auth.provider === 'custom'` resolution can stay symmetric
|
|
79
|
+
* with `'jwt'` and `'oauth'`.
|
|
80
|
+
*/
|
|
81
|
+
declare function createCustomProvider(provider: AuthProvider): AuthProvider;
|
|
82
|
+
|
|
83
|
+
interface SidebarContextValue {
|
|
84
|
+
sections: NavSection[];
|
|
85
|
+
collapsed: boolean;
|
|
86
|
+
setCollapsed: (v: boolean) => void;
|
|
87
|
+
toggle: () => void;
|
|
88
|
+
mobileOpen: boolean;
|
|
89
|
+
setMobileOpen: (v: boolean) => void;
|
|
90
|
+
}
|
|
91
|
+
declare const SidebarContext: react.Context<SidebarContextValue | null>;
|
|
92
|
+
interface SidebarProviderProps {
|
|
93
|
+
sections: NavSection[];
|
|
94
|
+
defaultCollapsed?: boolean;
|
|
95
|
+
children: ReactNode;
|
|
96
|
+
}
|
|
97
|
+
declare function SidebarProvider({ sections, defaultCollapsed, children }: SidebarProviderProps): react.JSX.Element;
|
|
98
|
+
|
|
99
|
+
declare function useSidebar(): SidebarContextValue;
|
|
100
|
+
|
|
101
|
+
interface RouterAdapter {
|
|
102
|
+
useRouter: () => {
|
|
103
|
+
push: (href: string) => void;
|
|
104
|
+
replace: (href: string) => void;
|
|
105
|
+
back: () => void;
|
|
106
|
+
};
|
|
107
|
+
usePathname: () => string;
|
|
108
|
+
useSearchParams: () => URLSearchParams;
|
|
109
|
+
Link: ComponentType<LinkProps>;
|
|
110
|
+
}
|
|
111
|
+
interface LinkProps {
|
|
112
|
+
href: string;
|
|
113
|
+
prefetch?: boolean;
|
|
114
|
+
replace?: boolean;
|
|
115
|
+
className?: string;
|
|
116
|
+
children?: ReactNode;
|
|
117
|
+
onClick?: (e: unknown) => void;
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface SidebarProps {
|
|
122
|
+
Link: ComponentType<LinkProps>;
|
|
123
|
+
currentPath: string;
|
|
124
|
+
header?: ReactNode;
|
|
125
|
+
footer?: ReactNode;
|
|
126
|
+
className?: string;
|
|
127
|
+
}
|
|
128
|
+
declare function Sidebar({ Link, currentPath, header, footer, className }: SidebarProps): react.JSX.Element;
|
|
129
|
+
|
|
130
|
+
interface SidebarSectionProps {
|
|
131
|
+
section: NavSection;
|
|
132
|
+
collapsed?: boolean;
|
|
133
|
+
currentPath: string;
|
|
134
|
+
Link: ComponentType<LinkProps>;
|
|
135
|
+
}
|
|
136
|
+
declare function SidebarSection({ section, collapsed, currentPath, Link }: SidebarSectionProps): react.JSX.Element;
|
|
137
|
+
|
|
138
|
+
interface SidebarItemProps {
|
|
139
|
+
item: NavItem;
|
|
140
|
+
active?: boolean;
|
|
141
|
+
collapsed?: boolean;
|
|
142
|
+
Link: ComponentType<LinkProps>;
|
|
143
|
+
currentPath: string;
|
|
144
|
+
depth?: number;
|
|
145
|
+
}
|
|
146
|
+
declare function SidebarItem({ item, collapsed, Link, currentPath, depth }: SidebarItemProps): react.JSX.Element;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Merge nav sections declared in config with any contributed by modules.
|
|
150
|
+
* Sections with the same `id` are merged: items are concatenated and sorted
|
|
151
|
+
* by `order` (ascending, stable).
|
|
152
|
+
*/
|
|
153
|
+
declare function buildNav(configSections: NavSection[], modules?: AdminModule[]): NavSection[];
|
|
154
|
+
|
|
155
|
+
declare function filterNav(sections: NavSection[], user: AuthUser | null): NavSection[];
|
|
156
|
+
|
|
157
|
+
interface ModuleRegistry {
|
|
158
|
+
readonly all: AdminModule[];
|
|
159
|
+
byId: (id: string) => AdminModule | undefined;
|
|
160
|
+
widgets: (slot: string) => Array<{
|
|
161
|
+
moduleId: string;
|
|
162
|
+
Component: AdminModule['widgets'] extends Record<string, infer V> ? V : never;
|
|
163
|
+
}>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Build a typed lookup over the modules declared in config. This is a pure
|
|
167
|
+
* function — no global state, no side effects, no `registerModule()` API —
|
|
168
|
+
* so SSR and client see the same module set.
|
|
169
|
+
*/
|
|
170
|
+
declare function createModuleRegistry(modules: AdminModule[], user: AuthUser | null): ModuleRegistry;
|
|
171
|
+
|
|
172
|
+
declare const ModuleContext: react.Context<ModuleRegistry | null>;
|
|
173
|
+
interface ModuleProviderProps {
|
|
174
|
+
modules: AdminModule[];
|
|
175
|
+
user: AuthUser | null;
|
|
176
|
+
children: ReactNode;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Composes each module's `Provider` in declaration order, then exposes the
|
|
180
|
+
* registry via ModuleContext. Modules cannot register themselves at runtime —
|
|
181
|
+
* everything is declared in config so SSR/CSR stay in sync.
|
|
182
|
+
*/
|
|
183
|
+
declare function ModuleProvider({ modules, user, children }: ModuleProviderProps): react.JSX.Element;
|
|
184
|
+
|
|
185
|
+
declare function useModules(): ModuleRegistry;
|
|
186
|
+
|
|
187
|
+
interface AdminLayoutProps {
|
|
188
|
+
config: ResolvedAdminConfig;
|
|
189
|
+
/** Router-specific bits. Pass the app or pages adapter. */
|
|
190
|
+
Link: ComponentType<LinkProps>;
|
|
191
|
+
currentPath: string;
|
|
192
|
+
/** Page title shown in the topbar. */
|
|
193
|
+
title?: ReactNode;
|
|
194
|
+
/** Extra elements rendered into the topbar (right side). */
|
|
195
|
+
topbarActions?: ReactNode;
|
|
196
|
+
children: ReactNode;
|
|
197
|
+
className?: string;
|
|
198
|
+
}
|
|
199
|
+
declare function AdminLayout({ config, Link, currentPath, title, topbarActions, children, className, }: AdminLayoutProps): react.JSX.Element;
|
|
200
|
+
|
|
201
|
+
interface TopbarProps {
|
|
202
|
+
title?: ReactNode;
|
|
203
|
+
actions?: ReactNode;
|
|
204
|
+
className?: string;
|
|
205
|
+
}
|
|
206
|
+
declare function Topbar({ title, actions, className }: TopbarProps): react.JSX.Element;
|
|
207
|
+
|
|
208
|
+
interface PageContainerProps {
|
|
209
|
+
title?: ReactNode;
|
|
210
|
+
description?: ReactNode;
|
|
211
|
+
actions?: ReactNode;
|
|
212
|
+
children?: ReactNode;
|
|
213
|
+
className?: string;
|
|
214
|
+
contentClassName?: string;
|
|
215
|
+
}
|
|
216
|
+
declare function PageContainer({ title, description, actions, children, className, contentClassName, }: PageContainerProps): react.JSX.Element;
|
|
217
|
+
|
|
218
|
+
interface StatCardProps {
|
|
219
|
+
label: ReactNode;
|
|
220
|
+
value: ReactNode;
|
|
221
|
+
delta?: {
|
|
222
|
+
value: number;
|
|
223
|
+
label?: ReactNode;
|
|
224
|
+
direction?: 'up' | 'down';
|
|
225
|
+
};
|
|
226
|
+
icon?: ReactNode;
|
|
227
|
+
className?: string;
|
|
228
|
+
}
|
|
229
|
+
declare function StatCard({ label, value, delta, icon, className }: StatCardProps): react.JSX.Element;
|
|
230
|
+
|
|
231
|
+
interface ChartCardProps {
|
|
232
|
+
title?: ReactNode;
|
|
233
|
+
subtitle?: ReactNode;
|
|
234
|
+
actions?: ReactNode;
|
|
235
|
+
children?: ReactNode;
|
|
236
|
+
className?: string;
|
|
237
|
+
contentClassName?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Lightweight chart card shell — does not ship a chart library. Plug in
|
|
241
|
+
* recharts / chart.js / visx in `children`.
|
|
242
|
+
*/
|
|
243
|
+
declare function ChartCard({ title, subtitle, actions, children, className, contentClassName }: ChartCardProps): react.JSX.Element;
|
|
244
|
+
|
|
245
|
+
interface ActivityItem {
|
|
246
|
+
id: string;
|
|
247
|
+
title: ReactNode;
|
|
248
|
+
description?: ReactNode;
|
|
249
|
+
timestamp?: string | Date;
|
|
250
|
+
icon?: ReactNode;
|
|
251
|
+
actor?: {
|
|
252
|
+
name?: string;
|
|
253
|
+
image?: string;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
interface ActivityFeedProps {
|
|
257
|
+
items: ActivityItem[];
|
|
258
|
+
emptyState?: ReactNode;
|
|
259
|
+
className?: string;
|
|
260
|
+
}
|
|
261
|
+
declare function ActivityFeed({ items, emptyState, className }: ActivityFeedProps): react.JSX.Element;
|
|
262
|
+
|
|
263
|
+
declare function useAppRouter(): {
|
|
264
|
+
push: (href: string) => void;
|
|
265
|
+
replace: (href: string) => void;
|
|
266
|
+
back: () => void;
|
|
267
|
+
};
|
|
268
|
+
declare function useAppPathname(): string;
|
|
269
|
+
declare function useAppSearchParams(): URLSearchParams;
|
|
270
|
+
declare const AppLink: ComponentType<LinkProps>;
|
|
271
|
+
declare const appRouterAdapter: RouterAdapter;
|
|
272
|
+
|
|
273
|
+
declare function usePagesRouter(): {
|
|
274
|
+
push: (href: string) => void;
|
|
275
|
+
replace: (href: string) => void;
|
|
276
|
+
back: () => void;
|
|
277
|
+
};
|
|
278
|
+
declare function usePagesPathname(): string;
|
|
279
|
+
declare function usePagesSearchParams(): URLSearchParams;
|
|
280
|
+
declare const PagesLink: ComponentType<LinkProps>;
|
|
281
|
+
declare const pagesRouterAdapter: RouterAdapter;
|
|
282
|
+
|
|
283
|
+
interface WithAdminLayoutOptions {
|
|
284
|
+
config: ResolvedAdminConfig;
|
|
285
|
+
title?: ReactNode;
|
|
286
|
+
topbarActions?: ReactNode;
|
|
287
|
+
}
|
|
288
|
+
declare function withAdminLayout<P extends object>(Page: ComponentType<P>, opts: WithAdminLayoutOptions): ComponentType<P>;
|
|
289
|
+
|
|
290
|
+
type ThemeMode = 'light' | 'dark' | 'system';
|
|
291
|
+
interface ThemeContextValue {
|
|
292
|
+
mode: ThemeMode;
|
|
293
|
+
resolvedMode: 'light' | 'dark';
|
|
294
|
+
setMode: (m: ThemeMode) => void;
|
|
295
|
+
}
|
|
296
|
+
declare const ThemeContext: react.Context<ThemeContextValue | null>;
|
|
297
|
+
interface ThemeProviderProps {
|
|
298
|
+
theme?: ThemeConfig;
|
|
299
|
+
children: ReactNode;
|
|
300
|
+
}
|
|
301
|
+
declare function ThemeProvider({ theme, children }: ThemeProviderProps): react.JSX.Element;
|
|
302
|
+
|
|
303
|
+
declare function useTheme(): ThemeContextValue;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Default theme tokens, exposed as CSS custom properties under `[data-admin-kit]`.
|
|
307
|
+
* Consumers can override any token via `config.theme.tokens`.
|
|
308
|
+
*/
|
|
309
|
+
declare const DEFAULT_TOKENS: {
|
|
310
|
+
readonly '--admin-color-bg': "#fafafa";
|
|
311
|
+
readonly '--admin-color-surface': "#ffffff";
|
|
312
|
+
readonly '--admin-color-border': "#e5e5e5";
|
|
313
|
+
readonly '--admin-color-text': "#171717";
|
|
314
|
+
readonly '--admin-color-text-muted': "#737373";
|
|
315
|
+
readonly '--admin-color-primary': "#171717";
|
|
316
|
+
readonly '--admin-color-primary-fg': "#ffffff";
|
|
317
|
+
readonly '--admin-color-accent': "#3b82f6";
|
|
318
|
+
readonly '--admin-radius': "0.5rem";
|
|
319
|
+
readonly '--admin-sidebar-width': "16rem";
|
|
320
|
+
readonly '--admin-sidebar-collapsed-width': "4rem";
|
|
321
|
+
readonly '--admin-topbar-height': "3.5rem";
|
|
322
|
+
};
|
|
323
|
+
type ThemeTokens = Partial<Record<keyof typeof DEFAULT_TOKENS | string, string>>;
|
|
324
|
+
declare function tokensToStyle(tokens: ThemeTokens): Record<string, string>;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Minimal classname combiner. Filters falsy values (false/null/undefined/'')
|
|
328
|
+
* and joins the rest with a space. Kept dependency-free on purpose; if the
|
|
329
|
+
* consumer wants tailwind-merge semantics they can wrap this in their own.
|
|
330
|
+
*/
|
|
331
|
+
type ClassValue = string | number | null | undefined | false | ClassValue[];
|
|
332
|
+
declare function cn(...values: ClassValue[]): string;
|
|
333
|
+
|
|
334
|
+
export { ActivityFeed, AdminLayout, AdminProvider, AppLink, AppRouterGuard, AuthContext, AuthContextProvider, ChartCard, DEFAULT_TOKENS, LoginPage, ModuleContext, ModuleProvider, PageContainer, PagesLink, PagesRouterGuard, Sidebar, SidebarContext, SidebarItem, SidebarProvider, SidebarSection, StatCard, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, Topbar, appRouterAdapter, buildNav, cn, createCustomProvider, createJWTProvider, createModuleRegistry, createOAuthProvider, filterNav, pagesRouterAdapter, tokensToStyle, useAppPathname, useAppRouter, useAppSearchParams, useAuth, useModules, usePagesPathname, usePagesRouter, usePagesSearchParams, useSidebar, useTheme, withAdminLayout };
|