@nsxbet/admin-sdk 0.6.0 → 0.7.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 CHANGED
@@ -256,6 +256,18 @@ If your module was scaffolded by Lovable, the following differences apply:
256
256
  - [ ] Lovable's existing `server`, `resolve.alias`, and plugin settings are preserved — `adminModule()` only affects `vite build`
257
257
  - [ ] Build script can be `"vite build"` (Lovable default) or `"tsc && vite build"` — both work
258
258
 
259
+ ### Environment Configuration (automatic)
260
+
261
+ `adminModule()` automatically injects `VITE_ADMIN_GATEWAY_URL` with the staging gateway URL (`https://admin-bff-stg.nsx.dev`). No `.env.staging` file or `--mode staging` script is needed for Lovable projects.
262
+
263
+ - [ ] Do NOT create `.env.staging` — the Vite plugin handles it
264
+ - [ ] Do NOT add `--mode staging` to the dev script
265
+
266
+ To override the gateway URL, either:
267
+ - Set `VITE_ADMIN_GATEWAY_URL` in a `.env` or `.env.local` file
268
+ - Pass `gatewayUrl` option: `...adminModule({ gatewayUrl: "http://localhost:8080" })`
269
+ - Disable injection: `...adminModule({ gatewayUrl: null })`
270
+
259
271
  Expected `vite.config.ts` for Lovable:
260
272
 
261
273
  ```typescript
package/README.md CHANGED
@@ -676,6 +676,38 @@ export default defineConfig(({ mode }) => ({
676
676
  | `entry` | string | `"./src/spa.tsx"` | Entry file path |
677
677
  | `outDir` | string | `"dist"` | Output directory |
678
678
  | `additionalExternals` | string[] | `[]` | Extra externals |
679
+ | `gatewayUrl` | `string \| null` | `undefined` | Admin gateway URL for env injection. `undefined` = auto-inject staging URL, `string` = inject custom URL, `null` = disable injection. Explicit env vars always take precedence. |
680
+
681
+ ### Automatic Environment Injection
682
+
683
+ `adminModule()` includes an env injection plugin that automatically sets `VITE_ADMIN_GATEWAY_URL` at build time. This ensures Lovable projects get real JWT tokens from the staging gateway without any manual `.env` configuration.
684
+
685
+ **Precedence order** (highest to lowest):
686
+
687
+ 1. Explicit env var (`.env`, `.env.local`, shell environment)
688
+ 2. `gatewayUrl` option passed to `adminModule()` or `defineModuleConfig()`
689
+ 3. Default: `https://admin-bff-stg.nsx.dev` (staging)
690
+
691
+ **Known gateway URLs:**
692
+
693
+ | Environment | URL |
694
+ |---|---|
695
+ | Staging | `https://admin-bff-stg.nsx.dev` |
696
+ | Homol | `https://admin-bff-homol.nsx.dev` |
697
+ | Local | `http://localhost:8080` |
698
+
699
+ **Examples:**
700
+
701
+ ```ts
702
+ // Default: staging URL auto-injected
703
+ ...adminModule()
704
+
705
+ // Custom URL
706
+ ...adminModule({ gatewayUrl: "http://localhost:8080" })
707
+
708
+ // Disable injection entirely
709
+ ...adminModule({ gatewayUrl: null })
710
+ ```
679
711
 
680
712
  ### Shared Externals
681
713
 
@@ -1103,6 +1135,8 @@ When `VITE_ADMIN_GATEWAY_URL` is set (or `gatewayUrl` is passed explicitly), the
1103
1135
  2. `import.meta.env.VITE_ADMIN_GATEWAY_URL` environment variable
1104
1136
  3. If neither is set, BFF integration is disabled (mock tokens, current behavior)
1105
1137
 
1138
+ > **Vite plugin auto-injection:** When using `adminModule()` or `defineModuleConfig()` from `@nsxbet/admin-sdk/vite`, the `VITE_ADMIN_GATEWAY_URL` environment variable is automatically set to the staging gateway URL. No `.env.staging` file or `--mode staging` script is needed. See the [Vite Configuration](#vite-configuration) section for override options.
1139
+
1106
1140
  **Error handling:**
1107
1141
 
1108
1142
  The UserSelector shows loading, error, and timeout states during the token fetch. If the gateway is unreachable, the developer can:
@@ -1,4 +1,9 @@
1
- import type { Plugin } from "vite";
1
+ import { type Plugin } from "vite";
2
+ /**
3
+ * Default admin gateway URL (staging environment).
4
+ * Used by the env injection plugin when no explicit value is configured.
5
+ */
6
+ export declare const ADMIN_GATEWAY_STAGING_URL = "https://admin-bff-stg.nsx.dev";
2
7
  /**
3
8
  * Shared dependencies that are externalized in module builds.
4
9
  * These are provided by the shell via import maps.
@@ -28,6 +33,15 @@ export interface AdminModuleOptions {
28
33
  * - "always": Always apply during `vite build`. Used by defineModuleConfig().
29
34
  */
30
35
  buildMode?: "auto" | "always";
36
+ /**
37
+ * Admin gateway URL for BFF token integration (InMemory auth).
38
+ * - `undefined` (default): auto-inject staging URL (`https://admin-bff-stg.nsx.dev`)
39
+ * - `string`: inject the provided URL
40
+ * - `null`: disable automatic injection entirely
41
+ *
42
+ * Explicit env vars (`.env` files, shell env) always take precedence over this option.
43
+ */
44
+ gatewayUrl?: string | null;
31
45
  }
32
46
  export interface ModuleConfigOptions extends AdminModuleOptions {
33
47
  /**
@@ -1,6 +1,13 @@
1
+ import { loadEnv } from "vite";
1
2
  import { generateModuleManifestPlugin, serveDistPlugin } from "./plugins.js";
2
3
  import { adminModuleI18nPlugin } from "./i18n-plugin.js";
3
4
  import { getSharedExternals } from "./AdminShellSharedDeps.js";
5
+ const ENV_KEY = "VITE_ADMIN_GATEWAY_URL";
6
+ /**
7
+ * Default admin gateway URL (staging environment).
8
+ * Used by the env injection plugin when no explicit value is configured.
9
+ */
10
+ export const ADMIN_GATEWAY_STAGING_URL = "https://admin-bff-stg.nsx.dev";
4
11
  /**
5
12
  * Shared dependencies that are externalized in module builds.
6
13
  * These are provided by the shell via import maps.
@@ -40,13 +47,33 @@ export const SHARED_EXTERNALS = getSharedExternals();
40
47
  * ```
41
48
  */
42
49
  export function adminModule(options = {}) {
43
- const { entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], buildMode = "auto", } = options;
50
+ const { entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], buildMode = "auto", gatewayUrl, } = options;
44
51
  const externals = [...SHARED_EXTERNALS, ...additionalExternals];
45
52
  function isModuleBuild() {
46
53
  if (buildMode === "always")
47
54
  return true;
48
55
  return process.env.ADMIN_MODULE === "true";
49
56
  }
57
+ const envPlugin = {
58
+ name: "admin-module-env",
59
+ config(_config, { mode }) {
60
+ if (gatewayUrl === null)
61
+ return;
62
+ const env = loadEnv(mode, process.cwd(), "VITE_");
63
+ const fromEnv = process.env[ENV_KEY] || env[ENV_KEY];
64
+ if (fromEnv) {
65
+ console.log(`[admin-module-env] ${ENV_KEY} → ${fromEnv} (from env)`);
66
+ return;
67
+ }
68
+ const url = gatewayUrl ?? ADMIN_GATEWAY_STAGING_URL;
69
+ console.log(`[admin-module-env] ${ENV_KEY} → ${url} (auto-injected)`);
70
+ return {
71
+ define: {
72
+ [`import.meta.env.${ENV_KEY}`]: JSON.stringify(url),
73
+ },
74
+ };
75
+ },
76
+ };
50
77
  const buildConfigPlugin = {
51
78
  name: "admin-module-build-config",
52
79
  config(_config, { command }) {
@@ -73,6 +100,7 @@ export function adminModule(options = {}) {
73
100
  },
74
101
  };
75
102
  return [
103
+ envPlugin,
76
104
  adminModuleI18nPlugin(),
77
105
  serveDistPlugin({ distDir: outDir }),
78
106
  generateModuleManifestPlugin(),
@@ -15,5 +15,5 @@
15
15
  */
16
16
  export { generateModuleManifestPlugin, serveDistPlugin, type GenerateModuleManifestPluginOptions, type ServeDistPluginOptions, } from "./plugins.js";
17
17
  export { adminModuleI18nPlugin, type AdminModuleI18nPluginOptions, } from "./i18n-plugin.js";
18
- export { adminModule, defineModuleConfig, SHARED_EXTERNALS, type AdminModuleOptions, type ModuleConfigOptions, } from "./config.js";
18
+ export { adminModule, defineModuleConfig, SHARED_EXTERNALS, ADMIN_GATEWAY_STAGING_URL, type AdminModuleOptions, type ModuleConfigOptions, } from "./config.js";
19
19
  export { AdminShellSharedDeps, SHARED_DEPS_CONFIG, getSharedExternals, type SharedDepConfig, } from "./AdminShellSharedDeps.js";
@@ -15,5 +15,5 @@
15
15
  */
16
16
  export { generateModuleManifestPlugin, serveDistPlugin, } from "./plugins.js";
17
17
  export { adminModuleI18nPlugin, } from "./i18n-plugin.js";
18
- export { adminModule, defineModuleConfig, SHARED_EXTERNALS, } from "./config.js";
18
+ export { adminModule, defineModuleConfig, SHARED_EXTERNALS, ADMIN_GATEWAY_STAGING_URL, } from "./config.js";
19
19
  export { AdminShellSharedDeps, SHARED_DEPS_CONFIG, getSharedExternals, } from "./AdminShellSharedDeps.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsxbet/admin-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "SDK for building NSX Admin modules with integrated shell",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",