@metagptx/web-sdk 0.0.45 → 0.0.46
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 +5 -21
- package/dist/index.js +7 -5
- package/package.json +3 -2
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
|
/**
|
|
@@ -118,27 +119,10 @@ type IntegrationFunction = (params?: IntegrationParams) => Promise<AnyType>;
|
|
|
118
119
|
* @returns Proxy object that dynamically creates integration calls
|
|
119
120
|
*/
|
|
120
121
|
//#endregion
|
|
121
|
-
//#region src/plugins/vite-
|
|
122
|
-
interface RouteConfig {
|
|
123
|
-
path: string;
|
|
124
|
-
componentName: string;
|
|
125
|
-
componentCode: string;
|
|
126
|
-
}
|
|
127
|
-
interface PluginOptions {
|
|
128
|
-
routes?: RouteConfig[];
|
|
129
|
-
}
|
|
122
|
+
//#region src/plugins/vite-plugin-404.d.ts
|
|
130
123
|
/**
|
|
131
|
-
* Vite plugin to automatically
|
|
124
|
+
* Vite plugin to create a virtual 404 React component and automatically add a 404 route
|
|
132
125
|
*/
|
|
133
|
-
declare function
|
|
134
|
-
name: string;
|
|
135
|
-
enforce: string;
|
|
136
|
-
resolveId(id: string): string | null;
|
|
137
|
-
load(id: string): string | null;
|
|
138
|
-
transform(code: string, id: string): {
|
|
139
|
-
code: string;
|
|
140
|
-
map: null;
|
|
141
|
-
} | null;
|
|
142
|
-
};
|
|
126
|
+
declare function vitePlugin404(): Plugin;
|
|
143
127
|
//#endregion
|
|
144
|
-
export { type AnyType, type ApiCallParams, type ClientConfig, type IntegrationFunction, type IntegrationParams, type RequestConfig, createClient,
|
|
128
|
+
export { type AnyType, type ApiCallParams, type ClientConfig, type IntegrationFunction, type IntegrationParams, type RequestConfig, createClient, vitePlugin404 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"axios";import t from"qs";const
|
|
1
|
+
import e from"axios";import t from"qs";import{transformWithEsbuild as n}from"vite";const r=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)}},i=(n={})=>{let{onUnauthorized:i,...a}=n,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`,"App-Host":globalThis?.window?.location?.origin??``,...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(),r(e),Promise.reject(e)}),c},a=[`stripe.com`],o=e=>typeof e==`string`?e.startsWith(`_`)||e.startsWith(`$`)||e===`constructor`||e===`toString`||e===`valueOf`||e===`inspect`||e===`toJSON`:!0,s=()=>{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()}`},c=()=>globalThis?.window?.name?.includes(`devIframe`),l=e=>e?a.some(t=>e.toString().includes(t)):!1,u=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 typeof globalThis<`u`&&`window`in globalThis&&(globalThis.window.opener=null),window.location.href=`/`,e},toLogin:s}},d=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)}}},f=e=>{let{requestInstance:t}=e,n=new Map;return new Proxy({},{get(e,r){if(!o(r))return n.has(r)||n.set(r,d({requestInstance:t,entityName:r})),n.get(r)}})},p=e=>{let{requestInstance:t}=e;return{async invoke(e){let{url:n,method:r=`GET`,data:i,options:a={}}=e;if(typeof window<`u`&&a?.responseType===`stream`){let e;try{typeof globalThis<`u`&&`localStorage`in globalThis&&typeof globalThis.localStorage?.getItem==`function`&&(e=globalThis.localStorage.getItem(`token`)??void 0)}catch{}let t={"Content-Type":`application/json`,"App-Host":globalThis?.window?.location?.origin??``,...e?{Authorization:`Bearer ${e}`}:{},...a.headers||{}},o;i&&[`POST`,`PUT`,`PATCH`].includes(r.toUpperCase())&&(o=JSON.stringify(i));let s=await fetch(n,{method:r.toUpperCase(),headers:t,body:o});return s}let 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)}}},m=e=>{let{requestInstance:t}=e;return new Proxy({},{get(e,n){if(!o(n))return new Proxy({},{get(e,r){if(!o(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)}}})}})};let h=null;const g=e=>{if(h)return;let{requestInstance:t}=e,n=async e=>{let n=globalThis?.localStorage?.getItem(`token`);if(n)return;let r=e.token,i=await t.post(`/api/v1/auth/token/exchange`,{platform_token:r});i.status===200&&i.data.token&&(globalThis?.localStorage?.setItem(`token`,i.data.token),window.location.href=`/`)},r=e=>{switch(e.data.type){case`mgx-token-saved`:n(e.data.data);break;default:break}};h={requestInstance:t,handleMessage:r},globalThis?.window?.addEventListener(`message`,r)},_=()=>{let e=(e,t,n,r)=>{if(globalThis?.window===void 0||!globalThis?.window?.top){console.warn(`postMessage: window.top is not available`);return}try{let{targetOrigin:i=`*`,targetName:a=globalThis?.window?.name??``}=n||{},o={type:e,targetName:a,data:t};(r??globalThis?.window?.top)?.postMessage(o,i)}catch(e){console.warn(`Failed to send postMessage:`,e)}};return{postMessage:e}};let v=!1;const y=e=>{g(e);let{postMessage:t}=_(),n=()=>{if(v)return;v=!0;let e=globalThis?.localStorage?.getItem(`token`);e||(t(`mgx-token-request`,{domain:globalThis?.window?.location?.href??``},{},globalThis?.window?.opener),t(`mgx-token-request`,{domain:globalThis?.window?.location?.href??``}))};return n(),{createPage(e){let n=e??globalThis?.window?.location?.pathname??``;t(`mgx-create-page`,{path:n})}}},b=()=>{let{postMessage:e}=_(),t=t=>{if(t){if(globalThis?.window===void 0){console.warn(`openUrl: window is not available`);return}if(l(t)&&c()){e(`mgx-open-url`,{url:t.toString()},{},globalThis?.window?.opener);return}globalThis.window.location.href=t.toString()}};return{openUrl:t}},x=(e={})=>{let t=i({baseURL:`/`,...e}),n=u({requestInstance:t}),r=f({requestInstance:t}),a=p({requestInstance:t}),o=m({requestInstance:t}),s=y({requestInstance:t}),c=b();return{auth:n,entities:r,apiCall:a,integrations:o,frame:s,utils:c}};function S(){let e=`virtual:404-page`,t=`import { Button } from '@/components/ui/button';
|
|
2
2
|
import { createClient } from '@metagptx/web-sdk';
|
|
3
3
|
|
|
4
4
|
// Create client instance
|
|
@@ -11,7 +11,7 @@ export default function NotFoundPage() {
|
|
|
11
11
|
<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">
|
|
12
12
|
<div className="space-y-6 max-w-md">
|
|
13
13
|
<div className="space-y-3">
|
|
14
|
-
<h1 className="text-
|
|
14
|
+
<h1 className="text-5xl font-bold text-primary">404</h1>
|
|
15
15
|
<h2 className="text-2xl font-semibold text-gray-800">
|
|
16
16
|
Page Not Found
|
|
17
17
|
</h2>
|
|
@@ -41,6 +41,8 @@ export default function NotFoundPage() {
|
|
|
41
41
|
</div>
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
`;return{name:`vite-plugin-404`,enforce:`pre`,resolveId(t){return t===e||t.startsWith(e)?`\0${e}`:null},async load(r){if(r===`\0${e}`||r.includes(`virtual:404-page`)){let e=await n(t,`virtual-404.tsx`,{jsx:`automatic`,loader:`tsx`});return e.code}return null},transform(e,t){if(!t.includes(`App.tsx`)||!t.endsWith(`.tsx`))return null;let n=e.includes(`virtual:404-page`)||e.includes(`NotFound404`)||e.includes(`NotFoundPage`)||/path\s*=\s*["']\*["']/.test(e);if(n)return null;let r=!1,i=e.includes(`virtual:404-page`);if(!i){let t=/(import\s+AuthError\s+from\s+['"][^'"]+AuthError[^'"]*['"];)/;if(t.test(e))e=e.replace(t,`$1
|
|
45
|
+
import NotFoundPage from 'virtual:404-page';`),r=!0;else if(/\/\/\s*MODULE_IMPORTS_END/.test(e))e=e.replace(/(\/\/\s*MODULE_IMPORTS_END)/,`$1
|
|
46
|
+
import NotFoundPage from 'virtual:404-page';`),r=!0;else if(/\/\/\s*MODULE_IMPORTS_START/.test(e))e=e.replace(/(\/\/\s*MODULE_IMPORTS_START)/,`import NotFoundPage from 'virtual:404-page';
|
|
47
|
+
$1`),r=!0;else{let t=/(^import\s[^;]+;)/gm,n=[...e.matchAll(t)];if(n.length>0){let t=n[n.length-1],i=t.index+t[0].length,a=e.substring(0,i),o=e.substring(i);e=`${a}\nimport NotFoundPage from 'virtual:404-page';${o}`,r=!0}}}let a=/path\s*=\s*["']\*["']/.test(e);if(!a){if(/\/\/\s*MODULE_ROUTES_END/.test(e)){let t=e.match(/(\s*)\/\/\s*MODULE_ROUTES_END/);if(t){let n=t[1];e=e.replace(/(\s*)\/\/\s*MODULE_ROUTES_END/,`${n}<Route path="*" element={<NotFoundPage />} />\n$1// MODULE_ROUTES_END`),r=!0}}else if(/<\/Routes>/.test(e)){let t=e.match(/(\s*)<\/Routes>/);if(t){let n=t[1],i=e.match(/(\s+)<Route\s+path=/),a=i?i[1]:`${n} `;e=e.replace(/(\s*)<\/Routes>/,`${a}<Route path="*" element={<NotFoundPage />} />\n$1</Routes>`),r=!0}}else if(/<Route\s+path=/.test(e)){let t=/<Route\s[^>]*\/>|<Route\s[^>]*>[\s\S]*?<\/Route>/g,n=[...e.matchAll(t)];if(n.length>0){let t=n[n.length-1],i=t.index+t[0].length,a=e.substring(0,i),o=e.substring(i),s=a.split(`
|
|
48
|
+
`),c=s[s.length-1],l=c.match(/^(\s*)/)?.[1]||``;e=`${a}\n${l}<Route path="*" element={<NotFoundPage />} />${o}`,r=!0}}}return r?{code:e,map:null}:null}}}export{x as createClient,S as vitePlugin404};
|
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.46",
|
|
5
5
|
"packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
|
|
6
6
|
"description": "TypeScript SDK for interacting with FuncSea API",
|
|
7
7
|
"author": "MetaGPTX",
|
|
@@ -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.3.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@antfu/eslint-config": "^5.4.1",
|