starpro-plugin-sdk 1.0.1 → 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.
@@ -0,0 +1,699 @@
1
+ import {
2
+ __require
3
+ } from "./chunk-Y6FXYEAI.mjs";
4
+
5
+ // src/react.tsx
6
+ import { useState as useState2 } from "react";
7
+
8
+ // src/bridge.ts
9
+ function setupStarProAuthBridge(payload) {
10
+ if (typeof window === "undefined") return;
11
+ const { accessToken, refreshToken, user } = payload || {};
12
+ if (!accessToken) return;
13
+ console.log("\u26A1 [StarPro Plugin SDK] Auto-syncing auth tokens across storage & HTTP clients...");
14
+ const tokenKeys = ["accessToken", "access_token", "token", "starpro_token", "authToken"];
15
+ tokenKeys.forEach((key) => {
16
+ try {
17
+ localStorage.setItem(key, accessToken);
18
+ sessionStorage.setItem(key, accessToken);
19
+ } catch (e) {
20
+ }
21
+ });
22
+ if (refreshToken) {
23
+ try {
24
+ localStorage.setItem("refreshToken", refreshToken);
25
+ localStorage.setItem("refresh_token", refreshToken);
26
+ sessionStorage.setItem("refreshToken", refreshToken);
27
+ } catch (e) {
28
+ }
29
+ }
30
+ if (user) {
31
+ try {
32
+ localStorage.setItem("user", JSON.stringify(user));
33
+ localStorage.setItem("user_email", user.email || "");
34
+ } catch (e) {
35
+ }
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
+ }
49
+ try {
50
+ localStorage.setItem("is_starpro_plugin", "true");
51
+ sessionStorage.setItem("is_starpro_plugin", "true");
52
+ } catch (e) {
53
+ }
54
+ if (window.axios) {
55
+ try {
56
+ window.axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
57
+ } catch (e) {
58
+ }
59
+ }
60
+ if (typeof window.fetch === "function") {
61
+ const originalFetch = window.fetch;
62
+ window.fetch = function(input, init) {
63
+ const options = init || {};
64
+ options.headers = options.headers || {};
65
+ if (options.headers instanceof Headers) {
66
+ if (!options.headers.has("Authorization")) {
67
+ options.headers.set("Authorization", `Bearer ${accessToken}`);
68
+ }
69
+ } else if (Array.isArray(options.headers)) {
70
+ const hasAuth = options.headers.some(([k]) => k.toLowerCase() === "authorization");
71
+ if (!hasAuth) {
72
+ options.headers.push(["Authorization", `Bearer ${accessToken}`]);
73
+ }
74
+ } else {
75
+ const headersRecord = options.headers;
76
+ if (!headersRecord["Authorization"] && !headersRecord["authorization"]) {
77
+ headersRecord["Authorization"] = `Bearer ${accessToken}`;
78
+ }
79
+ }
80
+ return originalFetch.call(this, input, options);
81
+ };
82
+ }
83
+ }
84
+ function isStarProPlugin() {
85
+ if (typeof window === "undefined") return false;
86
+ return localStorage.getItem("is_starpro_plugin") === "true" || sessionStorage.getItem("is_starpro_plugin") === "true" || Boolean(window.StarProPlugins);
87
+ }
88
+
89
+ // src/router.tsx
90
+ import React, { useState, useEffect } from "react";
91
+ import { jsx, jsxs } from "react/jsx-runtime";
92
+ function matchRoute(pattern, pathname) {
93
+ const cleanPattern = pattern.length > 1 && pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
94
+ const cleanPath = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
95
+ if (cleanPattern === cleanPath) {
96
+ return { matched: true, params: {} };
97
+ }
98
+ const paramNames = [];
99
+ const regexPattern = cleanPattern.replace(/\[\.\.\.([^\]]+)\]/g, (_, name) => {
100
+ paramNames.push(name);
101
+ return "(.*)";
102
+ }).replace(/\[([^\]]+)\]/g, (_, name) => {
103
+ paramNames.push(name);
104
+ return "([^/]+)";
105
+ }).replace(/:([a-zA-Z0-9_]+)/g, (_, name) => {
106
+ paramNames.push(name);
107
+ return "([^/]+)";
108
+ }).replace(/\*([a-zA-Z0-9_]*)/g, (_, name) => {
109
+ paramNames.push(name || "wildcard");
110
+ return "(.*)";
111
+ });
112
+ const regex = new RegExp(`^${regexPattern}$`);
113
+ const match = cleanPath.match(regex);
114
+ if (!match) {
115
+ return { matched: false, params: {} };
116
+ }
117
+ const params = {};
118
+ paramNames.forEach((name, index) => {
119
+ params[name] = decodeURIComponent(match[index + 1] || "");
120
+ });
121
+ return { matched: true, params };
122
+ }
123
+ var StarProRouter = class {
124
+ constructor(initialUrl = "/") {
125
+ this.currentUrl = "/";
126
+ this.history = ["/"];
127
+ this.listeners = /* @__PURE__ */ new Set();
128
+ this.routes = [];
129
+ this.notifyScheduled = false;
130
+ this.currentUrl = initialUrl;
131
+ this.history = [initialUrl];
132
+ }
133
+ setRoutes(routes) {
134
+ this.routes = routes;
135
+ this.notify();
136
+ }
137
+ getRoutes() {
138
+ return this.routes;
139
+ }
140
+ getState() {
141
+ const [pathPart, searchPart] = (this.currentUrl || "/").split("?");
142
+ const pathname = pathPart || "/";
143
+ const searchParams = new URLSearchParams(searchPart || "");
144
+ let params = {};
145
+ for (const r of this.routes) {
146
+ const match = matchRoute(r.path, pathname);
147
+ if (match.matched) {
148
+ params = match.params;
149
+ break;
150
+ }
151
+ }
152
+ return {
153
+ url: this.currentUrl,
154
+ pathname,
155
+ searchParams,
156
+ params,
157
+ history: [...this.history]
158
+ };
159
+ }
160
+ getPathname() {
161
+ return this.getState().pathname;
162
+ }
163
+ getSearchParams() {
164
+ return this.getState().searchParams;
165
+ }
166
+ getParams() {
167
+ return this.getState().params;
168
+ }
169
+ subscribe(listener) {
170
+ this.listeners.add(listener);
171
+ return () => {
172
+ this.listeners.delete(listener);
173
+ };
174
+ }
175
+ /**
176
+ * Asynchronously notifies listeners on the next microtask tick.
177
+ * This completely prevents React warnings when navigating or redirecting
178
+ * during a component's render lifecycle.
179
+ */
180
+ notify() {
181
+ if (this.notifyScheduled) return;
182
+ this.notifyScheduled = true;
183
+ Promise.resolve().then(() => {
184
+ this.notifyScheduled = false;
185
+ const state = this.getState();
186
+ this.listeners.forEach((fn) => {
187
+ try {
188
+ fn(state);
189
+ } catch (err) {
190
+ console.error("[StarPro Router] Listener error:", err);
191
+ }
192
+ });
193
+ });
194
+ }
195
+ push(url) {
196
+ if (!url || url === this.currentUrl) return;
197
+ this.currentUrl = url;
198
+ this.history.push(url);
199
+ this.notify();
200
+ }
201
+ replace(url) {
202
+ if (!url) return;
203
+ this.currentUrl = url;
204
+ if (this.history.length > 0) {
205
+ this.history[this.history.length - 1] = url;
206
+ } else {
207
+ this.history.push(url);
208
+ }
209
+ this.notify();
210
+ }
211
+ redirect(url) {
212
+ this.replace(url);
213
+ }
214
+ back() {
215
+ if (this.history.length > 1) {
216
+ this.history.pop();
217
+ this.currentUrl = this.history[this.history.length - 1];
218
+ this.notify();
219
+ }
220
+ }
221
+ forward() {
222
+ }
223
+ };
224
+ var starproRouter = new StarProRouter("/");
225
+ function useStarProRouter() {
226
+ const [state, setState] = useState(
227
+ () => starproRouter.getState()
228
+ );
229
+ useEffect(() => {
230
+ return starproRouter.subscribe(setState);
231
+ }, []);
232
+ return {
233
+ ...state,
234
+ push: (url) => starproRouter.push(url),
235
+ replace: (url) => starproRouter.replace(url),
236
+ redirect: (url) => starproRouter.replace(url),
237
+ back: () => starproRouter.back(),
238
+ forward: () => starproRouter.forward()
239
+ };
240
+ }
241
+ function useStarProPathname() {
242
+ const [pathname, setPathname] = useState(
243
+ () => starproRouter.getState().pathname
244
+ );
245
+ useEffect(() => {
246
+ return starproRouter.subscribe((s) => setPathname(s.pathname));
247
+ }, []);
248
+ return pathname;
249
+ }
250
+ function useStarProSearchParams() {
251
+ const [searchParams, setSearchParams] = useState(
252
+ () => starproRouter.getState().searchParams
253
+ );
254
+ useEffect(() => {
255
+ return starproRouter.subscribe((s) => setSearchParams(s.searchParams));
256
+ }, []);
257
+ return searchParams;
258
+ }
259
+ function useStarProParams() {
260
+ const [params, setParams] = useState(
261
+ () => starproRouter.getState().params
262
+ );
263
+ useEffect(() => {
264
+ return starproRouter.subscribe((s) => setParams(s.params));
265
+ }, []);
266
+ return params;
267
+ }
268
+ function autoRoutesFromGlob(modules, options = {}) {
269
+ const routes = [];
270
+ const { stripGroups = true } = options;
271
+ for (const [rawPath, moduleExports] of Object.entries(modules)) {
272
+ let routePath = rawPath.replace(/^[./]+/, "").replace(/^src\//, "").replace(/^(app|pages)\//, "").replace(/\/page\.(tsx|jsx|js|ts)$/, "").replace(/\/index\.(tsx|jsx|js|ts)$/, "").replace(/^page\.(tsx|jsx|js|ts)$/, "").replace(/^index\.(tsx|jsx|js|ts)$/, "");
273
+ if (stripGroups) {
274
+ routePath = routePath.split("/").filter((segment) => !/^\([^)]+\)$/.test(segment)).join("/");
275
+ }
276
+ routePath = routePath.replace(/\[\.\.\.([^\]]+)\]/g, "*$1").replace(/\[([^\]]+)\]/g, ":$1");
277
+ if (!routePath.startsWith("/")) {
278
+ routePath = "/" + routePath;
279
+ }
280
+ if (routePath === "") {
281
+ routePath = "/";
282
+ }
283
+ const Component = moduleExports?.default || moduleExports;
284
+ if (!Component) continue;
285
+ let label = void 0;
286
+ const isDynamic = routePath.includes(":") || routePath.includes("*");
287
+ if (!isDynamic && routePath !== "/") {
288
+ const lastSegment = routePath.split("/").pop() || "";
289
+ label = lastSegment.split(/[-_]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
290
+ if (label) {
291
+ label = label.replace(/\bWater Waste Water\b/gi, "Water & Wastewater");
292
+ }
293
+ }
294
+ routes.push({
295
+ path: routePath,
296
+ component: Component,
297
+ label,
298
+ exact: routePath === "/"
299
+ });
300
+ }
301
+ return routes.sort((a, b) => {
302
+ if (a.path === "/") return -1;
303
+ if (b.path === "/") return 1;
304
+ const aDyn = a.path.includes(":") || a.path.includes("*");
305
+ const bDyn = b.path.includes(":") || b.path.includes("*");
306
+ if (aDyn && !bDyn) return 1;
307
+ if (!aDyn && bDyn) return -1;
308
+ return a.path.localeCompare(b.path);
309
+ });
310
+ }
311
+ var StarProRedirectBoundary = class extends React.Component {
312
+ constructor(props) {
313
+ super(props);
314
+ this.state = { hasError: false };
315
+ }
316
+ static getDerivedStateFromError(error) {
317
+ if (error?.isStarProRedirect || error?.message === "NEXT_REDIRECT" || typeof error?.digest === "string" && error.digest.startsWith("NEXT_REDIRECT")) {
318
+ return { hasError: true };
319
+ }
320
+ return { hasError: false };
321
+ }
322
+ componentDidCatch(error) {
323
+ if (error?.isStarProRedirect || error?.message === "NEXT_REDIRECT" || typeof error?.digest === "string" && error.digest.startsWith("NEXT_REDIRECT")) {
324
+ const targetUrl = error.url || (typeof error.digest === "string" ? error.digest.split(";")[2] : null);
325
+ if (targetUrl) {
326
+ starproRouter.replace(targetUrl);
327
+ }
328
+ Promise.resolve().then(() => {
329
+ this.setState({ hasError: false });
330
+ });
331
+ return;
332
+ }
333
+ console.error("[StarPro Router] Page render error:", error);
334
+ }
335
+ render() {
336
+ if (this.state.hasError) {
337
+ return this.props.fallback || null;
338
+ }
339
+ return this.props.children;
340
+ }
341
+ };
342
+ var StarProRouterView = ({
343
+ routes,
344
+ defaultRoute,
345
+ payload,
346
+ layout: CustomLayout,
347
+ title,
348
+ badge,
349
+ showNav,
350
+ themeColor = "#059669",
351
+ // emerald
352
+ fallback
353
+ }) => {
354
+ const [routeState, setRouteState] = useState(
355
+ () => starproRouter.getState()
356
+ );
357
+ useEffect(() => {
358
+ starproRouter.setRoutes(routes);
359
+ const current = starproRouter.getState().pathname;
360
+ const hasExactRoot = routes.some((r) => r.path === "/" || r.path === "");
361
+ if (current === "/" || current === "") {
362
+ if (defaultRoute) {
363
+ starproRouter.replace(defaultRoute);
364
+ } else if (!hasExactRoot && routes.length > 0) {
365
+ const first = routes.find((r) => r.path !== "/" && !r.path.includes(":"));
366
+ if (first) {
367
+ starproRouter.replace(first.path);
368
+ }
369
+ }
370
+ }
371
+ return starproRouter.subscribe(setRouteState);
372
+ }, [routes, defaultRoute]);
373
+ const { pathname, searchParams, params } = routeState;
374
+ const navTabs = routes.filter((r) => Boolean(r.label));
375
+ const shouldShowNav = showNav !== void 0 ? showNav : !CustomLayout && navTabs.length > 0;
376
+ let MatchedComponent = null;
377
+ for (const r of routes) {
378
+ const match = matchRoute(r.path, pathname);
379
+ if (match.matched) {
380
+ MatchedComponent = r.component;
381
+ break;
382
+ }
383
+ }
384
+ const activeTab = navTabs.find((tab) => {
385
+ if (tab.path === pathname) return true;
386
+ if (tab.path !== "/" && pathname.startsWith(tab.path)) return true;
387
+ return false;
388
+ });
389
+ const pageContent = MatchedComponent ? /* @__PURE__ */ jsx(
390
+ MatchedComponent,
391
+ {
392
+ params,
393
+ searchParams,
394
+ payload
395
+ }
396
+ ) : fallback ? fallback : /* @__PURE__ */ jsxs("div", { className: "p-8 text-center border border-dashed border-zinc-300 dark:border-zinc-700 rounded-xl my-4", children: [
397
+ /* @__PURE__ */ jsxs("h3", { className: "text-base font-semibold text-zinc-800 dark:text-zinc-200", children: [
398
+ "Page Not Found (",
399
+ pathname,
400
+ ")"
401
+ ] }),
402
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-zinc-500 mt-1", children: "Rute ini belum didaftarkan di StarPro plugin router." }),
403
+ defaultRoute && /* @__PURE__ */ jsx(
404
+ "button",
405
+ {
406
+ type: "button",
407
+ onClick: () => starproRouter.push(defaultRoute),
408
+ style: { backgroundColor: themeColor },
409
+ className: "mt-4 px-4 py-2 text-xs font-medium text-white rounded-lg cursor-pointer",
410
+ children: "Kembali ke Beranda"
411
+ }
412
+ )
413
+ ] });
414
+ return /* @__PURE__ */ jsxs("div", { className: "starpro-universal-router-view w-full min-h-screen text-zinc-900 dark:text-zinc-100", children: [
415
+ shouldShowNav && navTabs.length > 0 && /* @__PURE__ */ jsx("div", { className: "sticky top-0 z-30 mb-6 border-b border-zinc-200 bg-white/95 pb-3 pt-2 backdrop-blur dark:border-zinc-800 dark:bg-zinc-900/95", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
416
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5", children: [
417
+ /* @__PURE__ */ jsx(
418
+ "span",
419
+ {
420
+ style: { backgroundColor: themeColor },
421
+ className: "flex h-8 w-8 items-center justify-center rounded-lg font-bold text-white shadow-xs text-xs",
422
+ children: badge || "PRO"
423
+ }
424
+ ),
425
+ /* @__PURE__ */ jsxs("div", { children: [
426
+ title && /* @__PURE__ */ jsx(
427
+ "div",
428
+ {
429
+ style: { color: themeColor },
430
+ className: "text-xs font-semibold tracking-wider uppercase",
431
+ children: title
432
+ }
433
+ ),
434
+ /* @__PURE__ */ jsx("div", { className: "text-xs text-zinc-500 dark:text-zinc-400", children: pathname })
435
+ ] })
436
+ ] }),
437
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-1 rounded-xl bg-zinc-100 p-1 dark:bg-zinc-800", children: navTabs.map((tab) => {
438
+ const isActive = activeTab?.path === tab.path;
439
+ return /* @__PURE__ */ jsxs(
440
+ "button",
441
+ {
442
+ type: "button",
443
+ onClick: () => starproRouter.push(tab.path),
444
+ className: `flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-all duration-150 cursor-pointer ${isActive ? "bg-white text-emerald-600 shadow-xs dark:bg-zinc-900 dark:text-emerald-400" : "text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100"}`,
445
+ children: [
446
+ tab.icon && /* @__PURE__ */ jsx("span", { children: tab.icon }),
447
+ /* @__PURE__ */ jsx("span", { children: tab.label })
448
+ ]
449
+ },
450
+ tab.path
451
+ );
452
+ }) })
453
+ ] }) }),
454
+ /* @__PURE__ */ jsx("div", { className: "starpro-page-container", children: /* @__PURE__ */ jsx(StarProRedirectBoundary, { fallback, children: CustomLayout ? /* @__PURE__ */ jsx(
455
+ CustomLayout,
456
+ {
457
+ params,
458
+ searchParams,
459
+ payload,
460
+ children: pageContent
461
+ }
462
+ ) : pageContent }) })
463
+ ] });
464
+ };
465
+
466
+ // src/define-app.tsx
467
+ import { createRoot } from "react-dom/client";
468
+
469
+ // src/define-plugin.ts
470
+ function defineStarProPlugin(options) {
471
+ if (typeof window === "undefined") return;
472
+ const {
473
+ pluginId = "default",
474
+ onMount,
475
+ onUnmount,
476
+ autoInjectAuth = true
477
+ } = options;
478
+ window.StarProPlugins = window.StarProPlugins || {};
479
+ const pluginModule = {
480
+ mount: function(container, payload) {
481
+ const targetElement = typeof container === "string" ? document.getElementById(container) : container;
482
+ if (!targetElement) {
483
+ console.error(
484
+ `[StarPro Plugin: ${pluginId}] Target container element not found!`
485
+ );
486
+ return;
487
+ }
488
+ if (autoInjectAuth) {
489
+ setupStarProAuthBridge(payload);
490
+ }
491
+ let cleanup = void 0;
492
+ if (typeof onMount === "function") {
493
+ cleanup = onMount(targetElement, payload);
494
+ }
495
+ return function unmount() {
496
+ if (typeof cleanup === "function") {
497
+ try {
498
+ cleanup();
499
+ } catch (err) {
500
+ console.warn(`[StarPro Plugin: ${pluginId}] Error in cleanup:`, err);
501
+ }
502
+ }
503
+ if (typeof onUnmount === "function") {
504
+ try {
505
+ onUnmount();
506
+ } catch (err) {
507
+ console.warn(
508
+ `[StarPro Plugin: ${pluginId}] Error in onUnmount:`,
509
+ err
510
+ );
511
+ }
512
+ }
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
+ }
519
+ };
520
+ }
521
+ };
522
+ window.StarProPlugins[pluginId] = pluginModule;
523
+ window.StarProPlugins["default"] = pluginModule;
524
+ window.mountStarProPlugin = pluginModule.mount;
525
+ console.log(`\u2713 [StarPro Plugin SDK] Registered plugin "${pluginId}"`);
526
+ }
527
+
528
+ // src/define-app.tsx
529
+ import { jsx as jsx2 } from "react/jsx-runtime";
530
+ function defineStarProApp(options = {}) {
531
+ const {
532
+ pluginId = "default",
533
+ defaultRoute,
534
+ component: RootComponent,
535
+ layout: CustomLayout,
536
+ title,
537
+ badge,
538
+ themeColor,
539
+ showNav,
540
+ autoInjectAuth = true,
541
+ banner = true,
542
+ fallback,
543
+ render: customRender
544
+ } = options;
545
+ let resolvedRoutes = options.routes || [];
546
+ if (resolvedRoutes.length === 0 && typeof window !== "undefined") {
547
+ if (window.__STARPRO_ROUTES__ && Array.isArray(window.__STARPRO_ROUTES__)) {
548
+ resolvedRoutes = window.__STARPRO_ROUTES__;
549
+ } else {
550
+ try {
551
+ const virtualModule = __require("starpro:routes");
552
+ if (virtualModule) {
553
+ resolvedRoutes = virtualModule.default || virtualModule.routes || virtualModule;
554
+ }
555
+ } catch (e) {
556
+ }
557
+ }
558
+ }
559
+ defineStarProPlugin({
560
+ pluginId,
561
+ autoInjectAuth,
562
+ onMount: (container, payload) => {
563
+ let contentNode;
564
+ if (RootComponent) {
565
+ contentNode = /* @__PURE__ */ jsx2(RootComponent, { payload });
566
+ } else {
567
+ contentNode = /* @__PURE__ */ jsx2(
568
+ StarProRouterView,
569
+ {
570
+ routes: resolvedRoutes,
571
+ defaultRoute,
572
+ payload,
573
+ layout: CustomLayout,
574
+ title,
575
+ badge,
576
+ showNav,
577
+ themeColor,
578
+ fallback
579
+ }
580
+ );
581
+ }
582
+ const appTree = /* @__PURE__ */ jsx2(StarProPluginWrapper, { payload, banner, children: contentNode });
583
+ if (typeof customRender === "function") {
584
+ const cleanup = customRender(appTree, container);
585
+ return () => {
586
+ if (typeof cleanup === "function") {
587
+ try {
588
+ cleanup();
589
+ } catch (e) {
590
+ }
591
+ }
592
+ container.innerHTML = "";
593
+ };
594
+ }
595
+ const root = createRoot(container);
596
+ root.render(appTree);
597
+ return () => {
598
+ try {
599
+ root.unmount();
600
+ } catch (e) {
601
+ }
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
+ }
608
+ };
609
+ }
610
+ });
611
+ }
612
+ var createStarProApp = defineStarProApp;
613
+
614
+ // src/react.tsx
615
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
616
+ function useStarProAuth() {
617
+ const [authState, setAuthState] = useState2(() => {
618
+ if (typeof window === "undefined") {
619
+ return {
620
+ accessToken: null,
621
+ refreshToken: null,
622
+ user: null,
623
+ isPlugin: false,
624
+ isLoading: true
625
+ };
626
+ }
627
+ const token = localStorage.getItem("accessToken") || localStorage.getItem("token");
628
+ const refresh = localStorage.getItem("refreshToken");
629
+ let userObj = null;
630
+ try {
631
+ const storedUser = localStorage.getItem("user");
632
+ if (storedUser) userObj = JSON.parse(storedUser);
633
+ } catch (e) {
634
+ }
635
+ return {
636
+ accessToken: token,
637
+ refreshToken: refresh,
638
+ user: userObj,
639
+ isPlugin: isStarProPlugin(),
640
+ isLoading: false
641
+ };
642
+ });
643
+ return authState;
644
+ }
645
+ var StarProPluginWrapper = ({
646
+ payload,
647
+ children,
648
+ banner = true
649
+ }) => {
650
+ const user = payload?.user;
651
+ return /* @__PURE__ */ jsxs2("div", { className: "starpro-plugin-root", children: [
652
+ banner && user && /* @__PURE__ */ jsxs2(
653
+ "div",
654
+ {
655
+ style: {
656
+ background: "#f0fdf4",
657
+ border: "1px solid #bbf7d0",
658
+ color: "#166534",
659
+ padding: "8px 14px",
660
+ fontSize: "12px",
661
+ borderRadius: "8px",
662
+ marginBottom: "16px",
663
+ display: "flex",
664
+ justifyContent: "space-between",
665
+ alignItems: "center",
666
+ fontFamily: "system-ui, -apple-system, sans-serif"
667
+ },
668
+ children: [
669
+ /* @__PURE__ */ jsxs2("span", { children: [
670
+ "\u2713 Terhubung ke StarPro sebagai: ",
671
+ /* @__PURE__ */ jsx3("strong", { children: user.name || user.email })
672
+ ] }),
673
+ /* @__PURE__ */ jsx3("span", { style: { fontSize: "11px", opacity: 0.8 }, children: "Login Otomatis Aktif" })
674
+ ]
675
+ }
676
+ ),
677
+ children
678
+ ] });
679
+ };
680
+
681
+ export {
682
+ setupStarProAuthBridge,
683
+ isStarProPlugin,
684
+ defineStarProPlugin,
685
+ matchRoute,
686
+ StarProRouter,
687
+ starproRouter,
688
+ useStarProRouter,
689
+ useStarProPathname,
690
+ useStarProSearchParams,
691
+ useStarProParams,
692
+ autoRoutesFromGlob,
693
+ StarProRedirectBoundary,
694
+ StarProRouterView,
695
+ useStarProAuth,
696
+ StarProPluginWrapper,
697
+ defineStarProApp,
698
+ createStarProApp
699
+ };
@@ -0,0 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ export {
9
+ __require
10
+ };