UNPKG

@wasserstoff/tribes-sdk

Version:

SDK for integrating with Tribes by Astrix platform on any EVM compatible chain

181 lines (180 loc) 6.89 kB
import { ethers } from 'ethers'; import { BaseModule } from '../core/BaseModule'; import { CreatePostParams, CreateEncryptedPostParams, BatchCreatePostsParams, GetPostsByTribeParams, GetPostsByUserParams, GetPostsByTribeAndUserParams, GetFeedForUserParams, PostDetails, PostPaginationResult, InteractionType, ParsedPostData, CreateSignatureGatedPostParams, ValidatePostMetadataParams } from '../types/content'; /** * Module for managing content (posts, comments, etc.) */ export declare class ContentModule extends BaseModule { /** * Get the PostMinter contract * @param useSigner Whether to use the signer */ private getPostMinterContract; /** * Get the PostFeedManager contract * @param useSigner Whether to use the signer */ private getPostFeedManagerContract; /** * Create a new post * @param params Post creation parameters * @returns Post ID of the created post */ createPost(params: CreatePostParams): Promise<number>; /** * Create multiple posts in a batch to save gas * @param params Batch post creation parameters * @returns Array of created post IDs */ createBatchPosts(params: BatchCreatePostsParams): Promise<number[]>; /** * Create an encrypted post * @param params Encrypted post creation parameters * @returns Post ID of the created encrypted post */ createEncryptedPost(params: CreateEncryptedPostParams): Promise<number>; /** * Create a signature-gated post that requires both collectible ownership and encryption * @param params Signature gated post creation parameters * @returns Post ID of the created signature-gated post */ createSignatureGatedPost(params: CreateSignatureGatedPostParams): Promise<number>; /** * Delete a post (can only be done by the creator) * @param postId ID of the post to delete * @returns Transaction receipt */ deletePost(postId: number): Promise<ethers.TransactionReceipt>; /** * Report a post for inappropriate content * @param postId ID of the post to report * @param reason Reason for reporting * @returns Transaction receipt */ reportPost(postId: number, reason: string): Promise<ethers.TransactionReceipt>; /** * Interact with a post (like, share, etc.) * @param postId ID of the post to interact with * @param interactionType Type of interaction * @returns Transaction receipt */ interactWithPost(postId: number, interactionType: InteractionType): Promise<ethers.TransactionReceipt>; /** * Get the numeric value of a post type for the contract * @param postType Post type enum * @returns Numeric value for the contract */ private getPostTypeValue; /** * Get the numeric value of an interaction type for the contract * @param interactionType Interaction type enum * @returns Numeric value for the contract */ private getInteractionTypeValue; /** * Authorize a viewer to access an encrypted post * @param postId ID of the post * @param viewer Address of the viewer to authorize * @returns Transaction receipt */ authorizeViewer(postId: number, viewer: string): Promise<ethers.TransactionReceipt>; /** * Validate post metadata format and required fields * @param params Validation parameters * @returns True if metadata is valid */ validatePostMetadata(params: ValidatePostMetadataParams): Promise<boolean>; /** * Get a post by ID * @param postId Post ID * @returns Post details */ getPost(postId: number): Promise<PostDetails>; /** * Filter posts by post type * @param postIds Array of post IDs * @param postType Post type to filter by * @returns Filtered post IDs and fetched post details if any were retrieved */ private filterPostsByType; /** * Get posts by tribe with pagination * @param params Query parameters * @returns Paginated posts */ getPostsByTribe(params: GetPostsByTribeParams): Promise<PostPaginationResult>; /** * Get posts by user with pagination * @param params Query parameters * @returns Paginated posts */ getPostsByUser(params: GetPostsByUserParams): Promise<PostPaginationResult>; /** * Get posts by tribe and user with pagination * @param params Query parameters * @returns Paginated posts */ getPostsByTribeAndUser(params: GetPostsByTribeAndUserParams): Promise<PostPaginationResult>; /** * Get feed for user with pagination * @param params Query parameters * @returns Paginated posts */ getFeedForUser(params: GetFeedForUserParams): Promise<PostPaginationResult>; /** * Get full post details for multiple post IDs * @param postIds Array of post IDs * @returns Array of post details */ getPostDetailsByIds(postIds: number[]): Promise<PostDetails[]>; /** * Refresh feed for user to get the latest posts * @param params Query parameters * @returns Paginated posts with latest content */ refreshFeed(params: GetFeedForUserParams): Promise<PostPaginationResult>; /** * Get feed with parsed metadata for UI display * @param params Query parameters * @returns Feed with parsed metadata */ getFeedWithParsedMetadata(params: GetFeedForUserParams): Promise<ParsedPostData[]>; /** * Get a post with parsed metadata * @param post Post details * @returns Post with parsed metadata */ getParsedPostDetails(post: PostDetails): Promise<ParsedPostData>; /** * Invalidate cache for a specific post */ invalidatePostCache(postId: number): void; /** * Invalidate cache for posts in a tribe */ invalidateTribePostsCache(tribeId: number): void; /** * Invalidate user feed cache */ invalidateUserFeedCache(userAddress: string): void; /** * Set up a listener for post interaction events * @param callback Callback function to handle interaction events * @param postId Optional specific post ID to filter by * @returns Function to call to remove the listener */ setupPostInteractionListener(callback: (postId: number, user: string, interactionType: InteractionType) => void, postId?: number): () => void; /** * Convert numeric interaction type to enum * @param value Numeric interaction type from contract * @returns InteractionType enum value */ private getInteractionTypeFromValue; /** * Create a test post - ONLY FOR TESTING PURPOSES * This bypasses tribe membership checks by using tribeId=0 * @param metadata Post metadata JSON string * @returns Post ID of the created post */ createTestPost(metadata: string): Promise<number>; }