@lobehub/market-sdk 0.22.3 → 0.22.4
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/package.json +1 -1
- package/README.md +0 -335
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
# LobeHub Market JavaScript SDK
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.org/package/@lobehub/market-sdk)
|
|
4
|
-
[](https://npmjs.org/package/@lobehub/market-sdk)
|
|
5
|
-
|
|
6
|
-
JavaScript SDK for accessing the LobeHub Market API, providing easy integration with the LobeHub ecosystem.
|
|
7
|
-
|
|
8
|
-
## Features
|
|
9
|
-
|
|
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
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
# Using npm
|
|
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
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Package Structure
|
|
32
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { MarketSDK } from '@lobehub/market-sdk';
|
|
58
|
-
|
|
59
|
-
// Create a client instance
|
|
60
|
-
const market = new MarketSDK({
|
|
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',
|
|
67
|
-
});
|
|
68
|
-
|
|
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
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Admin SDK
|
|
108
|
-
|
|
109
|
-
For administrative operations, use the `MarketAdmin` class:
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
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',
|
|
120
|
-
});
|
|
121
|
-
|
|
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
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### M2M (Machine-to-Machine) Authentication
|
|
159
|
-
|
|
160
|
-
For server-to-server authentication, you can use M2M authentication with client credentials:
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
import { MarketAdmin, MarketSDK } from '@lobehub/market-sdk';
|
|
164
|
-
|
|
165
|
-
// Using M2M authentication for Market SDK
|
|
166
|
-
const market = new MarketSDK({
|
|
167
|
-
baseURL: 'https://market.lobehub.com/api',
|
|
168
|
-
clientId: 'your-client-id',
|
|
169
|
-
clientSecret: 'your-client-secret',
|
|
170
|
-
defaultLocale: 'en-US',
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Using M2M authentication for Admin SDK
|
|
174
|
-
const admin = new MarketAdmin({
|
|
175
|
-
baseURL: 'https://market.lobehub.com/api',
|
|
176
|
-
clientId: 'your-client-id',
|
|
177
|
-
clientSecret: 'your-client-secret',
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
// The SDK will automatically handle token exchange
|
|
181
|
-
async function useM2MAuthentication() {
|
|
182
|
-
try {
|
|
183
|
-
// For protected APIs that require authentication
|
|
184
|
-
const result = await market.plugins.reportInstallation({
|
|
185
|
-
identifier: 'plugin-id',
|
|
186
|
-
version: '1.0.0',
|
|
187
|
-
success: true,
|
|
188
|
-
installDurationMs: 1500,
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
console.log('Installation reported:', result);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
console.error('Error with M2M authentication:', error);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
#### How M2M Authentication Works
|
|
199
|
-
|
|
200
|
-
1. **Client Credentials**: You need to obtain `clientId` and `clientSecret` from the LobeHub Market administrator.
|
|
201
|
-
|
|
202
|
-
2. **Automatic Token Exchange**: The SDK automatically:
|
|
203
|
-
|
|
204
|
-
- Creates a signed JWT using your client credentials
|
|
205
|
-
- Exchanges this JWT for an access token
|
|
206
|
-
- Uses the access token for authenticated API requests
|
|
207
|
-
|
|
208
|
-
3. **Token Management**: The SDK handles token refresh automatically when needed.
|
|
209
|
-
|
|
210
|
-
#### M2M vs API Key Authentication
|
|
211
|
-
|
|
212
|
-
- **M2M Authentication**: More secure, uses JWT-based authentication with automatic token refresh
|
|
213
|
-
- **API Key Authentication**: Simple but less secure, uses static API keys
|
|
214
|
-
|
|
215
|
-
Choose M2M authentication for production environments and API keys for development/testing.
|
|
216
|
-
|
|
217
|
-
## API Reference
|
|
218
|
-
|
|
219
|
-
### MarketSDK Services
|
|
220
|
-
|
|
221
|
-
#### plugins
|
|
222
|
-
|
|
223
|
-
Methods for accessing plugin resources:
|
|
224
|
-
|
|
225
|
-
- `getPluginList(params)`: Get a paginated list of plugins
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
market.plugins.getPluginList({
|
|
229
|
-
page: 1,
|
|
230
|
-
pageSize: 10,
|
|
231
|
-
locale: 'en-US',
|
|
232
|
-
category: 'tools',
|
|
233
|
-
searchKey: 'weather',
|
|
234
|
-
tags: ['api'],
|
|
235
|
-
sort: 'downloads',
|
|
236
|
-
});
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
- `getCategories()`: Get plugin categories
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
market.plugins.getCategories();
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
- `getPublishedIdentifiers()`: Get all published plugin identifiers
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
market.plugins.getPublishedIdentifiers();
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
- `getPluginManifest(params)`: Get a plugin's manifest
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
market.plugins.getPluginManifest({ id: 'plugin-id' });
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
- `getPluginDetail(params)`: Get detailed information about a plugin
|
|
258
|
-
```typescript
|
|
259
|
-
market.plugins.getPluginDetail({ id: 'plugin-id' });
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### discovery
|
|
263
|
-
|
|
264
|
-
- `getDiscoveryDocument()`: Get API capability information
|
|
265
|
-
```typescript
|
|
266
|
-
market.discovery.getDiscoveryDocument();
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
### MarketAdmin Services
|
|
270
|
-
|
|
271
|
-
#### plugins
|
|
272
|
-
|
|
273
|
-
Methods for managing plugins:
|
|
274
|
-
|
|
275
|
-
- `createPlugin(data)`: Create a new plugin
|
|
276
|
-
- `updatePlugin(params, data)`: Update an existing plugin
|
|
277
|
-
- `getPluginList(params)`: Get a list of plugins (admin view)
|
|
278
|
-
- `getPluginDetail(params)`: Get detailed plugin information
|
|
279
|
-
- `deletePlugin(params)`: Delete a plugin
|
|
280
|
-
- `publishPlugin(params)`: Publish a plugin
|
|
281
|
-
- `unpublishPlugin(params)`: Unpublish a plugin
|
|
282
|
-
- `approvePlugin(params)`: Approve a plugin
|
|
283
|
-
- `rejectPlugin(params)`: Reject a plugin
|
|
284
|
-
|
|
285
|
-
#### reviews
|
|
286
|
-
|
|
287
|
-
Methods for managing user reviews:
|
|
288
|
-
|
|
289
|
-
- `getReviewList(params)`: Get a list of reviews
|
|
290
|
-
- `createReview(data)`: Create a new review
|
|
291
|
-
- `deleteReview(params)`: Delete a review
|
|
292
|
-
- `approveReview(params)`: Approve a review
|
|
293
|
-
- `rejectReview(params)`: Reject a review
|
|
294
|
-
|
|
295
|
-
#### settings
|
|
296
|
-
|
|
297
|
-
Methods for managing marketplace settings:
|
|
298
|
-
|
|
299
|
-
- `getSettings()`: Get current marketplace settings
|
|
300
|
-
- `updateSettings(data)`: Update marketplace settings
|
|
301
|
-
|
|
302
|
-
#### dependencies
|
|
303
|
-
|
|
304
|
-
Methods for managing system dependencies:
|
|
305
|
-
|
|
306
|
-
- `getDependencyList(params)`: Get a list of system dependencies
|
|
307
|
-
- `createDependency(data)`: Create a new system dependency
|
|
308
|
-
- `updateDependency(params, data)`: Update an existing dependency
|
|
309
|
-
- `deleteDependency(params)`: Delete a system dependency
|
|
310
|
-
|
|
311
|
-
## TypeScript Support
|
|
312
|
-
|
|
313
|
-
This SDK is written in TypeScript and provides comprehensive type definitions for all APIs. The types are automatically included when you install the package.
|
|
314
|
-
|
|
315
|
-
## Error Handling
|
|
316
|
-
|
|
317
|
-
The SDK throws standard errors with detailed information:
|
|
318
|
-
|
|
319
|
-
```typescript
|
|
320
|
-
try {
|
|
321
|
-
await market.plugins.getPluginList();
|
|
322
|
-
} catch (error) {
|
|
323
|
-
console.error('Error code:', error.code);
|
|
324
|
-
console.error('Error message:', error.message);
|
|
325
|
-
console.error('Error details:', error.details);
|
|
326
|
-
}
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
## Contributing
|
|
330
|
-
|
|
331
|
-
We welcome contributions! Please see our [contributing guidelines](https://github.com/lobehub/lobehub-market/blob/main/CONTRIBUTING.md) for details.
|
|
332
|
-
|
|
333
|
-
## License
|
|
334
|
-
|
|
335
|
-
MIT
|