pubky-app-specs 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/example.js DELETED
@@ -1,295 +0,0 @@
1
- import {
2
- PubkyAppPostKind,
3
- PubkySpecsBuilder,
4
- PubkyAppPostEmbed,
5
- userUriBuilder,
6
- postUriBuilder,
7
- bookmarkUriBuilder,
8
- followUriBuilder,
9
- tagUriBuilder,
10
- muteUriBuilder,
11
- lastReadUriBuilder,
12
- blobUriBuilder,
13
- fileUriBuilder,
14
- feedUriBuilder,
15
- getValidMimeTypes,
16
- } from "./index.js";
17
-
18
- // =============================================================================
19
- // ANSI color helpers for pretty output
20
- // =============================================================================
21
- const c = {
22
- reset: "\x1b[0m",
23
- bright: "\x1b[1m",
24
- dim: "\x1b[2m",
25
- cyan: "\x1b[36m",
26
- green: "\x1b[32m",
27
- yellow: "\x1b[33m",
28
- blue: "\x1b[34m",
29
- magenta: "\x1b[35m",
30
- gray: "\x1b[90m",
31
- white: "\x1b[37m",
32
- bgBlue: "\x1b[44m",
33
- };
34
-
35
- const divider = () => console.log(c.gray + "─".repeat(70) + c.reset);
36
- const header = (title) => {
37
- console.log();
38
- console.log(`${c.bright}${c.blue}${title}${c.reset}`);
39
- divider();
40
- };
41
- const field = (label, value) => {
42
- console.log(` ${c.dim}${label.padEnd(12)}${c.reset} ${c.white}${value}${c.reset}`);
43
- };
44
-
45
- // =============================================================================
46
- // Setup
47
- // =============================================================================
48
- const OTTO = "8kkppkmiubfq4pxn6f73nqrhhhgkb5xyfprntc9si3np9ydbotto";
49
- const RIO = "dzswkfy7ek3bqnoc89jxuqqfbzhjrj6mi8qthgbxxcqkdugm3rio";
50
-
51
- console.log();
52
- console.log(`${c.bgBlue}${c.white}${c.bright} ${c.reset}`);
53
- console.log(`${c.bgBlue}${c.white}${c.bright} PUBKY APP SPECS - EXAMPLES ${c.reset}`);
54
- console.log(`${c.bgBlue}${c.white}${c.bright} ${c.reset}`);
55
- console.log();
56
-
57
- const specsBuilder = new PubkySpecsBuilder(OTTO);
58
- console.log(`${c.dim}Using PubkyId: ${c.reset}${c.cyan}${OTTO}${c.reset}`);
59
-
60
- // =============================================================================
61
- // 1. User Profile
62
- // =============================================================================
63
- header("USER PROFILE");
64
- const { user, meta: userMeta } = specsBuilder.createUser(
65
- "Alice Smith",
66
- "Software Developer",
67
- null,
68
- null,
69
- "active"
70
- );
71
- field("URL", userMeta.url);
72
- field("Name", user.toJson().name);
73
- field("Bio", user.toJson().bio);
74
- field("Status", user.toJson().status);
75
-
76
- // =============================================================================
77
- // 2. Posts
78
- // =============================================================================
79
- header("POSTS");
80
-
81
- // Simple post
82
- console.log(` ${c.yellow}▸ Simple Post${c.reset}`);
83
- const { post, meta } = specsBuilder.createPost(
84
- "Hello, Pubky world! This is my first post.",
85
- PubkyAppPostKind.Short,
86
- null,
87
- null,
88
- null
89
- );
90
- field("ID", meta.id);
91
- field("URL", meta.url);
92
- field("Content", post.toJson().content);
93
- console.log();
94
-
95
- // Reply post
96
- console.log(` ${c.yellow}▸ Reply Post${c.reset}`);
97
- const { post: replyPost, meta: replyMeta } = specsBuilder.createPost(
98
- "This is a reply to the first post!",
99
- PubkyAppPostKind.Short,
100
- userMeta.url,
101
- null,
102
- null
103
- );
104
- field("ID", replyMeta.id);
105
- field("Parent", replyPost.toJson().parent);
106
- console.log();
107
-
108
- // Repost with embed
109
- console.log(` ${c.yellow}▸ Repost with Embed${c.reset}`);
110
- const embed = new PubkyAppPostEmbed(
111
- `pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`,
112
- PubkyAppPostKind.Video
113
- );
114
- const { post: repost, meta: repostMeta } = specsBuilder.createPost(
115
- "Check out this awesome video!",
116
- PubkyAppPostKind.Short,
117
- null,
118
- embed,
119
- null
120
- );
121
- field("ID", repostMeta.id);
122
- field("Embed URI", repost.toJson().embed.uri);
123
- field("Embed Kind", repost.toJson().embed.kind);
124
- console.log();
125
-
126
- // Post with attachments
127
- console.log(` ${c.yellow}▸ Post with Attachments${c.reset}`);
128
- const { post: postWithAttachments, meta: postWithAttachmentsMeta } = specsBuilder.createPost(
129
- "Check out these photos from my trip!",
130
- PubkyAppPostKind.Image,
131
- null,
132
- null,
133
- [
134
- `pubky://${OTTO}/pub/pubky.app/files/0034A0X7NJ52G`,
135
- `pubky://${OTTO}/pub/pubky.app/files/0034A0X7NJ53H`,
136
- ]
137
- );
138
- field("ID", postWithAttachmentsMeta.id);
139
- field("Attachments", `${postWithAttachments.toJson().attachments.length} files`);
140
-
141
- // =============================================================================
142
- // 3. Social Actions
143
- // =============================================================================
144
- header("SOCIAL ACTIONS");
145
-
146
- // Bookmark
147
- console.log(` ${c.yellow}▸ Bookmark${c.reset}`);
148
- const { bookmark, meta: bookmarkMeta } = specsBuilder.createBookmark(
149
- `pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`
150
- );
151
- field("ID", bookmarkMeta.id);
152
- field("URI", bookmark.toJson().uri);
153
- console.log();
154
-
155
- // Follow
156
- console.log(` ${c.yellow}▸ Follow${c.reset}`);
157
- const { follow, meta: followMeta } = specsBuilder.createFollow(RIO);
158
- field("ID", followMeta.id);
159
- field("URL", followMeta.url);
160
- console.log();
161
-
162
- // Tag
163
- console.log(` ${c.yellow}▸ Tag${c.reset}`);
164
- const { tag, meta: tagMeta } = specsBuilder.createTag(
165
- `pubky://${OTTO}/pub/pubky.app/profile.json`,
166
- "developer"
167
- );
168
- field("ID", tagMeta.id);
169
- field("Label", tag.toJson().label);
170
- field("URI", tag.toJson().uri);
171
- console.log();
172
-
173
- // Mute
174
- console.log(` ${c.yellow}▸ Mute${c.reset}`);
175
- const { mute, meta: muteMeta } = specsBuilder.createMute(RIO);
176
- field("ID", muteMeta.id);
177
- field("URL", muteMeta.url);
178
-
179
- // =============================================================================
180
- // 4. Files & Blobs
181
- // =============================================================================
182
- header("FILES & BLOBS");
183
-
184
- // Blob
185
- console.log(` ${c.yellow}▸ Blob (raw data)${c.reset}`);
186
- const blobData = Array.from({ length: 8 }, () => Math.floor(Math.random() * 256));
187
- const { blob, meta: blobMeta } = specsBuilder.createBlob(blobData);
188
- field("ID", blobMeta.id);
189
- field("URL", blobMeta.url);
190
- field("Size", `${blobData.length} bytes`);
191
- console.log();
192
-
193
- // File
194
- console.log(` ${c.yellow}▸ File (metadata)${c.reset}`);
195
- const { file, meta: fileMeta } = specsBuilder.createFile(
196
- "vacation-photos.pdf",
197
- blobMeta.url,
198
- "application/pdf",
199
- 1024
200
- );
201
- field("ID", fileMeta.id);
202
- field("Name", file.toJson().name);
203
- field("Type", file.toJson().content_type);
204
- field("Size", `${file.toJson().size} bytes`);
205
- field("Source", file.toJson().src);
206
-
207
- // =============================================================================
208
- // 5. Feeds & LastRead
209
- // =============================================================================
210
- header("FEEDS & LAST READ");
211
-
212
- // Feed
213
- console.log(` ${c.yellow}▸ Custom Feed${c.reset}`);
214
- const { feed, meta: feedMeta } = specsBuilder.createFeed(
215
- ["mountain", "hiking", "nature"],
216
- "all",
217
- "columns",
218
- "recent",
219
- "image",
220
- "Outdoor Adventures"
221
- );
222
- field("ID", feedMeta.id);
223
- field("Name", feed.toJson().name);
224
- field("Tags", feed.toJson().feed.tags.join(", "));
225
- field("Layout", feed.toJson().feed.layout);
226
- field("Sort", feed.toJson().feed.sort);
227
- console.log();
228
-
229
- // LastRead
230
- console.log(` ${c.yellow}▸ Last Read Marker${c.reset}`);
231
- const { last_read, meta: lastReadMeta } = specsBuilder.createLastRead();
232
- field("URL", lastReadMeta.url);
233
- field("Timestamp", new Date(last_read.toJson().timestamp / 1000).toISOString());
234
-
235
- // =============================================================================
236
- // 6. URI Builders
237
- // =============================================================================
238
- header("URI BUILDERS");
239
- const uris = [
240
- ["User", userUriBuilder(OTTO)],
241
- ["Post", postUriBuilder(OTTO, meta.id)],
242
- ["Bookmark", bookmarkUriBuilder(OTTO, bookmarkMeta.id)],
243
- ["Follow", followUriBuilder(OTTO, RIO)],
244
- ["Tag", tagUriBuilder(OTTO, tagMeta.id)],
245
- ["Mute", muteUriBuilder(OTTO, RIO)],
246
- ["LastRead", lastReadUriBuilder(OTTO)],
247
- ["Blob", blobUriBuilder(OTTO, blobMeta.id)],
248
- ["File", fileUriBuilder(OTTO, fileMeta.id)],
249
- ["Feed", feedUriBuilder(OTTO, feedMeta.id)],
250
- ];
251
- uris.forEach(([name, uri]) => {
252
- console.log(` ${c.dim}${name.padEnd(10)}${c.reset} ${c.cyan}${uri}${c.reset}`);
253
- });
254
-
255
- // =============================================================================
256
- // 7. Valid MIME Types
257
- // =============================================================================
258
- header("VALID MIME TYPES");
259
- const validMimeTypes = getValidMimeTypes();
260
- console.log(` ${c.dim}Total types:${c.reset} ${c.bright}${validMimeTypes.length}${c.reset}`);
261
- console.log();
262
-
263
- // Group by category
264
- const categories = {
265
- "Images": validMimeTypes.filter(t => t.startsWith("image/")),
266
- "Videos": validMimeTypes.filter(t => t.startsWith("video/")),
267
- "Audio": validMimeTypes.filter(t => t.startsWith("audio/")),
268
- "Documents": validMimeTypes.filter(t => t.startsWith("application/") || t.startsWith("text/")),
269
- };
270
-
271
- Object.entries(categories).forEach(([category, types]) => {
272
- if (types.length > 0) {
273
- console.log(` ${c.yellow}${category}:${c.reset}`);
274
- types.forEach(type => console.log(` ${c.dim}-${c.reset} ${type}`));
275
- console.log();
276
- }
277
- });
278
-
279
- // Validation example
280
- console.log(` ${c.yellow}Validation Example:${c.reset}`);
281
- const testTypes = ["image/png", "video/mp4", "application/x-executable"];
282
- testTypes.forEach(type => {
283
- const isValid = validMimeTypes.includes(type);
284
- const icon = isValid ? `${c.green}[ok]${c.reset}` : `${c.magenta}[x]${c.reset}`;
285
- console.log(` ${icon} ${type}`);
286
- });
287
-
288
- // =============================================================================
289
- // Done!
290
- // =============================================================================
291
- console.log();
292
- console.log(`${c.bgBlue}${c.white}${c.bright} ${c.reset}`);
293
- console.log(`${c.bgBlue}${c.white}${c.bright} ALL EXAMPLES COMPLETED SUCCESSFULLY! ${c.reset}`);
294
- console.log(`${c.bgBlue}${c.white}${c.bright} ${c.reset}`);
295
- console.log();