@metagptx/web-sdk 0.0.49 → 0.0.51
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 +169 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# FuncSea WebSDK
|
|
2
2
|
|
|
3
|
-
A TypeScript SDK for interacting with FuncSea API, providing modules for authentication, entity management, API calls, and
|
|
3
|
+
A TypeScript SDK for interacting with FuncSea API, providing modules for authentication, entity management, API calls, integrations, and a Vite plugin for automatic 404 page setup.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -14,6 +14,8 @@ yarn add @metagptx/web-sdk
|
|
|
14
14
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
17
19
|
```typescript
|
|
18
20
|
import { createClient } from '@metagptx/web-sdk';
|
|
19
21
|
|
|
@@ -24,9 +26,27 @@ const client = createClient();
|
|
|
24
26
|
const user = await client.auth.me();
|
|
25
27
|
```
|
|
26
28
|
|
|
29
|
+
### Using the Vite Plugin
|
|
30
|
+
|
|
31
|
+
If you're using Vite with React Router, you can use the included plugin to automatically add a 404 page:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// vite.config.ts
|
|
35
|
+
import { defineConfig } from 'vite';
|
|
36
|
+
import react from '@vitejs/plugin-react';
|
|
37
|
+
import { vitePlugin404 } from '@metagptx/web-sdk';
|
|
38
|
+
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
plugins: [
|
|
41
|
+
react(),
|
|
42
|
+
vitePlugin404(), // Automatically adds 404 page to your routes
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
27
47
|
## Modules
|
|
28
48
|
|
|
29
|
-
The SDK provides six main modules:
|
|
49
|
+
The SDK provides six main modules and a Vite plugin:
|
|
30
50
|
|
|
31
51
|
- **auth**: User authentication operations
|
|
32
52
|
- **entities**: Dynamic entity CRUD operations
|
|
@@ -34,6 +54,7 @@ The SDK provides six main modules:
|
|
|
34
54
|
- **integrations**: Integration function invocations
|
|
35
55
|
- **frame**: Frame communication operations for iframe/parent window messaging
|
|
36
56
|
- **utils**: Utility functions for URL opening and window management
|
|
57
|
+
- **vitePlugin404**: Vite plugin for automatically adding a 404 page to React Router applications
|
|
37
58
|
|
|
38
59
|
## API Reference
|
|
39
60
|
|
|
@@ -598,6 +619,117 @@ The SDK automatically handles 401 (Unauthorized) responses by redirecting to the
|
|
|
598
619
|
|
|
599
620
|
---
|
|
600
621
|
|
|
622
|
+
## Vite Plugin
|
|
623
|
+
|
|
624
|
+
The SDK provides a Vite plugin for automatically adding a 404 page to your React Router application.
|
|
625
|
+
|
|
626
|
+
### `vitePlugin404()`
|
|
627
|
+
|
|
628
|
+
A Vite plugin that automatically creates a virtual 404 React component and adds it to your routing configuration.
|
|
629
|
+
|
|
630
|
+
**Features:**
|
|
631
|
+
- Automatically creates a beautiful 404 page component
|
|
632
|
+
- Automatically adds a wildcard route (`path="*"`) to your `App.tsx`
|
|
633
|
+
- Detects if already configured (won't duplicate routes)
|
|
634
|
+
- Works seamlessly with React Router
|
|
635
|
+
- Provides "Create page" functionality when running in MGX iframe
|
|
636
|
+
|
|
637
|
+
**Setup:**
|
|
638
|
+
|
|
639
|
+
1. Import the plugin in your `vite.config.ts`:
|
|
640
|
+
|
|
641
|
+
```typescript
|
|
642
|
+
import { defineConfig } from 'vite';
|
|
643
|
+
import react from '@vitejs/plugin-react';
|
|
644
|
+
import { vitePlugin404 } from '@metagptx/web-sdk';
|
|
645
|
+
|
|
646
|
+
export default defineConfig({
|
|
647
|
+
plugins: [
|
|
648
|
+
react(),
|
|
649
|
+
vitePlugin404(), // Add the plugin
|
|
650
|
+
],
|
|
651
|
+
});
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
2. The plugin will automatically:
|
|
655
|
+
- Create a virtual `NotFoundPage` component
|
|
656
|
+
- Add the import statement to your `App.tsx`
|
|
657
|
+
- Add a `<Route path="*" element={<NotFoundPage />} />` route
|
|
658
|
+
|
|
659
|
+
**Requirements:**
|
|
660
|
+
|
|
661
|
+
- Your project must have an `App.tsx` file (or any file containing `App.tsx` in the path)
|
|
662
|
+
- Your project must use React Router with `<Routes>` component
|
|
663
|
+
- Your project should have `@/components/ui/button` component (or adjust the import in the plugin code)
|
|
664
|
+
|
|
665
|
+
**How it works:**
|
|
666
|
+
|
|
667
|
+
The plugin uses multiple strategies to intelligently add the 404 route:
|
|
668
|
+
|
|
669
|
+
1. **Import placement strategies:**
|
|
670
|
+
- After `AuthError` import (if exists)
|
|
671
|
+
- After `MODULE_IMPORTS_END` comment (if exists)
|
|
672
|
+
- Before `MODULE_IMPORTS_START` comment (if exists)
|
|
673
|
+
- After the last import statement (fallback)
|
|
674
|
+
|
|
675
|
+
2. **Route placement strategies:**
|
|
676
|
+
- Before `MODULE_ROUTES_END` comment (if exists)
|
|
677
|
+
- Before closing `</Routes>` tag
|
|
678
|
+
- After the last `<Route>` tag (fallback)
|
|
679
|
+
|
|
680
|
+
**Example - Before plugin:**
|
|
681
|
+
|
|
682
|
+
```tsx
|
|
683
|
+
// App.tsx
|
|
684
|
+
import { Route, Routes } from 'react-router-dom';
|
|
685
|
+
|
|
686
|
+
export default function App() {
|
|
687
|
+
return (
|
|
688
|
+
<Routes>
|
|
689
|
+
<Route path="/" element={<Home />} />
|
|
690
|
+
<Route path="/about" element={<About />} />
|
|
691
|
+
</Routes>
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
**Example - After plugin (automatically transformed):**
|
|
697
|
+
|
|
698
|
+
```tsx
|
|
699
|
+
// App.tsx
|
|
700
|
+
import { Route, Routes } from 'react-router-dom';
|
|
701
|
+
import NotFoundPage from 'virtual:404-page';
|
|
702
|
+
|
|
703
|
+
export default function App() {
|
|
704
|
+
return (
|
|
705
|
+
<Routes>
|
|
706
|
+
<Route path="/" element={<Home />} />
|
|
707
|
+
<Route path="/about" element={<About />} />
|
|
708
|
+
<Route path="*" element={<NotFoundPage />} />
|
|
709
|
+
</Routes>
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
**404 Page Features:**
|
|
715
|
+
|
|
716
|
+
The generated 404 page includes:
|
|
717
|
+
- Modern, responsive design with gradient background
|
|
718
|
+
- "Return Home" button
|
|
719
|
+
- "Create page" button (when running in MGX iframe) - uses `client.frame.createPage()`
|
|
720
|
+
- "Go to MGX" button (when not in iframe)
|
|
721
|
+
|
|
722
|
+
**Customization:**
|
|
723
|
+
|
|
724
|
+
If you need to customize the 404 page, you can:
|
|
725
|
+
1. Create your own 404 component
|
|
726
|
+
2. Import it manually in `App.tsx`
|
|
727
|
+
3. The plugin will detect existing 404 routes and skip automatic addition
|
|
728
|
+
|
|
729
|
+
**Note:** The plugin only processes files that contain `App.tsx` in their path and end with `.tsx`. It will skip files that already have a 404 route configured.
|
|
730
|
+
|
|
731
|
+
---
|
|
732
|
+
|
|
601
733
|
## TypeScript Support
|
|
602
734
|
|
|
603
735
|
The SDK is written in TypeScript and provides full type definitions. You can use generic types for typed responses:
|
|
@@ -636,3 +768,38 @@ try {
|
|
|
636
768
|
}
|
|
637
769
|
}
|
|
638
770
|
```
|
|
771
|
+
|
|
772
|
+
---
|
|
773
|
+
|
|
774
|
+
## Exports
|
|
775
|
+
|
|
776
|
+
The SDK exports the following:
|
|
777
|
+
|
|
778
|
+
### Main Exports
|
|
779
|
+
|
|
780
|
+
```typescript
|
|
781
|
+
import { createClient, vitePlugin404 } from '@metagptx/web-sdk';
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
- **`createClient(config?)`**: Creates a new SDK client instance
|
|
785
|
+
- **`vitePlugin404()`**: Vite plugin for automatic 404 page setup
|
|
786
|
+
|
|
787
|
+
### Type Exports
|
|
788
|
+
|
|
789
|
+
```typescript
|
|
790
|
+
import type {
|
|
791
|
+
AnyType,
|
|
792
|
+
ApiCallParams,
|
|
793
|
+
ClientConfig,
|
|
794
|
+
IntegrationFunction,
|
|
795
|
+
IntegrationParams,
|
|
796
|
+
RequestConfig,
|
|
797
|
+
} from '@metagptx/web-sdk';
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
- **`ClientConfig`**: Configuration options for `createClient()`
|
|
801
|
+
- **`ApiCallParams`**: Parameters for `apiCall.invoke()`
|
|
802
|
+
- **`IntegrationFunction`**: Type for integration functions
|
|
803
|
+
- **`IntegrationParams`**: Parameters for integration function calls
|
|
804
|
+
- **`RequestConfig`**: Axios request configuration options
|
|
805
|
+
- **`AnyType`**: Generic type utility
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metagptx/web-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.51",
|
|
5
5
|
"packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
|
|
6
6
|
"description": "TypeScript SDK for interacting with FuncSea API",
|
|
7
7
|
"author": "MetaGPTX",
|