@metagptx/web-sdk 0.0.23 → 0.0.24-beta.1

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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as axios0 from "axios";
2
2
  import { AxiosRequestConfig } from "axios";
3
+ import { Plugin } from "vite";
3
4
 
4
5
  //#region src/utils/request.d.ts
5
6
  /**
@@ -168,6 +169,19 @@ type IntegrationFunction = (params?: IntegrationParams) => Promise<AnyType>;
168
169
  * @param params.requestInstance - Axios instance for making HTTP requests
169
170
  * @returns Proxy object that dynamically creates integration calls
170
171
  */
171
-
172
172
  //#endregion
173
- export { type AnyType, type ApiCallParams, type ClientConfig, type DefaultFrameMessageTypes, type FrameMessageData, type FrameMessageType, type FrameMessageTypes, type IntegrationFunction, type IntegrationParams, type PostMessageOptions, type RequestConfig, createClient };
173
+ //#region src/plugins/vite-default-routes-plugins.d.ts
174
+ interface RouteConfig {
175
+ path: string;
176
+ componentName: string;
177
+ componentCode: string;
178
+ }
179
+ interface PluginOptions {
180
+ routes?: RouteConfig[];
181
+ }
182
+ /**
183
+ * Vite plugin to automatically create routes
184
+ */
185
+ declare function vitePluginPlayground(options?: PluginOptions): Plugin;
186
+ //#endregion
187
+ export { type AnyType, type ApiCallParams, type ClientConfig, type DefaultFrameMessageTypes, type FrameMessageData, type FrameMessageType, type FrameMessageTypes, type IntegrationFunction, type IntegrationParams, type PostMessageOptions, type RequestConfig, createClient, vitePluginPlayground };
package/dist/index.js CHANGED
@@ -1 +1,38 @@
1
- import e from"axios";import t from"qs";const n=e=>{let t=e.response?.status;if(t&&t>=400&&t!==401)try{typeof window<`u`&&window.top&&window.top?.postMessage({type:`mgx-appview-error`,targetName:window.name,data:{errMsg:e.response?.data?.message||e.response?.data?.detail||`Server Error`,stack:JSON.stringify({url:e.response?.config?.url,data:e.response?.data,status:e.response?.status})}},`*`)}catch(e){console.warn(`Failed to notify parent window about API error:`,e)}},r=(r={})=>{let{onUnauthorized:i,...a}=r,o=typeof globalThis<`u`&&`localStorage`in globalThis&&typeof globalThis.localStorage?.getItem==`function`?globalThis.localStorage.getItem(`token`)??void 0:void 0,s={timeout:6e4,paramsSerializer:e=>t.stringify(e,{arrayFormat:`brackets`}),...a,headers:{"Content-Type":`application/json`,...o?{Authorization:`Bearer ${o}`}:{},...a.headers}},c=e.create(s);return c.interceptors.request.use(e=>e,e=>Promise.reject(e)),c.interceptors.response.use(e=>e,e=>{let t=e.response?.status;return t===401&&i&&i(),n(e),Promise.reject(e)}),c},i=e=>typeof e==`string`?e.startsWith(`_`)||e.startsWith(`$`)||e===`constructor`||e===`toString`||e===`valueOf`||e===`inspect`||e===`toJSON`:!0,a=()=>{let e=window.location?.href??``,t=``;e.startsWith(`/`)?t=e:e&&(t=e.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]+/i,``));let n=new URLSearchParams({from_url:t});window.location.href=`/api/v1/auth/login?${n.toString()}`},o=e=>{let{requestInstance:t}=e;return{async login(){let e=new URLSearchParams(window.location.search),t=e.get(`token`);return t&&typeof globalThis<`u`&&`localStorage`in globalThis&&(globalThis.localStorage?.setItem(`token`,t),window.location.href=`/`),t},async me(){return t.get(`/api/v1/auth/me`)},async logout(){typeof globalThis<`u`&&`localStorage`in globalThis&&globalThis.localStorage?.removeItem(`token`);let e=await t.get(`/api/v1/auth/logout`);return window.location.href=`/`,e},toLogin:a}},s=e=>{let{requestInstance:t,entityName:n}=e,r=`/api/v1/entities/${n}`,i=e=>{if(!e)return;let t={...e};return e.fields&&Array.isArray(e.fields)&&(t.fields=e.fields.join(`,`)),e.query&&typeof e.query==`object`&&(t.query=JSON.stringify(e.query)),t};return{async query(e){let n=i(e);return t.get(r,{params:n})},async queryAll(e){let n=i(e);return t.get(`${r}/all`,{params:n})},async get(e){let{id:n,...a}=e,o=i(a);return t.get(`${r}/${n}`,{params:o})},async create(e){return t.post(r,e.data)},async update(e){return t.put(`${r}/${e.id}`,e.data)},async delete(e){return t.delete(`${r}/${e.id}`)},async deleteBatch(e){return t.delete(`${r}/batch`,{data:{ids:e.ids}})},async createBatch(e){return t.post(`${r}/batch`,e.data)},async updateBatch(e){return t.put(`${r}/batch`,e.data)}}},c=e=>{let{requestInstance:t}=e,n=new Map;return new Proxy({},{get(e,r){if(!i(r))return n.has(r)||n.set(r,s({requestInstance:t,entityName:r})),n.get(r)}})},l=e=>{let{requestInstance:t}=e;return{async invoke(e){let{url:n,method:r=`GET`,data:i,options:a={}}=e,o={method:r.toUpperCase(),url:n,...a};return i&&[`POST`,`PUT`,`PATCH`].includes(o.method)?o.data=i:i&&[`GET`,`DELETE`].includes(o.method)&&(o.params=i),t.request(o)}}},u=e=>{let{requestInstance:t}=e;return new Proxy({},{get(e,n){if(!i(n))return new Proxy({},{get(e,r){if(!i(r))return(e={})=>{let i=`/api/integrations/core/${r}`;n!==`core`&&(i=`/api/integrations/providers/${n}/${r}`);let{payload:a={},option:o={}}=e,s=a instanceof FormData?{...o,headers:{...o.headers,"Content-Type":void 0}}:o;return t.post(i,a,s)}}})}})},d=()=>({postMessage(e,t,n){if(typeof window>`u`||!window.top){console.warn(`postMessage: window.top is not available`);return}try{let{targetOrigin:r=`*`,targetName:i=window.name}=n||{},a={type:e,targetName:i,data:t};window.top.postMessage(a,r)}catch(e){console.warn(`Failed to send postMessage:`,e)}},createPage(e){let t=e??window.location.pathname;this.postMessage(`mgx-create-page`,{path:t})}}),f=(e={})=>{let t=r({baseURL:`/`,...e}),n=o({requestInstance:t}),i=c({requestInstance:t}),a=l({requestInstance:t}),s=u({requestInstance:t}),f=d();return{auth:n,entities:i,apiCall:a,integrations:s,frame:f}};export{f as createClient};
1
+ import e from"axios";import t from"qs";const n=e=>{let t=e.response?.status;if(t&&t>=400&&t!==401)try{typeof window<`u`&&window.top&&window.top?.postMessage({type:`mgx-appview-error`,targetName:window.name,data:{errMsg:e.response?.data?.message||e.response?.data?.detail||`Server Error`,stack:JSON.stringify({url:e.response?.config?.url,data:e.response?.data,status:e.response?.status})}},`*`)}catch(e){console.warn(`Failed to notify parent window about API error:`,e)}},r=(r={})=>{let{onUnauthorized:i,...a}=r,o=typeof globalThis<`u`&&`localStorage`in globalThis&&typeof globalThis.localStorage?.getItem==`function`?globalThis.localStorage.getItem(`token`)??void 0:void 0,s={timeout:6e4,paramsSerializer:e=>t.stringify(e,{arrayFormat:`brackets`}),...a,headers:{"Content-Type":`application/json`,...o?{Authorization:`Bearer ${o}`}:{},...a.headers}},c=e.create(s);return c.interceptors.request.use(e=>e,e=>Promise.reject(e)),c.interceptors.response.use(e=>e,e=>{let t=e.response?.status;return t===401&&i&&i(),n(e),Promise.reject(e)}),c},i=e=>typeof e==`string`?e.startsWith(`_`)||e.startsWith(`$`)||e===`constructor`||e===`toString`||e===`valueOf`||e===`inspect`||e===`toJSON`:!0,a=()=>{let e=window.location?.href??``,t=``;e.startsWith(`/`)?t=e:e&&(t=e.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]+/i,``));let n=new URLSearchParams({from_url:t});window.location.href=`/api/v1/auth/login?${n.toString()}`},o=e=>{let{requestInstance:t}=e;return{async login(){let e=new URLSearchParams(window.location.search),t=e.get(`token`);return t&&typeof globalThis<`u`&&`localStorage`in globalThis&&(globalThis.localStorage?.setItem(`token`,t),window.location.href=`/`),t},async me(){return t.get(`/api/v1/auth/me`)},async logout(){typeof globalThis<`u`&&`localStorage`in globalThis&&globalThis.localStorage?.removeItem(`token`);let e=await t.get(`/api/v1/auth/logout`);return window.location.href=`/`,e},toLogin:a}},s=e=>{let{requestInstance:t,entityName:n}=e,r=`/api/v1/entities/${n}`,i=e=>{if(!e)return;let t={...e};return e.fields&&Array.isArray(e.fields)&&(t.fields=e.fields.join(`,`)),e.query&&typeof e.query==`object`&&(t.query=JSON.stringify(e.query)),t};return{async query(e){let n=i(e);return t.get(r,{params:n})},async queryAll(e){let n=i(e);return t.get(`${r}/all`,{params:n})},async get(e){let{id:n,...a}=e,o=i(a);return t.get(`${r}/${n}`,{params:o})},async create(e){return t.post(r,e.data)},async update(e){return t.put(`${r}/${e.id}`,e.data)},async delete(e){return t.delete(`${r}/${e.id}`)},async deleteBatch(e){return t.delete(`${r}/batch`,{data:{ids:e.ids}})},async createBatch(e){return t.post(`${r}/batch`,e.data)},async updateBatch(e){return t.put(`${r}/batch`,e.data)}}},c=e=>{let{requestInstance:t}=e,n=new Map;return new Proxy({},{get(e,r){if(!i(r))return n.has(r)||n.set(r,s({requestInstance:t,entityName:r})),n.get(r)}})},l=e=>{let{requestInstance:t}=e;return{async invoke(e){let{url:n,method:r=`GET`,data:i,options:a={}}=e,o={method:r.toUpperCase(),url:n,...a};return i&&[`POST`,`PUT`,`PATCH`].includes(o.method)?o.data=i:i&&[`GET`,`DELETE`].includes(o.method)&&(o.params=i),t.request(o)}}},u=e=>{let{requestInstance:t}=e;return new Proxy({},{get(e,n){if(!i(n))return new Proxy({},{get(e,r){if(!i(r))return(e={})=>{let i=`/api/integrations/core/${r}`;n!==`core`&&(i=`/api/integrations/providers/${n}/${r}`);let{payload:a={},option:o={}}=e,s=a instanceof FormData?{...o,headers:{...o.headers,"Content-Type":void 0}}:o;return t.post(i,a,s)}}})}})},d=()=>({postMessage(e,t,n){if(typeof window>`u`||!window.top){console.warn(`postMessage: window.top is not available`);return}try{let{targetOrigin:r=`*`,targetName:i=window.name}=n||{},a={type:e,targetName:i,data:t};window.top.postMessage(a,r)}catch(e){console.warn(`Failed to send postMessage:`,e)}},createPage(e){let t=e??window.location.pathname;this.postMessage(`mgx-create-page`,{path:t})}}),f=(e={})=>{let t=r({baseURL:`/`,...e}),n=o({requestInstance:t}),i=c({requestInstance:t}),a=l({requestInstance:t}),s=u({requestInstance:t}),f=d();return{auth:n,entities:i,apiCall:a,integrations:s,frame:f}},p=`import { Button } from '@/components/ui/button';
2
+ import { createClient } from '@metagptx/web-sdk';
3
+
4
+ // Create client instance
5
+ export const client = createClient();
6
+
7
+ export default function NotFoundPage() {
8
+ return (
9
+ <div className="min-h-screen flex flex-col items-center justify-center bg-gradient-to-br from-gray-50 to-blue-50 p-6 text-center">
10
+ <div className="space-y-6 max-w-md">
11
+ <div className="space-y-3">
12
+ <h1 className="text-8xl font-bold text-primary">404</h1>
13
+ <h2 className="text-2xl font-semibold text-gray-800">
14
+ Page Not Found
15
+ </h2>
16
+ <p className="text-muted-foreground">
17
+ The page you're looking for doesn't exist or may have been moved.
18
+ </p>
19
+ </div>
20
+
21
+ <div className="flex flex-col sm:flex-row gap-3 justify-center">
22
+ <Button asChild>
23
+ <a href="/">Return Home</a>
24
+ </Button>
25
+ <Button variant="outline" onClick={() =>
26
+ client.frame.createPage()
27
+ }>
28
+ Create page
29
+ </Button>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ );
34
+ }
35
+
36
+ `,m=[{path:`*`,componentName:`NotFoundPage`,componentCode:p}];function h(e={}){let t=e.routes||m,n=new Map;return t.forEach(e=>{let t=`\0virtual:${e.componentName.toLowerCase()}.tsx`;n.set(t,e.componentCode)}),{name:`vite-plugin-playground`,enforce:`pre`,resolveId(e){for(let n of t){let t=`virtual:${n.componentName.toLowerCase()}`;if(e===t)return`\0${t}.tsx`}return null},load(e){return n.get(e)||null},transform(e,n){if(!n.includes(`App.tsx`)||n.includes(`node_modules`))return null;let r=t.every(t=>e.includes(`import ${t.componentName}`)&&e.includes(t.path));if(r)return null;let i=e,a=[];if(t.forEach(t=>{if(!e.includes(`import ${t.componentName}`)){let e=`virtual:${t.componentName.toLowerCase()}`;a.push(`import ${t.componentName} from '${e}';`)}}),a.length>0){let n=e.match(/(import AuthError from[^;]+;)/);n&&(i=i.replace(n[0],`${n[0]}\n${a.join(`
37
+ `)}`));let r=t,o=r.map(e=>` <Route path="${e.path}" element={<${e.componentName} />} />`).join(`
38
+ `),s=i.match(/(\s+)(<\/Routes>)/i);s&&(i=i.replace(s[0],`${s[1]}${o}\n${s[0]}`))}return i===e?null:{code:i,map:null}}}}export{f as createClient,h as vitePluginPlayground};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@metagptx/web-sdk",
3
3
  "type": "module",
4
- "version": "0.0.23",
4
+ "version": "0.0.24-beta.1",
5
5
  "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
6
6
  "description": "TypeScript SDK for interacting with FuncSea API",
7
7
  "author": "MetaGPTX",
@@ -25,7 +25,7 @@
25
25
  "test": "vitest run",
26
26
  "test:coverage": "vitest --coverage run",
27
27
  "typecheck": "tsc --noEmit",
28
- "release": "bumpp && npm publish",
28
+ "release": "bumpp && npm publish --tag beta",
29
29
  "lint": "eslint",
30
30
  "lint:fix": "eslint --fix",
31
31
  "precommit": "npm run typecheck && lint-staged && npm run test:coverage",
@@ -38,7 +38,8 @@
38
38
  "eslint-plugin-prettier": "^5.5.4",
39
39
  "lint-staged": "^16.2.3",
40
40
  "qs": "^6.14.0",
41
- "simple-git-hooks": "^2.13.1"
41
+ "simple-git-hooks": "^2.13.1",
42
+ "vite": "^7.2.2"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@antfu/eslint-config": "^5.4.1",