@nsxbet/admin-sdk 0.2.1 → 0.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/CHECKLIST.md +212 -0
- package/README.md +19 -4
- package/dist/vite/config.d.ts +2 -1
- package/dist/vite/config.d.ts.map +1 -1
- package/dist/vite/config.js +1 -1
- package/package.json +5 -2
- package/scripts/postinstall.js +1 -0
package/CHECKLIST.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Admin Module Setup Checklist
|
|
2
|
+
|
|
3
|
+
> Verify each item to ensure your module is correctly configured.
|
|
4
|
+
> For module-specific values, run `npx adminx checklist` (requires `@nsxbet/admin-cli`).
|
|
5
|
+
|
|
6
|
+
**Usage for LLMs:** Work through each section, check off items as you verify them. Compare your files against the expected content blocks.
|
|
7
|
+
|
|
8
|
+
## Required Files
|
|
9
|
+
|
|
10
|
+
- [ ] `admin.module.json` — Module manifest
|
|
11
|
+
- [ ] `package.json` — Package configuration
|
|
12
|
+
- [ ] `vite.config.ts` — Vite build config
|
|
13
|
+
- [ ] `index.html` — HTML entry point
|
|
14
|
+
- [ ] `src/spa.tsx` — Shell entry (default export)
|
|
15
|
+
- [ ] `src/standalone.tsx` — Dev entry (AdminShell wrapper)
|
|
16
|
+
- [ ] `src/App.tsx` — Main app component (Routes)
|
|
17
|
+
- [ ] `src/index.css` — Styles with Tailwind directives
|
|
18
|
+
- [ ] `tailwind.config.js` — Tailwind config
|
|
19
|
+
- [ ] `postcss.config.js` — PostCSS config
|
|
20
|
+
- [ ] `tsconfig.json` — TypeScript config
|
|
21
|
+
- [ ] `tsconfig.node.json` — Node TypeScript config
|
|
22
|
+
- [ ] `src/globals.d.ts` — Global type declarations
|
|
23
|
+
|
|
24
|
+
## Module Manifest (`admin.module.json`)
|
|
25
|
+
|
|
26
|
+
- [ ] Has `id` field (format: `@admin/<name>`)
|
|
27
|
+
- [ ] Has `title` field
|
|
28
|
+
- [ ] Has `routeBase` field (starts with `/`)
|
|
29
|
+
- [ ] Has `description` field (recommended)
|
|
30
|
+
- [ ] Has `version` field (recommended)
|
|
31
|
+
- [ ] Has `category` field (recommended)
|
|
32
|
+
- [ ] Has `permissions` object (recommended, values are string arrays)
|
|
33
|
+
- [ ] Has `commands` array (recommended, each with `id`, `title`, `route`)
|
|
34
|
+
- [ ] All command `route` values start with the module's `routeBase`
|
|
35
|
+
|
|
36
|
+
Expected structure:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"id": "@admin/my-module",
|
|
41
|
+
"title": "My Module",
|
|
42
|
+
"routeBase": "/my-module",
|
|
43
|
+
"description": "My Module admin module",
|
|
44
|
+
"version": "1.0.0",
|
|
45
|
+
"category": "Tools",
|
|
46
|
+
"commands": [{ "id": "home", "title": "Home", "route": "/my-module/home" }],
|
|
47
|
+
"permissions": {
|
|
48
|
+
"view": ["admin.my-module.view"],
|
|
49
|
+
"edit": ["admin.my-module.edit"],
|
|
50
|
+
"delete": ["admin.my-module.delete"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Dependencies (`package.json`)
|
|
56
|
+
|
|
57
|
+
- [ ] `"type": "module"` is set
|
|
58
|
+
- [ ] Build script is `"tsc && vite build"`
|
|
59
|
+
|
|
60
|
+
### Runtime Dependencies
|
|
61
|
+
|
|
62
|
+
- [ ] `@nsxbet/admin-sdk` — `workspace:*` or git tag version
|
|
63
|
+
- [ ] `@nsxbet/admin-ui` — `workspace:*` or git tag version
|
|
64
|
+
- [ ] `react` — `^18.2.0`
|
|
65
|
+
- [ ] `react-dom` — `^18.2.0`
|
|
66
|
+
- [ ] `react-router-dom` — `^6.20.1`
|
|
67
|
+
|
|
68
|
+
### Dev Dependencies
|
|
69
|
+
|
|
70
|
+
- [ ] `@vitejs/plugin-react` — `^4.2.1`
|
|
71
|
+
- [ ] `vite` — `^5.0.8`
|
|
72
|
+
- [ ] `typescript` — `^5.2.2`
|
|
73
|
+
- [ ] `tailwindcss` — `^3.4.0`
|
|
74
|
+
- [ ] `postcss` — `^8.4.32`
|
|
75
|
+
- [ ] `autoprefixer` — `^10.4.16`
|
|
76
|
+
- [ ] `@nsxbet/eslint-plugin-admin` — (same version as SDK)
|
|
77
|
+
|
|
78
|
+
## Vite Configuration
|
|
79
|
+
|
|
80
|
+
- [ ] Imports `defineModuleConfig` from `@nsxbet/admin-sdk/vite`
|
|
81
|
+
- [ ] Imports and uses `react()` from `@vitejs/plugin-react`
|
|
82
|
+
|
|
83
|
+
Expected:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { defineModuleConfig } from "@nsxbet/admin-sdk/vite";
|
|
87
|
+
import react from "@vitejs/plugin-react";
|
|
88
|
+
|
|
89
|
+
export default defineModuleConfig({
|
|
90
|
+
port: 3003, // Choose a unique port for your module
|
|
91
|
+
plugins: [react()],
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Tailwind Configuration
|
|
96
|
+
|
|
97
|
+
- [ ] Imports `withAdminSdk` from `@nsxbet/admin-sdk/tailwind`
|
|
98
|
+
|
|
99
|
+
Expected:
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
import { withAdminSdk } from "@nsxbet/admin-sdk/tailwind";
|
|
103
|
+
|
|
104
|
+
export default withAdminSdk({
|
|
105
|
+
content: ["./index.html", "./src/**/*.{ts,tsx}"],
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## PostCSS Configuration
|
|
110
|
+
|
|
111
|
+
- [ ] Has `tailwindcss` and `autoprefixer` plugins
|
|
112
|
+
|
|
113
|
+
Expected:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
export default {
|
|
117
|
+
plugins: {
|
|
118
|
+
tailwindcss: {},
|
|
119
|
+
autoprefixer: {},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## CSS Setup (`src/index.css`)
|
|
125
|
+
|
|
126
|
+
- [ ] Imports `@nsxbet/admin-ui/styles.css`
|
|
127
|
+
- [ ] Has `@tailwind base`, `@tailwind components`, `@tailwind utilities`
|
|
128
|
+
|
|
129
|
+
Expected:
|
|
130
|
+
|
|
131
|
+
```css
|
|
132
|
+
@import "@nsxbet/admin-ui/styles.css";
|
|
133
|
+
|
|
134
|
+
@tailwind base;
|
|
135
|
+
@tailwind components;
|
|
136
|
+
@tailwind utilities;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Entry Points
|
|
140
|
+
|
|
141
|
+
### `src/spa.tsx`
|
|
142
|
+
|
|
143
|
+
- [ ] Has `export default` (the App component)
|
|
144
|
+
|
|
145
|
+
Expected:
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { App } from "./App";
|
|
149
|
+
|
|
150
|
+
export default App;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### `src/standalone.tsx`
|
|
154
|
+
|
|
155
|
+
- [ ] Uses `AdminShell` from `@nsxbet/admin-sdk`
|
|
156
|
+
- [ ] Imports manifest and passes to `modules` prop
|
|
157
|
+
- [ ] Permissions use namespace `admin.<module-name>.*`
|
|
158
|
+
|
|
159
|
+
Expected (simplified):
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import { AdminShell } from "@nsxbet/admin-sdk";
|
|
163
|
+
import manifest from "../admin.module.json";
|
|
164
|
+
import { App } from "./App";
|
|
165
|
+
|
|
166
|
+
<AdminShell modules={[manifest]} keycloak={config}>
|
|
167
|
+
<App />
|
|
168
|
+
</AdminShell>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### `src/App.tsx`
|
|
172
|
+
|
|
173
|
+
- [ ] Uses `<Routes>` from `react-router-dom`
|
|
174
|
+
|
|
175
|
+
Expected:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
import { Routes, Route, Navigate } from "react-router-dom";
|
|
179
|
+
|
|
180
|
+
export function App() {
|
|
181
|
+
return (
|
|
182
|
+
<Routes>
|
|
183
|
+
<Route path="/" element={<Navigate to="home" replace />} />
|
|
184
|
+
<Route path="home" element={<HomePage />} />
|
|
185
|
+
</Routes>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## SDK Hook Usage
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
import { useAuth, useFetch, useTelemetry } from "@nsxbet/admin-sdk";
|
|
194
|
+
import { useNavigate } from "react-router-dom";
|
|
195
|
+
|
|
196
|
+
function MyComponent() {
|
|
197
|
+
const { hasPermission, getUser } = useAuth();
|
|
198
|
+
const fetch = useFetch(); // Use this instead of raw fetch()
|
|
199
|
+
const { track } = useTelemetry();
|
|
200
|
+
const navigate = useNavigate(); // From react-router-dom, NOT from SDK
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Anti-Patterns (MUST NOT be present)
|
|
205
|
+
|
|
206
|
+
- [ ] No `@supabase/supabase-js` or `supabase` imports in `src/**`
|
|
207
|
+
- [ ] No `firebase` imports in `src/**`
|
|
208
|
+
- [ ] No `BrowserRouter` or `MemoryRouter` in `src/**` (except `standalone.tsx`)
|
|
209
|
+
- [ ] No `useNavigate` imported from `@nsxbet/admin-sdk` (use `react-router-dom`)
|
|
210
|
+
- [ ] No `@supabase/supabase-js` or `firebase` in `package.json` dependencies
|
|
211
|
+
- [ ] No raw `fetch()` or `window.fetch()` calls — use `useFetch()` from the SDK
|
|
212
|
+
- [ ] Do NOT scaffold shadcn/ui components locally — use `@nsxbet/admin-ui` which ships them pre-configured
|
package/README.md
CHANGED
|
@@ -45,6 +45,8 @@ The CLI scaffolds all 13 required files with correct configuration, dependency v
|
|
|
45
45
|
|
|
46
46
|
> **Required for LLMs:** After creating or modifying a module, run `npx @nsxbet/admin-cli checklist --output CHECKLIST.md` and verify every item in the generated file before considering the setup complete. The checklist is a self-contained verification guide—no CLI installation needed to consume it.
|
|
47
47
|
|
|
48
|
+
> **Static checklist:** A ready-to-use `CHECKLIST.md` is also shipped inside the SDK package at `node_modules/@nsxbet/admin-sdk/CHECKLIST.md`. You can use it directly without installing the CLI.
|
|
49
|
+
|
|
48
50
|
## Quick Start
|
|
49
51
|
|
|
50
52
|
This SDK enables you to build admin modules that integrate with the NSX Admin shell. Modules are loaded dynamically via React.lazy and share the shell's Router context.
|
|
@@ -354,7 +356,7 @@ export default withAdminSdk({
|
|
|
354
356
|
"type": "module",
|
|
355
357
|
"scripts": {
|
|
356
358
|
"dev": "vite",
|
|
357
|
-
"build": "tsc && vite build
|
|
359
|
+
"build": "tsc && vite build",
|
|
358
360
|
"preview": "vite preview"
|
|
359
361
|
},
|
|
360
362
|
"dependencies": {
|
|
@@ -382,7 +384,7 @@ export default withAdminSdk({
|
|
|
382
384
|
|
|
383
385
|
> **Note:** Exact versions for runtime deps (react, i18next) avoid conflicts with the shell. Exact versions for styling (tailwindcss, postcss) ensure design system consistency.
|
|
384
386
|
|
|
385
|
-
> **Note:**
|
|
387
|
+
> **Note:** `module.manifest.json` is generated automatically by `defineModuleConfig` at build time. No manual copy step is needed.
|
|
386
388
|
|
|
387
389
|
### File: `tsconfig.json`
|
|
388
390
|
|
|
@@ -549,7 +551,7 @@ export default defineModuleConfig({
|
|
|
549
551
|
});
|
|
550
552
|
```
|
|
551
553
|
|
|
552
|
-
> **Important:** Each module must use a unique port. Standard assignments:
|
|
554
|
+
> **Important:** Each module must use a unique port. The default is `8080` (matching Lovable's default). Modules running alongside Keycloak (which also uses port 8080) should specify an explicit port. Standard assignments:
|
|
553
555
|
> - Shell: 3000
|
|
554
556
|
> - API: 4000
|
|
555
557
|
> - Modules: 3002, 3003, 3004, etc.
|
|
@@ -558,7 +560,7 @@ export default defineModuleConfig({
|
|
|
558
560
|
|
|
559
561
|
| Option | Type | Default | Description |
|
|
560
562
|
|--------|------|---------|-------------|
|
|
561
|
-
| `port` | number |
|
|
563
|
+
| `port` | number | `8080` | Dev server port |
|
|
562
564
|
| `entry` | string | `"./src/spa.tsx"` | Entry file path |
|
|
563
565
|
| `outDir` | string | `"dist"` | Output directory |
|
|
564
566
|
| `plugins` | Plugin[] | `[]` | Additional Vite plugins |
|
|
@@ -573,6 +575,19 @@ These dependencies are provided by the shell (do not bundle them):
|
|
|
573
575
|
["react", "react-dom", "react-router-dom", "i18next", "react-i18next"]
|
|
574
576
|
```
|
|
575
577
|
|
|
578
|
+
## ESLint Plugin
|
|
579
|
+
|
|
580
|
+
Install `@nsxbet/eslint-plugin-admin` (requires ESLint 9+) to catch common mistakes at development time:
|
|
581
|
+
|
|
582
|
+
```javascript
|
|
583
|
+
// eslint.config.js
|
|
584
|
+
import adminPlugin from "@nsxbet/eslint-plugin-admin";
|
|
585
|
+
|
|
586
|
+
export default [adminPlugin.configs.recommended];
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
This enables all recommended rules including `@nsxbet/no-raw-fetch` which flags direct `fetch()`/`window.fetch()` calls that bypass authentication. Use `useFetch()` from the SDK instead.
|
|
590
|
+
|
|
576
591
|
## SDK Hooks
|
|
577
592
|
|
|
578
593
|
### `useAuth()`
|
package/dist/vite/config.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export declare const SHARED_EXTERNALS: readonly ["react", "react-dom", "react-ro
|
|
|
6
6
|
export interface ModuleConfigOptions {
|
|
7
7
|
/**
|
|
8
8
|
* Development server port
|
|
9
|
+
* @default 8080
|
|
9
10
|
*/
|
|
10
|
-
port
|
|
11
|
+
port?: number;
|
|
11
12
|
/**
|
|
12
13
|
* Entry file for the module SPA
|
|
13
14
|
* @default "./src/spa.tsx"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/vite/config.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,iFAMnB,CAAC;AAEX,MAAM,WAAW,mBAAmB;IAClC
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/vite/config.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,iFAMnB,CAAC;AAEX,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE/B;;OAEG;IAEH,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAEhB;;OAEG;IAEH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,GAAG,CA8CpE"}
|
package/dist/vite/config.js
CHANGED
|
@@ -48,7 +48,7 @@ export const SHARED_EXTERNALS = [
|
|
|
48
48
|
*/
|
|
49
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
50
|
export function defineModuleConfig(options) {
|
|
51
|
-
const { port, entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], plugins = [], overrides = {}, } = options;
|
|
51
|
+
const { port = 8080, entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], plugins = [], overrides = {}, } = options;
|
|
52
52
|
const externals = [...SHARED_EXTERNALS, ...additionalExternals];
|
|
53
53
|
return {
|
|
54
54
|
plugins: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsxbet/admin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "SDK for building NSX Admin modules with integrated shell",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,9 +25,12 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"CHECKLIST.md",
|
|
30
|
+
"scripts"
|
|
29
31
|
],
|
|
30
32
|
"scripts": {
|
|
33
|
+
"postinstall": "node scripts/postinstall.js",
|
|
31
34
|
"build": "tsc",
|
|
32
35
|
"dev": "tsc --watch --preserveWatchOutput",
|
|
33
36
|
"type-check": "tsc --noEmit",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("@nsxbet/admin-sdk: Module setup checklist available at node_modules/@nsxbet/admin-sdk/CHECKLIST.md");
|