@lobehub/market-sdk 0.0.27 → 0.0.29
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 +210 -112
- package/dist/index.d.mts +689 -385
- package/dist/index.mjs +468 -383
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,172 +1,270 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LobeHub Market JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://npmjs.org/package/@lobehub/market-sdk)
|
|
4
|
+
[](https://npmjs.org/package/@lobehub/market-sdk)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
A JavaScript SDK for accessing the LobeHub Market API, providing easy integration with the LobeHub ecosystem.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- 支持 TypeScript,提供完整类型定义
|
|
9
|
-
- 简单易用的 API 设计
|
|
10
|
-
- 支持 ESM 模块
|
|
8
|
+
## Features
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
- 🚀 **Easy Integration**: Simple API for accessing LobeHub Marketplace resources
|
|
11
|
+
- 🔌 **Plugin Support**: Browse, search, and fetch plugin manifests
|
|
12
|
+
- 🔒 **Authentication**: Secure API access with token-based authentication
|
|
13
|
+
- 🧩 **Modular Architecture**: Logically separated services for different API domains
|
|
14
|
+
- 🌐 **Localization**: Built-in support for localized content
|
|
15
|
+
- 🔍 **Discovery**: Automatic service discovery for API capabilities
|
|
16
|
+
- 📊 **Admin Tools**: Comprehensive admin APIs for marketplace management
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
13
19
|
|
|
14
20
|
```bash
|
|
21
|
+
# Using npm
|
|
15
22
|
npm install @lobehub/market-sdk
|
|
23
|
+
|
|
24
|
+
# Using yarn
|
|
25
|
+
yarn add @lobehub/market-sdk
|
|
26
|
+
|
|
27
|
+
# Using pnpm
|
|
28
|
+
pnpm add @lobehub/market-sdk
|
|
16
29
|
```
|
|
17
30
|
|
|
18
|
-
##
|
|
31
|
+
## Package Structure
|
|
19
32
|
|
|
20
|
-
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
├── market/ - Market SDK implementation
|
|
36
|
+
│ ├── services/ - Market services
|
|
37
|
+
│ │ ├── PluginsService.ts - Plugin-related operations
|
|
38
|
+
│ │ └── DiscoveryService.ts - API discovery
|
|
39
|
+
│ └── market-sdk.ts - Main SDK class
|
|
40
|
+
├── admin/ - Admin SDK implementation
|
|
41
|
+
│ ├── services/ - Admin services
|
|
42
|
+
│ │ ├── PluginService.ts - Plugin management
|
|
43
|
+
│ │ ├── ReviewService.ts - Review management
|
|
44
|
+
│ │ ├── SettingsService.ts - Settings management
|
|
45
|
+
│ │ └── SystemDependencyService.ts - Dependencies management
|
|
46
|
+
│ └── MarketAdmin.ts - Admin SDK class
|
|
47
|
+
├── core/ - Core utilities and base classes
|
|
48
|
+
├── types/ - TypeScript type definitions
|
|
49
|
+
└── index.ts - Main entry point
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Market SDK
|
|
21
55
|
|
|
22
56
|
```typescript
|
|
23
57
|
import { MarketSDK } from '@lobehub/market-sdk';
|
|
24
58
|
|
|
25
|
-
//
|
|
59
|
+
// Create a client instance
|
|
26
60
|
const market = new MarketSDK({
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const discovery = await market.getDiscoveryDocument();
|
|
34
|
-
console.log(discovery);
|
|
35
|
-
|
|
36
|
-
// 获取插件列表
|
|
37
|
-
const plugins = await market.getPluginList({
|
|
38
|
-
page: 1,
|
|
39
|
-
pageSize: 10,
|
|
40
|
-
category: 'tools',
|
|
41
|
-
sort: 'installCount',
|
|
42
|
-
order: 'desc',
|
|
61
|
+
// Optional: custom API base URL (defaults to https://market.lobehub.com/api)
|
|
62
|
+
baseURL: 'https://your-api-url.com/api',
|
|
63
|
+
// Optional: API key for authentication
|
|
64
|
+
apiKey: 'your-api-key',
|
|
65
|
+
// Optional: default locale for localized content
|
|
66
|
+
defaultLocale: 'en-US',
|
|
43
67
|
});
|
|
44
|
-
console.log(plugins);
|
|
45
68
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
// Example: Get a list of plugins
|
|
70
|
+
async function getPlugins() {
|
|
71
|
+
try {
|
|
72
|
+
const result = await market.plugins.getPluginList({
|
|
73
|
+
page: 1,
|
|
74
|
+
pageSize: 10,
|
|
75
|
+
locale: 'en-US',
|
|
76
|
+
// Additional filter parameters
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log(`Found ${result.data.items.length} plugins`);
|
|
80
|
+
console.log('Plugins:', result.data.items);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('Error fetching plugins:', error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Example: Get plugin categories
|
|
87
|
+
async function getCategories() {
|
|
88
|
+
try {
|
|
89
|
+
const result = await market.plugins.getCategories();
|
|
90
|
+
console.log('Categories:', result.data);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error('Error fetching categories:', error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Example: Get a plugin's manifest
|
|
97
|
+
async function getPluginManifest(pluginId) {
|
|
98
|
+
try {
|
|
99
|
+
const result = await market.plugins.getPluginManifest({ id: pluginId });
|
|
100
|
+
console.log('Plugin manifest:', result.data);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error('Error fetching plugin manifest:', error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
49
105
|
```
|
|
50
106
|
|
|
51
|
-
###
|
|
107
|
+
### Admin SDK
|
|
52
108
|
|
|
53
|
-
|
|
109
|
+
For administrative operations, use the `MarketAdmin` class:
|
|
54
110
|
|
|
55
111
|
```typescript
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
112
|
+
import { MarketAdmin } from '@lobehub/market-sdk';
|
|
113
|
+
|
|
114
|
+
// Create an admin client instance
|
|
115
|
+
const admin = new MarketAdmin({
|
|
116
|
+
// Required: Admin API key
|
|
117
|
+
apiKey: 'your-admin-api-key',
|
|
118
|
+
// Optional: custom API base URL
|
|
119
|
+
baseURL: 'https://your-api-url.com/api',
|
|
59
120
|
});
|
|
60
121
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
122
|
+
// Example: Create a new plugin
|
|
123
|
+
async function createPlugin() {
|
|
124
|
+
try {
|
|
125
|
+
const result = await admin.plugins.createPlugin({
|
|
126
|
+
meta: {
|
|
127
|
+
title: 'My Plugin',
|
|
128
|
+
description: 'A sample plugin',
|
|
129
|
+
author: 'LobeHub',
|
|
130
|
+
homepage: 'https://github.com/lobehub/my-plugin',
|
|
131
|
+
},
|
|
132
|
+
manifest: {
|
|
133
|
+
// Plugin manifest details
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
console.log('Plugin created:', result.data);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error('Error creating plugin:', error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Example: Update plugin settings
|
|
144
|
+
async function updateSettings() {
|
|
145
|
+
try {
|
|
146
|
+
const result = await admin.settings.updateSettings({
|
|
147
|
+
pluginReviewEnabled: true,
|
|
148
|
+
publishPluginEnabled: true,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
console.log('Settings updated:', result.data);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error('Error updating settings:', error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
75
156
|
```
|
|
76
157
|
|
|
77
|
-
## API
|
|
158
|
+
## API Reference
|
|
78
159
|
|
|
79
|
-
###
|
|
160
|
+
### MarketSDK Services
|
|
80
161
|
|
|
81
|
-
|
|
162
|
+
#### plugins
|
|
82
163
|
|
|
83
|
-
|
|
164
|
+
Methods for accessing plugin resources:
|
|
84
165
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
```
|
|
166
|
+
- `getPluginList(params)`: Get a paginated list of plugins
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
market.plugins.getPluginList({
|
|
170
|
+
page: 1,
|
|
171
|
+
pageSize: 10,
|
|
172
|
+
locale: 'en-US',
|
|
173
|
+
category: 'tools',
|
|
174
|
+
searchKey: 'weather',
|
|
175
|
+
tags: ['api'],
|
|
176
|
+
sort: 'downloads',
|
|
177
|
+
});
|
|
178
|
+
```
|
|
88
179
|
|
|
89
|
-
|
|
180
|
+
- `getCategories()`: Get plugin categories
|
|
90
181
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
182
|
+
```typescript
|
|
183
|
+
market.plugins.getCategories();
|
|
184
|
+
```
|
|
94
185
|
|
|
95
|
-
|
|
186
|
+
- `getPluginManifest(params)`: Get a plugin's manifest
|
|
96
187
|
|
|
97
|
-
|
|
188
|
+
```typescript
|
|
189
|
+
market.plugins.getPluginManifest({ id: 'plugin-id' });
|
|
190
|
+
```
|
|
98
191
|
|
|
99
|
-
|
|
192
|
+
- `getPluginDetail(params)`: Get detailed information about a plugin
|
|
193
|
+
```typescript
|
|
194
|
+
market.plugins.getPluginDetail({ id: 'plugin-id' });
|
|
195
|
+
```
|
|
100
196
|
|
|
101
|
-
|
|
197
|
+
#### discovery
|
|
102
198
|
|
|
103
|
-
|
|
199
|
+
- `getDiscoveryDocument()`: Get API capability information
|
|
200
|
+
```typescript
|
|
201
|
+
market.discovery.getDiscoveryDocument();
|
|
202
|
+
```
|
|
104
203
|
|
|
105
|
-
|
|
204
|
+
### MarketAdmin Services
|
|
106
205
|
|
|
107
|
-
|
|
108
|
-
- `params.pageSize`: 每页数量,默认为 20
|
|
109
|
-
- `params.category`: 按分类筛选
|
|
110
|
-
- `params.tags`: 按标签筛选 (逗号分隔)
|
|
111
|
-
- `params.q`: 搜索关键词
|
|
112
|
-
- `params.sort`: 排序字段 ('installCount', 'createdAt', 'updatedAt', 'ratingAverage')
|
|
113
|
-
- `params.order`: 排序方向 ('asc' 或 'desc')
|
|
114
|
-
- `params.locale`: 语言,默认为构造函数中设置的值
|
|
206
|
+
#### plugins
|
|
115
207
|
|
|
116
|
-
|
|
208
|
+
Methods for managing plugins:
|
|
117
209
|
|
|
118
|
-
|
|
210
|
+
- `createPlugin(data)`: Create a new plugin
|
|
211
|
+
- `updatePlugin(params, data)`: Update an existing plugin
|
|
212
|
+
- `getPluginList(params)`: Get a list of plugins (admin view)
|
|
213
|
+
- `getPluginDetail(params)`: Get detailed plugin information
|
|
214
|
+
- `deletePlugin(params)`: Delete a plugin
|
|
215
|
+
- `publishPlugin(params)`: Publish a plugin
|
|
216
|
+
- `unpublishPlugin(params)`: Unpublish a plugin
|
|
217
|
+
- `approvePlugin(params)`: Approve a plugin
|
|
218
|
+
- `rejectPlugin(params)`: Reject a plugin
|
|
119
219
|
|
|
120
|
-
|
|
220
|
+
#### reviews
|
|
121
221
|
|
|
122
|
-
|
|
123
|
-
- `locale`: 语言,可选,默认为构造函数中设置的值
|
|
124
|
-
- `version`: 版本号,可选,默认获取最新版本
|
|
222
|
+
Methods for managing user reviews:
|
|
125
223
|
|
|
126
|
-
|
|
224
|
+
- `getReviewList(params)`: Get a list of reviews
|
|
225
|
+
- `createReview(data)`: Create a new review
|
|
226
|
+
- `deleteReview(params)`: Delete a review
|
|
227
|
+
- `approveReview(params)`: Approve a review
|
|
228
|
+
- `rejectReview(params)`: Reject a review
|
|
127
229
|
|
|
128
|
-
|
|
230
|
+
#### settings
|
|
129
231
|
|
|
130
|
-
|
|
232
|
+
Methods for managing marketplace settings:
|
|
131
233
|
|
|
132
|
-
- `
|
|
133
|
-
- `
|
|
234
|
+
- `getSettings()`: Get current marketplace settings
|
|
235
|
+
- `updateSettings(data)`: Update marketplace settings
|
|
134
236
|
|
|
135
|
-
|
|
237
|
+
#### dependencies
|
|
136
238
|
|
|
137
|
-
|
|
239
|
+
Methods for managing system dependencies:
|
|
138
240
|
|
|
139
|
-
|
|
241
|
+
- `getDependencyList(params)`: Get a list of system dependencies
|
|
242
|
+
- `createDependency(data)`: Create a new system dependency
|
|
243
|
+
- `updateDependency(params, data)`: Update an existing dependency
|
|
244
|
+
- `deleteDependency(params)`: Delete a system dependency
|
|
140
245
|
|
|
141
|
-
|
|
246
|
+
## TypeScript Support
|
|
142
247
|
|
|
143
|
-
|
|
248
|
+
This SDK is written in TypeScript and provides comprehensive type definitions for all APIs. The types are automatically included when you install the package.
|
|
144
249
|
|
|
145
|
-
|
|
250
|
+
## Error Handling
|
|
146
251
|
|
|
147
|
-
|
|
148
|
-
- `ConnectionType`
|
|
149
|
-
- `InstallationMethod`
|
|
150
|
-
- `SystemDependency`
|
|
151
|
-
- `ConnectionConfig`
|
|
152
|
-
- `DeploymentOption`
|
|
153
|
-
- `PluginCompatibility`
|
|
154
|
-
- `PluginItem`
|
|
155
|
-
- `PluginListResponse`
|
|
156
|
-
- `PluginManifest`
|
|
157
|
-
- `DiscoveryDocument`
|
|
158
|
-
- `MarketSDKOptions`
|
|
252
|
+
The SDK throws standard errors with detailed information:
|
|
159
253
|
|
|
160
|
-
|
|
254
|
+
```typescript
|
|
255
|
+
try {
|
|
256
|
+
await market.plugins.getPluginList();
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error('Error code:', error.code);
|
|
259
|
+
console.error('Error message:', error.message);
|
|
260
|
+
console.error('Error details:', error.details);
|
|
261
|
+
}
|
|
262
|
+
```
|
|
161
263
|
|
|
162
|
-
|
|
264
|
+
## Contributing
|
|
163
265
|
|
|
164
|
-
-
|
|
165
|
-
- Node.js 18+
|
|
166
|
-
- Deno
|
|
167
|
-
- Bun
|
|
168
|
-
- 其他支持fetch API的运行时
|
|
266
|
+
We welcome contributions! Please see our [contributing guidelines](https://github.com/lobehub/lobehub-market/blob/main/CONTRIBUTING.md) for details.
|
|
169
267
|
|
|
170
|
-
##
|
|
268
|
+
## License
|
|
171
269
|
|
|
172
270
|
MIT
|