@specscreen/backoffice-core 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -35
- package/dist/styles.css +38 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,11 @@ Include the stylesheet once in your app (Next.js: `app/layout.tsx`, Vite: `main.
|
|
|
16
16
|
import "@specscreen/backoffice-core/styles";
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
Tailwind v4 note:
|
|
20
|
+
|
|
21
|
+
- No extra `@source` or theme mapping is required in consumer apps when using this package stylesheet.
|
|
22
|
+
- The package exports its own token mappings and source scanning directives.
|
|
23
|
+
|
|
19
24
|
---
|
|
20
25
|
|
|
21
26
|
## Quick Start
|
|
@@ -153,7 +158,11 @@ const NavLink = ({ href, children, className }: any) => (
|
|
|
153
158
|
</Link>
|
|
154
159
|
);
|
|
155
160
|
|
|
156
|
-
export default function RootLayout({
|
|
161
|
+
export default function RootLayout({
|
|
162
|
+
children,
|
|
163
|
+
}: {
|
|
164
|
+
children: React.ReactNode;
|
|
165
|
+
}) {
|
|
157
166
|
const currentPath = usePathname();
|
|
158
167
|
|
|
159
168
|
return (
|
|
@@ -213,12 +222,12 @@ export function App() {
|
|
|
213
222
|
|
|
214
223
|
### `AuthProvider` interface
|
|
215
224
|
|
|
216
|
-
| Method
|
|
217
|
-
|
|
218
|
-
| `login`
|
|
219
|
-
| `logout`
|
|
220
|
-
| `checkAuth` | `() → Promise<boolean>`
|
|
221
|
-
| `getUser`
|
|
225
|
+
| Method | Signature | Description |
|
|
226
|
+
| ----------- | --------------------------------------- | ----------------------------------------------- |
|
|
227
|
+
| `login` | `({ email, password }) → Promise<void>` | Throw on failure |
|
|
228
|
+
| `logout` | `() → Promise<void>` | Clear session |
|
|
229
|
+
| `checkAuth` | `() → Promise<boolean>` | Return `false` (never throw) on invalid session |
|
|
230
|
+
| `getUser` | `() → Promise<User \| null>` | Return `null` if unauthenticated |
|
|
222
231
|
|
|
223
232
|
### Boot flow
|
|
224
233
|
|
|
@@ -240,15 +249,15 @@ function MyComponent() {
|
|
|
240
249
|
}
|
|
241
250
|
```
|
|
242
251
|
|
|
243
|
-
| Property
|
|
244
|
-
|
|
245
|
-
| `user`
|
|
246
|
-
| `isAuthenticated` | `boolean`
|
|
247
|
-
| `isLoading`
|
|
248
|
-
| `error`
|
|
249
|
-
| `login`
|
|
250
|
-
| `logout`
|
|
251
|
-
| `refreshUser`
|
|
252
|
+
| Property | Type | Description |
|
|
253
|
+
| ----------------- | ----------------------------------- | ---------------------------------- |
|
|
254
|
+
| `user` | `User \| null` | Current authenticated user |
|
|
255
|
+
| `isAuthenticated` | `boolean` | Session is active |
|
|
256
|
+
| `isLoading` | `boolean` | Auth boot is in progress |
|
|
257
|
+
| `error` | `string \| null` | Last auth error message |
|
|
258
|
+
| `login` | `(email, password) → Promise<void>` | Delegates to `authProvider.login` |
|
|
259
|
+
| `logout` | `() → Promise<void>` | Delegates to `authProvider.logout` |
|
|
260
|
+
| `refreshUser` | `() → Promise<void>` | Re-fetch user profile |
|
|
252
261
|
|
|
253
262
|
---
|
|
254
263
|
|
|
@@ -290,14 +299,14 @@ function ActionsBar() {
|
|
|
290
299
|
}
|
|
291
300
|
```
|
|
292
301
|
|
|
293
|
-
| Method
|
|
294
|
-
|
|
295
|
-
| `can(permission)`
|
|
296
|
-
| `canAny(permissions[])` | User has at least one of these
|
|
297
|
-
| `canAll(permissions[])` | User has all of these
|
|
298
|
-
| `hasRole(role)`
|
|
299
|
-
| `roles`
|
|
300
|
-
| `permissions`
|
|
302
|
+
| Method | Description |
|
|
303
|
+
| ----------------------- | --------------------------------- |
|
|
304
|
+
| `can(permission)` | User has this specific permission |
|
|
305
|
+
| `canAny(permissions[])` | User has at least one of these |
|
|
306
|
+
| `canAll(permissions[])` | User has all of these |
|
|
307
|
+
| `hasRole(role)` | User has this role |
|
|
308
|
+
| `roles` | `string[]` — all user roles |
|
|
309
|
+
| `permissions` | `string[]` — all user permissions |
|
|
301
310
|
|
|
302
311
|
### `<Can>` guard component
|
|
303
312
|
|
|
@@ -357,9 +366,9 @@ The root component. Wraps everything with auth context, guards, and layout.
|
|
|
357
366
|
<BackofficeApp
|
|
358
367
|
config={config}
|
|
359
368
|
authProvider={authProvider}
|
|
360
|
-
dataProvider={dataProvider}
|
|
361
|
-
NavLink={NavLink}
|
|
362
|
-
currentPath={pathname}
|
|
369
|
+
dataProvider={dataProvider} // optional
|
|
370
|
+
NavLink={NavLink} // optional, pass your router's Link
|
|
371
|
+
currentPath={pathname} // optional, for active sidebar item
|
|
363
372
|
loginPageProps={{ logo: "/logo.svg", appName: "My App" }}
|
|
364
373
|
headerActionLabel="New Record"
|
|
365
374
|
onHeaderAction={() => router.push("/new")}
|
|
@@ -486,9 +495,9 @@ interface Resource {
|
|
|
486
495
|
|
|
487
496
|
```ts
|
|
488
497
|
interface ResourceMeta {
|
|
489
|
-
requiredRoles?: string[];
|
|
490
|
-
requiredPermissions?: string[];
|
|
491
|
-
hideIfUnauthorized?: boolean;
|
|
498
|
+
requiredRoles?: string[]; // at least one role must match
|
|
499
|
+
requiredPermissions?: string[]; // all permissions must match
|
|
500
|
+
hideIfUnauthorized?: boolean; // default true
|
|
492
501
|
}
|
|
493
502
|
```
|
|
494
503
|
|
|
@@ -500,7 +509,11 @@ interface BackofficeConfig {
|
|
|
500
509
|
logo?: ComponentType<{ className?: string }> | string;
|
|
501
510
|
resources?: Resource[];
|
|
502
511
|
sidebarGroups?: SidebarGroup[];
|
|
503
|
-
sidebarFooterLinks?: Array<{
|
|
512
|
+
sidebarFooterLinks?: Array<{
|
|
513
|
+
label: string;
|
|
514
|
+
path: string;
|
|
515
|
+
icon?: ComponentType;
|
|
516
|
+
}>;
|
|
504
517
|
loginRedirect?: string;
|
|
505
518
|
logoutRedirect?: string;
|
|
506
519
|
}
|
|
@@ -530,7 +543,11 @@ export { AuthGuard, ResourceGuard, Can } from "@specscreen/backoffice-core";
|
|
|
530
543
|
export { AppShell, Sidebar, SidebarToggle } from "@specscreen/backoffice-core";
|
|
531
544
|
|
|
532
545
|
// Feedback
|
|
533
|
-
export {
|
|
546
|
+
export {
|
|
547
|
+
LoginPage,
|
|
548
|
+
AccessDenied,
|
|
549
|
+
LoadingScreen,
|
|
550
|
+
} from "@specscreen/backoffice-core";
|
|
534
551
|
|
|
535
552
|
// RBAC utilities (pure functions, no React)
|
|
536
553
|
export {
|
|
@@ -543,9 +560,14 @@ export {
|
|
|
543
560
|
|
|
544
561
|
// Types
|
|
545
562
|
export type {
|
|
546
|
-
User,
|
|
547
|
-
|
|
548
|
-
|
|
563
|
+
User,
|
|
564
|
+
AuthProvider,
|
|
565
|
+
AuthState,
|
|
566
|
+
Resource,
|
|
567
|
+
ResourceMeta,
|
|
568
|
+
SidebarGroup,
|
|
569
|
+
BackofficeConfig,
|
|
570
|
+
DataProvider,
|
|
549
571
|
} from "@specscreen/backoffice-core";
|
|
550
572
|
|
|
551
573
|
// Styles
|
package/dist/styles.css
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
@tailwind components;
|
|
3
3
|
@tailwind utilities;
|
|
4
4
|
|
|
5
|
+
/* Tailwind v4: scan this package's built files when stylesheet is imported. */
|
|
6
|
+
@source "./**/*.{js,mjs,cjs}";
|
|
7
|
+
|
|
8
|
+
/* Tailwind v4 tokens: expose utilities like bg-background, border-border, etc. */
|
|
9
|
+
@theme {
|
|
10
|
+
--color-border: hsl(var(--border));
|
|
11
|
+
--color-input: hsl(var(--input));
|
|
12
|
+
--color-ring: hsl(var(--ring));
|
|
13
|
+
--color-background: hsl(var(--background));
|
|
14
|
+
--color-foreground: hsl(var(--foreground));
|
|
15
|
+
--color-card: hsl(var(--card));
|
|
16
|
+
--color-card-foreground: hsl(var(--card-foreground));
|
|
17
|
+
--color-popover: hsl(var(--popover));
|
|
18
|
+
--color-popover-foreground: hsl(var(--popover-foreground));
|
|
19
|
+
--color-primary: hsl(var(--primary));
|
|
20
|
+
--color-primary-foreground: hsl(var(--primary-foreground));
|
|
21
|
+
--color-secondary: hsl(var(--secondary));
|
|
22
|
+
--color-secondary-foreground: hsl(var(--secondary-foreground));
|
|
23
|
+
--color-muted: hsl(var(--muted));
|
|
24
|
+
--color-muted-foreground: hsl(var(--muted-foreground));
|
|
25
|
+
--color-accent: hsl(var(--accent));
|
|
26
|
+
--color-accent-foreground: hsl(var(--accent-foreground));
|
|
27
|
+
--color-destructive: hsl(var(--destructive));
|
|
28
|
+
--color-destructive-foreground: hsl(var(--destructive-foreground));
|
|
29
|
+
--color-sidebar: hsl(var(--sidebar));
|
|
30
|
+
--color-sidebar-foreground: hsl(var(--sidebar-foreground));
|
|
31
|
+
--color-sidebar-border: hsl(var(--sidebar-border));
|
|
32
|
+
--color-sidebar-accent: hsl(var(--sidebar-accent));
|
|
33
|
+
--color-sidebar-accent-foreground: hsl(var(--sidebar-accent-foreground));
|
|
34
|
+
|
|
35
|
+
--radius-lg: var(--radius);
|
|
36
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
37
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
38
|
+
}
|
|
39
|
+
|
|
5
40
|
/*
|
|
6
41
|
* @specscreen/backoffice-core — Design Tokens
|
|
7
42
|
*
|
|
@@ -93,11 +128,12 @@
|
|
|
93
128
|
|
|
94
129
|
@layer base {
|
|
95
130
|
* {
|
|
96
|
-
|
|
131
|
+
border-color: hsl(var(--border));
|
|
97
132
|
}
|
|
98
133
|
|
|
99
134
|
body {
|
|
100
|
-
|
|
135
|
+
background-color: hsl(var(--background));
|
|
136
|
+
color: hsl(var(--foreground));
|
|
101
137
|
font-feature-settings: "rlig" 1, "calt" 1;
|
|
102
138
|
}
|
|
103
139
|
}
|