@bandprotocol/membit
v0.0.1
Published
Official JavaScript library for Membit.
Readme
Membit JavaScript SDK
Membit's JavaScript SDK allows for easy interaction with the Membit API, offering intelligent search and content discovery capabilities directly from your JavaScript and TypeScript programs. Easily integrate smart search functionality into your applications, harnessing the powerful Membit Search API with advanced TypeScript support and automatic type inference.
Installing
npm i @bandprotocol/membitMembit Cluster Search
Discover trending topics and clusters of related content using the Membit Cluster Search API. Perfect for understanding what's trending and finding relevant content clusters.
Usage
Below is a simple code snippet that shows you how to use Membit Cluster Search:
const { membit } = require("@bandprotocol/membit");
// Step 1. Instantiating your Membit client
const client = membit({ apiKey: "your-api-key" });
// Step 2. Executing a cluster search query
const clusters = await client.cluster_search("artificial intelligence", {
limit: 3,
});
// Step 3. Printing the cluster results
console.log(clusters);Membit Cluster Info
Get detailed information about specific content clusters. Use this to dive deeper into topics discovered through cluster search.
Usage
Below is a simple code snippet demonstrating how to use Membit Cluster Info:
const { membit } = require("@bandprotocol/membit");
// Step 1. Instantiating your Membit client
const client = membit({ apiKey: "your-api-key" });
// Step 2. Get detailed cluster information
const clusterInfo = await client.cluster_info("AI Learning Resources", {
limit: 5,
format: "json",
});
// Step 3. Printing the cluster details
console.log("Cluster Info:", clusterInfo);Membit Post Search
Search for individual posts and content across the Membit platform. Perfect for finding specific content and articles.
Usage
Below is a simple code snippet demonstrating how to use Membit Post Search:
const { membit } = require("@bandprotocol/membit");
// Step 1. Instantiating your Membit client
const client = membit({ apiKey: "your-api-key" });
// Step 2. Search for posts
const posts = await client.post_search("machine learning", {
limit: 10,
format: "json",
});
// Step 3. Printing the post results
console.log("Found posts:", posts);TypeScript Benefits
Method Overloads
The SDK uses TypeScript method overloads to provide precise type safety:
// TypeScript automatically infers return types
const jsonData = await client.cluster_search("query"); // Record<string, any>
const textData = await client.cluster_search("query", { format: "llm" }); // stringFormat Options
Each method supports two output formats with automatic type inference:
| Format | Return Type | Use Case | TypeScript Type |
| -------- | --------------------- | -------------------------------------- | --------------- |
| "json" | Record<string, any> | Structured data for further processing | Object |
| "llm" | string | Human-readable text for direct display | String |
Configuration Options
import { membit, MembitClientOptions } from "@bandprotocol/membit";
const client = membit({
apiKey: "your-api-key", // Required (or set MEMBIT_API_KEY env var)
apiBaseURL: "https://custom.api", // Optional (defaults to Membit API)
});
// All methods support these options (showing defaults)
const result = await client.cluster_search("query", {
limit: 10, // number (default: 10)
format: "json", // "json" | "llm" (default: "json")
timeout: 60, // seconds (default: 60)
});Default Parameters
All search methods use the following defaults when options are not specified:
- limit:
10- Maximum number of results to return - format:
"json"- Return structured data as objects - timeout:
60- Request timeout in seconds
Environment Variables
You can set your API key using environment variables:
export MEMBIT_API_KEY="your-api-key-here"The client will automatically use this if no API key is provided in the constructor.
Examples
See the examples/ directory for more detailed usage examples:
examples/basic-usage.ts- Complete workflow with realistic API usage
API Methods
| Method | Purpose | Example Usage |
| ---------------- | ----------------------- | ------------------------------------------------------------------ |
| cluster_search | Search within clusters | client.cluster_search("artificial intelligence", { limit: 5 }) |
| cluster_info | Get cluster information | client.cluster_info("AI Learning Resources", { format: "llm" }) |
| post_search | Search posts | client.post_search("artificial intelligence", { format: "llm" }) |
License
This project is licensed under the terms of the MIT license.
