starpro-plugin-sdk 1.1.0 → 1.2.1
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 +95 -8
- package/dist/build/index.js +62 -1
- package/dist/build/index.mjs +62 -1
- package/dist/{chunk-HFHUB6W5.mjs → chunk-4C5LPF23.mjs} +22 -0
- package/dist/index.js +22 -0
- package/dist/index.mjs +1 -1
- package/dist/react.js +22 -0
- package/dist/react.mjs +1 -1
- package/package.json +1 -1
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",
|
|
34
|
-
|
|
35
|
-
title: "Tenant Access",
|
|
36
|
-
badge: "STA",
|
|
37
|
-
themeColor: "#059669",
|
|
33
|
+
pluginId: "star-tenant-access", // UUID Plugin (bebas apa saja asal tidak ada yg sama)
|
|
34
|
+
layout: ApplicationLayout, // Component Layout untuk memuat halaman/view
|
|
35
|
+
title: "Tenant Access", // Judul Plugin
|
|
36
|
+
badge: "STA", // Singkatan Plugin
|
|
37
|
+
themeColor: "#059669", // Warna Theme Plugin
|
|
38
38
|
});
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -49,10 +49,97 @@ Simpan file `build-plugin.js` di root folder proyek web Anda:
|
|
|
49
49
|
```javascript
|
|
50
50
|
// build-plugin.js
|
|
51
51
|
const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
52
|
+
const fs = require("fs");
|
|
53
|
+
const path = require("path");
|
|
54
|
+
const postcss = require("postcss");
|
|
55
|
+
const tailwind = require("@tailwindcss/postcss");
|
|
56
|
+
|
|
57
|
+
async function build() {
|
|
58
|
+
// 1. Compile Tailwind CSS and scope all rules to .starpro-plugin-root
|
|
59
|
+
console.log(
|
|
60
|
+
"🎨 Compiling and scoping Tailwind CSS from src/app/globals.css...",
|
|
61
|
+
);
|
|
62
|
+
const cssInput = fs.readFileSync(
|
|
63
|
+
path.resolve(__dirname, "src/app/globals.css"),
|
|
64
|
+
"utf-8",
|
|
65
|
+
);
|
|
66
|
+
const postcssResult = await postcss([tailwind()]).process(cssInput, {
|
|
67
|
+
from: path.resolve(__dirname, "src/app/globals.css"),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Prefix all selectors so plugin styles NEVER pollute StarPro's header, sidebar, or host dropdowns
|
|
71
|
+
const prefixPlugin = () => ({
|
|
72
|
+
postcssPlugin: "prefix-starpro",
|
|
73
|
+
Rule(rule) {
|
|
74
|
+
if (
|
|
75
|
+
rule.parent &&
|
|
76
|
+
rule.parent.type === "atrule" &&
|
|
77
|
+
(rule.parent.name === "keyframes" || rule.parent.name === "property")
|
|
78
|
+
) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
rule.selectors = rule.selectors.map((selector) => {
|
|
82
|
+
const s = selector.trim();
|
|
83
|
+
if (
|
|
84
|
+
s.startsWith(":root") ||
|
|
85
|
+
s.startsWith(":host") ||
|
|
86
|
+
s === "html" ||
|
|
87
|
+
s === "body"
|
|
88
|
+
) {
|
|
89
|
+
return s.replace(/^(:root|:host|html|body)/, ".starpro-plugin-root");
|
|
90
|
+
}
|
|
91
|
+
return ".starpro-plugin-root " + s;
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
prefixPlugin.postcss = true;
|
|
96
|
+
|
|
97
|
+
const scopedResult = await postcss([prefixPlugin]).process(
|
|
98
|
+
postcssResult.css,
|
|
99
|
+
{
|
|
100
|
+
from: undefined,
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
const compiledCss = scopedResult.css;
|
|
104
|
+
|
|
105
|
+
// 2. Build plugin JS with StarPro SDK
|
|
106
|
+
await buildStarProPlugin({
|
|
107
|
+
entry: "src/plugin-entry.tsx",
|
|
108
|
+
out: "public/plugin.js",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// 3. Inject CSS loader into public/plugin.js so styles work 100% in StarPro
|
|
112
|
+
const jsContent = fs.readFileSync(
|
|
113
|
+
path.resolve(__dirname, "public/plugin.js"),
|
|
114
|
+
"utf-8",
|
|
115
|
+
);
|
|
116
|
+
const cssInjector = `
|
|
117
|
+
(function() {
|
|
118
|
+
if (typeof document !== "undefined") {
|
|
119
|
+
var existing = document.getElementById("starpro-tenant-access-styles");
|
|
120
|
+
if (!existing) {
|
|
121
|
+
var style = document.createElement("style");
|
|
122
|
+
style.id = "starpro-tenant-access-styles";
|
|
123
|
+
style.setAttribute("data-plugin-id", "star-tenant-access");
|
|
124
|
+
style.textContent = ${JSON.stringify(compiledCss)};
|
|
125
|
+
document.head.appendChild(style);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
`;
|
|
130
|
+
fs.writeFileSync(
|
|
131
|
+
path.resolve(__dirname, "public/plugin.js"),
|
|
132
|
+
cssInjector + "\n" + jsContent,
|
|
133
|
+
"utf-8",
|
|
134
|
+
);
|
|
135
|
+
console.log(
|
|
136
|
+
"✨ Successfully bundled and injected Tailwind CSS into public/plugin.js!",
|
|
137
|
+
);
|
|
138
|
+
}
|
|
52
139
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
140
|
+
build().catch((err) => {
|
|
141
|
+
console.error("❌ Build error:", err);
|
|
142
|
+
process.exit(1);
|
|
56
143
|
});
|
|
57
144
|
```
|
|
58
145
|
|
package/dist/build/index.js
CHANGED
|
@@ -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:
|
|
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",
|
package/dist/build/index.mjs
CHANGED
|
@@ -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:
|
|
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
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpro-plugin-sdk",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|