JavaScript SDK for accessing the LobeHub Market API, providing easy integration with the LobeHub ecosystem.
- 🚀 Easy Integration: Simple API for accessing LobeHub Marketplace resources
- 🔌 Plugin Support: Browse, search, and fetch plugin manifests
- 🔒 Authentication: Secure API access with token-based authentication
- 🧩 Modular Architecture: Logically separated services for different API domains
- 🌐 Localization: Built-in support for localized content
- 🔍 Discovery: Automatic service discovery for API capabilities
- 📊 Admin Tools: Comprehensive admin APIs for marketplace management
# Using npm
npm install @lobehub/market-sdk
# Using yarn
yarn add @lobehub/market-sdk
# Using pnpm
pnpm add @lobehub/market-sdk
src/
├── market/ - Market SDK implementation
│ ├── services/ - Market services
│ │ ├── PluginsService.ts - Plugin-related operations
│ │ └── DiscoveryService.ts - API discovery
│ └── market-sdk.ts - Main SDK class
├── admin/ - Admin SDK implementation
│ ├── services/ - Admin services
│ │ ├── PluginService.ts - Plugin management
│ │ ├── ReviewService.ts - Review management
│ │ ├── SettingsService.ts - Settings management
│ │ └── SystemDependencyService.ts - Dependencies management
│ └── MarketAdmin.ts - Admin SDK class
├── core/ - Core utilities and base classes
├── types/ - TypeScript type definitions
└── index.ts - Main entry point
import { MarketSDK } from '@lobehub/market-sdk';
// Create a client instance
const market = new MarketSDK({
// Optional: custom API base URL (defaults to https://market.lobehub.com/api)
baseURL: 'https://your-api-url.com/api',
// Optional: API key for authentication
apiKey: 'your-api-key',
// Optional: default locale for localized content
defaultLocale: 'en-US',
});
// Example: Get a list of plugins
async function getPlugins() {
try {
const result = await market.plugins.getPluginList({
page: 1,
pageSize: 10,
locale: 'en-US',
// Additional filter parameters
});
console.log(`Found ${result.data.items.length} plugins`);
console.log('Plugins:', result.data.items);
} catch (error) {
console.error('Error fetching plugins:', error);
}
}
// Example: Get plugin categories
async function getCategories() {
try {
const result = await market.plugins.getCategories();
console.log('Categories:', result.data);
} catch (error) {
console.error('Error fetching categories:', error);
}
}
// Example: Get a plugin's manifest
async function getPluginManifest(pluginId) {
try {
const result = await market.plugins.getPluginManifest({ id: pluginId });
console.log('Plugin manifest:', result.data);
} catch (error) {
console.error('Error fetching plugin manifest:', error);
}
}
For administrative operations, use the MarketAdmin
class:
import { MarketAdmin } from '@lobehub/market-sdk';
// Create an admin client instance
const admin = new MarketAdmin({
// Required: Admin API key
apiKey: 'your-admin-api-key',
// Optional: custom API base URL
baseURL: 'https://your-api-url.com/api',
});
// Example: Create a new plugin
async function createPlugin() {
try {
const result = await admin.plugins.createPlugin({
meta: {
title: 'My Plugin',
description: 'A sample plugin',
author: 'LobeHub',
homepage: 'https://github.com/lobehub/my-plugin',
},
manifest: {
// Plugin manifest details
},
});
console.log('Plugin created:', result.data);
} catch (error) {
console.error('Error creating plugin:', error);
}
}
// Example: Update plugin settings
async function updateSettings() {
try {
const result = await admin.settings.updateSettings({
pluginReviewEnabled: true,
publishPluginEnabled: true,
});
console.log('Settings updated:', result.data);
} catch (error) {
console.error('Error updating settings:', error);
}
}
Methods for accessing plugin resources:
-
getPluginList(params)
: Get a paginated list of pluginsmarket.plugins.getPluginList({ page: 1, pageSize: 10, locale: 'en-US', category: 'tools', searchKey: 'weather', tags: ['api'], sort: 'downloads', });
-
getCategories()
: Get plugin categoriesmarket.plugins.getCategories();
-
getPublishedIdentifiers()
: Get all published plugin identifiersmarket.plugins.getPublishedIdentifiers();
-
getPluginManifest(params)
: Get a plugin's manifestmarket.plugins.getPluginManifest({ id: 'plugin-id' });
-
getPluginDetail(params)
: Get detailed information about a pluginmarket.plugins.getPluginDetail({ id: 'plugin-id' });
-
getDiscoveryDocument()
: Get API capability informationmarket.discovery.getDiscoveryDocument();
Methods for managing plugins:
-
createPlugin(data)
: Create a new plugin -
updatePlugin(params, data)
: Update an existing plugin -
getPluginList(params)
: Get a list of plugins (admin view) -
getPluginDetail(params)
: Get detailed plugin information -
deletePlugin(params)
: Delete a plugin -
publishPlugin(params)
: Publish a plugin -
unpublishPlugin(params)
: Unpublish a plugin -
approvePlugin(params)
: Approve a plugin -
rejectPlugin(params)
: Reject a plugin
Methods for managing user reviews:
-
getReviewList(params)
: Get a list of reviews -
createReview(data)
: Create a new review -
deleteReview(params)
: Delete a review -
approveReview(params)
: Approve a review -
rejectReview(params)
: Reject a review
Methods for managing marketplace settings:
-
getSettings()
: Get current marketplace settings -
updateSettings(data)
: Update marketplace settings
Methods for managing system dependencies:
-
getDependencyList(params)
: Get a list of system dependencies -
createDependency(data)
: Create a new system dependency -
updateDependency(params, data)
: Update an existing dependency -
deleteDependency(params)
: Delete a system dependency
This SDK is written in TypeScript and provides comprehensive type definitions for all APIs. The types are automatically included when you install the package.
The SDK throws standard errors with detailed information:
try {
await market.plugins.getPluginList();
} catch (error) {
console.error('Error code:', error.code);
console.error('Error message:', error.message);
console.error('Error details:', error.details);
}
We welcome contributions! Please see our contributing guidelines for details.
MIT