@nsxbet/admin-sdk 0.2.1 → 0.5.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 ADDED
@@ -0,0 +1,301 @@
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
+ - [ ] React plugin — either `@vitejs/plugin-react` `^4.2.1` OR `@vitejs/plugin-react-swc` `^3.0.0` (Lovable default)
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
+ - [ ] Uses `defineModuleConfig` from `@nsxbet/admin-sdk/vite` OR spreads `adminModule()` into an existing Vite config
81
+ - [ ] Imports and uses a React plugin (`@vitejs/plugin-react` or `@vitejs/plugin-react-swc`)
82
+
83
+ Expected (option A — full config):
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
+ Expected (option B — composable plugin for Lovable / existing config):
96
+
97
+ ```typescript
98
+ import { defineConfig } from "vite";
99
+ import react from "@vitejs/plugin-react-swc";
100
+ import { adminModule } from "@nsxbet/admin-sdk/vite";
101
+
102
+ export default defineConfig({
103
+ plugins: [react(), ...adminModule()],
104
+ });
105
+ ```
106
+
107
+ ## Tailwind Configuration
108
+
109
+ - [ ] Imports `withAdminSdk` from `@nsxbet/admin-sdk/tailwind`
110
+
111
+ Expected:
112
+
113
+ ```javascript
114
+ import { withAdminSdk } from "@nsxbet/admin-sdk/tailwind";
115
+
116
+ export default withAdminSdk({
117
+ content: ["./index.html", "./src/**/*.{ts,tsx}"],
118
+ });
119
+ ```
120
+
121
+ ## PostCSS Configuration
122
+
123
+ - [ ] Has `tailwindcss` and `autoprefixer` plugins
124
+
125
+ Expected:
126
+
127
+ ```javascript
128
+ export default {
129
+ plugins: {
130
+ tailwindcss: {},
131
+ autoprefixer: {},
132
+ },
133
+ };
134
+ ```
135
+
136
+ ## CSS Setup (`src/index.css`)
137
+
138
+ - [ ] Imports `@nsxbet/admin-ui/styles.css`
139
+ - [ ] Has `@tailwind base`, `@tailwind components`, `@tailwind utilities`
140
+
141
+ Expected:
142
+
143
+ ```css
144
+ @import "@nsxbet/admin-ui/styles.css";
145
+
146
+ @tailwind base;
147
+ @tailwind components;
148
+ @tailwind utilities;
149
+ ```
150
+
151
+ ## Entry Points
152
+
153
+ ### `src/spa.tsx`
154
+
155
+ - [ ] Has `export default` (the App component)
156
+
157
+ Expected:
158
+
159
+ ```tsx
160
+ import { App } from "./App";
161
+
162
+ export default App;
163
+ ```
164
+
165
+ ### `src/standalone.tsx`
166
+
167
+ - [ ] Uses `AdminShell` from `@nsxbet/admin-sdk`
168
+ - [ ] Imports manifest and passes to `modules` prop
169
+ - [ ] Permissions use namespace `admin.<module-name>.*`
170
+
171
+ Expected (simplified):
172
+
173
+ ```tsx
174
+ import { AdminShell } from "@nsxbet/admin-sdk";
175
+ import manifest from "../admin.module.json";
176
+ import { App } from "./App";
177
+
178
+ <AdminShell modules={[manifest]} keycloak={config}>
179
+ <App />
180
+ </AdminShell>
181
+ ```
182
+
183
+ ### `src/App.tsx`
184
+
185
+ - [ ] Uses `<Routes>` from `react-router-dom`
186
+
187
+ Expected:
188
+
189
+ ```tsx
190
+ import { Routes, Route, Navigate } from "react-router-dom";
191
+
192
+ export function App() {
193
+ return (
194
+ <Routes>
195
+ <Route path="/" element={<Navigate to="home" replace />} />
196
+ <Route path="home" element={<HomePage />} />
197
+ </Routes>
198
+ );
199
+ }
200
+ ```
201
+
202
+ ## SDK Hook Usage
203
+
204
+ ```tsx
205
+ import { useAuth, useFetch, useTelemetry } from "@nsxbet/admin-sdk";
206
+ import { useNavigate } from "react-router-dom";
207
+
208
+ function MyComponent() {
209
+ const { hasPermission, getUser } = useAuth();
210
+ const fetch = useFetch(); // Use this instead of raw fetch()
211
+ const { track } = useTelemetry();
212
+ const navigate = useNavigate(); // From react-router-dom, NOT from SDK
213
+ }
214
+ ```
215
+
216
+ ## Lovable Projects (additional guidance)
217
+
218
+ If your module was scaffolded by Lovable, the following differences apply:
219
+
220
+ - [ ] `vite.config.ts` uses `adminModule()` spread into the existing plugins array (option B above), NOT `defineModuleConfig`
221
+ - [ ] React plugin is `@vitejs/plugin-react-swc` (Lovable default) — this is supported
222
+ - [ ] `index.html` entry point references `/src/main.tsx` (Lovable default) — this serves as the standalone dev entry
223
+ - [ ] `src/main.tsx` wraps your App with `AdminShell` (same role as `src/standalone.tsx` in non-Lovable modules)
224
+ - [ ] `src/spa.tsx` still required — `export default App` for shell mode
225
+ - [ ] `admin.module.json` still required at project root
226
+ - [ ] `module.manifest.json` is auto-generated at build time by `adminModule()` — do NOT manually copy `admin.module.json` to `dist/`
227
+ - [ ] Lovable's existing `server`, `resolve.alias`, and plugin settings are preserved — `adminModule()` only affects `vite build`
228
+ - [ ] Build script can be `"vite build"` (Lovable default) or `"tsc && vite build"` — both work
229
+
230
+ Expected `vite.config.ts` for Lovable:
231
+
232
+ ```typescript
233
+ import { defineConfig } from "vite";
234
+ import react from "@vitejs/plugin-react-swc";
235
+ import path from "path";
236
+ import { componentTagger } from "lovable-tagger";
237
+ import { adminModule } from "@nsxbet/admin-sdk/vite";
238
+
239
+ export default defineConfig(({ mode }) => ({
240
+ server: {
241
+ host: "::",
242
+ port: 8080,
243
+ hmr: { overlay: false },
244
+ },
245
+ plugins: [
246
+ react(),
247
+ mode === "development" && componentTagger(),
248
+ ...adminModule(),
249
+ ].filter(Boolean),
250
+ resolve: {
251
+ alias: {
252
+ "@": path.resolve(__dirname, "./src"),
253
+ },
254
+ },
255
+ }));
256
+ ```
257
+
258
+ Expected `src/main.tsx` for Lovable (standalone dev entry):
259
+
260
+ ```tsx
261
+ import React from "react";
262
+ import ReactDOM from "react-dom/client";
263
+ import {
264
+ AdminShell,
265
+ createInMemoryAuthClient,
266
+ createMockUsersFromRoles,
267
+ } from "@nsxbet/admin-sdk";
268
+ import type { AdminModuleManifest } from "@nsxbet/admin-sdk";
269
+ import { App } from "./App";
270
+ import manifest from "../admin.module.json";
271
+ import "./index.css";
272
+
273
+ const moduleManifest = manifest as AdminModuleManifest;
274
+
275
+ const mockUsers = createMockUsersFromRoles({
276
+ admin: ["admin.mymodule.view", "admin.mymodule.edit", "admin.mymodule.delete"],
277
+ editor: ["admin.mymodule.view", "admin.mymodule.edit"],
278
+ viewer: ["admin.mymodule.view"],
279
+ noAccess: [],
280
+ });
281
+
282
+ const authClient = createInMemoryAuthClient({ users: mockUsers });
283
+
284
+ ReactDOM.createRoot(document.getElementById("root")!).render(
285
+ <React.StrictMode>
286
+ <AdminShell modules={[moduleManifest]} authClient={authClient}>
287
+ <App />
288
+ </AdminShell>
289
+ </React.StrictMode>
290
+ );
291
+ ```
292
+
293
+ ## Anti-Patterns (MUST NOT be present)
294
+
295
+ - [ ] No `@supabase/supabase-js` or `supabase` imports in `src/**`
296
+ - [ ] No `firebase` imports in `src/**`
297
+ - [ ] No `BrowserRouter` or `MemoryRouter` in `src/**` (except `standalone.tsx`)
298
+ - [ ] No `useNavigate` imported from `@nsxbet/admin-sdk` (use `react-router-dom`)
299
+ - [ ] No `@supabase/supabase-js` or `firebase` in `package.json` dependencies
300
+ - [ ] No raw `fetch()` or `window.fetch()` calls — use `useFetch()` from the SDK
301
+ - [ ] 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 && cp admin.module.json dist/",
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:** The build script copies `admin.module.json` to `dist/` because the shell needs the manifest to register your module.
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
 
@@ -537,7 +539,16 @@ Use [Lucide](https://lucide.dev/icons) icon names in **kebab-case**:
537
539
 
538
540
  ## Vite Configuration
539
541
 
540
- The SDK provides `defineModuleConfig` to simplify Vite setup:
542
+ The SDK provides two ways to configure Vite for admin modules:
543
+
544
+ 1. **`defineModuleConfig()`** — returns a complete Vite config. Best for new modules with no existing Vite setup.
545
+ 2. **`adminModule()`** — returns a `Plugin[]` you spread into an existing config. Best for Lovable projects or any existing Vite config.
546
+
547
+ Both produce identical build artifacts. Both support `@vitejs/plugin-react` and `@vitejs/plugin-react-swc`.
548
+
549
+ > **Note:** `module.manifest.json` is generated automatically at build time by both `defineModuleConfig` and `adminModule`. No manual `cp admin.module.json dist/` step is needed.
550
+
551
+ ### `defineModuleConfig()` — Full Config
541
552
 
542
553
  ```typescript
543
554
  import { defineModuleConfig } from "@nsxbet/admin-sdk/vite";
@@ -545,26 +556,66 @@ import react from "@vitejs/plugin-react";
545
556
 
546
557
  export default defineModuleConfig({
547
558
  port: 3003,
548
- plugins: [react()], // REQUIRED: you must add the React plugin
559
+ plugins: [react()], // REQUIRED: you must add a React plugin
549
560
  });
550
561
  ```
551
562
 
552
- > **Important:** Each module must use a unique port. Standard assignments:
563
+ > **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
564
  > - Shell: 3000
554
565
  > - API: 4000
555
566
  > - Modules: 3002, 3003, 3004, etc.
556
567
 
557
- ### Options
568
+ #### `defineModuleConfig` Options
558
569
 
559
570
  | Option | Type | Default | Description |
560
571
  |--------|------|---------|-------------|
561
- | `port` | number | **required** | Dev server port |
572
+ | `port` | number | `8080` | Dev server port |
562
573
  | `entry` | string | `"./src/spa.tsx"` | Entry file path |
563
574
  | `outDir` | string | `"dist"` | Output directory |
564
575
  | `plugins` | Plugin[] | `[]` | Additional Vite plugins |
565
576
  | `additionalExternals` | string[] | `[]` | Extra externals |
566
577
  | `overrides` | object | `{}` | Override any Vite config |
567
578
 
579
+ ### `adminModule()` — Composable Plugin (Lovable / Custom Vite Config)
580
+
581
+ Use `adminModule()` when you already have a `vite.config.ts` and want to add admin module support without replacing it. This is the recommended approach for **Lovable projects**.
582
+
583
+ `adminModule()` only affects `vite build` — during `vite dev`, your app runs as a normal SPA with HMR working as expected.
584
+
585
+ ```typescript
586
+ import { defineConfig } from "vite";
587
+ import react from "@vitejs/plugin-react-swc";
588
+ import path from "path";
589
+ import { componentTagger } from "lovable-tagger";
590
+ import { adminModule } from "@nsxbet/admin-sdk/vite";
591
+
592
+ export default defineConfig(({ mode }) => ({
593
+ server: {
594
+ host: "::",
595
+ port: 8080,
596
+ hmr: { overlay: false },
597
+ },
598
+ plugins: [
599
+ react(),
600
+ mode === "development" && componentTagger(),
601
+ ...adminModule(),
602
+ ].filter(Boolean),
603
+ resolve: {
604
+ alias: {
605
+ "@": path.resolve(__dirname, "./src"),
606
+ },
607
+ },
608
+ }));
609
+ ```
610
+
611
+ #### `adminModule` Options
612
+
613
+ | Option | Type | Default | Description |
614
+ |--------|------|---------|-------------|
615
+ | `entry` | string | `"./src/spa.tsx"` | Entry file path |
616
+ | `outDir` | string | `"dist"` | Output directory |
617
+ | `additionalExternals` | string[] | `[]` | Extra externals |
618
+
568
619
  ### Shared Externals
569
620
 
570
621
  These dependencies are provided by the shell (do not bundle them):
@@ -573,6 +624,78 @@ These dependencies are provided by the shell (do not bundle them):
573
624
  ["react", "react-dom", "react-router-dom", "i18next", "react-i18next"]
574
625
  ```
575
626
 
627
+ ### Getting Started in Lovable
628
+
629
+ Lovable projects come with a default `vite.config.ts`, `index.html`, and `src/main.tsx` entry point. To turn a Lovable project into an admin module:
630
+
631
+ 1. **Install the SDK:**
632
+
633
+ ```bash
634
+ npm install @nsxbet/admin-sdk @nsxbet/admin-ui
635
+ ```
636
+
637
+ 2. **Add `adminModule()` to your existing `vite.config.ts`:**
638
+
639
+ ```typescript
640
+ import { adminModule } from "@nsxbet/admin-sdk/vite";
641
+
642
+ // Inside your plugins array:
643
+ plugins: [
644
+ react(),
645
+ mode === "development" && componentTagger(),
646
+ ...adminModule(),
647
+ ].filter(Boolean),
648
+ ```
649
+
650
+ 3. **Create `admin.module.json`** at the project root with your module metadata.
651
+
652
+ 4. **Create `src/spa.tsx`** — the shell entry point:
653
+
654
+ ```tsx
655
+ import { App } from "./App";
656
+ export default App;
657
+ ```
658
+
659
+ 5. **Update `src/main.tsx`** — wrap your app with `AdminShell` for standalone dev:
660
+
661
+ ```tsx
662
+ import { AdminShell, createInMemoryAuthClient, createMockUsersFromRoles } from "@nsxbet/admin-sdk";
663
+ import manifest from "../admin.module.json";
664
+ import { App } from "./App";
665
+
666
+ const mockUsers = createMockUsersFromRoles({
667
+ admin: ["admin.mymodule.view", "admin.mymodule.edit"],
668
+ editor: ["admin.mymodule.view", "admin.mymodule.edit"],
669
+ viewer: ["admin.mymodule.view"],
670
+ noAccess: [],
671
+ });
672
+
673
+ const authClient = createInMemoryAuthClient({ users: mockUsers });
674
+
675
+ ReactDOM.createRoot(document.getElementById("root")!).render(
676
+ <AdminShell modules={[manifest]} authClient={authClient}>
677
+ <App />
678
+ </AdminShell>
679
+ );
680
+ ```
681
+
682
+ 6. **Build:** `npm run build` produces `dist/assets/spa-[hash].js` + `dist/module.manifest.json`
683
+
684
+ Your Lovable preview (`vite dev`) continues to work as before — `adminModule()` only changes the `vite build` output.
685
+
686
+ ## ESLint Plugin
687
+
688
+ Install `@nsxbet/eslint-plugin-admin` (requires ESLint 9+) to catch common mistakes at development time:
689
+
690
+ ```javascript
691
+ // eslint.config.js
692
+ import adminPlugin from "@nsxbet/eslint-plugin-admin";
693
+
694
+ export default [adminPlugin.configs.recommended];
695
+ ```
696
+
697
+ 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.
698
+
576
699
  ## SDK Hooks
577
700
 
578
701
  ### `useAuth()`
@@ -1,13 +1,10 @@
1
+ import type { Plugin } from "vite";
1
2
  /**
2
3
  * Shared dependencies that are externalized in module builds.
3
4
  * These are provided by the shell via import maps.
4
5
  */
5
6
  export declare const SHARED_EXTERNALS: readonly ["react", "react-dom", "react-router-dom", "i18next", "react-i18next"];
6
- export interface ModuleConfigOptions {
7
- /**
8
- * Development server port
9
- */
10
- port: number;
7
+ export interface AdminModuleOptions {
11
8
  /**
12
9
  * Entry file for the module SPA
13
10
  * @default "./src/spa.tsx"
@@ -22,6 +19,13 @@ export interface ModuleConfigOptions {
22
19
  * Additional externals to add to SHARED_EXTERNALS
23
20
  */
24
21
  additionalExternals?: string[];
22
+ }
23
+ export interface ModuleConfigOptions extends AdminModuleOptions {
24
+ /**
25
+ * Development server port
26
+ * @default 8080
27
+ */
28
+ port?: number;
25
29
  /**
26
30
  * Additional Vite plugins (will be spread into plugins array)
27
31
  */
@@ -31,17 +35,47 @@ export interface ModuleConfigOptions {
31
35
  */
32
36
  overrides?: Record<string, any>;
33
37
  }
38
+ /**
39
+ * Composable Vite plugin array for admin modules.
40
+ * Returns plugins that handle build-time lib config, dist serving, and manifest generation.
41
+ *
42
+ * Use this when you already have a Vite config (e.g. Lovable) and want to add
43
+ * admin module support without replacing your entire config.
44
+ *
45
+ * The build config plugin only applies during `vite build` — dev server works as a normal SPA.
46
+ *
47
+ * @example In a Lovable project
48
+ * ```ts
49
+ * import { defineConfig } from "vite";
50
+ * import react from "@vitejs/plugin-react-swc";
51
+ * import { adminModule } from "@nsxbet/admin-sdk/vite";
52
+ *
53
+ * export default defineConfig(({ mode }) => ({
54
+ * plugins: [
55
+ * react(),
56
+ * mode === "development" && componentTagger(),
57
+ * ...adminModule(),
58
+ * ].filter(Boolean),
59
+ * }));
60
+ * ```
61
+ *
62
+ * @example With custom entry and externals
63
+ * ```ts
64
+ * ...adminModule({
65
+ * entry: "./src/custom-spa.tsx",
66
+ * additionalExternals: ["lodash"],
67
+ * })
68
+ * ```
69
+ */
70
+ export declare function adminModule(options?: AdminModuleOptions): Plugin[];
34
71
  /**
35
72
  * Creates a pre-configured Vite config for admin modules.
36
73
  *
37
74
  * **Note:** This function does NOT include the React plugin automatically.
38
75
  * You must import and add it yourself to avoid version conflicts.
39
76
  *
40
- * Includes:
41
- * - serveDistPlugin (serves dist files during dev)
42
- * - generateModuleManifestPlugin (generates module.manifest.json)
43
- * - ES module build format
44
- * - Externalized shared dependencies
77
+ * For Lovable or other existing Vite configs, use the composable `adminModule()` plugin
78
+ * instead it can be spread into any existing plugins array.
45
79
  *
46
80
  * @example
47
81
  * ```ts
@@ -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;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;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"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/vite/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,iFAMnB,CAAC;AAEX,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IAEH,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAEhB;;OAEG;IAEH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,EAAE,CAwCtE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,GAAG,CAiBpE"}
@@ -10,17 +10,80 @@ export const SHARED_EXTERNALS = [
10
10
  "i18next",
11
11
  "react-i18next",
12
12
  ];
13
+ /**
14
+ * Composable Vite plugin array for admin modules.
15
+ * Returns plugins that handle build-time lib config, dist serving, and manifest generation.
16
+ *
17
+ * Use this when you already have a Vite config (e.g. Lovable) and want to add
18
+ * admin module support without replacing your entire config.
19
+ *
20
+ * The build config plugin only applies during `vite build` — dev server works as a normal SPA.
21
+ *
22
+ * @example In a Lovable project
23
+ * ```ts
24
+ * import { defineConfig } from "vite";
25
+ * import react from "@vitejs/plugin-react-swc";
26
+ * import { adminModule } from "@nsxbet/admin-sdk/vite";
27
+ *
28
+ * export default defineConfig(({ mode }) => ({
29
+ * plugins: [
30
+ * react(),
31
+ * mode === "development" && componentTagger(),
32
+ * ...adminModule(),
33
+ * ].filter(Boolean),
34
+ * }));
35
+ * ```
36
+ *
37
+ * @example With custom entry and externals
38
+ * ```ts
39
+ * ...adminModule({
40
+ * entry: "./src/custom-spa.tsx",
41
+ * additionalExternals: ["lodash"],
42
+ * })
43
+ * ```
44
+ */
45
+ export function adminModule(options = {}) {
46
+ const { entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], } = options;
47
+ const externals = [...SHARED_EXTERNALS, ...additionalExternals];
48
+ const buildConfigPlugin = {
49
+ name: "admin-module-build-config",
50
+ config(_config, { command }) {
51
+ if (command !== "build")
52
+ return;
53
+ return {
54
+ build: {
55
+ outDir,
56
+ emptyOutDir: true,
57
+ lib: {
58
+ entry,
59
+ formats: ["es"],
60
+ fileName: () => `assets/spa-[hash].js`,
61
+ },
62
+ rollupOptions: {
63
+ external: externals,
64
+ output: {
65
+ entryFileNames: "assets/[name]-[hash].js",
66
+ chunkFileNames: "assets/[name]-[hash].js",
67
+ },
68
+ },
69
+ },
70
+ };
71
+ },
72
+ };
73
+ return [
74
+ serveDistPlugin({ distDir: outDir }),
75
+ generateModuleManifestPlugin(),
76
+ buildConfigPlugin,
77
+ ];
78
+ }
13
79
  /**
14
80
  * Creates a pre-configured Vite config for admin modules.
15
81
  *
16
82
  * **Note:** This function does NOT include the React plugin automatically.
17
83
  * You must import and add it yourself to avoid version conflicts.
18
84
  *
19
- * Includes:
20
- * - serveDistPlugin (serves dist files during dev)
21
- * - generateModuleManifestPlugin (generates module.manifest.json)
22
- * - ES module build format
23
- * - Externalized shared dependencies
85
+ * For Lovable or other existing Vite configs, use the composable `adminModule()` plugin
86
+ * instead it can be spread into any existing plugins array.
24
87
  *
25
88
  * @example
26
89
  * ```ts
@@ -48,34 +111,13 @@ export const SHARED_EXTERNALS = [
48
111
  */
49
112
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
113
  export function defineModuleConfig(options) {
51
- const { port, entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], plugins = [], overrides = {}, } = options;
52
- const externals = [...SHARED_EXTERNALS, ...additionalExternals];
114
+ const { port = 8080, plugins = [], overrides = {} } = options;
53
115
  return {
54
- plugins: [
55
- serveDistPlugin({ distDir: outDir }),
56
- generateModuleManifestPlugin(),
57
- ...plugins,
58
- ],
116
+ plugins: [...adminModule(options), ...plugins],
59
117
  define: {
60
118
  "process.env": {},
61
119
  "process.env.NODE_ENV": JSON.stringify("production"),
62
120
  },
63
- build: {
64
- outDir,
65
- emptyOutDir: true,
66
- lib: {
67
- entry,
68
- formats: ["es"],
69
- fileName: () => `assets/spa-[hash].js`,
70
- },
71
- rollupOptions: {
72
- external: externals,
73
- output: {
74
- entryFileNames: "assets/[name]-[hash].js",
75
- chunkFileNames: "assets/[name]-[hash].js",
76
- },
77
- },
78
- },
79
121
  server: {
80
122
  port,
81
123
  },
@@ -14,5 +14,5 @@
14
14
  * @packageDocumentation
15
15
  */
16
16
  export { generateModuleManifestPlugin, serveDistPlugin, type GenerateModuleManifestPluginOptions, type ServeDistPluginOptions, } from "./plugins.js";
17
- export { defineModuleConfig, SHARED_EXTERNALS, type ModuleConfigOptions, } from "./config.js";
17
+ export { adminModule, defineModuleConfig, SHARED_EXTERNALS, type AdminModuleOptions, type ModuleConfigOptions, } from "./config.js";
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,KAAK,mCAAmC,EACxC,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,KAAK,mCAAmC,EACxC,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC"}
@@ -14,4 +14,4 @@
14
14
  * @packageDocumentation
15
15
  */
16
16
  export { generateModuleManifestPlugin, serveDistPlugin, } from "./plugins.js";
17
- export { defineModuleConfig, SHARED_EXTERNALS, } from "./config.js";
17
+ export { adminModule, defineModuleConfig, SHARED_EXTERNALS, } from "./config.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsxbet/admin-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.5.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",
@@ -36,6 +39,7 @@
36
39
  "peerDependencies": {
37
40
  "@nsxbet/admin-ui": "^0.2.0",
38
41
  "@vitejs/plugin-react": "^4.0.0",
42
+ "@vitejs/plugin-react-swc": "^3.0.0",
39
43
  "i18next": "^23.0.0 || ^24.0.0 || ^25.0.0",
40
44
  "react": "^18.2.0",
41
45
  "react-dom": "^18.2.0",
@@ -47,6 +51,9 @@
47
51
  "@vitejs/plugin-react": {
48
52
  "optional": true
49
53
  },
54
+ "@vitejs/plugin-react-swc": {
55
+ "optional": true
56
+ },
50
57
  "vite": {
51
58
  "optional": true
52
59
  }
@@ -0,0 +1 @@
1
+ console.log("@nsxbet/admin-sdk: Module setup checklist available at node_modules/@nsxbet/admin-sdk/CHECKLIST.md");