Tapestry Social SDK
A TypeScript/JavaScript SDK for interacting with the Tapestry Social API. Build social features into your app with ease.
Installation
npm install socialfi
yarn add socialfi
pnpm add socialfi
Quick Start
import TapestryClient from "socialfi";
const client = new TapestryClient({
apiKey: "YOUR_API_KEY",
});
async function createProfile() {
try {
const profile = await client.createProfile({
username: "johndoe",
walletAddress: "YOUR_WALLET_ADDRESS",
bio: "Hello, World!",
});
console.log("Profile created:", profile);
} catch (error) {
console.error("Error creating profile:", error);
}
}
async function followUser() {
try {
await client.followUser("YOUR_PROFILE_ID", "TARGET_PROFILE_ID");
console.log("Successfully followed user");
} catch (error) {
console.error("Error following user:", error);
}
}
async function getFollowers(profileId: string) {
try {
const followers = await client.getProfile(profileId);
console.log("Profile details:", followers);
} catch (error) {
console.error("Error getting followers:", error);
}
}
async function advancedUsage() {
const result = await client.api.profiles.profilesList({
apiKey: client.apiKey,
page: "1",
pageSize: "20",
sortBy: "created_at",
sortDirection: "DESC",
});
}
Features
- 🔑 Profile Management: Create, update, and manage user profiles
- 👥 Social Graph: Handle follows/unfollows and social relationships
- 💬 Content & Comments: Manage user-generated content and interactions
- ❤️ Likes: Handle social engagement through likes
- 🔍 Search: Search for profiles and content
- 📱 Notifications: Send notifications to users
- 📊 Activity Feed: Get user activity feeds
- 🔓 Direct API Access: Access the underlying API client for advanced use cases
API Documentation
Profile Management
const profile = await client.createProfile({
username: "username",
walletAddress: "address",
bio: "bio",
image: "image_url",
});
const updatedProfile = await client.updateProfile("profile_id", {
username: "new_username",
bio: "new_bio",
});
const profileDetails = await client.getProfile("profile_id");
Social Graph
await client.followUser("follower_id", "target_id");
await client.unfollowUser("follower_id", "target_id");
const isFollowing = await client.isFollowing("user_id", "target_id");
Content & Interactions
const content = await client.createContent({
id: "content_id",
profileId: "author_id",
});
const comment = await client.createComment({
contentId: "content_id",
profileId: "author_id",
text: "Great post!",
});
await client.likeContent("content_id", "user_id");
await client.unlikeContent("content_id", "user_id");
Search & Activity
const searchResults = await client.searchProfiles("search query");
const activityFeed = await client.getActivityFeed("username");
Advanced Usage: Direct API Access
For advanced use cases or accessing API endpoints not yet wrapped by the SDK, you can use the underlying API client directly:
const { api } = client;
const profiles = await api.profiles.profilesList({
apiKey: "YOUR_API_KEY",
page: "1",
pageSize: "20",
sortBy: "created_at",
sortDirection: "DESC",
});
const batchResults = await api.contents.batchReadCreate(
{ apiKey: "YOUR_API_KEY" },
["content_id_1", "content_id_2"]
);
const searchResults = await api.search.profilesList({
apiKey: "YOUR_API_KEY",
query: "search term",
includeExternalProfiles: "true",
page: "1",
pageSize: "50",
});
TypeScript Support
This SDK is written in TypeScript and provides full type definitions for all API responses and parameters. You can import and use the types directly:
import TapestryClient, {
ProfileSchema,
FindOrCreateProfileSchema,
UpdateProfileSchema,
GetProfileDetailsSchema,
ContentSchema,
ContentDetailsSchema,
FindOrCreateContentSchema,
CommentSchema,
CommentDetailsSchema,
CreateCommentSchema,
CreateFollowSchema,
IsFollowingSchema,
FeedDetailData,
SearchProfilesResponseSchema,
CustomPropertySchema,
SocialInfoSchema,
FollowCountsSchema,
} from "socialfi";
const profile: ProfileSchema = await client.getProfile("profile_id");
function handleProfile(profile: ProfileSchema) {
console.log(`Handling profile: ${profile.username}`);
}
async function searchUsers(
query: string
): Promise<SearchProfilesResponseSchema> {
return client.searchProfiles(query);
}
async function advancedSearch(): Promise<SearchProfilesResponseSchema> {
return client.api.search.profilesList({
apiKey: "YOUR_API_KEY",
query: "search term",
includeExternalProfiles: "true",
});
}
Error Handling
The SDK uses Axios for HTTP requests. All API calls can throw errors that should be handled appropriately:
try {
const result = await client.getProfile("profile_id");
} catch (error) {
if (axios.isAxiosError(error)) {
console.error("API Error:", error.response?.data);
} else {
console.error("Unknown error:", error);
}
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Support
For support, please visit Tapestry Documentation or contact the Tapestry team.