@metagptx/web-sdk 0.0.1 → 0.0.3
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 +15 -11
- package/package.json +1 -1
- package/dist/index.d.ts +0 -108
- package/dist/index.js +0 -1
package/README.md
CHANGED
|
@@ -83,19 +83,21 @@ client.auth.toLogin();
|
|
|
83
83
|
|
|
84
84
|
Provides dynamic CRUD operations for any entity type. Access entities using property syntax: `client.entities.{entityName}.{operation}()`.
|
|
85
85
|
|
|
86
|
+
**Note:** The `fields` parameter (array) will be automatically converted to a comma-separated string, and the `query` parameter (object) will be automatically converted to a JSON string before sending to the API.
|
|
87
|
+
|
|
86
88
|
#### `entities[entityName].query(params?)`
|
|
87
89
|
|
|
88
90
|
Query entities with filtering, sorting, and pagination.
|
|
89
91
|
|
|
90
92
|
**HTTP Details:**
|
|
91
93
|
- **Method:** `GET`
|
|
92
|
-
- **Path:** `/api/entities/{entityName}`
|
|
94
|
+
- **Path:** `/api/v1/entities/{entityName}`
|
|
93
95
|
- **Parameters:**
|
|
94
|
-
- `query` (optional): Query conditions object
|
|
96
|
+
- `query` (optional): Query conditions object (will be converted to JSON string)
|
|
95
97
|
- `sort` (optional): Sort field and order (e.g., `"-createdAt"`)
|
|
96
98
|
- `limit` (optional): Maximum number of results
|
|
97
99
|
- `skip` (optional): Number of results to skip
|
|
98
|
-
- `fields` (optional): Array of fields to return
|
|
100
|
+
- `fields` (optional): Array of fields to return (will be converted to comma-separated string)
|
|
99
101
|
|
|
100
102
|
**Example:**
|
|
101
103
|
```typescript
|
|
@@ -106,6 +108,7 @@ const response = await client.entities.users.query({
|
|
|
106
108
|
skip: 0,
|
|
107
109
|
fields: ['id', 'name', 'email'],
|
|
108
110
|
});
|
|
111
|
+
// Actual API call: GET /api/v1/entities/users?query={"status":"active"}&sort=-createdAt&limit=10&skip=0&fields=id,name,email
|
|
109
112
|
```
|
|
110
113
|
|
|
111
114
|
#### `entities[entityName].get(params)`
|
|
@@ -114,10 +117,10 @@ Get a single entity by ID.
|
|
|
114
117
|
|
|
115
118
|
**HTTP Details:**
|
|
116
119
|
- **Method:** `GET`
|
|
117
|
-
- **Path:** `/api/entities/{entityName}/{id}`
|
|
120
|
+
- **Path:** `/api/v1/entities/{entityName}/{id}`
|
|
118
121
|
- **Parameters:**
|
|
119
122
|
- `id` (required): Entity ID
|
|
120
|
-
- `fields` (optional): Array of fields to return
|
|
123
|
+
- `fields` (optional): Array of fields to return (will be converted to comma-separated string)
|
|
121
124
|
|
|
122
125
|
**Example:**
|
|
123
126
|
```typescript
|
|
@@ -125,6 +128,7 @@ const response = await client.entities.users.get({
|
|
|
125
128
|
id: '12345',
|
|
126
129
|
fields: ['id', 'name', 'email'],
|
|
127
130
|
});
|
|
131
|
+
// Actual API call: GET /api/v1/entities/users/12345?fields=id,name,email
|
|
128
132
|
```
|
|
129
133
|
|
|
130
134
|
#### `entities[entityName].create(params)`
|
|
@@ -133,7 +137,7 @@ Create a new entity.
|
|
|
133
137
|
|
|
134
138
|
**HTTP Details:**
|
|
135
139
|
- **Method:** `POST`
|
|
136
|
-
- **Path:** `/api/entities/{entityName}`
|
|
140
|
+
- **Path:** `/api/v1/entities/{entityName}`
|
|
137
141
|
- **Body:**
|
|
138
142
|
- `data` (required): Entity data object
|
|
139
143
|
|
|
@@ -154,7 +158,7 @@ Update an existing entity.
|
|
|
154
158
|
|
|
155
159
|
**HTTP Details:**
|
|
156
160
|
- **Method:** `PUT`
|
|
157
|
-
- **Path:** `/api/entities/{entityName}/{id}`
|
|
161
|
+
- **Path:** `/api/v1/entities/{entityName}/{id}`
|
|
158
162
|
- **Body:**
|
|
159
163
|
- `id` (required): Entity ID
|
|
160
164
|
- `data` (required): Updated entity data
|
|
@@ -176,7 +180,7 @@ Delete a single entity by ID.
|
|
|
176
180
|
|
|
177
181
|
**HTTP Details:**
|
|
178
182
|
- **Method:** `DELETE`
|
|
179
|
-
- **Path:** `/api/entities/{entityName}/{id}`
|
|
183
|
+
- **Path:** `/api/v1/entities/{entityName}/{id}`
|
|
180
184
|
- **Parameters:**
|
|
181
185
|
- `id` (required): Entity ID
|
|
182
186
|
|
|
@@ -191,7 +195,7 @@ Create multiple entities in a single request.
|
|
|
191
195
|
|
|
192
196
|
**HTTP Details:**
|
|
193
197
|
- **Method:** `POST`
|
|
194
|
-
- **Path:** `/api/entities/{entityName}/batch`
|
|
198
|
+
- **Path:** `/api/v1/entities/{entityName}/batch`
|
|
195
199
|
- **Body:**
|
|
196
200
|
- `data` (required): Array of entity data objects
|
|
197
201
|
|
|
@@ -211,7 +215,7 @@ Update multiple entities in a single request.
|
|
|
211
215
|
|
|
212
216
|
**HTTP Details:**
|
|
213
217
|
- **Method:** `PUT`
|
|
214
|
-
- **Path:** `/api/entities/{entityName}/batch`
|
|
218
|
+
- **Path:** `/api/v1/entities/{entityName}/batch`
|
|
215
219
|
- **Body:**
|
|
216
220
|
- `data` (required): Array of entity data objects (must include `id` for each)
|
|
217
221
|
|
|
@@ -231,7 +235,7 @@ Delete multiple entities by their IDs.
|
|
|
231
235
|
|
|
232
236
|
**HTTP Details:**
|
|
233
237
|
- **Method:** `DELETE`
|
|
234
|
-
- **Path:** `/api/entities/{entityName}/batch`
|
|
238
|
+
- **Path:** `/api/v1/entities/{entityName}/batch`
|
|
235
239
|
- **Body:**
|
|
236
240
|
- `ids` (required): Array of entity IDs
|
|
237
241
|
|
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.3",
|
|
5
5
|
"packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
|
|
6
6
|
"description": "TypeScript SDK for interacting with FuncSea API",
|
|
7
7
|
"author": "MetaGPTX",
|
package/dist/index.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import * as axios0 from "axios";
|
|
2
|
-
import { AxiosRequestConfig } from "axios";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/request.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Request instance configuration options
|
|
7
|
-
*/
|
|
8
|
-
interface RequestConfig extends AxiosRequestConfig {
|
|
9
|
-
baseURL?: string;
|
|
10
|
-
timeout?: number;
|
|
11
|
-
onUnauthorized?: () => void;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates an axios request instance with default configuration
|
|
15
|
-
* @param config - Optional configuration for the request instance
|
|
16
|
-
* @returns Configured axios instance
|
|
17
|
-
*/
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/client.d.ts
|
|
20
|
-
interface ClientConfig extends RequestConfig {}
|
|
21
|
-
declare const createClient: (config?: ClientConfig) => {
|
|
22
|
-
auth: {
|
|
23
|
-
me(): Promise<axios0.AxiosResponse<any, any, {}>>;
|
|
24
|
-
logout(): Promise<axios0.AxiosResponse<any, any, {}>>;
|
|
25
|
-
toLogin: () => void;
|
|
26
|
-
};
|
|
27
|
-
entities: Record<string, {
|
|
28
|
-
query<T = any>(params?: {
|
|
29
|
-
query?: Record<string, unknown>;
|
|
30
|
-
sort?: string;
|
|
31
|
-
limit?: number;
|
|
32
|
-
skip?: number;
|
|
33
|
-
fields?: string[];
|
|
34
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
35
|
-
get<T = any>(params: {
|
|
36
|
-
id: string;
|
|
37
|
-
fields?: string[];
|
|
38
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
39
|
-
create<T = any>(params: {
|
|
40
|
-
data: Record<string, unknown>;
|
|
41
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
42
|
-
update<T = any>(params: {
|
|
43
|
-
id: string;
|
|
44
|
-
data: Record<string, unknown>;
|
|
45
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
46
|
-
delete<T = any>(params: {
|
|
47
|
-
id: string;
|
|
48
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
49
|
-
deleteBatch<T = any>(params: {
|
|
50
|
-
ids: string[];
|
|
51
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
52
|
-
createBatch<T = any>(params: {
|
|
53
|
-
data: Record<string, unknown>[];
|
|
54
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
55
|
-
updateBatch<T = any>(params: {
|
|
56
|
-
data: Record<string, unknown>[];
|
|
57
|
-
}): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
58
|
-
}>;
|
|
59
|
-
apiCall: {
|
|
60
|
-
invoke<T = any>(params: ApiCallParams): Promise<axios0.AxiosResponse<T, any, {}>>;
|
|
61
|
-
};
|
|
62
|
-
integrations: Record<string, Record<string, IntegrationFunction>>;
|
|
63
|
-
};
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/types/index.d.ts
|
|
66
|
-
/**
|
|
67
|
-
* Common reusable types for the funcsea-websdk
|
|
68
|
-
*/
|
|
69
|
-
type AnyType = any;
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/modules/apiCall.d.ts
|
|
72
|
-
/**
|
|
73
|
-
* API call parameters interface
|
|
74
|
-
*/
|
|
75
|
-
interface ApiCallParams {
|
|
76
|
-
url: string;
|
|
77
|
-
method?: string;
|
|
78
|
-
data?: Record<string, AnyType>;
|
|
79
|
-
options?: AxiosRequestConfig;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Creates an API call module for making custom HTTP requests
|
|
83
|
-
* @param params - Configuration object
|
|
84
|
-
* @param params.requestInstance - Axios instance for making HTTP requests
|
|
85
|
-
* @returns Object containing invoke method for API calls
|
|
86
|
-
*/
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/modules/integrations.d.ts
|
|
89
|
-
/**
|
|
90
|
-
* Integration function parameters interface
|
|
91
|
-
*/
|
|
92
|
-
interface IntegrationParams {
|
|
93
|
-
payload?: Record<string, AnyType> | FormData;
|
|
94
|
-
option?: Record<string, AnyType>;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Integration function type
|
|
98
|
-
*/
|
|
99
|
-
type IntegrationFunction = (params?: IntegrationParams) => Promise<AnyType>;
|
|
100
|
-
/**
|
|
101
|
-
* Creates an integrations module using proxy for dynamic package and function access
|
|
102
|
-
* @param params - Configuration object
|
|
103
|
-
* @param params.requestInstance - Axios instance for making HTTP requests
|
|
104
|
-
* @returns Proxy object that dynamically creates integration calls
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
export { type AnyType, type ApiCallParams, type ClientConfig, type IntegrationFunction, type IntegrationParams, type RequestConfig, createClient };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"axios";import t from"qs";const n=(n={})=>{let{onUnauthorized:r,...i}=n,a={timeout:6e4,paramsSerializer:e=>t.stringify(e,{arrayFormat:`brackets`}),...i,headers:{"Content-Type":`application/json`,...i.headers}},o=e.create(a);return o.interceptors.request.use(e=>e,e=>Promise.reject(e)),o.interceptors.response.use(e=>e,e=>(e.response?.status===401&&r&&r(),Promise.reject(e))),o},r=e=>typeof e==`string`?e.startsWith(`_`)||e.startsWith(`$`)||e===`constructor`||e===`toString`||e===`valueOf`||e===`inspect`||e===`toJSON`:!0,i=()=>{let e=window.location.href,t=new URLSearchParams({from_url:e});window.location.href=`/api/v1/auth/login?${t.toString()}`},a=e=>{let{requestInstance:t}=e;return{async me(){return t.get(`/api/v1/auth/me`)},async logout(){return t.post(`/api/v1/auth/logout`)},toLogin:i}},o=e=>{let{requestInstance:t,entityName:n}=e,r=`/api/entities/${n}`;return{async query(e){return t.get(r,{params:e})},async get(e){let{id:n,...i}=e;return t.get(`${r}/${n}`,{params:i})},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)}}},s=e=>{let{requestInstance:t}=e,n=new Map;return new Proxy({},{get(e,i){if(!r(i))return n.has(i)||n.set(i,o({requestInstance:t,entityName:i})),n.get(i)}})},c=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)}}},l=e=>{let{requestInstance:t}=e;return new Proxy({},{get(e,n){if(!r(n))return new Proxy({},{get(e,i){if(!r(i))return(e={})=>{let r=`/api/integrations/core/${i}`;n!==`core`&&(r=`/api/integrations/providers/${n}/${i}`);let{payload:a={},option:o={}}=e,s=a instanceof FormData?{...o,headers:{...o.headers,"Content-Type":void 0}}:o;return t.post(r,a,s)}}})}})},u=(e={})=>{let t=n({baseURL:`/`,...e,onUnauthorized:i}),r=a({requestInstance:t}),o=s({requestInstance:t}),u=c({requestInstance:t}),d=l({requestInstance:t});return{auth:r,entities:o,apiCall:u,integrations:d}};export{u as createClient};
|