UNPKG

lunarcrush-sdk

Version:

TypeScript/JavaScript SDK for LunarCrush API v4 with GraphQL and MCP support for AI workflows

868 lines (864 loc) 33.3 kB
/** MCP client configuration */ interface MCPConfig { apiKey: string; endpoint?: string; timeout?: number; } /** Parsed data from MCP markdown responses */ interface ParsedMCPData { raw: string; tables?: Array<Record<string, string>>; metadata?: Record<string, any>; tsv?: Array<Record<string, string>>; } declare class MCPError extends Error { toolName?: string | undefined; constructor(message: string, toolName?: string | undefined); } /** * 🤖 LunarCrush MCP Client - Direct AI Integration * * Clean, simple API - each tool is a direct function call */ declare class LunarCrushMCP { private client?; private config; constructor(apiKeyOrConfig: string | MCPConfig); private buildConfig; /** * Connect to MCP server */ connect(): Promise<void>; /** * Execute MCP tool with error handling */ private callTool; /** * Parse MCP markdown response into structured data */ private parseResponse; /** * Parse markdown tables into objects */ private parseMarkdownTables; /** * Parse TSV data into objects */ private parseTSV; /** * Extract metadata from markdown headers and text */ private extractMetadata; /** * Get topics within a category * @example await mcp.list('cryptocurrencies') */ list: (category?: string) => Promise<ParsedMCPData>; /** * Get sorted cryptocurrencies * @example await mcp.cryptocurrencies({ filter: 'ai', limit: 10 }) */ cryptocurrencies: (options?: { filter?: string; sort?: string; limit?: number; }) => Promise<ParsedMCPData>; /** * Get sorted stocks * @example await mcp.stocks({ sector: 'technology', limit: 5 }) */ stocks: (options?: { sector?: string; sort?: string; limit?: number; }) => Promise<ParsedMCPData>; /** * Get full topic details * @example await mcp.topics('bitcoin') */ topics: (topic: string) => Promise<ParsedMCPData>; /** * Get creator insights * @example await mcp.creators('elonmusk', 'x') */ creators: (screenName: string, network?: string) => Promise<ParsedMCPData>; /** * Get specific post details * @example await mcp.posts('1234567890', 'x') */ posts: (id: string, network?: string) => Promise<ParsedMCPData>; /** * Get historical time series * @example await mcp.timeSeries('bitcoin', { metrics: ['sentiment'], interval: '1w' }) */ timeSeries: (topic: string, options?: { metrics?: string[]; interval?: "1d" | "1w" | "1m" | "3m" | "6m" | "1y" | "all"; }) => Promise<ParsedMCPData>; /** * Get popular posts for a topic * @example await mcp.topicPosts('bitcoin', { interval: '1d' }) */ topicPosts: (topic: string, options?: { interval?: string; from_date?: string; to_date?: string; }) => Promise<ParsedMCPData>; /** * Universal search * @example await mcp.search('AI cryptocurrency') */ search: (query: string) => Promise<ParsedMCPData>; /** * Direct API path access * @example await mcp.fetch('/topic/bitcoin') */ fetch: (id: string) => Promise<ParsedMCPData>; /** * Authenticate session */ authenticate: (apiKey: string) => Promise<ParsedMCPData>; /** * Close MCP connection */ close(): Promise<void>; } /** Unix timestamp as string (e.g., "1640995200") */ type UnixTimestamp = string; declare class LunarCrushError extends Error { statusCode?: number | undefined; statusText?: string | undefined; constructor(message: string, statusCode?: number | undefined, statusText?: string | undefined); } interface LunarCrushConfig { apiKey: string; endpoint?: string; timeout?: number; headers?: Record<string, string>; cache?: boolean; retries?: number; } interface TimeSeriesOptions { interval?: string; /** Unix timestamp string (e.g., "1640995200") */ start?: UnixTimestamp; /** Unix timestamp string (e.g., "1640995200") */ end?: UnixTimestamp; bucket?: string; } interface PostsOptions { /** Unix timestamp string (e.g., "1640995200") */ start?: UnixTimestamp; /** Unix timestamp string (e.g., "1640995200") */ end?: UnixTimestamp; } interface ListOptions { sort?: string; filter?: string; limit?: number; desc?: string; page?: number; } /** * 🌙 LunarCrush SDK - Complete Production Ready SDK * */ declare class LunarCrush { private sdk; constructor(apiKeyOrConfig?: string | LunarCrushConfig); private buildConfig; private withErrorHandling; topics: { list: () => Promise<({ __typename?: "TopicListItem"; topic?: string | null; title?: string | null; topic_rank?: number | null; topic_rank_1h_previous?: number | null; topic_rank_24h_previous?: number | null; num_contributors?: number | null; num_posts?: number | null; interactions_24h?: number | null; } | null)[] | null | undefined>; get: (topic: string) => Promise<{ __typename?: "TopicDetails"; topic?: string | null; title?: string | null; topic_rank?: number | null; related_topics?: Array<string | null> | null; types_count?: Record<string, any> | null; types_interactions?: Record<string, any> | null; types_sentiment?: Record<string, any> | null; types_sentiment_detail?: Record<string, any> | null; interactions_24h?: number | null; num_contributors?: number | null; num_posts?: number | null; categories?: Array<string | null> | null; trend?: string | null; } | null | undefined>; whatsup: (topic: string) => Promise<{ __typename?: "TopicWhatsup"; summary?: string | null; } | null | undefined>; timeSeries: (topic: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "TopicTimeSeriesItem"; time?: number | null; contributors_active?: number | null; contributors_created?: number | null; interactions?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; spam?: number | null; alt_rank?: number | null; circulating_supply?: number | null; close?: number | null; galaxy_score?: number | null; high?: number | null; low?: number | null; market_cap?: number | null; market_dominance?: number | null; open?: number | null; social_dominance?: number | null; volume_24h?: number | null; } | null)[] | null | undefined>; timeSeriesV2: (topic: string, bucket?: string) => Promise<({ __typename?: "TopicTimeSeriesItem"; time?: number | null; contributors_active?: number | null; contributors_created?: number | null; interactions?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; spam?: number | null; alt_rank?: number | null; circulating_supply?: number | null; close?: number | null; galaxy_score?: number | null; high?: number | null; low?: number | null; market_cap?: number | null; market_dominance?: number | null; open?: number | null; social_dominance?: number | null; volume_24h?: number | null; } | null)[] | null | undefined>; posts: (topic: string, options?: PostsOptions) => Promise<({ __typename?: "TopicPost"; id?: string | null; post_type?: string | null; post_title?: string | null; post_link?: string | null; post_image?: string | null; post_created?: number | null; post_sentiment?: number | null; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_followers?: number | null; creator_avatar?: string | null; interactions_24h?: number | null; interactions_total?: number | null; } | null)[] | null | undefined>; news: (topic: string) => Promise<({ __typename?: "TopicNews"; id?: string | null; post_type?: string | null; post_title?: string | null; post_link?: string | null; post_image?: string | null; post_created?: number | null; post_sentiment?: number | null; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_followers?: number | null; creator_avatar?: string | null; interactions_24h?: number | null; interactions_total?: number | null; } | null)[] | null | undefined>; creators: (topic: string) => Promise<({ __typename?: "TopicCreator"; creator_id?: string | null; creator_name?: string | null; creator_avatar?: string | null; creator_followers?: number | null; creator_rank?: number | null; interactions_24h?: number | null; } | null)[] | null | undefined>; }; categories: { list: () => Promise<({ __typename?: "CategoryListItem"; category?: string | null; title?: string | null; category_rank?: number | null; category_rank_1h_previous?: number | null; category_rank_24h_previous?: number | null; interactions_24h?: number | null; num_contributors?: number | null; num_posts?: number | null; social_dominance?: number | null; } | null)[] | null | undefined>; get: (category: string) => Promise<{ __typename?: "CategoryDetails"; topic?: string | null; title?: string | null; related_topics?: Array<string | null> | null; types_count?: Record<string, any> | null; types_interactions?: Record<string, any> | null; types_sentiment?: Record<string, any> | null; types_sentiment_detail?: Record<string, any> | null; interactions_24h?: number | null; num_contributors?: number | null; num_posts?: number | null; trend?: string | null; } | null | undefined>; topics: (category: string) => Promise<({ __typename?: "CategoryTopic"; topic?: number | null; title?: string | null; topic_rank?: number | null; topic_rank_1h_previous?: number | null; topic_rank_24h_previous?: number | null; num_contributors?: number | null; social_dominance?: number | null; num_posts?: number | null; interactions_24h?: number | null; } | null)[] | null | undefined>; timeSeries: (category: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "CategoryTimeSeriesItem"; time?: number | null; contributors_active?: number | null; contributors_created?: number | null; interactions?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; spam?: number | null; } | null)[] | null | undefined>; posts: (category: string, options?: PostsOptions) => Promise<({ __typename?: "CategoryPost"; id?: string | null; post_type?: string | null; post_title?: string | null; post_link?: string | null; post_image?: string | null; post_created?: number | null; post_sentiment?: number | null; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_followers?: number | null; creator_avatar?: string | null; interactions_24h?: number | null; interactions_total?: number | null; } | null)[] | null | undefined>; news: (category: string) => Promise<({ __typename?: "CategoryNews"; id?: string | null; post_title?: string | null; post_type?: string | null; post_link?: string | null; post_image?: string | null; post_created?: number | null; post_sentiment?: number | null; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_followers?: number | null; creator_avatar?: string | null; interactions_24h?: number | null; interactions_total?: number | null; } | null)[] | null | undefined>; creators: (category: string) => Promise<({ __typename?: "CategoryCreator"; creator_id?: string | null; creator_name?: string | null; creator_avatar?: string | null; creator_followers?: number | null; creator_rank?: number | null; interactions_24h?: number | null; } | null)[] | null | undefined>; }; creators: { list: () => Promise<({ __typename?: "CreatorListItem"; creator_display_name?: string | null; creator_id?: string | null; creator_network?: string | null; creator_avatar?: string | null; creator_followers?: number | null; creator_name?: string | null; creator_posts?: number | null; creator_rank?: number | null; interactions_24h?: number | null; } | null)[] | null | undefined>; get: (network: string, id: string) => Promise<{ __typename?: "CreatorDetails"; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_avatar?: string | null; creator_followers?: number | null; creator_rank?: string | null; interactions_24h?: number | null; topic_influence?: Array<{ __typename?: "TopicInfluence"; topic?: string | null; count?: number | null; percent?: number | null; rank?: number | null; } | null> | null; } | null | undefined>; timeSeries: (network: string, id: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "CreatorTimeSeriesItem"; time?: number | null; followers?: number | null; interactions?: number | null; posts_active?: number | null; creator_rank?: number | null; } | null)[] | null | undefined>; posts: (network: string, id: string, options?: PostsOptions) => Promise<({ __typename?: "CreatorPost"; id?: string | null; post_type?: string | null; post_title?: string | null; post_created?: number | null; post_sentiment?: number | null; post_link?: string | null; post_image?: string | null; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_followers?: number | null; creator_avatar?: string | null; interactions_24h?: number | null; interactions_total?: number | null; } | null)[] | null | undefined>; }; coins: { list: (options?: ListOptions) => Promise<({ __typename?: "CoinListItem"; id?: number | null; symbol?: string | null; name?: string | null; price?: number | null; price_btc?: number | null; volume_24h?: number | null; volatility?: number | null; circulating_supply?: number | null; max_supply?: number | null; percent_change_1h?: number | null; percent_change_24h?: number | null; percent_change_7d?: number | null; percent_change_30d?: number | null; market_cap?: number | null; market_cap_rank?: number | null; interactions_24h?: number | null; social_volume_24h?: number | null; social_dominance?: number | null; market_dominance?: number | null; market_dominance_prev?: number | null; galaxy_score?: number | null; galaxy_score_previous?: number | null; alt_rank?: number | null; alt_rank_previous?: number | null; sentiment?: number | null; categories?: string | null; last_updated_price?: number | null; last_updated_price_by?: string | null; topic?: string | null; logo?: string | null; blockchains?: Array<{ __typename?: "Blockchain"; type?: string | null; network?: string | null; address?: string | null; decimals?: number | null; } | null> | null; } | null)[] | null | undefined>; listV2: (options?: ListOptions) => Promise<({ __typename?: "CoinListItem"; id?: number | null; symbol?: string | null; name?: string | null; price?: number | null; price_btc?: number | null; volume_24h?: number | null; volatility?: number | null; circulating_supply?: number | null; max_supply?: number | null; percent_change_1h?: number | null; percent_change_24h?: number | null; percent_change_7d?: number | null; percent_change_30d?: number | null; market_cap?: number | null; market_cap_rank?: number | null; interactions_24h?: number | null; social_volume_24h?: number | null; social_dominance?: number | null; market_dominance?: number | null; market_dominance_prev?: number | null; galaxy_score?: number | null; galaxy_score_previous?: number | null; alt_rank?: number | null; alt_rank_previous?: number | null; sentiment?: number | null; categories?: string | null; last_updated_price?: number | null; last_updated_price_by?: string | null; topic?: string | null; logo?: string | null; blockchains?: Array<{ __typename?: "Blockchain"; type?: string | null; network?: string | null; address?: string | null; decimals?: number | null; } | null> | null; } | null)[] | null | undefined>; get: (coin: string) => Promise<{ __typename?: "CoinDetails"; id?: number | null; name?: string | null; symbol?: string | null; price?: number | null; price_btc?: number | null; market_cap?: number | null; percent_change_24h?: number | null; percent_change_7d?: number | null; percent_change_30d?: number | null; volume_24h?: number | null; max_supply?: number | null; circulating_supply?: number | null; close?: number | null; galaxy_score?: number | null; alt_rank?: number | null; volatility?: number | null; market_cap_rank?: number | null; } | null | undefined>; meta: (coin: string) => Promise<{ __typename?: "CoinMeta"; id?: number | null; name?: string | null; symbol?: string | null; market_categories?: string | null; updated?: number | null; short_summary?: string | null; description?: string | null; github_link?: string | null; website_link?: string | null; whitepaper_link?: string | null; twitter_link?: string | null; reddit_link?: string | null; header_image?: string | null; header_text?: string | null; videos?: string | null; coingecko_link?: string | null; coinmarketcap_link?: string | null; blockchain?: Array<{ __typename?: "Blockchain"; type?: string | null; network?: string | null; address?: string | null; decimals?: number | null; } | null> | null; } | null | undefined>; timeSeries: (coin: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "CoinTimeSeriesItem"; time?: number | null; contributors_active?: number | null; contributors_created?: number | null; interactions?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; spam?: number | null; alt_rank?: number | null; circulating_supply?: number | null; close?: number | null; galaxy_score?: number | null; high?: number | null; low?: number | null; market_cap?: number | null; market_dominance?: number | null; open?: number | null; social_dominance?: number | null; volume_24h?: number | null; } | null)[] | null | undefined>; }; stocks: { list: () => Promise<({ __typename?: "StockListItem"; id?: number | null; symbol?: string | null; name?: string | null; price?: number | null; volume_24h?: number | null; percent_change_24h?: number | null; market_cap?: string | null; market_cap_rank?: number | null; interactions_24h?: number | null; social_volume_24h?: number | null; social_dominance?: number | null; market_dominance?: number | null; market_dominance_prev?: number | null; galaxy_score?: number | null; galaxy_score_previous?: number | null; alt_rank?: number | null; alt_rank_previous?: number | null; sentiment?: number | null; categories?: string | null; last_updated_price?: number | null; last_updated_price_by?: string | null; topic?: string | null; logo?: string | null; } | null)[] | null | undefined>; listV2: (options?: Omit<ListOptions, "filter">) => Promise<({ __typename?: "StockListItem"; id?: number | null; symbol?: string | null; name?: string | null; price?: number | null; volume_24h?: number | null; percent_change_24h?: number | null; market_cap?: string | null; market_cap_rank?: number | null; interactions_24h?: number | null; social_volume_24h?: number | null; social_dominance?: number | null; market_dominance?: number | null; market_dominance_prev?: number | null; galaxy_score?: number | null; galaxy_score_previous?: number | null; alt_rank?: number | null; alt_rank_previous?: number | null; sentiment?: number | null; categories?: string | null; last_updated_price?: number | null; last_updated_price_by?: string | null; topic?: string | null; logo?: string | null; } | null)[] | null | undefined>; get: (stock: string) => Promise<{ __typename?: "StockDetails"; id?: number | null; name?: string | null; symbol?: string | null; price?: number | null; market_cap?: number | null; percent_change_24h?: number | null; volume_24h?: number | null; close?: number | null; market_cap_rank?: number | null; } | null | undefined>; timeSeries: (stock: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "StockTimeSeriesItem"; time?: number | null; close?: number | null; alt_rank?: number | null; contributors_active?: number | null; contributors_created?: number | null; galaxy_score?: number | null; high?: number | null; interactions?: number | null; low?: number | null; market_cap?: number | null; market_dominance?: number | null; open?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; social_dominance?: number | null; spam?: number | null; } | null)[] | null | undefined>; }; nfts: { list: (options?: Omit<ListOptions, "filter">) => Promise<({ __typename?: "NftListItem"; id?: number | null; name?: string | null; logo?: string | null; floor_price?: number | null; alt_rank?: number | null; base_crypto?: string | null; galaxy_score?: number | null; interactions_24h?: number | null; lunar_id?: string | null; market_cap?: number | null; percent_change_24h?: number | null; social_contributors?: number | null; social_dominance?: number | null; social_volume_24h?: number | null; volume_24h?: number | null; } | null)[] | null | undefined>; listV2: (options?: Omit<ListOptions, "filter">) => Promise<({ __typename?: "NftListItem"; id?: number | null; name?: string | null; logo?: string | null; floor_price?: number | null; alt_rank?: number | null; base_crypto?: string | null; galaxy_score?: number | null; interactions_24h?: number | null; lunar_id?: string | null; market_cap?: number | null; percent_change_24h?: number | null; social_contributors?: number | null; social_dominance?: number | null; social_volume_24h?: number | null; volume_24h?: number | null; } | null)[] | null | undefined>; get: (id: string) => Promise<{ __typename?: "NftDetails"; id?: number | null; name?: string | null; floor_price?: number | null; market_cap?: number | null; percent_change_24h?: number | null; volume_24h?: number | null; } | null | undefined>; timeSeries: (id: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "NftTimeSeriesItem"; time?: number | null; alt_rank?: number | null; contributors_active?: number | null; contributors_created?: number | null; interactions?: number | null; market_cap?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; social_dominance?: number | null; } | null)[] | null | undefined>; timeSeriesV2: (nft: string, options?: TimeSeriesOptions) => Promise<({ __typename?: "NftTimeSeriesItem"; time?: number | null; alt_rank?: number | null; contributors_active?: number | null; contributors_created?: number | null; interactions?: number | null; market_cap?: number | null; posts_active?: number | null; posts_created?: number | null; sentiment?: number | null; social_dominance?: number | null; } | null)[] | null | undefined>; }; posts: { details: (post_type: string, post_id: string) => Promise<{ __typename?: "PostDetails"; type?: string | null; id?: string | null; title?: string | null; description?: string | null; extraText?: string | null; video?: string | null; images?: Array<string | null> | null; creator_id?: string | null; creator_name?: string | null; creator_display_name?: string | null; creator_avatar?: string | null; topics?: Array<string | null> | null; categories?: Array<string | null> | null; metrics?: { __typename?: "PostMetrics"; bookmarks?: number | null; favorites?: number | null; retweets?: number | null; replies?: number | null; views?: number | null; } | null; image?: { __typename?: "PostImage"; src?: string | null; width?: number | null; height?: number | null; } | null; } | null | undefined>; timeSeries: (post_type: string, post_id: string) => Promise<({ __typename?: "PostTimeSeriesItem"; time?: string | null; interactions?: number | null; } | null)[] | null | undefined>; }; system: { health: () => Promise<{ __typename?: "SystemHealthResponse"; status: string; uptime: number; version: string; timestamp: string; } | null | undefined>; ping: () => Promise<{ __typename?: "PingResponse"; status: string; timestamp: string; } | null | undefined>; hello: () => Promise<string | null | undefined>; changes: (options?: PostsOptions) => Promise<({ __typename?: "SystemChange"; asset_id?: string | null; asset_name?: string | null; asset_type?: string | null; change?: string | null; description?: string | null; time?: number | null; } | null)[] | null | undefined>; }; } /** * Create a new LunarCrush SDK instance * * @param apiKeyOrConfig - API key string or full configuration object * @returns Configured LunarCrush SDK instance with complete API coverage * * @example * ```typescript * // Simple initialization * const lc = createLunarCrush('your-api-key'); * * // Advanced configuration * const lc = createLunarCrush({ * apiKey: 'your-api-key', * endpoint: 'https://your-custom-endpoint.com/graphql', * timeout: 30000, * headers: { 'Custom-Header': 'value' } * }); * * // Usage examples * const topics = await lc.topics.list(); * const bitcoinData = await lc.coins.get('bitcoin'); * const sentiment = await lc.topics.whatsup('bitcoin'); * ``` */ declare function createLunarCrush(apiKeyOrConfig?: string | LunarCrushConfig): LunarCrush; /** * Create a LunarCrush MCP client for AI workflows * * @param apiKeyOrConfig - API key string or full configuration * @returns MCP client for real-time AI data integration * * @example * ```typescript * // Simple usage * const mcpClient = await createLunarCrushMCP('your-api-key'); * const bitcoinData = await mcpClient.topics.get('bitcoin'); * * // Access parsed data * console.log(bitcoinData.raw); // Full markdown * console.log(bitcoinData.metadata.title); // "Bitcoin (BTC)" * console.log(bitcoinData.tables); // Parsed tables if any * * // AI Assistant integration * const sentiment = await mcpClient.topics.timeSeries('bitcoin', { * metrics: ['sentiment', 'interactions'], * interval: '1d' * }); * ``` */ declare function createLunarCrushMCP(apiKeyOrConfig: string | MCPConfig): Promise<LunarCrushMCP>; export { type ListOptions, LunarCrush, type LunarCrushConfig, LunarCrushError, LunarCrushMCP, type MCPConfig, MCPError, type ParsedMCPData, type PostsOptions, type TimeSeriesOptions, type UnixTimestamp, createLunarCrush, createLunarCrushMCP, LunarCrush as default };