@seliseblocks/genesis-os 4.0.0 → 4.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.
- package/CHANGELOG.md +18 -18
- package/README.md +250 -250
- package/dist/{chunk-ICC7VU5S.js → chunk-2QDH2N7Z.js} +6 -6
- package/dist/chunk-2QDH2N7Z.js.map +1 -0
- package/dist/{chunk-BBK7W3YW.js → chunk-4GXQNT77.js} +24 -24
- package/dist/chunk-4GXQNT77.js.map +1 -0
- package/dist/{chunk-IDLLTKIG.cjs → chunk-AL2E2WC4.cjs} +21 -21
- package/dist/chunk-AL2E2WC4.cjs.map +1 -0
- package/dist/{chunk-PSYK3CIF.js → chunk-CC33UJZK.js} +7 -7
- package/dist/chunk-CC33UJZK.js.map +1 -0
- package/dist/{chunk-CYOTAUOX.js → chunk-CEXYN2ZD.js} +3 -3
- package/dist/chunk-CEXYN2ZD.js.map +1 -0
- package/dist/{chunk-QIUPVNC3.js → chunk-CTVKY3LO.js} +5 -5
- package/dist/chunk-CTVKY3LO.js.map +1 -0
- package/dist/{chunk-2AHYFVPZ.js → chunk-ENK42YC4.js} +2 -2
- package/dist/chunk-ENK42YC4.js.map +1 -0
- package/dist/{chunk-VLNRQEGU.cjs → chunk-GEPWXPS7.cjs} +19 -19
- package/dist/chunk-GEPWXPS7.cjs.map +1 -0
- package/dist/{chunk-432ILOO2.js → chunk-GWZQFBJ5.js} +4 -4
- package/dist/chunk-GWZQFBJ5.js.map +1 -0
- package/dist/{chunk-DTL2IWSR.cjs → chunk-HF24SZFI.cjs} +7 -7
- package/dist/chunk-HF24SZFI.cjs.map +1 -0
- package/dist/{chunk-ZYUTSSBP.cjs → chunk-K2HI6ZDD.cjs} +432 -432
- package/dist/chunk-K2HI6ZDD.cjs.map +1 -0
- package/dist/{chunk-3A2IBUPM.js → chunk-M4AKVWL4.js} +4 -4
- package/dist/chunk-M4AKVWL4.js.map +1 -0
- package/dist/{chunk-JY6SQDRS.js → chunk-MCOK3TFE.js} +5 -5
- package/dist/chunk-MCOK3TFE.js.map +1 -0
- package/dist/{chunk-7IDH2A7L.js → chunk-MWEREW2W.js} +2 -2
- package/dist/chunk-MWEREW2W.js.map +1 -0
- package/dist/{chunk-UDENCRUH.cjs → chunk-MXZIA4LA.cjs} +20 -20
- package/dist/chunk-MXZIA4LA.cjs.map +1 -0
- package/dist/{chunk-USALSR5X.js → chunk-NF54AHIF.js} +2 -2
- package/dist/chunk-NF54AHIF.js.map +1 -0
- package/dist/{chunk-VMQOFMEM.cjs → chunk-PSATBGVF.cjs} +26 -26
- package/dist/chunk-PSATBGVF.cjs.map +1 -0
- package/dist/{chunk-6A7VSGOJ.cjs → chunk-Q7Y32IBM.cjs} +2 -2
- package/dist/chunk-Q7Y32IBM.cjs.map +1 -0
- package/dist/{chunk-4FMWATPK.cjs → chunk-SDWR3F3Y.cjs} +2 -2
- package/dist/chunk-SDWR3F3Y.cjs.map +1 -0
- package/dist/{chunk-KXY33QAB.cjs → chunk-VAKGHXK6.cjs} +2 -2
- package/dist/chunk-VAKGHXK6.cjs.map +1 -0
- package/dist/{chunk-63ZVMUCD.cjs → chunk-VNUPOJ7H.cjs} +5 -5
- package/dist/chunk-VNUPOJ7H.cjs.map +1 -0
- package/dist/{chunk-6GIOOEHR.js → chunk-XUQVWFG5.js} +2 -2
- package/dist/chunk-XUQVWFG5.js.map +1 -0
- package/dist/{chunk-2R476BM5.cjs → chunk-Z6N3Y5AQ.cjs} +8 -8
- package/dist/chunk-Z6N3Y5AQ.cjs.map +1 -0
- package/dist/{chunk-S5IVIAPZ.cjs → chunk-ZK3WUWET.cjs} +2 -2
- package/dist/chunk-ZK3WUWET.cjs.map +1 -0
- package/dist/components/index.cjs +349 -349
- package/dist/components/index.js +12 -12
- package/dist/guards/index.cjs +12 -12
- package/dist/guards/index.js +6 -6
- package/dist/hooks/index.cjs +62 -62
- package/dist/hooks/index.js +8 -8
- package/dist/index.cjs +520 -520
- package/dist/index.js +12 -12
- package/dist/layouts/index.cjs +19 -19
- package/dist/layouts/index.js +12 -12
- package/dist/lib/index.cjs +22 -22
- package/dist/lib/index.js +3 -3
- package/dist/pages/index.cjs +17 -17
- package/dist/pages/index.js +12 -12
- package/dist/providers/index.cjs +11 -11
- package/dist/providers/index.js +6 -6
- package/dist/store/index.cjs +9 -9
- package/dist/store/index.js +2 -2
- package/dist/utils/index.cjs +73 -73
- package/dist/utils/index.js +5 -5
- package/package.json +24 -23
- package/LICENSE +0 -21
- package/dist/chunk-2AHYFVPZ.js.map +0 -1
- package/dist/chunk-2R476BM5.cjs.map +0 -1
- package/dist/chunk-3A2IBUPM.js.map +0 -1
- package/dist/chunk-432ILOO2.js.map +0 -1
- package/dist/chunk-4FMWATPK.cjs.map +0 -1
- package/dist/chunk-63ZVMUCD.cjs.map +0 -1
- package/dist/chunk-6A7VSGOJ.cjs.map +0 -1
- package/dist/chunk-6GIOOEHR.js.map +0 -1
- package/dist/chunk-7IDH2A7L.js.map +0 -1
- package/dist/chunk-BBK7W3YW.js.map +0 -1
- package/dist/chunk-CYOTAUOX.js.map +0 -1
- package/dist/chunk-DTL2IWSR.cjs.map +0 -1
- package/dist/chunk-ICC7VU5S.js.map +0 -1
- package/dist/chunk-IDLLTKIG.cjs.map +0 -1
- package/dist/chunk-JY6SQDRS.js.map +0 -1
- package/dist/chunk-KXY33QAB.cjs.map +0 -1
- package/dist/chunk-PSYK3CIF.js.map +0 -1
- package/dist/chunk-QIUPVNC3.js.map +0 -1
- package/dist/chunk-S5IVIAPZ.cjs.map +0 -1
- package/dist/chunk-UDENCRUH.cjs.map +0 -1
- package/dist/chunk-USALSR5X.js.map +0 -1
- package/dist/chunk-VLNRQEGU.cjs.map +0 -1
- package/dist/chunk-VMQOFMEM.cjs.map +0 -1
- package/dist/chunk-ZYUTSSBP.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
# @seliseblocks/genesis-os
|
|
2
|
-
|
|
3
|
-
## 4.0.0
|
|
4
|
-
|
|
5
|
-
### Major Changes
|
|
6
|
-
|
|
7
|
-
- Renamed the package from `@seliseblocks/blocks-kit` to `@seliseblocks/genesis-os`. Update the dependency name and all import paths; no exported API changed.
|
|
8
|
-
- Require React 19.2.8 or newer. Support for React 18 is dropped, as is React 19.0.0 through 19.2.7: the `react`, `react-dom`, and `@types/react` peer ranges are now `^19.2.8`.
|
|
9
|
-
- Switched the router peer from `react-router-dom@^7` to `react-router@^8`. `react-router-dom` is frozen at 7.18.1 and never received a v8, and every 7.x release is affected by GHSA-qwww-vcr4-c8h2 (RSC-mode CSRF bypass, high), which is only patched in `react-router@8.3.0`. Host applications must install `react-router@^8` and change their own `react-router-dom` imports to `react-router`; the exported symbols are unchanged.
|
|
10
|
-
- Raised the `nuqs` peer floor to `^2.9.0`. Earlier 2.x releases declare no `react-router@8` support and ship no `nuqs/adapters/react-router/v8` entry point. Applications wiring up nuqs should import `NuqsAdapter` from `nuqs/adapters/react-router/v8`.
|
|
11
|
-
|
|
12
|
-
Releases before 4.0.0 were published under the `@seliseblocks/blocks-kit` name on the `0.0.x` line.
|
|
13
|
-
|
|
14
|
-
## 0.0.66
|
|
15
|
-
|
|
16
|
-
### Patch Changes
|
|
17
|
-
|
|
18
|
-
- fix project store issue after project create
|
|
1
|
+
# @seliseblocks/genesis-os
|
|
2
|
+
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Renamed the package from `@seliseblocks/blocks-kit` to `@seliseblocks/genesis-os`. Update the dependency name and all import paths; no exported API changed.
|
|
8
|
+
- Require React 19.2.8 or newer. Support for React 18 is dropped, as is React 19.0.0 through 19.2.7: the `react`, `react-dom`, and `@types/react` peer ranges are now `^19.2.8`.
|
|
9
|
+
- Switched the router peer from `react-router-dom@^7` to `react-router@^8`. `react-router-dom` is frozen at 7.18.1 and never received a v8, and every 7.x release is affected by GHSA-qwww-vcr4-c8h2 (RSC-mode CSRF bypass, high), which is only patched in `react-router@8.3.0`. Host applications must install `react-router@^8` and change their own `react-router-dom` imports to `react-router`; the exported symbols are unchanged.
|
|
10
|
+
- Raised the `nuqs` peer floor to `^2.9.0`. Earlier 2.x releases declare no `react-router@8` support and ship no `nuqs/adapters/react-router/v8` entry point. Applications wiring up nuqs should import `NuqsAdapter` from `nuqs/adapters/react-router/v8`.
|
|
11
|
+
|
|
12
|
+
Releases before 4.0.0 were published under the `@seliseblocks/blocks-kit` name on the `0.0.x` line.
|
|
13
|
+
|
|
14
|
+
## 0.0.66
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- fix project store issue after project create
|
package/README.md
CHANGED
|
@@ -1,250 +1,250 @@
|
|
|
1
|
-
# @seliseblocks/genesis-os
|
|
2
|
-
|
|
3
|
-
React app-shell composition package for SELISE Blocks applications: guards, layouts, providers, pages, stores, hooks, an HTTP client, and a shadcn/Radix based component library. It is the shared frontend foundation consumed by the Blocks service applications (IAM, OS, Data, Logic, Monitor, Release, Studio, Utilities, Localization).
|
|
4
|
-
|
|
5
|
-
Ships as ESM and CJS with bundled TypeScript declarations. Every module carries a `"use client"` banner, and `sideEffects` is `false`, so bundlers can tree-shake unused exports.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @seliseblocks/genesis-os
|
|
11
|
-
# or
|
|
12
|
-
yarn add @seliseblocks/genesis-os
|
|
13
|
-
# or
|
|
14
|
-
pnpm add @seliseblocks/genesis-os
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Peer Dependencies
|
|
18
|
-
|
|
19
|
-
Your application must provide these packages (`@types/react` is optional, for TypeScript users):
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"@tanstack/react-query": "^5.0.0",
|
|
24
|
-
"nuqs": "^2.9.0",
|
|
25
|
-
"react": "^19.2.8",
|
|
26
|
-
"react-dom": "^19.2.8",
|
|
27
|
-
"react-router": "^8.0.0",
|
|
28
|
-
"zustand": "^5.0.0"
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Styling Contract
|
|
33
|
-
|
|
34
|
-
This package intentionally ships **no CSS files**. Host applications are responsible for:
|
|
35
|
-
|
|
36
|
-
- Tailwind CSS setup, including scanning this package's dist output so its utility classes are generated:
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
// tailwind.config.ts
|
|
40
|
-
export default {
|
|
41
|
-
content: ["./app/**/*.{ts,tsx}", "./node_modules/@seliseblocks/genesis-os/dist/**/*.{js,jsx,ts,tsx}"],
|
|
42
|
-
};
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
- Tailwind CSS setup
|
|
46
|
-
- shared design tokens (CSS variables) for theming
|
|
47
|
-
- Any global CSS imports required by their design system
|
|
48
|
-
|
|
49
|
-
## Runtime Configuration
|
|
50
|
-
|
|
51
|
-
Service base URLs and keys are read at runtime, not baked in at build time. Provide them on `window.__BLOCKS_ENV__` before the app boots (typically an inline script in `index.html`), or through `import.meta.env`:
|
|
52
|
-
|
|
53
|
-
```html
|
|
54
|
-
<script>
|
|
55
|
-
window.__BLOCKS_ENV__ = {
|
|
56
|
-
BLOCKS_IAM_BASE_URL: "https://iam.example.com",
|
|
57
|
-
BLOCKS_LOGIC_BASE_URL: "https://logic.example.com",
|
|
58
|
-
BLOCKS_X_BLOCKS_KEY: "your-blocks-key",
|
|
59
|
-
};
|
|
60
|
-
</script>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Read values with `getRuntimeEnv` from `@seliseblocks/genesis-os/lib`. The full key list is the `RuntimeKey` union exported from `@seliseblocks/genesis-os/types` (per-service `*_BASE_URL`, `*_CLIENT_ID`, and `*_CALLBACK_URL` keys plus `BLOCKS_X_BLOCKS_KEY` and others).
|
|
64
|
-
|
|
65
|
-
## Quick Start
|
|
66
|
-
|
|
67
|
-
Wrap your app in the providers, then compose routes from the guards, layouts, and pages:
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
import { NuqsAdapter } from "nuqs/adapters/react-router/v8";
|
|
71
|
-
import { StrictMode } from "react";
|
|
72
|
-
import { createRoot } from "react-dom/client";
|
|
73
|
-
import { createBrowserRouter, Navigate, Outlet, RouterProvider } from "react-router";
|
|
74
|
-
|
|
75
|
-
import { AuthResolver, ProtectedGuard, PublicGuard } from "@seliseblocks/genesis-os/guards";
|
|
76
|
-
import { ConsoleLayout } from "@seliseblocks/genesis-os/layouts";
|
|
77
|
-
import { CallbackPage, ConsolePage, LoginPage, ProfilePage } from "@seliseblocks/genesis-os/pages";
|
|
78
|
-
import { BlocksAppLayout, QueryProvider, ThemeProvider } from "@seliseblocks/genesis-os/providers";
|
|
79
|
-
|
|
80
|
-
const router = createBrowserRouter([
|
|
81
|
-
{
|
|
82
|
-
path: "/login/callback",
|
|
83
|
-
element: <CallbackPage defaultRedirectUrl="/app/console" />,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
element: (
|
|
87
|
-
<AuthResolver>
|
|
88
|
-
<Outlet />
|
|
89
|
-
</AuthResolver>
|
|
90
|
-
),
|
|
91
|
-
children: [
|
|
92
|
-
{
|
|
93
|
-
element: (
|
|
94
|
-
<PublicGuard>
|
|
95
|
-
<Outlet />
|
|
96
|
-
</PublicGuard>
|
|
97
|
-
),
|
|
98
|
-
children: [{ path: "/login", element: <LoginPage /> }],
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
path: "/app",
|
|
102
|
-
element: (
|
|
103
|
-
<ProtectedGuard>
|
|
104
|
-
<ConsoleLayout>
|
|
105
|
-
<Outlet />
|
|
106
|
-
</ConsoleLayout>
|
|
107
|
-
</ProtectedGuard>
|
|
108
|
-
),
|
|
109
|
-
children: [
|
|
110
|
-
{ index: true, element: <Navigate to="console" replace /> },
|
|
111
|
-
{ path: "console", element: <ConsolePage /> },
|
|
112
|
-
{ path: "profile", element: <ProfilePage /> },
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
]);
|
|
118
|
-
|
|
119
|
-
createRoot(document.getElementById("root")!).render(
|
|
120
|
-
<StrictMode>
|
|
121
|
-
<QueryProvider>
|
|
122
|
-
<ThemeProvider>
|
|
123
|
-
<NuqsAdapter>
|
|
124
|
-
<BlocksAppLayout
|
|
125
|
-
config={{
|
|
126
|
-
name: "blocks-monitor",
|
|
127
|
-
appLogoUrl: { dark: "/logo-dark.svg", light: "/logo-light.svg" },
|
|
128
|
-
}}
|
|
129
|
-
>
|
|
130
|
-
<RouterProvider router={router} />
|
|
131
|
-
</BlocksAppLayout>
|
|
132
|
-
</NuqsAdapter>
|
|
133
|
-
</ThemeProvider>
|
|
134
|
-
</QueryProvider>
|
|
135
|
-
</StrictMode>,
|
|
136
|
-
);
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
`BlocksAppLayout` takes a `config` with the service `name` (one of the `ServiceName` union values, for example `"blocks-os"` or `"blocks-monitor"`) and an `appLogoUrl` (a string, or `{ dark, light }` variants).
|
|
140
|
-
|
|
141
|
-
## Package Exports
|
|
142
|
-
|
|
143
|
-
The main entry (`@seliseblocks/genesis-os`) re-exports everything below. Subpath imports keep intent clearer and are what the Blocks applications use.
|
|
144
|
-
|
|
145
|
-
| Subpath | Contents |
|
|
146
|
-
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
147
|
-
| `./guards` | `AuthResolver`, `ProtectedGuard`, `PublicGuard`, `ImpersonationChecker`, `ImpersonationSynchronizer`, `ImpersonationTerminator` |
|
|
148
|
-
| `./layouts` | `AuthLayout`, `ConsoleLayout`, `DashboardLayout`, `DashboardRoute`, `OidcLayout`, `PublicLayout`, `useOidcContext` |
|
|
149
|
-
| `./providers` | `BlocksAppLayout`, `QueryProvider`, `ThemeProvider`, `DashboardLayoutProvider`, `getQueryClient` |
|
|
150
|
-
| `./pages` | `CallbackPage`, `ConsolePage`, `DashboardOverview`, `LoginPage`, `ProfilePage` |
|
|
151
|
-
| `./store` | `useAuthStore`, `useAppSettingsStore`, `useImpersonateStore`, `useLanguageViewStore`, `useProjectStore`, `useUserStore`, `CreateAppConfigStore` |
|
|
152
|
-
| `./hooks` | See [Hooks](#hooks) below |
|
|
153
|
-
| `./components` | See [Components](#components) below |
|
|
154
|
-
| `./lib` | See [HTTP Client and Lib](#http-client-and-lib) below |
|
|
155
|
-
| `./utils` | General-purpose helpers, see [Utils](#utils) below |
|
|
156
|
-
| `./models` | Domain models: `AuthStateShape`, `AuthTokenPair`, `BaseUser`, `UserDetails`, `IProject`, `IProjectGroup`, `IDomain`, `IEnvRepository`, `INotification`, `IMyOrganization`, `ImpersonationState`, `RegisteredService`, and related payload/response types |
|
|
157
|
-
| `./types` | Shared types: `ApiResponse`, `ApiError`, `ApiErrorResponse`, `ApiPaginatedResponse`, `BaseRequestParams`, `Menu`, `NavigationMenuItem`, `NavigationNode`, `RuntimeKey`, `ProjectKey`, `Id` |
|
|
158
|
-
|
|
159
|
-
### Components
|
|
160
|
-
|
|
161
|
-
`@seliseblocks/genesis-os/components` bundles two groups:
|
|
162
|
-
|
|
163
|
-
- **Core components** (Radix UI + shadcn based): `Accordion`, `Alert`, `AlertDialog`, `AspectRatio`, `Avatar`, `Badge`, `Breadcrumb`, `Button`, `Calendar`, `Card`, `Carousel`, `ChartContainer`, `Checkbox`, `Collapsible`, `Command`, `ContextMenu`, `CopyToClipboardButton`, `DateRangePicker`, `Dialog`, `Drawer`, `DropdownMenu`, `FileUploader`, `Form`, `HoverCard`, `InfiniteScroller`, `Input`, `InputOTP`, `KanbanBoard`, `Label`, `MaskedText`, `Menubar`, `MultiSelect`, `NavigationMenu`, `Pagination`, `PasswordInput`, `Popover`, `Progress`, `RadioGroup`, `RenderConditionally`, `RenderAlternatively`, `ResizablePanel`, `ScrollArea`, `Select`, `Separator`, `Sheet`, `Sidebar`, `Skeleton`, `Slider`, `Spinner`, `Stepper`, `Switch`, `Table`, `TablePagination`, `Tabs`, `Textarea`, `Timeline`, `Toast`, `Toaster`, `Toggle`, `ToggleGroup`, `Tooltip`, and the `WizardStepper` family, along with their subcomponents (`CardContent`, `DialogTrigger`, `SelectItem`, and so on).
|
|
164
|
-
|
|
165
|
-
- **Common composites**: `AppSwitcher`, `ArchiveProject`, `BackToConsoleNavigator`, `ConfirmationModal`, `ConsoleHeader`, `CopyableSnippet`, `DashboardHeader`, `DashboardSectionCard`, `DataTable`, `EnvironmentCard`, `EnvironmentList`, `EnvironmentSelected`, `ErrorBoundary`, `ErrorDisplay`, `FilterToolbar`, `ImportFileModal`, `LanguageSelector`, `LoaderSpinner`, `LoadingButton`, `LoginHeader`, `Logo`, `LogoutButton`, `ModeToggle`, `Notification`, `NotificationBell`, `NotificationHeader`, `NotificationItem`, `NotificationList`, `ProjectList`, `ProjectDetail`, `ProjectEdit`, `ProjectActions`, `SidebarMenu`, `ThemeSwitcher`, `UserDropdownMenu`, and more.
|
|
166
|
-
|
|
167
|
-
```tsx
|
|
168
|
-
import { Button, Card, CardContent } from "@seliseblocks/genesis-os/components";
|
|
169
|
-
|
|
170
|
-
function MyComponent() {
|
|
171
|
-
return (
|
|
172
|
-
<Card>
|
|
173
|
-
<CardContent>
|
|
174
|
-
<Button variant="default">Click Me</Button>
|
|
175
|
-
</CardContent>
|
|
176
|
-
</Card>
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Hooks
|
|
182
|
-
|
|
183
|
-
State and UI helpers: `useBoolean`, `useCopyToClipboard`, `useCountDown`, `useDebounce`, `useMediaQuery`, `useIsMobile`, `usePathSegments`, `usePopoverWidth`, `useTheme`, `useToast`, `useIcon`, `useLogo`, `useScopedPath`, `useBlocksAppConfigStore`.
|
|
184
|
-
|
|
185
|
-
Search: `useFuseIndex`, `useFuseSearch`, `useDebouncedFuseFilter`.
|
|
186
|
-
|
|
187
|
-
Query helpers: `useQueryClientKit`, `useQueryStatesKit`, `createQueryKeyFactory`.
|
|
188
|
-
|
|
189
|
-
Domain data (TanStack Query backed): `useGetProject`, `useGetProjects`, `useUpdateProject`, `useDisableProject`, `useGetEnvRepositories`, `useGetAllServices`, `useGetMyOrganizations`, `useGetNotifications`, `useMarkAsRead`, `useMarkAllAsRead`, `useStartImpersonation`, `useStopImpersonation`, `useImpersonationStatusChecker`, `useInitiateRedirect`, `usePrefetchRedirect`, `useLanguage`, `useLanguageSwitcher`, `useLogout`, `useFilteredMenus`, `useIsActiveMenu`.
|
|
190
|
-
|
|
191
|
-
```tsx
|
|
192
|
-
import { useBoolean, useToast } from "@seliseblocks/genesis-os/hooks";
|
|
193
|
-
|
|
194
|
-
function MyComponent() {
|
|
195
|
-
const { toast } = useToast();
|
|
196
|
-
const { value: isOpen, toggle } = useBoolean(false);
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<button
|
|
200
|
-
onClick={() => {
|
|
201
|
-
toggle();
|
|
202
|
-
toast({ title: isOpen ? "Closed" : "Opened" });
|
|
203
|
-
}}
|
|
204
|
-
>
|
|
205
|
-
Toggle
|
|
206
|
-
</button>
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### HTTP Client and Lib
|
|
212
|
-
|
|
213
|
-
`@seliseblocks/genesis-os/lib` exports:
|
|
214
|
-
|
|
215
|
-
- `HttpClient` and `HttpError`: a fetch-based client with Blocks key headers, token refresh queueing, and auth-failure redirects
|
|
216
|
-
- Preconfigured instances wired to the runtime env: `iamClient`, `logicClient`, `notificationClient`
|
|
217
|
-
- `getRuntimeEnv`, `createRuntimeEnvGetter`, `resolveBaseUrl`, `resolveEnv`
|
|
218
|
-
- `CookieStorage`, `cn`, theme helpers (`applyTheme`, `getSystemTheme`), and motion presets (`fadeInUp`, `fadeInScale`, `fadeTransition`, `motionEase`, `staggerContainer`, `staggerItem`)
|
|
219
|
-
|
|
220
|
-
```tsx
|
|
221
|
-
import { getRuntimeEnv, HttpClient, logicClient } from "@seliseblocks/genesis-os/lib";
|
|
222
|
-
|
|
223
|
-
// Use a preconfigured instance:
|
|
224
|
-
async function fetchProjects() {
|
|
225
|
-
return logicClient.get("/api/Project/Gets?page=0&pageSize=100");
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Or configure your own:
|
|
229
|
-
const client = new HttpClient({
|
|
230
|
-
baseURL: () => getRuntimeEnv("BLOCKS_LOGIC_BASE_URL"),
|
|
231
|
-
blocksKey: () => getRuntimeEnv("BLOCKS_X_BLOCKS_KEY"),
|
|
232
|
-
});
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
### Utils
|
|
236
|
-
|
|
237
|
-
`@seliseblocks/genesis-os/utils` covers formatting (`formatDate`, `formatFullDate`, `formatNumber`, `formatCurrency`, `formatBytes`, `formatFileSize`, `formatDuration`), objects and arrays (`pick`, `omit`, `deepClone`, `deepEqual`, `deepMerge`, `groupBy`, `uniqueBy`), functions (`debounce`, `throttle`, `memoize`, `sleep`), validation (`isEmail`, `isUrl`, `isUuid`, `isPhone`, `isValidDomain`, `isValidSubdomain`), query strings (`parseQueryString`, `stringifyQueryString`), ids (`generateId`, `getUniqueID`), storage (`createStorage`, `createCookieStore`), error handling (`getErrorMessage`, `handleErrorMessages`, `hasErrorCode`), and toast helpers (`showSuccessToast`, `showErrorToast`, `showInfoToast`).
|
|
238
|
-
|
|
239
|
-
## Versioning and Compatibility
|
|
240
|
-
|
|
241
|
-
- The package is on a `0.0.x` release line and is versioned and published with [Changesets](https://github.com/changesets/changesets). While the major version is 0, any release may contain breaking changes; pin or use a caret range consciously.
|
|
242
|
-
- This package is consumed by ten downstream Blocks service repositories. Its exported names, signatures, types, and defaults are treated as a public API; changes to them are coordinated across all consumers. See [CONTRIBUTING](https://github.com/SELISEdigitalplatforms/blocks-genesis-react/blob/main/CONTRIBUTING.md) in the repository.
|
|
243
|
-
|
|
244
|
-
## Changelog
|
|
245
|
-
|
|
246
|
-
Release notes are generated by Changesets into `CHANGELOG.md`, which is included in the published npm package.
|
|
247
|
-
|
|
248
|
-
## License
|
|
249
|
-
|
|
250
|
-
MIT (c) SELISE Blocks
|
|
1
|
+
# @seliseblocks/genesis-os
|
|
2
|
+
|
|
3
|
+
React app-shell composition package for SELISE Blocks applications: guards, layouts, providers, pages, stores, hooks, an HTTP client, and a shadcn/Radix based component library. It is the shared frontend foundation consumed by the Blocks service applications (IAM, OS, Data, Logic, Monitor, Release, Studio, Utilities, Localization).
|
|
4
|
+
|
|
5
|
+
Ships as ESM and CJS with bundled TypeScript declarations. Every module carries a `"use client"` banner, and `sideEffects` is `false`, so bundlers can tree-shake unused exports.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @seliseblocks/genesis-os
|
|
11
|
+
# or
|
|
12
|
+
yarn add @seliseblocks/genesis-os
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @seliseblocks/genesis-os
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Peer Dependencies
|
|
18
|
+
|
|
19
|
+
Your application must provide these packages (`@types/react` is optional, for TypeScript users):
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"@tanstack/react-query": "^5.0.0",
|
|
24
|
+
"nuqs": "^2.9.0",
|
|
25
|
+
"react": "^19.2.8",
|
|
26
|
+
"react-dom": "^19.2.8",
|
|
27
|
+
"react-router": "^8.0.0",
|
|
28
|
+
"zustand": "^5.0.0"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Styling Contract
|
|
33
|
+
|
|
34
|
+
This package intentionally ships **no CSS files**. Host applications are responsible for:
|
|
35
|
+
|
|
36
|
+
- Tailwind CSS setup, including scanning this package's dist output so its utility classes are generated:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// tailwind.config.ts
|
|
40
|
+
export default {
|
|
41
|
+
content: ["./app/**/*.{ts,tsx}", "./node_modules/@seliseblocks/genesis-os/dist/**/*.{js,jsx,ts,tsx}"],
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Tailwind CSS setup
|
|
46
|
+
- shared design tokens (CSS variables) for theming
|
|
47
|
+
- Any global CSS imports required by their design system
|
|
48
|
+
|
|
49
|
+
## Runtime Configuration
|
|
50
|
+
|
|
51
|
+
Service base URLs and keys are read at runtime, not baked in at build time. Provide them on `window.__BLOCKS_ENV__` before the app boots (typically an inline script in `index.html`), or through `import.meta.env`:
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<script>
|
|
55
|
+
window.__BLOCKS_ENV__ = {
|
|
56
|
+
BLOCKS_IAM_BASE_URL: "https://iam.example.com",
|
|
57
|
+
BLOCKS_LOGIC_BASE_URL: "https://logic.example.com",
|
|
58
|
+
BLOCKS_X_BLOCKS_KEY: "your-blocks-key",
|
|
59
|
+
};
|
|
60
|
+
</script>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Read values with `getRuntimeEnv` from `@seliseblocks/genesis-os/lib`. The full key list is the `RuntimeKey` union exported from `@seliseblocks/genesis-os/types` (per-service `*_BASE_URL`, `*_CLIENT_ID`, and `*_CALLBACK_URL` keys plus `BLOCKS_X_BLOCKS_KEY` and others).
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
Wrap your app in the providers, then compose routes from the guards, layouts, and pages:
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { NuqsAdapter } from "nuqs/adapters/react-router/v8";
|
|
71
|
+
import { StrictMode } from "react";
|
|
72
|
+
import { createRoot } from "react-dom/client";
|
|
73
|
+
import { createBrowserRouter, Navigate, Outlet, RouterProvider } from "react-router";
|
|
74
|
+
|
|
75
|
+
import { AuthResolver, ProtectedGuard, PublicGuard } from "@seliseblocks/genesis-os/guards";
|
|
76
|
+
import { ConsoleLayout } from "@seliseblocks/genesis-os/layouts";
|
|
77
|
+
import { CallbackPage, ConsolePage, LoginPage, ProfilePage } from "@seliseblocks/genesis-os/pages";
|
|
78
|
+
import { BlocksAppLayout, QueryProvider, ThemeProvider } from "@seliseblocks/genesis-os/providers";
|
|
79
|
+
|
|
80
|
+
const router = createBrowserRouter([
|
|
81
|
+
{
|
|
82
|
+
path: "/login/callback",
|
|
83
|
+
element: <CallbackPage defaultRedirectUrl="/app/console" />,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
element: (
|
|
87
|
+
<AuthResolver>
|
|
88
|
+
<Outlet />
|
|
89
|
+
</AuthResolver>
|
|
90
|
+
),
|
|
91
|
+
children: [
|
|
92
|
+
{
|
|
93
|
+
element: (
|
|
94
|
+
<PublicGuard>
|
|
95
|
+
<Outlet />
|
|
96
|
+
</PublicGuard>
|
|
97
|
+
),
|
|
98
|
+
children: [{ path: "/login", element: <LoginPage /> }],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
path: "/app",
|
|
102
|
+
element: (
|
|
103
|
+
<ProtectedGuard>
|
|
104
|
+
<ConsoleLayout>
|
|
105
|
+
<Outlet />
|
|
106
|
+
</ConsoleLayout>
|
|
107
|
+
</ProtectedGuard>
|
|
108
|
+
),
|
|
109
|
+
children: [
|
|
110
|
+
{ index: true, element: <Navigate to="console" replace /> },
|
|
111
|
+
{ path: "console", element: <ConsolePage /> },
|
|
112
|
+
{ path: "profile", element: <ProfilePage /> },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
createRoot(document.getElementById("root")!).render(
|
|
120
|
+
<StrictMode>
|
|
121
|
+
<QueryProvider>
|
|
122
|
+
<ThemeProvider>
|
|
123
|
+
<NuqsAdapter>
|
|
124
|
+
<BlocksAppLayout
|
|
125
|
+
config={{
|
|
126
|
+
name: "blocks-monitor",
|
|
127
|
+
appLogoUrl: { dark: "/logo-dark.svg", light: "/logo-light.svg" },
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<RouterProvider router={router} />
|
|
131
|
+
</BlocksAppLayout>
|
|
132
|
+
</NuqsAdapter>
|
|
133
|
+
</ThemeProvider>
|
|
134
|
+
</QueryProvider>
|
|
135
|
+
</StrictMode>,
|
|
136
|
+
);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`BlocksAppLayout` takes a `config` with the service `name` (one of the `ServiceName` union values, for example `"blocks-os"` or `"blocks-monitor"`) and an `appLogoUrl` (a string, or `{ dark, light }` variants).
|
|
140
|
+
|
|
141
|
+
## Package Exports
|
|
142
|
+
|
|
143
|
+
The main entry (`@seliseblocks/genesis-os`) re-exports everything below. Subpath imports keep intent clearer and are what the Blocks applications use.
|
|
144
|
+
|
|
145
|
+
| Subpath | Contents |
|
|
146
|
+
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
147
|
+
| `./guards` | `AuthResolver`, `ProtectedGuard`, `PublicGuard`, `ImpersonationChecker`, `ImpersonationSynchronizer`, `ImpersonationTerminator` |
|
|
148
|
+
| `./layouts` | `AuthLayout`, `ConsoleLayout`, `DashboardLayout`, `DashboardRoute`, `OidcLayout`, `PublicLayout`, `useOidcContext` |
|
|
149
|
+
| `./providers` | `BlocksAppLayout`, `QueryProvider`, `ThemeProvider`, `DashboardLayoutProvider`, `getQueryClient` |
|
|
150
|
+
| `./pages` | `CallbackPage`, `ConsolePage`, `DashboardOverview`, `LoginPage`, `ProfilePage` |
|
|
151
|
+
| `./store` | `useAuthStore`, `useAppSettingsStore`, `useImpersonateStore`, `useLanguageViewStore`, `useProjectStore`, `useUserStore`, `CreateAppConfigStore` |
|
|
152
|
+
| `./hooks` | See [Hooks](#hooks) below |
|
|
153
|
+
| `./components` | See [Components](#components) below |
|
|
154
|
+
| `./lib` | See [HTTP Client and Lib](#http-client-and-lib) below |
|
|
155
|
+
| `./utils` | General-purpose helpers, see [Utils](#utils) below |
|
|
156
|
+
| `./models` | Domain models: `AuthStateShape`, `AuthTokenPair`, `BaseUser`, `UserDetails`, `IProject`, `IProjectGroup`, `IDomain`, `IEnvRepository`, `INotification`, `IMyOrganization`, `ImpersonationState`, `RegisteredService`, and related payload/response types |
|
|
157
|
+
| `./types` | Shared types: `ApiResponse`, `ApiError`, `ApiErrorResponse`, `ApiPaginatedResponse`, `BaseRequestParams`, `Menu`, `NavigationMenuItem`, `NavigationNode`, `RuntimeKey`, `ProjectKey`, `Id` |
|
|
158
|
+
|
|
159
|
+
### Components
|
|
160
|
+
|
|
161
|
+
`@seliseblocks/genesis-os/components` bundles two groups:
|
|
162
|
+
|
|
163
|
+
- **Core components** (Radix UI + shadcn based): `Accordion`, `Alert`, `AlertDialog`, `AspectRatio`, `Avatar`, `Badge`, `Breadcrumb`, `Button`, `Calendar`, `Card`, `Carousel`, `ChartContainer`, `Checkbox`, `Collapsible`, `Command`, `ContextMenu`, `CopyToClipboardButton`, `DateRangePicker`, `Dialog`, `Drawer`, `DropdownMenu`, `FileUploader`, `Form`, `HoverCard`, `InfiniteScroller`, `Input`, `InputOTP`, `KanbanBoard`, `Label`, `MaskedText`, `Menubar`, `MultiSelect`, `NavigationMenu`, `Pagination`, `PasswordInput`, `Popover`, `Progress`, `RadioGroup`, `RenderConditionally`, `RenderAlternatively`, `ResizablePanel`, `ScrollArea`, `Select`, `Separator`, `Sheet`, `Sidebar`, `Skeleton`, `Slider`, `Spinner`, `Stepper`, `Switch`, `Table`, `TablePagination`, `Tabs`, `Textarea`, `Timeline`, `Toast`, `Toaster`, `Toggle`, `ToggleGroup`, `Tooltip`, and the `WizardStepper` family, along with their subcomponents (`CardContent`, `DialogTrigger`, `SelectItem`, and so on).
|
|
164
|
+
|
|
165
|
+
- **Common composites**: `AppSwitcher`, `ArchiveProject`, `BackToConsoleNavigator`, `ConfirmationModal`, `ConsoleHeader`, `CopyableSnippet`, `DashboardHeader`, `DashboardSectionCard`, `DataTable`, `EnvironmentCard`, `EnvironmentList`, `EnvironmentSelected`, `ErrorBoundary`, `ErrorDisplay`, `FilterToolbar`, `ImportFileModal`, `LanguageSelector`, `LoaderSpinner`, `LoadingButton`, `LoginHeader`, `Logo`, `LogoutButton`, `ModeToggle`, `Notification`, `NotificationBell`, `NotificationHeader`, `NotificationItem`, `NotificationList`, `ProjectList`, `ProjectDetail`, `ProjectEdit`, `ProjectActions`, `SidebarMenu`, `ThemeSwitcher`, `UserDropdownMenu`, and more.
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
import { Button, Card, CardContent } from "@seliseblocks/genesis-os/components";
|
|
169
|
+
|
|
170
|
+
function MyComponent() {
|
|
171
|
+
return (
|
|
172
|
+
<Card>
|
|
173
|
+
<CardContent>
|
|
174
|
+
<Button variant="default">Click Me</Button>
|
|
175
|
+
</CardContent>
|
|
176
|
+
</Card>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Hooks
|
|
182
|
+
|
|
183
|
+
State and UI helpers: `useBoolean`, `useCopyToClipboard`, `useCountDown`, `useDebounce`, `useMediaQuery`, `useIsMobile`, `usePathSegments`, `usePopoverWidth`, `useTheme`, `useToast`, `useIcon`, `useLogo`, `useScopedPath`, `useBlocksAppConfigStore`.
|
|
184
|
+
|
|
185
|
+
Search: `useFuseIndex`, `useFuseSearch`, `useDebouncedFuseFilter`.
|
|
186
|
+
|
|
187
|
+
Query helpers: `useQueryClientKit`, `useQueryStatesKit`, `createQueryKeyFactory`.
|
|
188
|
+
|
|
189
|
+
Domain data (TanStack Query backed): `useGetProject`, `useGetProjects`, `useUpdateProject`, `useDisableProject`, `useGetEnvRepositories`, `useGetAllServices`, `useGetMyOrganizations`, `useGetNotifications`, `useMarkAsRead`, `useMarkAllAsRead`, `useStartImpersonation`, `useStopImpersonation`, `useImpersonationStatusChecker`, `useInitiateRedirect`, `usePrefetchRedirect`, `useLanguage`, `useLanguageSwitcher`, `useLogout`, `useFilteredMenus`, `useIsActiveMenu`.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import { useBoolean, useToast } from "@seliseblocks/genesis-os/hooks";
|
|
193
|
+
|
|
194
|
+
function MyComponent() {
|
|
195
|
+
const { toast } = useToast();
|
|
196
|
+
const { value: isOpen, toggle } = useBoolean(false);
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<button
|
|
200
|
+
onClick={() => {
|
|
201
|
+
toggle();
|
|
202
|
+
toast({ title: isOpen ? "Closed" : "Opened" });
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
Toggle
|
|
206
|
+
</button>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### HTTP Client and Lib
|
|
212
|
+
|
|
213
|
+
`@seliseblocks/genesis-os/lib` exports:
|
|
214
|
+
|
|
215
|
+
- `HttpClient` and `HttpError`: a fetch-based client with Blocks key headers, token refresh queueing, and auth-failure redirects
|
|
216
|
+
- Preconfigured instances wired to the runtime env: `iamClient`, `logicClient`, `notificationClient`
|
|
217
|
+
- `getRuntimeEnv`, `createRuntimeEnvGetter`, `resolveBaseUrl`, `resolveEnv`
|
|
218
|
+
- `CookieStorage`, `cn`, theme helpers (`applyTheme`, `getSystemTheme`), and motion presets (`fadeInUp`, `fadeInScale`, `fadeTransition`, `motionEase`, `staggerContainer`, `staggerItem`)
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
import { getRuntimeEnv, HttpClient, logicClient } from "@seliseblocks/genesis-os/lib";
|
|
222
|
+
|
|
223
|
+
// Use a preconfigured instance:
|
|
224
|
+
async function fetchProjects() {
|
|
225
|
+
return logicClient.get("/api/Project/Gets?page=0&pageSize=100");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Or configure your own:
|
|
229
|
+
const client = new HttpClient({
|
|
230
|
+
baseURL: () => getRuntimeEnv("BLOCKS_LOGIC_BASE_URL"),
|
|
231
|
+
blocksKey: () => getRuntimeEnv("BLOCKS_X_BLOCKS_KEY"),
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Utils
|
|
236
|
+
|
|
237
|
+
`@seliseblocks/genesis-os/utils` covers formatting (`formatDate`, `formatFullDate`, `formatNumber`, `formatCurrency`, `formatBytes`, `formatFileSize`, `formatDuration`), objects and arrays (`pick`, `omit`, `deepClone`, `deepEqual`, `deepMerge`, `groupBy`, `uniqueBy`), functions (`debounce`, `throttle`, `memoize`, `sleep`), validation (`isEmail`, `isUrl`, `isUuid`, `isPhone`, `isValidDomain`, `isValidSubdomain`), query strings (`parseQueryString`, `stringifyQueryString`), ids (`generateId`, `getUniqueID`), storage (`createStorage`, `createCookieStore`), error handling (`getErrorMessage`, `handleErrorMessages`, `hasErrorCode`), and toast helpers (`showSuccessToast`, `showErrorToast`, `showInfoToast`).
|
|
238
|
+
|
|
239
|
+
## Versioning and Compatibility
|
|
240
|
+
|
|
241
|
+
- The package is on a `0.0.x` release line and is versioned and published with [Changesets](https://github.com/changesets/changesets). While the major version is 0, any release may contain breaking changes; pin or use a caret range consciously.
|
|
242
|
+
- This package is consumed by ten downstream Blocks service repositories. Its exported names, signatures, types, and defaults are treated as a public API; changes to them are coordinated across all consumers. See [CONTRIBUTING](https://github.com/SELISEdigitalplatforms/blocks-genesis-react/blob/main/CONTRIBUTING.md) in the repository.
|
|
243
|
+
|
|
244
|
+
## Changelog
|
|
245
|
+
|
|
246
|
+
Release notes are generated by Changesets into `CHANGELOG.md`, which is included in the published npm package.
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
MIT (c) SELISE Blocks
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useImpersonationStatusChecker, useStopImpersonation, useStartImpersonation, useGetProjects, projectService } from './chunk-
|
|
2
|
-
import { iamClient, AUTH_ENDPOINTS, HttpError } from './chunk-
|
|
3
|
-
import { useImpersonateStore } from './chunk-
|
|
4
|
-
import { useAuthStore, useProjectStore } from './chunk-
|
|
1
|
+
import { useImpersonationStatusChecker, useStopImpersonation, useStartImpersonation, useGetProjects, projectService } from './chunk-MCOK3TFE.js';
|
|
2
|
+
import { iamClient, AUTH_ENDPOINTS, HttpError } from './chunk-GWZQFBJ5.js';
|
|
3
|
+
import { useImpersonateStore } from './chunk-CEXYN2ZD.js';
|
|
4
|
+
import { useAuthStore, useProjectStore } from './chunk-ENK42YC4.js';
|
|
5
5
|
import { useEffect, useRef, useState, useCallback } from 'react';
|
|
6
6
|
import { useNavigate } from 'react-router';
|
|
7
7
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
@@ -243,5 +243,5 @@ function ImpersonationSynchronizer({
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
export { AppLoadingSpinner, AuthResolver, ImpersonationChecker, ImpersonationSynchronizer, ImpersonationTerminator, ProtectedGuard, PublicGuard };
|
|
246
|
-
//# sourceMappingURL=chunk-
|
|
247
|
-
//# sourceMappingURL=chunk-
|
|
246
|
+
//# sourceMappingURL=chunk-2QDH2N7Z.js.map
|
|
247
|
+
//# sourceMappingURL=chunk-2QDH2N7Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/guards/protected.guard.tsx","../src/guards/public.guard.tsx","../src/guards/auth.guard.tsx","../src/components/common/loader-spinner/loader-spinner.tsx","../src/guards/impersonation.guard.tsx"],"names":["useEffect","useNavigate","jsx","Fragment","useRef","useState","project"],"mappings":";;;;;;;;AAUO,SAAS,cAAA,CAAe;AAAA,EAC7B,QAAA;AAAA,EACA,iBAAA,GAAoB;AACtB,CAAA,EAAwB;AACtB,EAAA,MAAM,EAAE,eAAA,EAAgB,GAAI,YAAA,EAAa;AACzC,EAAA,MAAM,WAAW,WAAA,EAAY;AAE7B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,eAAA,EAAiB,QAAA,CAAS,iBAAiB,CAAA;AAAA,EAClD,CAAA,EAAG,CAAC,eAAA,EAAiB,iBAAA,EAAmB,QAAQ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nB,GAAG,CAAC,oBAAA,EAAsB,eAAA,EAAiB,QAAA,EAAU,gBAAgB,CAAC,CAAA;AAEtE,EAAA,IAAI,eAAA,EAAiB,uBAAOE,GAAAA,CAAC,iBAAA,EAAA,EAAkB,CAAA;AAC/C,EAAA,IAAI,CAAC,cAAA,IAAkB,YAAA,CAAa,OAAA,EAAS,OAAO,IAAA;AACpD,EAAA,uBAAOA,GAAAA,CAAAC,QAAAA,EAAA,EAAG,QAAA,EAAS,CAAA;AACrB","file":"chunk-2QDH2N7Z.js","sourcesContent":["import type * as React from \"react\";\nimport { useEffect } from \"react\";\nimport { useNavigate } from \"react-router\";\nimport { useAuthStore } from \"../store/auth.store\";\n\ninterface ProtectedGuardProps {\n children: React.ReactNode;\n defaultPublicPath?: string;\n}\n\nexport function ProtectedGuard({\n children,\n defaultPublicPath = \"/login\",\n}: ProtectedGuardProps) {\n const { isAuthenticated } = useAuthStore();\n const navigate = useNavigate();\n\n useEffect(() => {\n if (!isAuthenticated) navigate(defaultPublicPath);\n }, [isAuthenticated, defaultPublicPath, navigate]);\n\n return <>{children}</>;\n}\n","import type * as React from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { useNavigate } from \"react-router\";\nimport { useAuthStore } from \"../store/auth.store\";\n\nconst useAppState = () => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n return { isMounted };\n};\n\nexport type PublicGuardProps = {\n children: React.ReactNode;\n defaultProtectedPath?: string;\n};\n\nexport function PublicGuard({\n children,\n defaultProtectedPath = \"/app/console\",\n}: PublicGuardProps) {\n const { isAuthenticated } = useAuthStore();\n const { isMounted } = useAppState();\n const navigate = useNavigate();\n\n useEffect(() => {\n if (!isMounted) return;\n if (isAuthenticated) navigate(defaultProtectedPath, { replace: true });\n }, [isAuthenticated, isMounted, navigate, defaultProtectedPath]);\n\n if (!isMounted) return null;\n return <>{children}</>;\n}\n","import { AUTH_ENDPOINTS } from \"@/constants/endpoint.constant\";\nimport { iamClient } from \"@/lib/http/instances\";\nimport type { BaseUser } from \"@/models\";\nimport { useAuthStore } from \"@/store/auth.store\";\nimport { useEffect, useRef } from \"react\";\n\nexport function AuthResolver({ children }: { children: React.ReactNode }) {\n const { setUser, setAuthenticated, setUnAuthenticated } = useAuthStore();\n const hasResolved = useRef(false);\n\n useEffect(() => {\n if (hasResolved.current) return;\n hasResolved.current = true;\n\n async function resolve() {\n try {\n const res = await iamClient.get<BaseUser>(`${AUTH_ENDPOINTS.ME}`);\n setUser(res);\n setAuthenticated();\n } catch {\n setUnAuthenticated();\n }\n }\n resolve();\n }, [setAuthenticated, setUnAuthenticated, setUser]);\n\n return <>{children}</>;\n}\n","const BlocksIcon = ({ size }: { size: number }) => (\n <svg\n width={size}\n height={size}\n viewBox=\"0 0 246 360\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M245.455 68.1627V129.877L168.982 156.67V93.9638L245.455 68.1627Z\"\n fill=\"#2D86C7\"\n />\n <path\n d=\"M240.389 62.3805L165.49 87.6573L5.30933 24.2563L85.3314 0L240.389 62.3805Z\"\n fill=\"#2D86C7\"\n />\n <path\n d=\"M161.797 93.8295V156.43L81.1141 122.607V188.07L0 152.738V29.6846L161.797 93.8295Z\"\n fill=\"#2D86C7\"\n />\n <path\n d=\"M76.4728 266.036L0 291.837V230.123L76.4728 203.329V266.036Z\"\n fill=\"#2D86C7\"\n />\n <path\n d=\"M160.123 360L5.07178 297.619L79.964 272.343L240.145 335.744L160.123 360Z\"\n fill=\"#2D86C7\"\n />\n <path\n d=\"M245.454 330.315L83.657 266.17V203.57L164.34 237.393V171.93L245.454 207.262V330.315Z\"\n fill=\"#2D86C7\"\n />\n </svg>\n);\n\nexport const AppLoadingSpinner = ({ size = 64 }: { size?: number }) => (\n <>\n <style>{`\n @keyframes breathe {\n 0%, 100% { transform: scaleY(1); }\n 50% { transform: scaleY(0.85); }\n\n }\n .animate-breathe {\n animation: breathe 2s ease-in-out infinite;\n transform-origin: center;\n }\n `}</style>\n <div className=\"bg-background fixed inset-0 z-50 flex items-center justify-center\">\n <div className=\"animate-breathe\">\n <BlocksIcon size={size} />\n </div>\n </div>\n </>\n);\n","import { AppLoadingSpinner } from \"@/components/common/loader-spinner\";\nimport {\n useImpersonationStatusChecker,\n useStartImpersonation,\n useStopImpersonation,\n} from \"@/hooks/use-impersonation\";\nimport { useGetProjects } from \"@/hooks/use-project\";\nimport { HttpError } from \"@/lib/http/error\";\nimport { useImpersonateStore, useProjectStore } from \"@/store\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { projectService } from \"@/services/project.service\";\nimport type { ImpersonationRequest } from \"@/models\";\n\nexport const ImpersonationChecker = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const { data, isLoading, isSuccess } = useImpersonationStatusChecker();\n const { setImpersonation, isInitialized, setInitialized } =\n useImpersonateStore();\n\n useEffect(() => {\n if (!data) return;\n setImpersonation(\n data.impersonated,\n data.originalTenantId,\n data.impersonated ? data.impersonatedTenantId : null,\n );\n setInitialized(true);\n }, [data, setImpersonation, setInitialized]);\n\n if (isLoading || !isSuccess || !isInitialized) return null;\n return <>{children}</>;\n};\n\nexport function ImpersonationTerminator({\n children,\n}: {\n children: React.ReactNode;\n}) {\n const { terminate, isImpersonated } = useImpersonateStore();\n const { mutateAsync } = useStopImpersonation();\n const isTriggering = useRef(false);\n const [isTerminating, setIsTerminating] = useState(false);\n\n useEffect(() => {\n if (isTriggering.current || !isImpersonated) return;\n\n isTriggering.current = true;\n setIsTerminating(true);\n const blocksKey = window.process?.env.BLOCKS_X_BLOCKS_KEY || \"\";\n\n const stopImpersonation = async () => {\n try {\n await mutateAsync(undefined);\n } catch (error) {\n // Stop can 401 when impersonation is already cleared server-side.\n // Always clear local state so we do not re-trigger stop on next layout.\n if (!(error instanceof HttpError) || error.status !== 401) {\n console.error(\"Error stopping impersonation:\", error);\n }\n } finally {\n terminate(blocksKey);\n isTriggering.current = false;\n setIsTerminating(false);\n }\n };\n\n void stopImpersonation();\n }, [mutateAsync, terminate, isImpersonated]);\n\n if (isImpersonated || isTerminating) return <AppLoadingSpinner />;\n return <>{children}</>;\n}\n\nexport function ImpersonationSynchronizer({\n children,\n}: {\n children: React.ReactNode;\n}) {\n const { impersonate, isImpersonated, impersonatedTenantId } =\n useImpersonateStore();\n const { mutateAsync } = useStartImpersonation();\n const { data: _data } = useGetProjects({ enabled: true });\n\n const { selectedProject, setSelectedProject, projects, setTenantGroup } =\n useProjectStore();\n const isTriggering = useRef(false);\n const [isImpersonating, setIsImpersonating] = useState(false);\n\n // Only safe to call once the token is already impersonated into the tenant we\n // want — the endpoint resolves the project from the token, not from an argument.\n const getImpersonatedProject = async () => {\n try {\n const res = projectService.getProject();\n return (await res).data;\n } catch (error) {\n console.error(\"Error fetching projects:\", error);\n }\n };\n\n const runImpersonation = useCallback(async () => {\n isTriggering.current = true;\n setIsImpersonating(true);\n try {\n if (impersonatedTenantId) {\n let project = projects.find(\n (project) => project.tenantId === impersonatedTenantId,\n );\n if (!project) project = await getImpersonatedProject();\n if (!project) {\n isTriggering.current = false;\n setIsImpersonating(false);\n return;\n }\n setSelectedProject(project);\n setTenantGroup(project.tenantGroupId);\n isTriggering.current = false;\n setIsImpersonating(false);\n return;\n }\n\n // need to impersonate for the selected project\n const payload: ImpersonationRequest = {\n targeted_tenant_id: selectedProject?.tenantId || \"\",\n };\n const blocksKey = window.process?.env.BLOCKS_X_BLOCKS_KEY || \"\";\n await mutateAsync(payload);\n impersonate(payload.targeted_tenant_id, blocksKey);\n isTriggering.current = false;\n setIsImpersonating(false);\n } catch (error) {\n console.error(\"Error during impersonation:\", error);\n isTriggering.current = false;\n setIsImpersonating(false);\n }\n }, [\n impersonatedTenantId,\n selectedProject?.tenantId,\n mutateAsync,\n projects,\n setSelectedProject,\n setTenantGroup,\n impersonate,\n ]);\n\n useEffect(() => {\n if (!impersonatedTenantId && !selectedProject?.tenantId) return;\n if (isTriggering.current) return;\n if (impersonatedTenantId === selectedProject?.tenantId) return;\n runImpersonation();\n }, [impersonatedTenantId, selectedProject?.tenantId, runImpersonation]);\n\n if (isImpersonating) return <AppLoadingSpinner />;\n if (!isImpersonated || isTriggering.current) return null;\n return <>{children}</>;\n}\n"]}
|