@lobehub/market-sdk 0.0.28 → 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 CHANGED
@@ -1,172 +1,270 @@
1
- # @lobehub/market-sdk
1
+ # LobeHub Market JavaScript SDK
2
2
 
3
- LobeHub Market 的 JavaScript SDK,提供对插件市场 API 的简单访问。
3
+ [![NPM version](https://img.shields.io/npm/v/@lobehub/market-sdk.svg?style=flat)](https://npmjs.org/package/@lobehub/market-sdk)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/@lobehub/market-sdk.svg?style=flat)](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
- - 使用原生 `fetch` API,无外部依赖
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
- // 创建 SDK 实例
59
+ // Create a client instance
26
60
  const market = new MarketSDK({
27
- // 可选配置
28
- baseUrl: 'https://market.lobehub.com/api', // 默认值
29
- defaultLocale: 'zh-CN', // 默认值
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
- const manifest = await market.getPluginManifest('lobehub/web-search');
48
- console.log(manifest);
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
- // 创建时提供 API Key
57
- const market = new MarketSDK({
58
- apiKey: 'your-api-key',
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
- market.setAuthToken('your-api-key');
63
-
64
- // 导入插件清单 (需要管理员权限)
65
- const result = await market.importManifests([
66
- {
67
- id: 'my-plugin',
68
- name: 'My Plugin',
69
- version: '1.0.0',
70
- description: '一个示例插件',
71
- // 其他清单字段...
72
- },
73
- ]);
74
- console.log(result);
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
- ### `MarketSDK`
160
+ ### MarketSDK Services
80
161
 
81
- 主要的 SDK 类
162
+ #### plugins
82
163
 
83
- #### 构造函数
164
+ Methods for accessing plugin resources:
84
165
 
85
- ```typescript
86
- constructor(options?: MarketSDKOptions)
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
- - `options.baseUrl`: API 基础 URL,默认为 'https://market.lobehub.com/api'
92
- - `options.defaultLocale`: 默认语言,默认为 'zh-CN'
93
- - `options.apiKey`: 可选的 API 认证密钥
182
+ ```typescript
183
+ market.plugins.getCategories();
184
+ ```
94
185
 
95
- #### 方法
186
+ - `getPluginManifest(params)`: Get a plugin's manifest
96
187
 
97
- ##### `getDiscoveryDocument()`
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
- ##### `getPluginList(params)`
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
- - `params.page`: 页码,默认为 1
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
- ##### `getPluginManifest(identifier, locale?, version?)`
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
- - `identifier`: 插件标识符 (必填)
123
- - `locale`: 语言,可选,默认为构造函数中设置的值
124
- - `version`: 版本号,可选,默认获取最新版本
222
+ Methods for managing user reviews:
125
223
 
126
- ##### `importManifests(manifests, ownerId?)`
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
- - `manifests`: 插件清单数组
133
- - `ownerId`: 所有者 ID (可选)
234
+ - `getSettings()`: Get current marketplace settings
235
+ - `updateSettings(data)`: Update marketplace settings
134
236
 
135
- ##### `setAuthToken(token)`
237
+ #### dependencies
136
238
 
137
- 设置认证令牌。
239
+ Methods for managing system dependencies:
138
240
 
139
- ##### `clearAuthToken()`
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
- SDK 导出以下类型:
250
+ ## Error Handling
146
251
 
147
- - `PluginType`
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
- 此SDK使用了原生fetch API,适用于:
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