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.
- package/README.md +65 -34
- package/dist/build/index.d.mts +87 -0
- package/dist/build/index.d.ts +87 -0
- package/dist/build/index.js +474 -0
- package/dist/build/index.mjs +441 -0
- package/dist/chunk-4C5LPF23.mjs +699 -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 +747 -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 +739 -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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# StarPro Plugin SDK (`starpro-plugin-sdk`)
|
|
2
2
|
|
|
3
|
-
SDK resmi untuk mengubah aplikasi web apa pun (**Next.js**, **React**, **Vue**, **Svelte**, atau **JavaScript biasa**) menjadi **Plugin Native StarPro (No-Iframe)** dengan sinkronisasi token autentikasi
|
|
3
|
+
SDK resmi untuk mengubah aplikasi web apa pun (**Next.js**, **React**, **Vue**, **Svelte**, atau **JavaScript biasa**) menjadi **Plugin Native StarPro (No-Iframe)** dengan sinkronisasi token autentikasi, auto-bypass login, dan **Auto Route & Redirect Discovery**.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -21,54 +21,74 @@ pnpm add starpro-plugin-sdk
|
|
|
21
21
|
|
|
22
22
|
## 🛠️ Cara Penggunaan di Proyek Anda
|
|
23
23
|
|
|
24
|
-
### 1. Di Aplikasi Next.js / React
|
|
24
|
+
### 1. Di Aplikasi Next.js / React (Cukup 8 Baris!)
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Anda **tidak perlu** mengimpor halaman satu per satu ataupun menuliskan daftar route yang panjang. Cukup buat file `src/plugin-entry.tsx`:
|
|
27
27
|
|
|
28
28
|
```tsx
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// src/plugin-entry.tsx
|
|
30
|
+
import { defineStarProApp } from "starpro-plugin-sdk";
|
|
31
|
+
|
|
32
|
+
defineStarProApp({
|
|
33
|
+
pluginId: "star-tenant-access", // UUID Plugin (bebas apa saja asal tidak ada yg sama)
|
|
34
|
+
defaultRoute: "/dashboard", // Rute awal yang dibuka saat plugin dimuat
|
|
35
|
+
title: "Tenant Access", // Judul Plugin
|
|
36
|
+
badge: "STA", // Singkatan Plugin
|
|
37
|
+
themeColor: "#059669", // Warna Theme Plugin
|
|
38
|
+
});
|
|
39
|
+
```
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
root.unmount();
|
|
50
|
-
};
|
|
51
|
-
},
|
|
41
|
+
_Semua file `page.tsx` di `src/app/**/page.tsx` akan otomatis dideteksi, route groups seperti `(app)` otomatis dibersihkan, dan navigasi redirect Next.js otomatis diikuti tanpa konfigurasi manual!_
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
### 2. Script Build Plugin (`build-plugin.js`)
|
|
46
|
+
|
|
47
|
+
Simpan file `build-plugin.js` di root folder proyek web Anda:
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// build-plugin.js
|
|
51
|
+
const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
52
|
+
|
|
53
|
+
buildStarProPlugin({
|
|
54
|
+
entry: "src/plugin-entry.tsx",
|
|
55
|
+
out: "public/plugin.js",
|
|
52
56
|
});
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
Lalu jalankan di terminal:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
node build-plugin.js
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
File `public/plugin.js` siap disajikan dan ditempelkan ke StarPro!
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### 3. Mengakses Autentikasi & Router di Komponen
|
|
70
|
+
|
|
71
|
+
Di dalam komponen React apa pun pada aplikasi Anda:
|
|
56
72
|
|
|
57
73
|
```tsx
|
|
58
|
-
import { useStarProAuth } from "starpro-plugin-sdk";
|
|
74
|
+
import { useStarProAuth, useStarProRouter } from "starpro-plugin-sdk";
|
|
59
75
|
|
|
60
76
|
export function ProfileWidget() {
|
|
61
77
|
const { accessToken, user, isPlugin } = useStarProAuth();
|
|
78
|
+
const router = useStarProRouter();
|
|
62
79
|
|
|
63
80
|
return (
|
|
64
|
-
<div>
|
|
81
|
+
<div>
|
|
82
|
+
{isPlugin && <p>Berjalan di StarPro sebagai: {user?.email}</p>}
|
|
83
|
+
<button onClick={() => router.push("/dashboard")}>Ke Dashboard</button>
|
|
84
|
+
</div>
|
|
65
85
|
);
|
|
66
86
|
}
|
|
67
87
|
```
|
|
68
88
|
|
|
69
89
|
---
|
|
70
90
|
|
|
71
|
-
###
|
|
91
|
+
### 4. Di Aplikasi Vue.js
|
|
72
92
|
|
|
73
93
|
```javascript
|
|
74
94
|
import { createApp } from "vue";
|
|
@@ -87,7 +107,7 @@ defineStarProPlugin({
|
|
|
87
107
|
|
|
88
108
|
---
|
|
89
109
|
|
|
90
|
-
###
|
|
110
|
+
### 5. Di Vanilla JavaScript / HTML
|
|
91
111
|
|
|
92
112
|
```javascript
|
|
93
113
|
import { defineStarProPlugin } from "starpro-plugin-sdk";
|
|
@@ -102,9 +122,20 @@ defineStarProPlugin({
|
|
|
102
122
|
|
|
103
123
|
---
|
|
104
124
|
|
|
125
|
+
## 6. Mendaftarkan Plugin ke StarPro
|
|
126
|
+
|
|
127
|
+
1. Buka aplikasi **StarPro** -> Buka menu **Plugin**.
|
|
128
|
+
2. Klik **`+ Tambah Plugin`**.
|
|
129
|
+
3. Isi formulir:
|
|
130
|
+
- **Nama**: _Star Tenant Access_
|
|
131
|
+
- **URL**: `https://startenantaccess.suryacipta.app/plugin.js` (atau `http://localhost:3001/plugin.js` saat pengujian lokal).
|
|
132
|
+
4. Klik **Simpan**. Web Anda akan langsung muncul dan berjalan secara native di StarPro tanpa iframe dan tanpa perlu deklarasi route manual!
|
|
133
|
+
|
|
105
134
|
## ⚙️ Fitur yang Dijalankan Otomatis oleh SDK:
|
|
106
135
|
|
|
107
|
-
1. **Auto
|
|
108
|
-
2. **Auto
|
|
109
|
-
3. **Auto
|
|
110
|
-
4. **Auto
|
|
136
|
+
1. **Auto Route & View Discovery**: Otomatis mendeteksi view/page di `src/app` tanpa deklarasi manual satu per satu.
|
|
137
|
+
2. **Auto Follow Redirect**: Otomatis menangani panggilan `redirect()` dan navigasi router Next.js tanpa error React lifecycle.
|
|
138
|
+
3. **Auto Storage Sync**: Menyimpan `accessToken` dan `refreshToken` ke `localStorage` dan `sessionStorage`.
|
|
139
|
+
4. **Auto Axios Interceptor**: Menyuntikkan `Authorization: Bearer <accessToken>` ke semua request Axios.
|
|
140
|
+
5. **Auto Fetch Interceptor**: Menyuntikkan header `Authorization` ke fungsi `fetch()` native browser.
|
|
141
|
+
6. **Auto-Bypass Flag**: Menyimpan flag `is_starpro_plugin: true` agar halaman login di-bypass otomatis.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
interface StarProEsbuildPluginOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Root folder containing the Next.js / React app pages.
|
|
4
|
+
* Defaults to auto-detecting "src/app", "app", "src/pages", or "pages".
|
|
5
|
+
*/
|
|
6
|
+
appDir?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Base working directory of the project. Defaults to `process.cwd()`.
|
|
9
|
+
*/
|
|
10
|
+
cwd?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to mock Next.js built-ins (`next/navigation`, `next/link`, `next/image`, `next/router`).
|
|
13
|
+
* Defaults to true.
|
|
14
|
+
*/
|
|
15
|
+
mockNext?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to strip route group directories (folders in parentheses e.g. `(app)`, `(auth)`).
|
|
18
|
+
* Defaults to true.
|
|
19
|
+
*/
|
|
20
|
+
stripRouteGroups?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface BuildStarProPluginOptions extends StarProEsbuildPluginOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Entry point file. Defaults to "src/plugin-entry.tsx" or "src/plugin-entry.ts".
|
|
25
|
+
*/
|
|
26
|
+
entry?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Destination output file path. Defaults to "public/plugin.js".
|
|
29
|
+
*/
|
|
30
|
+
out?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to minify the output bundle. Defaults to true.
|
|
33
|
+
*/
|
|
34
|
+
minify?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Environment mode (development / production). Defaults to `process.env.NODE_ENV || "production"`.
|
|
37
|
+
*/
|
|
38
|
+
env?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Additional environment variables or defines.
|
|
41
|
+
*/
|
|
42
|
+
define?: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* Additional esbuild plugins.
|
|
45
|
+
*/
|
|
46
|
+
plugins?: any[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Automatically discovers all page routes and layouts in an app directory.
|
|
50
|
+
*/
|
|
51
|
+
declare function discoverRoutes(appDir: string, options?: {
|
|
52
|
+
stripRouteGroups?: boolean;
|
|
53
|
+
}): {
|
|
54
|
+
routes: {
|
|
55
|
+
filePath: string;
|
|
56
|
+
routePath: string;
|
|
57
|
+
label?: string;
|
|
58
|
+
}[];
|
|
59
|
+
layoutFile: string | null;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Universal esbuild plugin for StarPro:
|
|
63
|
+
* 1. Automatically discovers all views in `src/app` and generates the `starpro:routes` module.
|
|
64
|
+
* 2. Mocks Next.js navigation, router, links, and image components.
|
|
65
|
+
* 3. Safely traps and forwards Next.js `redirect()` calls to the StarPro router.
|
|
66
|
+
*/
|
|
67
|
+
declare function starproEsbuildPlugin(options?: StarProEsbuildPluginOptions): {
|
|
68
|
+
name: string;
|
|
69
|
+
setup(build: any): void;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Complete, turnkey build function to compile a StarPro plugin into `public/plugin.js`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```javascript
|
|
76
|
+
* // build-plugin.js
|
|
77
|
+
* const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
78
|
+
*
|
|
79
|
+
* buildStarProPlugin({
|
|
80
|
+
* entry: "src/plugin-entry.tsx",
|
|
81
|
+
* out: "public/plugin.js",
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function buildStarProPlugin(options?: BuildStarProPluginOptions): Promise<any>;
|
|
86
|
+
|
|
87
|
+
export { type BuildStarProPluginOptions, type StarProEsbuildPluginOptions, buildStarProPlugin, discoverRoutes, starproEsbuildPlugin };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
interface StarProEsbuildPluginOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Root folder containing the Next.js / React app pages.
|
|
4
|
+
* Defaults to auto-detecting "src/app", "app", "src/pages", or "pages".
|
|
5
|
+
*/
|
|
6
|
+
appDir?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Base working directory of the project. Defaults to `process.cwd()`.
|
|
9
|
+
*/
|
|
10
|
+
cwd?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to mock Next.js built-ins (`next/navigation`, `next/link`, `next/image`, `next/router`).
|
|
13
|
+
* Defaults to true.
|
|
14
|
+
*/
|
|
15
|
+
mockNext?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to strip route group directories (folders in parentheses e.g. `(app)`, `(auth)`).
|
|
18
|
+
* Defaults to true.
|
|
19
|
+
*/
|
|
20
|
+
stripRouteGroups?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface BuildStarProPluginOptions extends StarProEsbuildPluginOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Entry point file. Defaults to "src/plugin-entry.tsx" or "src/plugin-entry.ts".
|
|
25
|
+
*/
|
|
26
|
+
entry?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Destination output file path. Defaults to "public/plugin.js".
|
|
29
|
+
*/
|
|
30
|
+
out?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to minify the output bundle. Defaults to true.
|
|
33
|
+
*/
|
|
34
|
+
minify?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Environment mode (development / production). Defaults to `process.env.NODE_ENV || "production"`.
|
|
37
|
+
*/
|
|
38
|
+
env?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Additional environment variables or defines.
|
|
41
|
+
*/
|
|
42
|
+
define?: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* Additional esbuild plugins.
|
|
45
|
+
*/
|
|
46
|
+
plugins?: any[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Automatically discovers all page routes and layouts in an app directory.
|
|
50
|
+
*/
|
|
51
|
+
declare function discoverRoutes(appDir: string, options?: {
|
|
52
|
+
stripRouteGroups?: boolean;
|
|
53
|
+
}): {
|
|
54
|
+
routes: {
|
|
55
|
+
filePath: string;
|
|
56
|
+
routePath: string;
|
|
57
|
+
label?: string;
|
|
58
|
+
}[];
|
|
59
|
+
layoutFile: string | null;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Universal esbuild plugin for StarPro:
|
|
63
|
+
* 1. Automatically discovers all views in `src/app` and generates the `starpro:routes` module.
|
|
64
|
+
* 2. Mocks Next.js navigation, router, links, and image components.
|
|
65
|
+
* 3. Safely traps and forwards Next.js `redirect()` calls to the StarPro router.
|
|
66
|
+
*/
|
|
67
|
+
declare function starproEsbuildPlugin(options?: StarProEsbuildPluginOptions): {
|
|
68
|
+
name: string;
|
|
69
|
+
setup(build: any): void;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Complete, turnkey build function to compile a StarPro plugin into `public/plugin.js`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```javascript
|
|
76
|
+
* // build-plugin.js
|
|
77
|
+
* const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
78
|
+
*
|
|
79
|
+
* buildStarProPlugin({
|
|
80
|
+
* entry: "src/plugin-entry.tsx",
|
|
81
|
+
* out: "public/plugin.js",
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function buildStarProPlugin(options?: BuildStarProPluginOptions): Promise<any>;
|
|
86
|
+
|
|
87
|
+
export { type BuildStarProPluginOptions, type StarProEsbuildPluginOptions, buildStarProPlugin, discoverRoutes, starproEsbuildPlugin };
|