@lobehub/market-sdk v0.9.0
LobeHub Market JavaScript SDK
JavaScript SDK for accessing the LobeHub Market API, providing easy integration with the LobeHub ecosystem.
Features
- š 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
Installation
# Using npm
npm install @lobehub/market-sdk
# Using yarn
yarn add @lobehub/market-sdk
# Using pnpm
pnpm add @lobehub/market-sdkPackage Structure
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 pointUsage
Market SDK
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);
}
}Admin SDK
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);
}
}API Reference
MarketSDK Services
plugins
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' });
discovery
getDiscoveryDocument(): Get API capability informationmarket.discovery.getDiscoveryDocument();
MarketAdmin Services
plugins
Methods for managing plugins:
createPlugin(data): Create a new pluginupdatePlugin(params, data): Update an existing plugingetPluginList(params): Get a list of plugins (admin view)getPluginDetail(params): Get detailed plugin informationdeletePlugin(params): Delete a pluginpublishPlugin(params): Publish a pluginunpublishPlugin(params): Unpublish a pluginapprovePlugin(params): Approve a pluginrejectPlugin(params): Reject a plugin
reviews
Methods for managing user reviews:
getReviewList(params): Get a list of reviewscreateReview(data): Create a new reviewdeleteReview(params): Delete a reviewapproveReview(params): Approve a reviewrejectReview(params): Reject a review
settings
Methods for managing marketplace settings:
getSettings(): Get current marketplace settingsupdateSettings(data): Update marketplace settings
dependencies
Methods for managing system dependencies:
getDependencyList(params): Get a list of system dependenciescreateDependency(data): Create a new system dependencyupdateDependency(params, data): Update an existing dependencydeleteDependency(params): Delete a system dependency
TypeScript Support
This SDK is written in TypeScript and provides comprehensive type definitions for all APIs. The types are automatically included when you install the package.
Error Handling
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);
}Contributing
We welcome contributions! Please see our contributing guidelines for details.
License
MIT
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago