starpro-plugin-sdk 1.0.0 → 1.1.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 +63 -36
- package/dist/build/index.d.mts +87 -0
- package/dist/build/index.d.ts +87 -0
- package/dist/build/index.js +413 -0
- package/dist/build/index.mjs +380 -0
- package/dist/chunk-HFHUB6W5.mjs +677 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +725 -0
- package/dist/index.mjs +39 -0
- package/dist/react-DS5S7U6B.d.mts +280 -0
- package/dist/react-DS5S7U6B.d.ts +280 -0
- package/dist/react.d.mts +2 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +717 -0
- package/dist/react.mjs +33 -0
- package/package.json +17 -2
- package/src/bridge.ts +0 -94
- package/src/define-plugin.ts +0 -79
- package/src/index.ts +0 -6
- package/src/react.tsx +0 -94
- package/src/types.ts +0 -66
- package/tsconfig.json +0 -17
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StarProPluginWrapper,
|
|
3
|
+
StarProRedirectBoundary,
|
|
4
|
+
StarProRouter,
|
|
5
|
+
StarProRouterView,
|
|
6
|
+
autoRoutesFromGlob,
|
|
7
|
+
createStarProApp,
|
|
8
|
+
defineStarProApp,
|
|
9
|
+
matchRoute,
|
|
10
|
+
starproRouter,
|
|
11
|
+
useStarProAuth,
|
|
12
|
+
useStarProParams,
|
|
13
|
+
useStarProPathname,
|
|
14
|
+
useStarProRouter,
|
|
15
|
+
useStarProSearchParams
|
|
16
|
+
} from "./chunk-HFHUB6W5.mjs";
|
|
17
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
18
|
+
export {
|
|
19
|
+
StarProPluginWrapper,
|
|
20
|
+
StarProRedirectBoundary,
|
|
21
|
+
StarProRouter,
|
|
22
|
+
StarProRouterView,
|
|
23
|
+
autoRoutesFromGlob,
|
|
24
|
+
createStarProApp,
|
|
25
|
+
defineStarProApp,
|
|
26
|
+
matchRoute,
|
|
27
|
+
starproRouter,
|
|
28
|
+
useStarProAuth,
|
|
29
|
+
useStarProParams,
|
|
30
|
+
useStarProPathname,
|
|
31
|
+
useStarProRouter,
|
|
32
|
+
useStarProSearchParams
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpro-plugin-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -15,10 +15,20 @@
|
|
|
15
15
|
"types": "./dist/react.d.ts",
|
|
16
16
|
"import": "./dist/react.mjs",
|
|
17
17
|
"require": "./dist/react.js"
|
|
18
|
+
},
|
|
19
|
+
"./build": {
|
|
20
|
+
"types": "./dist/build/index.d.ts",
|
|
21
|
+
"import": "./dist/build/index.mjs",
|
|
22
|
+
"require": "./dist/build/index.js"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
20
28
|
"scripts": {
|
|
21
|
-
"build": "tsup src/index.ts src/react.tsx --dts --format cjs,esm --clean"
|
|
29
|
+
"build": "tsup src/index.ts src/react.tsx src/build/index.ts --dts --format cjs,esm --external esbuild --clean",
|
|
30
|
+
"test": "node test/test-sdk.js",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
22
32
|
},
|
|
23
33
|
"keywords": [
|
|
24
34
|
"starpro",
|
|
@@ -44,6 +54,11 @@
|
|
|
44
54
|
}
|
|
45
55
|
},
|
|
46
56
|
"devDependencies": {
|
|
57
|
+
"@types/node": "^26.6.6",
|
|
58
|
+
"@types/react": "^19.3.0",
|
|
59
|
+
"@types/react-dom": "^19.3.0",
|
|
60
|
+
"react": "^19.3.1",
|
|
61
|
+
"react-dom": "^19.3.1",
|
|
47
62
|
"tsup": "^8.3.5",
|
|
48
63
|
"typescript": "^5.0.0"
|
|
49
64
|
}
|
package/src/bridge.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { StarProAuthPayload } from "./types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Injects StarPro authentication tokens across all standard channels:
|
|
5
|
-
* - localStorage & sessionStorage
|
|
6
|
-
* - Global Axios default headers & interceptors
|
|
7
|
-
* - Browser native window.fetch() interceptor
|
|
8
|
-
*/
|
|
9
|
-
export function setupStarProAuthBridge(payload: StarProAuthPayload): void {
|
|
10
|
-
if (typeof window === "undefined") return;
|
|
11
|
-
|
|
12
|
-
const { accessToken, refreshToken, user } = payload || {};
|
|
13
|
-
if (!accessToken) return;
|
|
14
|
-
|
|
15
|
-
console.log("⚡ [StarPro Plugin SDK] Auto-syncing auth tokens across storage & HTTP clients...");
|
|
16
|
-
|
|
17
|
-
// 1. Storage Injection
|
|
18
|
-
const tokenKeys = ["accessToken", "access_token", "token", "starpro_token", "authToken"];
|
|
19
|
-
tokenKeys.forEach((key) => {
|
|
20
|
-
try {
|
|
21
|
-
localStorage.setItem(key, accessToken);
|
|
22
|
-
sessionStorage.setItem(key, accessToken);
|
|
23
|
-
} catch (e) {
|
|
24
|
-
// Ignore storage quota or access issues
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (refreshToken) {
|
|
29
|
-
try {
|
|
30
|
-
localStorage.setItem("refreshToken", refreshToken);
|
|
31
|
-
localStorage.setItem("refresh_token", refreshToken);
|
|
32
|
-
sessionStorage.setItem("refreshToken", refreshToken);
|
|
33
|
-
} catch (e) {}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (user) {
|
|
37
|
-
try {
|
|
38
|
-
localStorage.setItem("user", JSON.stringify(user));
|
|
39
|
-
localStorage.setItem("user_email", user.email || "");
|
|
40
|
-
} catch (e) {}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
localStorage.setItem("is_starpro_plugin", "true");
|
|
45
|
-
sessionStorage.setItem("is_starpro_plugin", "true");
|
|
46
|
-
} catch (e) {}
|
|
47
|
-
|
|
48
|
-
// 2. Global Axios Injection (if window.axios exists)
|
|
49
|
-
if (window.axios) {
|
|
50
|
-
try {
|
|
51
|
-
window.axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
|
|
52
|
-
} catch (e) {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 3. Global Native fetch() Interceptor
|
|
56
|
-
if (typeof window.fetch === "function") {
|
|
57
|
-
const originalFetch = window.fetch;
|
|
58
|
-
window.fetch = function (input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
59
|
-
const options: RequestInit = init || {};
|
|
60
|
-
options.headers = options.headers || {};
|
|
61
|
-
|
|
62
|
-
if (options.headers instanceof Headers) {
|
|
63
|
-
if (!options.headers.has("Authorization")) {
|
|
64
|
-
options.headers.set("Authorization", `Bearer ${accessToken}`);
|
|
65
|
-
}
|
|
66
|
-
} else if (Array.isArray(options.headers)) {
|
|
67
|
-
const hasAuth = options.headers.some(([k]) => k.toLowerCase() === "authorization");
|
|
68
|
-
if (!hasAuth) {
|
|
69
|
-
options.headers.push(["Authorization", `Bearer ${accessToken}`]);
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
const headersRecord = options.headers as Record<string, string>;
|
|
73
|
-
if (!headersRecord["Authorization"] && !headersRecord["authorization"]) {
|
|
74
|
-
headersRecord["Authorization"] = `Bearer ${accessToken}`;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return originalFetch.call(this, input, options);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Returns true if the current application is currently running as a StarPro plugin.
|
|
85
|
-
*/
|
|
86
|
-
export function isStarProPlugin(): boolean {
|
|
87
|
-
if (typeof window === "undefined") return false;
|
|
88
|
-
return (
|
|
89
|
-
localStorage.getItem("is_starpro_plugin") === "true" ||
|
|
90
|
-
sessionStorage.getItem("is_starpro_plugin") === "true" ||
|
|
91
|
-
Boolean(window.StarProPlugins)
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
package/src/define-plugin.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { DefinePluginOptions, StarProAuthPayload } from "./types";
|
|
2
|
-
import { setupStarProAuthBridge } from "./bridge";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Universal registration function to define a StarPro plugin in any JavaScript web.
|
|
6
|
-
* Supports React, Next.js, Vue, Svelte, and Vanilla JS.
|
|
7
|
-
*/
|
|
8
|
-
export function defineStarProPlugin(options: DefinePluginOptions): void {
|
|
9
|
-
if (typeof window === "undefined") return;
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
pluginId = "default",
|
|
13
|
-
onMount,
|
|
14
|
-
onUnmount,
|
|
15
|
-
autoInjectAuth = true,
|
|
16
|
-
} = options;
|
|
17
|
-
|
|
18
|
-
window.StarProPlugins = window.StarProPlugins || {};
|
|
19
|
-
|
|
20
|
-
const pluginModule = {
|
|
21
|
-
mount: function (
|
|
22
|
-
container: HTMLElement | string,
|
|
23
|
-
payload: StarProAuthPayload,
|
|
24
|
-
) {
|
|
25
|
-
const targetElement =
|
|
26
|
-
typeof container === "string"
|
|
27
|
-
? document.getElementById(container)
|
|
28
|
-
: container;
|
|
29
|
-
|
|
30
|
-
if (!targetElement) {
|
|
31
|
-
console.error(
|
|
32
|
-
`[StarPro Plugin: ${pluginId}] Target container element not found!`,
|
|
33
|
-
);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Automatically setup bridge & inject tokens if enabled
|
|
38
|
-
if (autoInjectAuth) {
|
|
39
|
-
setupStarProAuthBridge(payload);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Execute user mount function
|
|
43
|
-
let cleanup: (() => void) | void = undefined;
|
|
44
|
-
if (typeof onMount === "function") {
|
|
45
|
-
cleanup = onMount(targetElement, payload);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Return cleanup function for StarPro to call when unmounting
|
|
49
|
-
return function unmount() {
|
|
50
|
-
if (typeof cleanup === "function") {
|
|
51
|
-
try {
|
|
52
|
-
cleanup();
|
|
53
|
-
} catch (err) {
|
|
54
|
-
console.warn(`[StarPro Plugin: ${pluginId}] Error in cleanup:`, err);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (typeof onUnmount === "function") {
|
|
58
|
-
try {
|
|
59
|
-
onUnmount();
|
|
60
|
-
} catch (err) {
|
|
61
|
-
console.warn(
|
|
62
|
-
`[StarPro Plugin: ${pluginId}] Error in onUnmount:`,
|
|
63
|
-
err,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
targetElement.innerHTML = "";
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Register under specific plugin ID and default fallback
|
|
73
|
-
window.StarProPlugins[pluginId] = pluginModule;
|
|
74
|
-
window.StarProPlugins["default"] = pluginModule;
|
|
75
|
-
window.mountStarProPlugin = pluginModule.mount;
|
|
76
|
-
|
|
77
|
-
console.log(`✓ [StarPro Plugin SDK] Registered plugin "${pluginId}"`);
|
|
78
|
-
}
|
|
79
|
-
|
package/src/index.ts
DELETED
package/src/react.tsx
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
|
2
|
-
import { StarProAuthPayload, StarProUser } from "./types";
|
|
3
|
-
import { isStarProPlugin } from "./bridge";
|
|
4
|
-
|
|
5
|
-
export interface StarProAuthState {
|
|
6
|
-
accessToken: string | null;
|
|
7
|
-
refreshToken: string | null;
|
|
8
|
-
user: StarProUser | null;
|
|
9
|
-
isPlugin: boolean;
|
|
10
|
-
isLoading: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* React Hook to access StarPro authentication state anywhere in your React/Next.js app.
|
|
15
|
-
*/
|
|
16
|
-
export function useStarProAuth(): StarProAuthState {
|
|
17
|
-
const [authState, setAuthState] = useState<StarProAuthState>(() => {
|
|
18
|
-
if (typeof window === "undefined") {
|
|
19
|
-
return {
|
|
20
|
-
accessToken: null,
|
|
21
|
-
refreshToken: null,
|
|
22
|
-
user: null,
|
|
23
|
-
isPlugin: false,
|
|
24
|
-
isLoading: true,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const token = localStorage.getItem("accessToken") || localStorage.getItem("token");
|
|
29
|
-
const refresh = localStorage.getItem("refreshToken");
|
|
30
|
-
let userObj: StarProUser | null = null;
|
|
31
|
-
try {
|
|
32
|
-
const storedUser = localStorage.getItem("user");
|
|
33
|
-
if (storedUser) userObj = JSON.parse(storedUser);
|
|
34
|
-
} catch (e) {}
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
accessToken: token,
|
|
38
|
-
refreshToken: refresh,
|
|
39
|
-
user: userObj,
|
|
40
|
-
isPlugin: isStarProPlugin(),
|
|
41
|
-
isLoading: false,
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return authState;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface StarProPluginWrapperProps {
|
|
49
|
-
payload?: StarProAuthPayload;
|
|
50
|
-
children: React.ReactNode;
|
|
51
|
-
fallback?: React.ReactNode;
|
|
52
|
-
banner?: boolean;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* React Wrapper Component that handles auto-bypass of the login screen.
|
|
57
|
-
* Displays a connected banner and directly renders your main dashboard component.
|
|
58
|
-
*/
|
|
59
|
-
export const StarProPluginWrapper: React.FC<StarProPluginWrapperProps> = ({
|
|
60
|
-
payload,
|
|
61
|
-
children,
|
|
62
|
-
banner = true,
|
|
63
|
-
}) => {
|
|
64
|
-
const user = payload?.user;
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<div className="starpro-plugin-root">
|
|
68
|
-
{banner && user && (
|
|
69
|
-
<div
|
|
70
|
-
style={{
|
|
71
|
-
background: "#f0fdf4",
|
|
72
|
-
border: "1px solid #bbf7d0",
|
|
73
|
-
color: "#166534",
|
|
74
|
-
padding: "8px 14px",
|
|
75
|
-
fontSize: "12px",
|
|
76
|
-
borderRadius: "8px",
|
|
77
|
-
marginBottom: "16px",
|
|
78
|
-
display: "flex",
|
|
79
|
-
justifyContent: "space-between",
|
|
80
|
-
alignItems: "center",
|
|
81
|
-
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
82
|
-
}}
|
|
83
|
-
>
|
|
84
|
-
<span>
|
|
85
|
-
✓ Terhubung ke StarPro sebagai: <strong>{user.name || user.email}</strong>
|
|
86
|
-
</span>
|
|
87
|
-
<span style={{ fontSize: "11px", opacity: 0.8 }}>Login Otomatis Aktif</span>
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
90
|
-
{children}
|
|
91
|
-
</div>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
package/src/types.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export interface StarProUser {
|
|
2
|
-
name?: string | null;
|
|
3
|
-
email?: string | null;
|
|
4
|
-
id?: string | null;
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface StarProAuthPayload {
|
|
9
|
-
accessToken: string;
|
|
10
|
-
refreshToken?: string;
|
|
11
|
-
user?: StarProUser;
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type MountCleanupFn = () => void;
|
|
16
|
-
|
|
17
|
-
export type PluginMountHandler = (
|
|
18
|
-
container: HTMLElement,
|
|
19
|
-
payload: StarProAuthPayload,
|
|
20
|
-
) => MountCleanupFn | void;
|
|
21
|
-
|
|
22
|
-
export interface DefinePluginOptions {
|
|
23
|
-
/**
|
|
24
|
-
* The identifier for this plugin (e.g. "star-tenant-access" or "subkon-progress").
|
|
25
|
-
* Defaults to "default".
|
|
26
|
-
*/
|
|
27
|
-
pluginId?: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Callback executed when StarPro mounts the plugin.
|
|
31
|
-
* Receives target DOM element and the authentication payload.
|
|
32
|
-
* Return an optional cleanup function to be called on unmount.
|
|
33
|
-
*/
|
|
34
|
-
onMount: PluginMountHandler;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Optional callback executed when StarPro unmounts the plugin.
|
|
38
|
-
*/
|
|
39
|
-
onUnmount?: () => void;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Whether to automatically inject auth tokens into localStorage, sessionStorage,
|
|
43
|
-
* Axios defaults, and native fetch() calls. Defaults to true.
|
|
44
|
-
*/
|
|
45
|
-
autoInjectAuth?: boolean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
declare global {
|
|
49
|
-
interface Window {
|
|
50
|
-
StarProPlugins?: Record<
|
|
51
|
-
string,
|
|
52
|
-
{
|
|
53
|
-
mount: (
|
|
54
|
-
container: HTMLElement | string,
|
|
55
|
-
payload: StarProAuthPayload,
|
|
56
|
-
) => MountCleanupFn | void;
|
|
57
|
-
}
|
|
58
|
-
>;
|
|
59
|
-
mountStarProPlugin?: (
|
|
60
|
-
container: HTMLElement | string,
|
|
61
|
-
payload: StarProAuthPayload,
|
|
62
|
-
) => MountCleanupFn | void;
|
|
63
|
-
axios?: any;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"outDir": "./dist"
|
|
14
|
-
},
|
|
15
|
-
"include": ["src/**/*"]
|
|
16
|
-
}
|
|
17
|
-
|