@mercurjs/dashboard-sdk 2.0.0-canary.6 → 2.0.0-canary.61

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/dist/index.cjs CHANGED
@@ -30,8 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- dashboardPlugin: () => dashboardPlugin,
34
- defineConfig: () => defineConfig
33
+ mercurDashboardPlugin: () => mercurDashboardPlugin
35
34
  });
36
35
  module.exports = __toCommonJS(index_exports);
37
36
 
@@ -73,7 +72,6 @@ function normalizePath(filePath) {
73
72
 
74
73
  // src/constants.ts
75
74
  var VALID_FILE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
76
- var CONFIG_NAME = "mercur.config.ts";
77
75
  var CONFIG_VIRTUAL_MODULE = "virtual:mercur/config";
78
76
  var ROUTES_VIRTUAL_MODULE = "virtual:mercur/routes";
79
77
  var COMPONENTS_VIRTUAL_MODULE = "virtual:mercur/components";
@@ -136,6 +134,14 @@ function hasDefaultExport(filePath) {
136
134
  return false;
137
135
  }
138
136
  }
137
+ function hasConfigPublic(filePath) {
138
+ try {
139
+ const content = import_fs.default.readFileSync(filePath, "utf-8");
140
+ return /export\s+const\s+config\s*=\s*\{[^}]*public\s*:\s*true/.test(content);
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
139
145
  function getNamedExports(filePath) {
140
146
  try {
141
147
  const content = import_fs.default.readFileSync(filePath, "utf-8");
@@ -170,12 +176,13 @@ function generateImports(file, index, hasHandle, hasLoader) {
170
176
  }
171
177
  return imports;
172
178
  }
173
- function generateRouteObject(routePath, index, hasHandle, hasLoader) {
179
+ function generateRouteObject(routePath, index, hasHandle, hasLoader, isPublic) {
174
180
  return {
175
181
  Component: generateRouteComponentName(index),
176
182
  path: routePath,
177
183
  handle: hasHandle ? generateHandleName(index) : void 0,
178
- loader: hasLoader ? generateLoaderName(index) : void 0
184
+ loader: hasLoader ? generateLoaderName(index) : void 0,
185
+ isPublic
179
186
  };
180
187
  }
181
188
  function formatRoute(route, indent = " ") {
@@ -191,6 +198,10 @@ ${indent} handle: ${route.handle}`;
191
198
  if (route.loader) {
192
199
  result += `,
193
200
  ${indent} loader: ${route.loader}`;
201
+ }
202
+ if (route.isPublic) {
203
+ result += `,
204
+ ${indent} isPublic: true`;
194
205
  }
195
206
  if (route.children?.length) {
196
207
  result += `,
@@ -209,9 +220,10 @@ function parseFile(file, pagesDir, index) {
209
220
  return null;
210
221
  }
211
222
  const { hasHandle, hasLoader } = getNamedExports(file);
223
+ const isPublic = hasConfigPublic(file);
212
224
  const routePath = getRoute(file, pagesDir);
213
225
  const imports = generateImports(file, index, hasHandle, hasLoader);
214
- const route = generateRouteObject(routePath, index, hasHandle, hasLoader);
226
+ const route = generateRouteObject(routePath, index, hasHandle, hasLoader, isPublic);
215
227
  return {
216
228
  imports,
217
229
  route
@@ -492,44 +504,60 @@ function loadI18nModule(mercurConfig) {
492
504
  }
493
505
 
494
506
  // src/plugin.ts
495
- function buildConfig(config, root) {
496
- const srcDir = import_path5.default.join(root, "src");
497
- return {
498
- ...config,
499
- backendUrl: config.backendUrl ?? "http://localhost:9000",
500
- root,
501
- srcDir,
502
- configPath: import_path5.default.resolve(root, CONFIG_NAME)
503
- };
504
- }
505
- async function loadMercurConfig(root) {
506
- const configPath = import_path5.default.resolve(root, CONFIG_NAME);
507
- try {
508
- const mod = await getFileExports(configPath);
509
- const content = mod.default ?? mod;
510
- return buildConfig(content, root);
511
- } catch (error) {
512
- console.error(error);
513
- throw new Error(
514
- `[@mercurjs/dashboard-sdk] Could not find or load ${CONFIG_NAME} in ${root}`
515
- );
516
- }
517
- }
518
507
  function isPageFile(file) {
519
508
  const basename = import_path5.default.basename(file, import_path5.default.extname(file));
520
509
  return basename === "page";
521
510
  }
522
- function dashboardPlugin() {
511
+ var UI_MODULE_KEYS = [
512
+ "@mercurjs/core-plugin/modules/admin-ui",
513
+ "@mercurjs/core-plugin/modules/vendor-ui"
514
+ ];
515
+ async function loadMedusaConfig(medusaConfigPath, root) {
516
+ try {
517
+ const mod = await getFileExports(medusaConfigPath);
518
+ const medusaConfig = mod.default ?? mod;
519
+ const modules = medusaConfig?.modules ?? {};
520
+ for (const key of UI_MODULE_KEYS) {
521
+ const value = modules[key];
522
+ if (!value || typeof value !== "object" || !value.options?.appDir) continue;
523
+ const appDir = import_path5.default.resolve(import_path5.default.dirname(medusaConfigPath), value.options.appDir);
524
+ if (appDir === root) {
525
+ return {
526
+ backendUrl: value.options.backendUrl ?? "http://localhost:9000",
527
+ base: value.options.path
528
+ };
529
+ }
530
+ }
531
+ return { backendUrl: "http://localhost:9000" };
532
+ } catch {
533
+ return { backendUrl: "http://localhost:9000" };
534
+ }
535
+ }
536
+ function mercurDashboardPlugin(pluginConfig) {
523
537
  let root;
524
538
  let config;
525
539
  return {
526
540
  name: "@mercurjs/dashboard-sdk",
527
541
  async config(viteConfig) {
528
542
  root = viteConfig.root || process.cwd();
529
- config = await loadMercurConfig(root);
543
+ const medusaConfigPath = import_path5.default.resolve(root, pluginConfig.medusaConfigPath);
544
+ const { backendUrl, base } = await loadMedusaConfig(medusaConfigPath, root);
545
+ const srcDir = import_path5.default.join(root, "src");
546
+ config = {
547
+ ...pluginConfig,
548
+ backendUrl,
549
+ base,
550
+ root,
551
+ srcDir
552
+ };
530
553
  return {
554
+ base: config.base,
531
555
  define: {
532
- "__BACKEND_URL__": JSON.stringify(config.backendUrl)
556
+ "__BACKEND_URL__": JSON.stringify(config.backendUrl),
557
+ "__BASE__": JSON.stringify(config.base || "/")
558
+ },
559
+ optimizeDeps: {
560
+ exclude: ["virtual:mercur/config", "virtual:mercur/routes", "virtual:mercur/components", "virtual:mercur/menu-items", "virtual:mercur/i18n"]
533
561
  }
534
562
  };
535
563
  },
@@ -558,11 +586,6 @@ function dashboardPlugin() {
558
586
  server.watcher.on("unlink", handlePageChange);
559
587
  },
560
588
  handleHotUpdate({ file, server }) {
561
- const configPath = import_path5.default.resolve(root, CONFIG_NAME);
562
- if (file === configPath) {
563
- server.restart();
564
- return;
565
- }
566
589
  if (isPageFile(file)) {
567
590
  const mod = server.moduleGraph.getModuleById(RESOLVED_ROUTES_MODULE);
568
591
  if (mod) {
@@ -572,13 +595,7 @@ function dashboardPlugin() {
572
595
  }
573
596
  };
574
597
  }
575
-
576
- // src/define-config.ts
577
- function defineConfig(config) {
578
- return config;
579
- }
580
598
  // Annotate the CommonJS export names for ESM import in node:
581
599
  0 && (module.exports = {
582
- dashboardPlugin,
583
- defineConfig
600
+ mercurDashboardPlugin
584
601
  });
package/dist/index.d.cts CHANGED
@@ -1,25 +1,25 @@
1
1
  import * as Vite from 'vite';
2
2
  import { ComponentType } from 'react';
3
3
 
4
- declare function dashboardPlugin(): Vite.Plugin;
5
-
6
4
  interface MercurConfig {
5
+ medusaConfigPath: string;
7
6
  name?: string;
8
7
  logo?: string;
9
8
  components?: {
10
9
  MainSidebar?: string;
11
10
  SettingsSidebar?: string;
11
+ TopbarActions?: string;
12
12
  };
13
13
  i18n?: {
14
14
  defaultLanguage: string;
15
15
  };
16
- backendUrl?: string;
16
+ enableSellerRegistration?: boolean;
17
17
  }
18
18
  interface BuiltMercurConfig extends MercurConfig {
19
19
  backendUrl: string;
20
+ base?: string;
20
21
  root: string;
21
22
  srcDir: string;
22
- configPath: string;
23
23
  }
24
24
  type RouteConfig = {
25
25
  label: string;
@@ -27,8 +27,9 @@ type RouteConfig = {
27
27
  rank?: number;
28
28
  nested?: string;
29
29
  translationNs?: string;
30
+ public?: boolean;
30
31
  };
31
32
 
32
- declare function defineConfig(config: MercurConfig): MercurConfig;
33
+ declare function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin;
33
34
 
34
- export { type BuiltMercurConfig, type MercurConfig, type RouteConfig, dashboardPlugin, defineConfig };
35
+ export { type BuiltMercurConfig, type MercurConfig, type RouteConfig, mercurDashboardPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/dashboard-sdk",
3
- "version": "2.0.0-canary.6",
3
+ "version": "2.0.0-canary.61",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",