starpro-plugin-sdk 1.1.0 → 1.2.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/README.md CHANGED
@@ -30,11 +30,11 @@ Anda **tidak perlu** mengimpor halaman satu per satu ataupun menuliskan daftar r
30
30
  import { defineStarProApp } from "starpro-plugin-sdk";
31
31
 
32
32
  defineStarProApp({
33
- pluginId: "star-tenant-access",
33
+ pluginId: "star-tenant-access", // UUID Plugin (bebas apa saja asal tidak ada yg sama)
34
34
  defaultRoute: "/dashboard", // Rute awal yang dibuka saat plugin dimuat
35
- title: "Tenant Access",
36
- badge: "STA",
37
- themeColor: "#059669",
35
+ title: "Tenant Access", // Judul Plugin
36
+ badge: "STA", // Singkatan Plugin
37
+ themeColor: "#059669", // Warna Theme Plugin
38
38
  });
39
39
  ```
40
40
 
@@ -377,9 +377,69 @@ async function buildStarProPlugin(options = {}) {
377
377
  if (fs.existsSync(path.join(targetNodeModules, "react/jsx-runtime"))) {
378
378
  alias["react/jsx-runtime"] = path.join(targetNodeModules, "react/jsx-runtime");
379
379
  }
380
+ let targetAppDir = options.appDir;
381
+ if (!targetAppDir) {
382
+ const candidates = [
383
+ path.join(cwd, "src/app"),
384
+ path.join(cwd, "app"),
385
+ path.join(cwd, "src/pages"),
386
+ path.join(cwd, "pages")
387
+ ];
388
+ for (const cand of candidates) {
389
+ if (fs.existsSync(cand)) {
390
+ targetAppDir = cand;
391
+ break;
392
+ }
393
+ }
394
+ }
395
+ const injectFiles = [];
396
+ if (targetAppDir && fs.existsSync(targetAppDir)) {
397
+ const { routes } = discoverRoutes(targetAppDir, {
398
+ stripRouteGroups: options.stripRouteGroups !== false
399
+ });
400
+ if (routes.length > 0) {
401
+ const starproCacheDir = path.join(cwd, "node_modules", ".starpro");
402
+ if (!fs.existsSync(starproCacheDir)) {
403
+ fs.mkdirSync(starproCacheDir, { recursive: true });
404
+ }
405
+ const autoRoutesPath = path.join(starproCacheDir, "auto-routes.tsx");
406
+ const importStatements = [];
407
+ const routeDefs = [];
408
+ routes.forEach((r, idx) => {
409
+ const varName = `__Page_${idx}`;
410
+ const normPath = r.filePath.replace(/\\/g, "/");
411
+ importStatements.push(
412
+ `import ${varName} from ${JSON.stringify(normPath)};`
413
+ );
414
+ routeDefs.push(
415
+ ` { path: ${JSON.stringify(r.routePath)}, component: ${varName}, label: ${r.label ? JSON.stringify(r.label) : "undefined"} }`
416
+ );
417
+ });
418
+ const autoRoutesContent = `// Auto-generated by starpro-plugin-sdk build
419
+ ${importStatements.join("\n")}
420
+
421
+ const __discoveredRoutes = [
422
+ ${routeDefs.join(",\n")}
423
+ ];
424
+
425
+ if (typeof window !== "undefined") {
426
+ window.__STARPRO_ROUTES__ = __discoveredRoutes;
427
+ }
428
+ export default __discoveredRoutes;
429
+ `;
430
+ fs.writeFileSync(autoRoutesPath, autoRoutesContent, "utf-8");
431
+ injectFiles.push(autoRoutesPath);
432
+ console.log(
433
+ `\u{1F9ED} [StarPro Plugin SDK] Auto-discovered ${routes.length} routes from ${path.relative(
434
+ cwd,
435
+ targetAppDir
436
+ )}`
437
+ );
438
+ }
439
+ }
380
440
  const plugins = [
381
441
  starproEsbuildPlugin({
382
- appDir: options.appDir,
442
+ appDir: targetAppDir,
383
443
  cwd,
384
444
  mockNext: options.mockNext,
385
445
  stripRouteGroups: options.stripRouteGroups
@@ -389,6 +449,7 @@ async function buildStarProPlugin(options = {}) {
389
449
  try {
390
450
  const result = await esbuild.build({
391
451
  entryPoints: [entry],
452
+ inject: injectFiles,
392
453
  bundle: true,
393
454
  minify,
394
455
  format: "iife",
@@ -345,9 +345,69 @@ async function buildStarProPlugin(options = {}) {
345
345
  if (fs.existsSync(path.join(targetNodeModules, "react/jsx-runtime"))) {
346
346
  alias["react/jsx-runtime"] = path.join(targetNodeModules, "react/jsx-runtime");
347
347
  }
348
+ let targetAppDir = options.appDir;
349
+ if (!targetAppDir) {
350
+ const candidates = [
351
+ path.join(cwd, "src/app"),
352
+ path.join(cwd, "app"),
353
+ path.join(cwd, "src/pages"),
354
+ path.join(cwd, "pages")
355
+ ];
356
+ for (const cand of candidates) {
357
+ if (fs.existsSync(cand)) {
358
+ targetAppDir = cand;
359
+ break;
360
+ }
361
+ }
362
+ }
363
+ const injectFiles = [];
364
+ if (targetAppDir && fs.existsSync(targetAppDir)) {
365
+ const { routes } = discoverRoutes(targetAppDir, {
366
+ stripRouteGroups: options.stripRouteGroups !== false
367
+ });
368
+ if (routes.length > 0) {
369
+ const starproCacheDir = path.join(cwd, "node_modules", ".starpro");
370
+ if (!fs.existsSync(starproCacheDir)) {
371
+ fs.mkdirSync(starproCacheDir, { recursive: true });
372
+ }
373
+ const autoRoutesPath = path.join(starproCacheDir, "auto-routes.tsx");
374
+ const importStatements = [];
375
+ const routeDefs = [];
376
+ routes.forEach((r, idx) => {
377
+ const varName = `__Page_${idx}`;
378
+ const normPath = r.filePath.replace(/\\/g, "/");
379
+ importStatements.push(
380
+ `import ${varName} from ${JSON.stringify(normPath)};`
381
+ );
382
+ routeDefs.push(
383
+ ` { path: ${JSON.stringify(r.routePath)}, component: ${varName}, label: ${r.label ? JSON.stringify(r.label) : "undefined"} }`
384
+ );
385
+ });
386
+ const autoRoutesContent = `// Auto-generated by starpro-plugin-sdk build
387
+ ${importStatements.join("\n")}
388
+
389
+ const __discoveredRoutes = [
390
+ ${routeDefs.join(",\n")}
391
+ ];
392
+
393
+ if (typeof window !== "undefined") {
394
+ window.__STARPRO_ROUTES__ = __discoveredRoutes;
395
+ }
396
+ export default __discoveredRoutes;
397
+ `;
398
+ fs.writeFileSync(autoRoutesPath, autoRoutesContent, "utf-8");
399
+ injectFiles.push(autoRoutesPath);
400
+ console.log(
401
+ `\u{1F9ED} [StarPro Plugin SDK] Auto-discovered ${routes.length} routes from ${path.relative(
402
+ cwd,
403
+ targetAppDir
404
+ )}`
405
+ );
406
+ }
407
+ }
348
408
  const plugins = [
349
409
  starproEsbuildPlugin({
350
- appDir: options.appDir,
410
+ appDir: targetAppDir,
351
411
  cwd,
352
412
  mockNext: options.mockNext,
353
413
  stripRouteGroups: options.stripRouteGroups
@@ -357,6 +417,7 @@ async function buildStarProPlugin(options = {}) {
357
417
  try {
358
418
  const result = await esbuild.build({
359
419
  entryPoints: [entry],
420
+ inject: injectFiles,
360
421
  bundle: true,
361
422
  minify,
362
423
  format: "iife",
@@ -34,6 +34,18 @@ function setupStarProAuthBridge(payload) {
34
34
  } catch (e) {
35
35
  }
36
36
  }
37
+ try {
38
+ const email = user?.email || user?.name || "starpro_user";
39
+ localStorage.setItem(
40
+ "_credentials",
41
+ JSON.stringify({
42
+ _accstkn: accessToken,
43
+ _refstkn: refreshToken || "",
44
+ _identifier: email
45
+ })
46
+ );
47
+ } catch (e) {
48
+ }
37
49
  try {
38
50
  localStorage.setItem("is_starpro_plugin", "true");
39
51
  sessionStorage.setItem("is_starpro_plugin", "true");
@@ -499,6 +511,11 @@ function defineStarProPlugin(options) {
499
511
  }
500
512
  }
501
513
  targetElement.innerHTML = "";
514
+ if (typeof document !== "undefined") {
515
+ const styleEl = document.getElementById("starpro-tenant-access-styles");
516
+ if (styleEl) styleEl.remove();
517
+ document.querySelectorAll(`style[data-plugin-id="${pluginId}"]`).forEach((s) => s.remove());
518
+ }
502
519
  };
503
520
  }
504
521
  };
@@ -583,6 +600,11 @@ function defineStarProApp(options = {}) {
583
600
  } catch (e) {
584
601
  }
585
602
  container.innerHTML = "";
603
+ if (typeof document !== "undefined") {
604
+ const styleEl = document.getElementById("starpro-tenant-access-styles");
605
+ if (styleEl) styleEl.remove();
606
+ document.querySelectorAll(`style[data-plugin-id="${pluginId}"]`).forEach((s) => s.remove());
607
+ }
586
608
  };
587
609
  }
588
610
  });
package/dist/index.js CHANGED
@@ -79,6 +79,18 @@ function setupStarProAuthBridge(payload) {
79
79
  } catch (e) {
80
80
  }
81
81
  }
82
+ try {
83
+ const email = user?.email || user?.name || "starpro_user";
84
+ localStorage.setItem(
85
+ "_credentials",
86
+ JSON.stringify({
87
+ _accstkn: accessToken,
88
+ _refstkn: refreshToken || "",
89
+ _identifier: email
90
+ })
91
+ );
92
+ } catch (e) {
93
+ }
82
94
  try {
83
95
  localStorage.setItem("is_starpro_plugin", "true");
84
96
  sessionStorage.setItem("is_starpro_plugin", "true");
@@ -164,6 +176,11 @@ function defineStarProPlugin(options) {
164
176
  }
165
177
  }
166
178
  targetElement.innerHTML = "";
179
+ if (typeof document !== "undefined") {
180
+ const styleEl = document.getElementById("starpro-tenant-access-styles");
181
+ if (styleEl) styleEl.remove();
182
+ document.querySelectorAll(`style[data-plugin-id="${pluginId}"]`).forEach((s) => s.remove());
183
+ }
167
184
  };
168
185
  }
169
186
  };
@@ -698,6 +715,11 @@ function defineStarProApp(options = {}) {
698
715
  } catch (e) {
699
716
  }
700
717
  container.innerHTML = "";
718
+ if (typeof document !== "undefined") {
719
+ const styleEl = document.getElementById("starpro-tenant-access-styles");
720
+ if (styleEl) styleEl.remove();
721
+ document.querySelectorAll(`style[data-plugin-id="${pluginId}"]`).forEach((s) => s.remove());
722
+ }
701
723
  };
702
724
  }
703
725
  });
package/dist/index.mjs CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  useStarProPathname,
17
17
  useStarProRouter,
18
18
  useStarProSearchParams
19
- } from "./chunk-HFHUB6W5.mjs";
19
+ } from "./chunk-4C5LPF23.mjs";
20
20
  import "./chunk-Y6FXYEAI.mjs";
21
21
  export {
22
22
  StarProPluginWrapper,
package/dist/react.js CHANGED
@@ -77,6 +77,18 @@ function setupStarProAuthBridge(payload) {
77
77
  } catch (e) {
78
78
  }
79
79
  }
80
+ try {
81
+ const email = user?.email || user?.name || "starpro_user";
82
+ localStorage.setItem(
83
+ "_credentials",
84
+ JSON.stringify({
85
+ _accstkn: accessToken,
86
+ _refstkn: refreshToken || "",
87
+ _identifier: email
88
+ })
89
+ );
90
+ } catch (e) {
91
+ }
80
92
  try {
81
93
  localStorage.setItem("is_starpro_plugin", "true");
82
94
  sessionStorage.setItem("is_starpro_plugin", "true");
@@ -542,6 +554,11 @@ function defineStarProPlugin(options) {
542
554
  }
543
555
  }
544
556
  targetElement.innerHTML = "";
557
+ if (typeof document !== "undefined") {
558
+ const styleEl = document.getElementById("starpro-tenant-access-styles");
559
+ if (styleEl) styleEl.remove();
560
+ document.querySelectorAll(`style[data-plugin-id="${pluginId}"]`).forEach((s) => s.remove());
561
+ }
545
562
  };
546
563
  }
547
564
  };
@@ -626,6 +643,11 @@ function defineStarProApp(options = {}) {
626
643
  } catch (e) {
627
644
  }
628
645
  container.innerHTML = "";
646
+ if (typeof document !== "undefined") {
647
+ const styleEl = document.getElementById("starpro-tenant-access-styles");
648
+ if (styleEl) styleEl.remove();
649
+ document.querySelectorAll(`style[data-plugin-id="${pluginId}"]`).forEach((s) => s.remove());
650
+ }
629
651
  };
630
652
  }
631
653
  });
package/dist/react.mjs CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useStarProPathname,
14
14
  useStarProRouter,
15
15
  useStarProSearchParams
16
- } from "./chunk-HFHUB6W5.mjs";
16
+ } from "./chunk-4C5LPF23.mjs";
17
17
  import "./chunk-Y6FXYEAI.mjs";
18
18
  export {
19
19
  StarProPluginWrapper,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpro-plugin-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Universal SDK to turn any React, Next.js, Vue, or JavaScript web app into a native StarPro plugin with automatic authentication & login bypass.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",