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/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
|
|
|
@@ -15,57 +15,72 @@ yarn add starpro-plugin-sdk
|
|
|
15
15
|
|
|
16
16
|
# Menggunakan pnpm
|
|
17
17
|
pnpm add starpro-plugin-sdk
|
|
18
|
-
|
|
19
|
-
# Atau langsung dari repository Git internal:
|
|
20
|
-
npm install git+https://github.com/suryacipta/starpro-plugin-sdk.git
|
|
21
18
|
```
|
|
22
19
|
|
|
23
20
|
---
|
|
24
21
|
|
|
25
22
|
## 🛠️ Cara Penggunaan di Proyek Anda
|
|
26
23
|
|
|
27
|
-
### 1. Di Aplikasi Next.js / React
|
|
24
|
+
### 1. Di Aplikasi Next.js / React (Cukup 8 Baris!)
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
Anda **tidak perlu** mengimpor halaman satu per satu ataupun menuliskan daftar route yang panjang. Cukup buat file `src/plugin-entry.tsx`:
|
|
30
27
|
|
|
31
28
|
```tsx
|
|
32
|
-
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
// src/plugin-entry.tsx
|
|
30
|
+
import { defineStarProApp } from "starpro-plugin-sdk";
|
|
31
|
+
|
|
32
|
+
defineStarProApp({
|
|
33
|
+
pluginId: "star-tenant-access",
|
|
34
|
+
defaultRoute: "/dashboard", // Rute awal yang dibuka saat plugin dimuat
|
|
35
|
+
title: "Tenant Access",
|
|
36
|
+
badge: "STA",
|
|
37
|
+
themeColor: "#059669",
|
|
38
|
+
});
|
|
39
|
+
```
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
root.unmount();
|
|
53
|
-
};
|
|
54
|
-
},
|
|
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",
|
|
55
56
|
});
|
|
56
57
|
```
|
|
57
58
|
|
|
58
|
-
|
|
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:
|
|
59
72
|
|
|
60
73
|
```tsx
|
|
61
|
-
import { useStarProAuth } from "starpro-plugin-sdk";
|
|
74
|
+
import { useStarProAuth, useStarProRouter } from "starpro-plugin-sdk";
|
|
62
75
|
|
|
63
76
|
export function ProfileWidget() {
|
|
64
77
|
const { accessToken, user, isPlugin } = useStarProAuth();
|
|
78
|
+
const router = useStarProRouter();
|
|
65
79
|
|
|
66
80
|
return (
|
|
67
81
|
<div>
|
|
68
82
|
{isPlugin && <p>Berjalan di StarPro sebagai: {user?.email}</p>}
|
|
83
|
+
<button onClick={() => router.push("/dashboard")}>Ke Dashboard</button>
|
|
69
84
|
</div>
|
|
70
85
|
);
|
|
71
86
|
}
|
|
@@ -73,7 +88,7 @@ export function ProfileWidget() {
|
|
|
73
88
|
|
|
74
89
|
---
|
|
75
90
|
|
|
76
|
-
###
|
|
91
|
+
### 4. Di Aplikasi Vue.js
|
|
77
92
|
|
|
78
93
|
```javascript
|
|
79
94
|
import { createApp } from "vue";
|
|
@@ -92,7 +107,7 @@ defineStarProPlugin({
|
|
|
92
107
|
|
|
93
108
|
---
|
|
94
109
|
|
|
95
|
-
###
|
|
110
|
+
### 5. Di Vanilla JavaScript / HTML
|
|
96
111
|
|
|
97
112
|
```javascript
|
|
98
113
|
import { defineStarProPlugin } from "starpro-plugin-sdk";
|
|
@@ -107,8 +122,20 @@ defineStarProPlugin({
|
|
|
107
122
|
|
|
108
123
|
---
|
|
109
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
|
+
|
|
110
134
|
## ⚙️ Fitur yang Dijalankan Otomatis oleh SDK:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
|
|
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 };
|