@lobehub/market-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.15.0 • Public • Published

LobeHub Market JavaScript SDK

NPM version NPM downloads

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-sdk

Package 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 point

Usage

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 plugins

    market.plugins.getPluginList({
      page: 1,
      pageSize: 10,
      locale: 'en-US',
      category: 'tools',
      searchKey: 'weather',
      tags: ['api'],
      sort: 'downloads',
    });
  • getCategories(): Get plugin categories

    market.plugins.getCategories();
  • getPublishedIdentifiers(): Get all published plugin identifiers

    market.plugins.getPublishedIdentifiers();
  • getPluginManifest(params): Get a plugin's manifest

    market.plugins.getPluginManifest({ id: 'plugin-id' });
  • getPluginDetail(params): Get detailed information about a plugin

    market.plugins.getPluginDetail({ id: 'plugin-id' });

discovery

  • getDiscoveryDocument(): Get API capability information
    market.discovery.getDiscoveryDocument();

MarketAdmin Services

plugins

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

reviews

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

settings

Methods for managing marketplace settings:

  • getSettings(): Get current marketplace settings
  • updateSettings(data): Update marketplace settings

dependencies

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

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

Package Sidebar

Install

npm i @lobehub/market-sdk

Weekly Downloads

323

Version

0.15.0

License

MIT

Unpacked Size

174 kB

Total Files

5

Last publish

Collaborators

  • arvinxx
  • canisminor1990