|
| 1 | +import { PubkyAppPostKind, PubkySpecsBuilder, PubkyAppPostEmbed } from "./index.js"; |
| 2 | + |
| 3 | +const OTTO = "8kkppkmiubfq4pxn6f73nqrhhhgkb5xyfprntc9si3np9ydbotto"; |
| 4 | +const RIO = "dzswkfy7ek3bqnoc89jxuqqfbzhjrj6mi8qthgbxxcqkdugm3rio"; |
| 5 | + |
| 6 | +// 👤 Create a user profile |
| 7 | +console.log("👤 Creating User Profile..."); |
| 8 | +const specsBuilder = new PubkySpecsBuilder(OTTO); |
| 9 | +const { user, meta: userMeta } = |
| 10 | + specsBuilder.createUser("Alice Smith", "Software Developer", null, null, "active"); |
| 11 | +console.log("User Profile URL:", userMeta.url); |
| 12 | +console.log("User Data:", JSON.stringify(user.toJson(), null, 2)); |
| 13 | +console.log("-".repeat(60)); |
| 14 | + |
| 15 | +// 📝 Create different posts |
| 16 | +console.log("📝 Creating First Post..."); |
| 17 | +const { post, meta } = specsBuilder.createPost("Hello, Pubky world! This is my first post.", PubkyAppPostKind.Short, null, null, null); |
| 18 | +console.log("Post ID:", meta.id); |
| 19 | +console.log("Post URL:", meta.url); |
| 20 | +console.log("Post Data:", JSON.stringify(post.toJson(), null, 2)); |
| 21 | +console.log("-".repeat(60)); |
| 22 | + |
| 23 | +console.log("💬 Creating Reply Post..."); |
| 24 | +const { post: replyPost, meta: replyMeta } = specsBuilder.createPost("This is a reply to the first post!", PubkyAppPostKind.Short, userMeta.url, null, null); |
| 25 | +console.log("Reply Post ID:", replyMeta.id); |
| 26 | +console.log("Reply Post URL:", replyMeta.url); |
| 27 | +console.log("Reply Data:", JSON.stringify(replyPost.toJson(), null, 2)); |
| 28 | +console.log("-".repeat(60)); |
| 29 | + |
| 30 | +console.log("🔄 Creating Repost with Embed..."); |
| 31 | +let embeed = new PubkyAppPostEmbed(`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`, PubkyAppPostKind.Video); |
| 32 | +const { post: repost, meta: repostMeta } = specsBuilder.createPost("This is a repost to random post!", PubkyAppPostKind.Short, null, embeed, null); |
| 33 | +console.log("Repost Post ID:", repostMeta.id); |
| 34 | +console.log("Repost Post URL:", repostMeta.url); |
| 35 | +console.log("Repost Data:", JSON.stringify(repost.toJson(), null, 2)); |
| 36 | +console.log("-".repeat(60)); |
| 37 | + |
| 38 | +console.log("🔖 Creating Bookmark..."); |
| 39 | +let { bookmark, meta: bookmarkMeta } = specsBuilder.createBookmark(`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`); |
| 40 | +console.log("Bookmark ID:", bookmarkMeta.id); |
| 41 | +console.log("Bookmark URL:", bookmarkMeta.url); |
| 42 | +console.log("Bookmark Data:", JSON.stringify(bookmark.toJson(), null, 2)); |
| 43 | +console.log("-".repeat(60)); |
| 44 | + |
| 45 | +console.log("👥 Creating Follow..."); |
| 46 | +let {follow, meta: followMeta} = specsBuilder.createFollow(RIO); |
| 47 | +console.log("Follow ID:", followMeta.id); |
| 48 | +console.log("Follow URL:", followMeta.url); |
| 49 | +console.log("Follow Data:", JSON.stringify(follow.toJson(), null, 2)); |
| 50 | +console.log("-".repeat(60)); |
| 51 | + |
| 52 | +console.log("🏷️ Creating Tag..."); |
| 53 | +let {tag, meta: tagMeta} = specsBuilder.createTag(`pubky://${OTTO}/pub/pubky.app/profile.json`, "otto"); |
| 54 | +console.log("Tag ID:", tagMeta.id); |
| 55 | +console.log("Tag URL:", tagMeta.url); |
| 56 | +console.log("Tag Data:", JSON.stringify(tag.toJson(), null, 2)); |
| 57 | +console.log("-".repeat(60)); |
| 58 | + |
| 59 | +console.log("🔇 Creating Mute..."); |
| 60 | +let {mute, meta: muteMeta} = specsBuilder.createMute(RIO); |
| 61 | +console.log("Mute ID:", muteMeta.id); |
| 62 | +console.log("Mute URL:", muteMeta.url); |
| 63 | +console.log("Mute Data:", JSON.stringify(mute.toJson(), null, 2)); |
| 64 | +console.log("-".repeat(60)); |
| 65 | + |
| 66 | +console.log("📖 Creating Last Read..."); |
| 67 | +let {last_read, meta: lastReadMeta} = specsBuilder.createLastRead(RIO); |
| 68 | +console.log("LastRead Timestamp:", lastReadMeta.url); |
| 69 | +console.log("LastRead Data:", JSON.stringify(last_read.toJson(), null, 2)); |
| 70 | +console.log("-".repeat(60)); |
| 71 | + |
| 72 | +console.log("💾 Creating Blob..."); |
| 73 | +let { blob, meta: blobMeta } = specsBuilder.createBlob(Array.from({length: 8}, () => Math.floor(Math.random() * 256))); |
| 74 | +console.log("Blob ID:", blobMeta.id); |
| 75 | +console.log("Blob URL:", blobMeta.url); |
| 76 | +console.log("Blob Data:", JSON.stringify(blob.toJson(), null, 2)); |
| 77 | +console.log("-".repeat(60)); |
| 78 | + |
| 79 | +console.log("📄 Creating File..."); |
| 80 | +let { file, meta: fileMeta } = specsBuilder.createFile("My adventures", blobMeta.url, "application/pdf", 88); |
| 81 | +console.log("File ID:", fileMeta.id); |
| 82 | +console.log("File URL:", fileMeta.url); |
| 83 | +console.log("File Data:", JSON.stringify(file.toJson(), null, 2)); |
| 84 | +console.log("-".repeat(60)); |
| 85 | + |
| 86 | +console.log("📰 Creating Feed..."); |
| 87 | +let { feed, meta: feedMeta } = specsBuilder.createFeed(["mountain","hike"], "all", "columns", "recent", "image", "nature"); |
| 88 | +console.log("Feed ID:", feedMeta.id); |
| 89 | +console.log("Feed URL:", feedMeta.url); |
| 90 | +console.log("Feed Data:", JSON.stringify(feed.toJson(), null, 2)); |
| 91 | +console.log("=".repeat(60)); |
| 92 | +console.log("🎉 All Pubky App Specs examples completed successfully!"); |
| 93 | +console.log("=".repeat(60)); |
0 commit comments