founder-schema 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,iEAAiE;AACjE,eAAO,MAAM,oBAAoB,QAAgB,CAAC;AAClD,eAAe;AACf,eAAO,MAAM,oBAAoB,QAA2B,CAAC;AAI7D;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,2BAA4B,CAAC;AAC7D,eAAO,MAAM,iBAAiB;;;EAA8B,CAAC;AAC7D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,yDAA0D,CAAC;AAC5F,eAAO,MAAM,kBAAkB;;;;;EAA+B,CAAC;AAC/D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,yBAA0B,CAAC;AACxD,eAAO,MAAM,cAAc;;;EAA2B,CAAC;AACvD,MAAM,MAAM,QAA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AC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF;mEACmE;AACnE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAEjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
package/dist/feed.js ADDED
@@ -0,0 +1,593 @@
1
+ /**
2
+ * founder-schema — Feed wire shapes: post, poll, comment, reaction
3
+ *
4
+ * ADAPTED FROM `jansathi-community-schema`, NOT DEPENDENT ON IT.
5
+ *
6
+ * The user ruled on 2026-09-21 that Founder Circle is a standalone app, so
7
+ * these shapes are copied and cut down rather than imported. The reason is
8
+ * worth keeping: `jansathi-community-schema` encodes Jansathi's reach levels,
9
+ * community designations, official-area kinds and crowdfunding audiences.
10
+ * Depending on it would put all of that permanently inside our contract for a
11
+ * feed that has none of those concepts, and would mean a Jansathi publish can
12
+ * break this product.
13
+ *
14
+ * DELIBERATELY NOT PORTED, so nobody "restores" them:
15
+ * - the five civic verticals (lost_found, suggestions_complaints,
16
+ * donate_item, crowdfunding, event). `contentKind` here is post | poll
17
+ * only, and comments and reactions key off that narrower union.
18
+ * - official communities, designations, identity verification badges.
19
+ * - social score, and the whole area-proximity ranking vocabulary
20
+ * (local / district / state / national / global).
21
+ * - `areaLineage` as a REQUIRED authorship snapshot. Jansathi gates its
22
+ * composer on a declared residence resolving to Indian district level or
23
+ * deeper; the user ruled location is never mandatory here, so nothing in
24
+ * this file requires one.
25
+ * - anonymous posting, which in Jansathi is gated on identity verification
26
+ * we do not have. A founders' network is an identified network.
27
+ *
28
+ * @module founder-schema/feed
29
+ */
30
+ import { z } from 'zod';
31
+ import { httpUrlSchema, objectIdSchema, paginationQuerySchema, usernameSchema } from './common.js';
32
+ import { topicSchema } from './onboarding.js';
33
+ // ─── Limits ──────────────────────────────────────────────────────────────────
34
+ /**
35
+ * Exported because the composer must count down to the SAME number the server
36
+ * rejects at. A client-side limit that disagrees with the server is a message
37
+ * a member cannot send and cannot see why.
38
+ */
39
+ export const POST_MAX_BODY_CHARS = 5000;
40
+ /**
41
+ * Total attachments on one post, images and videos together.
42
+ *
43
+ * ONE cap over ONE ordered list, rather than Jansathi's separate image and
44
+ * video arrays. A member who posts a screenshot, then a clip, then another
45
+ * screenshot means that order, and two parallel arrays cannot express it: the
46
+ * card would show both images and then the video, which is not what was
47
+ * written.
48
+ */
49
+ export const POST_MAX_MEDIA = 10;
50
+ /**
51
+ * Topics per item.
52
+ *
53
+ * Capped low on purpose: a post tagged with everything is about nothing, and
54
+ * one tagged with ten matches every member, which is how a relevance feature
55
+ * turns back into a chronological one.
56
+ */
57
+ export const MAX_TOPICS = 3;
58
+ export const COMMENT_MAX_BODY_CHARS = 2000;
59
+ export const POLL_QUESTION_MAX_CHARS = 280;
60
+ export const POLL_OPTION_MAX_CHARS = 80;
61
+ export const POLL_MIN_OPTIONS = 2;
62
+ export const POLL_MAX_OPTIONS = 6;
63
+ /** 5 minutes. Below this a poll closes before anyone sees it. */
64
+ export const POLL_MIN_DURATION_MS = 5 * 60 * 1000;
65
+ /** 30 days. */
66
+ export const POLL_MAX_DURATION_MS = 30 * 24 * 60 * 60 * 1000;
67
+ // ─── Enums ───────────────────────────────────────────────────────────────────
68
+ /**
69
+ * What can appear in the feed. Two kinds, not seven.
70
+ *
71
+ * Engagement is keyed by `(contentKind, contentId)` so one engagement bar
72
+ * serves both, and comments hang off the same pair. Adding a kind later is
73
+ * additive; the union is deliberately narrow now so the client never has to
74
+ * handle a kind this product does not have.
75
+ */
76
+ export const CONTENT_KIND_VALUES = ['post', 'poll'];
77
+ export const contentKindSchema = z.enum(CONTENT_KIND_VALUES);
78
+ /**
79
+ * Reactions. Jansathi's `support` is dropped: it exists for reacting to a
80
+ * civic complaint or a lost-and-found notice, which this feed does not carry.
81
+ *
82
+ * ⚠️ These values are stored per reaction row, so removing one orphans data.
83
+ * Append only.
84
+ */
85
+ export const REACTION_TYPE_VALUES = ['like', 'celebrate', 'insightful', 'curious'];
86
+ export const reactionTypeSchema = z.enum(REACTION_TYPE_VALUES);
87
+ /**
88
+ * Feed ordering.
89
+ *
90
+ * `new` is the default here, unlike Jansathi where `hot` leads. A hot ranking
91
+ * needs volume to be meaningful, and a brand-new network ranking a handful of
92
+ * posts by a blended score mostly hides the newest thing somebody just wrote.
93
+ * Revisit when there is enough content for `hot` to mean anything.
94
+ */
95
+ export const FEED_SORT_VALUES = ['new', 'top'];
96
+ export const feedSortSchema = z.enum(FEED_SORT_VALUES);
97
+ /**
98
+ * Counts keyed by reaction type, e.g. `{ like: 4, celebrate: 1 }`. Only the
99
+ * reactions an item actually has need appear.
100
+ *
101
+ * ⚠️ `partialRecord`, NOT `record`. In Zod 4 an enum-keyed `z.record` is
102
+ * EXHAUSTIVE: it demands every key, so `{ like: 4 }` fails with three missing
103
+ * keys and `{}` fails with four. That would force the server to ship a zero for
104
+ * every reaction on every item, and the day a fifth reaction is added every
105
+ * previously stored payload and every older client stops parsing.
106
+ * `partialRecord` keeps the key validation without the exhaustiveness, so an
107
+ * unknown key like Jansathi's `support` is still refused.
108
+ */
109
+ export const reactionCountsSchema = z.partialRecord(reactionTypeSchema, z.number().int().nonnegative());
110
+ // ─── Author byline ───────────────────────────────────────────────────────────
111
+ /**
112
+ * The author as a card renders them.
113
+ *
114
+ * Every field here is LIVE, joined against the profile at read time rather
115
+ * than frozen onto the post at write time. So a renamed handle, a new avatar
116
+ * or an edited headline updates on old posts, and the byline link always
117
+ * targets the current username instead of 404ing on a handle that moved.
118
+ *
119
+ * Jansathi additionally snapshots `localName` ("where the author was when
120
+ * posting"). Not ported: location is optional here, so a byline that depends
121
+ * on one would be blank for anyone who never set it.
122
+ */
123
+ export const feedAuthorSchema = z.object({
124
+ userId: z.string(),
125
+ username: usernameSchema,
126
+ displayName: z.string(),
127
+ /** Server-generated or from the login provider, never member-typed, so a
128
+ * plain URL check. Same reasoning as `avatarUrl` on the profile. */
129
+ avatarUrl: z.url().optional(),
130
+ /** The author's one-line headline, live-joined. Gives a founders' byline
131
+ * the context a civic byline got from an area label. */
132
+ headline: z.string().optional(),
133
+ });
134
+ // ─── Media ───────────────────────────────────────────────────────────────────
135
+ /**
136
+ * `width` and `height` are required so a card can reserve the right box before
137
+ * the image loads. Without them every image arrival shifts the feed under the
138
+ * reader's thumb.
139
+ *
140
+ * URLs here come from our own upload pipeline, so they take a plain `z.url()`
141
+ * rather than `httpUrlSchema`. ⚠️ If a "paste an image link" path is ever
142
+ * added, these become member-supplied and must move to `httpUrlSchema`.
143
+ */
144
+ export const feedImageSchema = z.object({
145
+ kind: z.literal('image'),
146
+ url: z.url(),
147
+ thumbnailUrl: z.url().optional(),
148
+ width: z.number().int().positive(),
149
+ height: z.number().int().positive(),
150
+ /** Author-supplied alt text. Optional, and worth asking for. */
151
+ alt: z.string().max(280).optional(),
152
+ });
153
+ export const feedVideoSchema = z.object({
154
+ kind: z.literal('video'),
155
+ url: z.url(),
156
+ /** Poster frame, server-extracted. Required: a video with no poster is a
157
+ * black rectangle in the feed. */
158
+ thumbnailUrl: z.url(),
159
+ width: z.number().int().positive(),
160
+ height: z.number().int().positive(),
161
+ /** Seconds. */
162
+ duration: z.number().positive(),
163
+ });
164
+ /**
165
+ * One ordered list, discriminated on `kind`, so the carousel renders
166
+ * attachments in the order they were attached and can switch on the kind
167
+ * without inspecting fields.
168
+ */
169
+ export const feedMediaSchema = z.discriminatedUnion('kind', [feedImageSchema, feedVideoSchema]);
170
+ // ─── Link preview ────────────────────────────────────────────────────────────
171
+ /**
172
+ * Preview for the first link in a post body. Server-derived at write time and
173
+ * stored, never re-fetched at render: a card that fetches a third-party page
174
+ * per scroll leaks every reader's address to that site and blocks the feed on
175
+ * somebody else's latency.
176
+ *
177
+ * `url` takes `httpUrlSchema` because it came out of text a member typed.
178
+ * `imageUrl` is whatever the remote page advertised, so it is not ours either,
179
+ * and a consumer still treats it as untrusted at render.
180
+ */
181
+ export const linkPreviewSchema = z.object({
182
+ url: httpUrlSchema,
183
+ title: z.string().max(200).optional(),
184
+ description: z.string().max(500).optional(),
185
+ imageUrl: httpUrlSchema.optional(),
186
+ });
187
+ // ─── Viewer state ────────────────────────────────────────────────────────────
188
+ /**
189
+ * What THIS viewer has done to this item, computed per request.
190
+ *
191
+ * Optional as a block, because an unauthenticated or server-rendered read has
192
+ * no viewer. ⚠️ A client must treat an absent `viewer` as "no state known",
193
+ * never as "has not reacted": rendering an empty reaction button off a missing
194
+ * block is how a member sees their own reaction disappear on reload.
195
+ */
196
+ export const viewerStateSchema = z.object({
197
+ reaction: reactionTypeSchema.nullable(),
198
+ bookmarked: z.boolean(),
199
+ isAuthor: z.boolean(),
200
+ /**
201
+ * What this viewer may DO, decided by the server and sent as plain answers.
202
+ *
203
+ * Not role data for the client to reason about. The moment a client derives
204
+ * "can I edit this" from roles and ownership, that derivation is a second
205
+ * implementation of the rule, it drifts from the server's, and the drift is
206
+ * invisible until the two disagree: either a button that 403s or a button
207
+ * that should not have been there. `isAuthor` stays because the byline reads
208
+ * differently for your own post, not because the client should compute rights
209
+ * from it.
210
+ *
211
+ * `canEdit` is false once the edit window closes, so it is not simply
212
+ * `isAuthor`.
213
+ */
214
+ canEdit: z.boolean(),
215
+ canDelete: z.boolean(),
216
+ canReport: z.boolean(),
217
+ });
218
+ // ─── Post ────────────────────────────────────────────────────────────────────
219
+ /**
220
+ * A post as the feed and the single-post page receive it.
221
+ *
222
+ * Counts are denormalised onto the row so one document serves a whole card.
223
+ *
224
+ * No `score` and no up/down vote. Jansathi's signed score exists to rank civic
225
+ * content by community judgement, and a downvote arrow on a founder's first
226
+ * post is a different product. Reactions and comments are the engagement axes
227
+ * here. Adding a score later is additive; removing a visible downvote after
228
+ * members have used it is not.
229
+ */
230
+ export const feedPostSchema = z.object({
231
+ id: objectIdSchema,
232
+ contentKind: z.literal('post'),
233
+ author: feedAuthorSchema,
234
+ /**
235
+ * The WHOLE body, never a server-side truncation.
236
+ *
237
+ * So there is no "was this shortened" flag and no second fetch to read the
238
+ * rest: the card clamps visually and expands in place. At a 5,000 character
239
+ * cap a page of twenty posts is small enough that trimming would cost a round
240
+ * trip to save nothing. If that ever stops being true, a truncation flag is
241
+ * an additive change; a client that has been guessing is not.
242
+ */
243
+ text: z.string().max(POST_MAX_BODY_CHARS),
244
+ /** Ordered as the author attached them. */
245
+ media: z.array(feedMediaSchema).max(POST_MAX_MEDIA),
246
+ /** Present only when the body had an embeddable link. */
247
+ linkPreview: linkPreviewSchema.optional(),
248
+ /**
249
+ * What this post is ABOUT, from the same vocabulary a member picks as their
250
+ * interests. This is the whole mechanism behind a relevant feed: matching is
251
+ * an intersection of two lists drawn from one enum, not a guess from who
252
+ * wrote it.
253
+ *
254
+ * ⚠️ An EMPTY array is allowed and means the post is untagged, so interest
255
+ * matching cannot reach it. That is a real consequence, not a nuance: an
256
+ * untagged post is only ever found chronologically.
257
+ */
258
+ topics: z.array(topicSchema).max(MAX_TOPICS),
259
+ commentCount: z.number().int().nonnegative(),
260
+ reactionCounts: reactionCountsSchema,
261
+ createdAt: z.iso.datetime(),
262
+ /** Null when never edited. The edit window is the server's to enforce. */
263
+ editedAt: z.iso.datetime().nullable(),
264
+ viewer: viewerStateSchema.optional(),
265
+ });
266
+ // ─── Poll ────────────────────────────────────────────────────────────────────
267
+ /**
268
+ * One choice. `index` is the identifier a vote refers to, not the label:
269
+ * sending indices avoids ambiguity between two options whose labels differ
270
+ * only by case, spacing or an invisible character.
271
+ */
272
+ export const pollOptionSchema = z.object({
273
+ index: z
274
+ .number()
275
+ .int()
276
+ .min(0)
277
+ .max(POLL_MAX_OPTIONS - 1),
278
+ label: z.string().min(1).max(POLL_OPTION_MAX_CHARS),
279
+ voteCount: z.number().int().nonnegative(),
280
+ });
281
+ /**
282
+ * A poll. Its own kind, not a post with extra fields, because votes are their
283
+ * own records keyed by (poll, voter) and a post has nothing equivalent.
284
+ *
285
+ * Polls are not editable. Changing a question or an option after a vote has
286
+ * been cast silently re-purposes that vote. Closing early is allowed; editing
287
+ * is not.
288
+ */
289
+ export const feedPollSchema = z.object({
290
+ id: objectIdSchema,
291
+ contentKind: z.literal('poll'),
292
+ author: feedAuthorSchema,
293
+ question: z.string().min(1).max(POLL_QUESTION_MAX_CHARS),
294
+ options: z.array(pollOptionSchema).min(POLL_MIN_OPTIONS).max(POLL_MAX_OPTIONS),
295
+ /** Unique voters, not votes: with multi-select the two differ. */
296
+ totalVoters: z.number().int().nonnegative(),
297
+ allowsMultipleChoices: z.boolean(),
298
+ closesAt: z.iso.datetime(),
299
+ /**
300
+ * Whether the poll is closed, decided by the SERVER's clock.
301
+ *
302
+ * Derivable from `closesAt`, and deliberately sent anyway: a device with a
303
+ * wrong clock would otherwise show a live poll as finished, or offer a vote
304
+ * the server then rejects, and the member sees a control that lies. `closesAt`
305
+ * stays for rendering "closes in 2 days"; this is what gates the control.
306
+ */
307
+ isClosed: z.boolean(),
308
+ /** As on a post. A poll is feed content and is matched the same way. */
309
+ topics: z.array(topicSchema).max(MAX_TOPICS),
310
+ commentCount: z.number().int().nonnegative(),
311
+ reactionCounts: reactionCountsSchema,
312
+ createdAt: z.iso.datetime(),
313
+ /** Always null. Kept so one byline component renders both kinds. */
314
+ editedAt: z.iso.datetime().nullable(),
315
+ viewer: viewerStateSchema
316
+ .extend({
317
+ /** Indices this viewer chose. Empty means not voted yet, and it is
318
+ * always populated for the viewer: a voter can always see their own
319
+ * answer even where others' results are hidden. */
320
+ votedOptionIndices: z.array(z.number().int().nonnegative()),
321
+ })
322
+ .optional(),
323
+ });
324
+ // ─── The feed item union ─────────────────────────────────────────────────────
325
+ /**
326
+ * Discriminated on `contentKind`, so a client narrows with a switch and the
327
+ * compiler catches an unhandled kind the day one is added. A plain union would
328
+ * need every field checked by hand and would silently accept a hybrid.
329
+ */
330
+ export const feedItemSchema = z.discriminatedUnion('contentKind', [feedPostSchema, feedPollSchema]);
331
+ // ─── Comments ────────────────────────────────────────────────────────────────
332
+ /**
333
+ * A comment, one level of nesting only: a reply to a comment is allowed, a
334
+ * reply to a reply is not. Two levels stay readable on a phone; three do not,
335
+ * and the server is what enforces it.
336
+ */
337
+ export const feedCommentSchema = z.object({
338
+ id: objectIdSchema,
339
+ contentKind: contentKindSchema,
340
+ contentId: objectIdSchema,
341
+ /** Null for a top-level comment. A non-null value may only name a top-level
342
+ * comment, never a reply. */
343
+ parentCommentId: objectIdSchema.nullable(),
344
+ author: feedAuthorSchema,
345
+ text: z.string().max(COMMENT_MAX_BODY_CHARS),
346
+ /** Meaningful only on a top-level comment; always 0 on a reply. */
347
+ replyCount: z.number().int().nonnegative(),
348
+ reactionCounts: reactionCountsSchema,
349
+ createdAt: z.iso.datetime(),
350
+ editedAt: z.iso.datetime().nullable(),
351
+ /** No `bookmarked`: the post is the right thing to save, not a comment. */
352
+ viewer: viewerStateSchema.omit({ bookmarked: true }).optional(),
353
+ });
354
+ // ─── Queries ─────────────────────────────────────────────────────────────────
355
+ /**
356
+ * The feed query. Inherits `limit` and `cursor`, which already tolerate an
357
+ * emptied control rather than answering 400.
358
+ *
359
+ * `authorId` powers "posts by this founder" on a profile page, so the profile
360
+ * feed and the main feed are the same endpoint and cannot drift apart.
361
+ */
362
+ export const feedQuerySchema = paginationQuerySchema.extend({
363
+ sort: feedSortSchema.default('new'),
364
+ authorId: objectIdSchema.optional(),
365
+ });
366
+ export const commentsQuerySchema = paginationQuerySchema.extend({
367
+ /** Omitted lists top-level comments; set, it lists that comment's replies. */
368
+ parentCommentId: objectIdSchema.optional(),
369
+ });
370
+ // ─── Write bodies ────────────────────────────────────────────────────────────
371
+ /**
372
+ * ⚠️ Every write body below is its own object with NO defaults, and none of
373
+ * them is built with `.pick().partial()`. `.partial()` does not switch off
374
+ * `.default()`, so a patch body built that way rewrites defaulted fields on
375
+ * every request. See `updateFounderProfileBodySchema` for the incident.
376
+ */
377
+ /**
378
+ * An attachment on the way IN: a reference to something already uploaded, and
379
+ * deliberately not a URL.
380
+ *
381
+ * Upload happens first, straight to storage, and the composer sends back the
382
+ * key it was given. The server resolves that key to the URL, dimensions and
383
+ * poster frame it already knows, and those become the read shape.
384
+ *
385
+ * ⚠️ The first draft of this took the full read shape, URL included. That is
386
+ * the same hole that was closed on the profile: a URL in a write body is a
387
+ * member-supplied URL, so a post could have carried `javascript:` in an image
388
+ * source, and nothing downstream re-checks a value the server itself stored.
389
+ * Taking a key instead removes the question rather than validating it, and it
390
+ * also stops a member pointing a post at somebody else's file.
391
+ *
392
+ * `width`, `height` and `duration` are NOT accepted here either. They are
393
+ * properties of the uploaded object, so the server reads them from the object;
394
+ * taking them from the client would let a caller claim a 1x1 image and collapse
395
+ * the card.
396
+ *
397
+ * FORMAT, set by the backend (hary, 2026-09-21), minted server-side and never
398
+ * by a client:
399
+ *
400
+ * media/<userId>/<uuid>.<ext>
401
+ *
402
+ * ⚠️ THIS SCHEMA IS THE FIRST OF THREE CHECKS AND THE WEAKEST. It proves the
403
+ * key is well FORMED. It cannot prove the two things that actually matter, and
404
+ * nobody should read a green parse as though it had:
405
+ *
406
+ * 1. OWNERSHIP. The `userId` segment is what makes "is this your object"
407
+ * checkable, and the backend compares it against the authenticated caller.
408
+ * A pattern happily accepts a perfectly well-formed key belonging to
409
+ * somebody else, which is the exact attack taking a key was meant to stop.
410
+ * 2. EXISTENCE. The backend calls HeadObject before writing the post, so a
411
+ * key for an object nobody uploaded cannot be committed.
412
+ *
413
+ * The length ceiling and the traversal refusal below are redundant against this
414
+ * pattern, which is anchored and admits no dots outside the extension. They are
415
+ * kept on purpose: they are what still holds if this pattern is ever loosened.
416
+ */
417
+ export const UPLOAD_KEY_MAX_CHARS = 300;
418
+ /**
419
+ * ⚠️ IMAGES ONLY, and that is now a product decision rather than an oversight.
420
+ *
421
+ * The asymmetry was real and was raised: `feedVideoSchema` is in the read union
422
+ * and a card can render a video, while nothing could ever upload one. The user
423
+ * settled it on 2026-09-21: members upload images, and share video by putting a
424
+ * link in the post text, which the client renders inline. So the minter stays
425
+ * images-only by intent.
426
+ *
427
+ * `feedVideoSchema` is deliberately KEPT. Widening the write path later is
428
+ * additive; removing video from the read union once a client handles it is not.
429
+ * A test named for refusing a video key holds this visible, so whoever adds
430
+ * video uploads has to delete a test that says out loud why it exists.
431
+ */
432
+ export const UPLOAD_KEY_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif'];
433
+ export const uploadKeySchema = z
434
+ .string()
435
+ .trim()
436
+ .min(1)
437
+ .max(UPLOAD_KEY_MAX_CHARS)
438
+ .regex(/^media\/[0-9a-f]{24}\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.(jpg|jpeg|png|webp|gif)$/, 'Invalid upload reference')
439
+ .refine((k) => !k.includes('..'), { message: 'Invalid upload reference' });
440
+ export const attachedMediaSchema = z.object({
441
+ uploadKey: uploadKeySchema,
442
+ /** Author-supplied alt text, the one media field a member does write. */
443
+ alt: z.string().trim().max(280).optional(),
444
+ });
445
+ /**
446
+ * A post must carry something. Text alone, media alone, or both; empty is
447
+ * refused here rather than reaching the feed as a blank card.
448
+ */
449
+ export const createPostBodySchema = z
450
+ .object({
451
+ text: z.string().trim().max(POST_MAX_BODY_CHARS).optional(),
452
+ /** Already uploaded. See `attachedMediaSchema`. Order is preserved. */
453
+ media: z.array(attachedMediaSchema).max(POST_MAX_MEDIA).optional(),
454
+ /** Absent means untagged, which means interest matching cannot find it. */
455
+ topics: z.array(topicSchema).max(MAX_TOPICS).optional(),
456
+ })
457
+ .refine((b) => Boolean(b.text?.length) || Boolean(b.media?.length), {
458
+ message: 'Write something or add a photo',
459
+ path: ['text'],
460
+ });
461
+ /** Only the text is editable. Changing media after the fact makes every
462
+ * earlier reply look like a reply to something else. */
463
+ export const updatePostBodySchema = z.object({
464
+ text: z.string().trim().min(1).max(POST_MAX_BODY_CHARS),
465
+ });
466
+ export const createPollBodySchema = z
467
+ .object({
468
+ question: z.string().trim().min(1).max(POLL_QUESTION_MAX_CHARS),
469
+ options: z
470
+ .array(z.object({ label: z.string().trim().min(1).max(POLL_OPTION_MAX_CHARS) }))
471
+ .min(POLL_MIN_OPTIONS)
472
+ .max(POLL_MAX_OPTIONS),
473
+ /**
474
+ * Duration from now, NOT an absolute closing time. A client whose clock is
475
+ * wrong would otherwise open a poll that is already closed, and the member
476
+ * would have no way to tell why.
477
+ */
478
+ durationMs: z.number().int().min(POLL_MIN_DURATION_MS).max(POLL_MAX_DURATION_MS),
479
+ allowsMultipleChoices: z.boolean(),
480
+ topics: z.array(topicSchema).max(MAX_TOPICS).optional(),
481
+ })
482
+ .refine((b) => {
483
+ const seen = new Set();
484
+ for (const o of b.options) {
485
+ const key = o.label.trim().toLowerCase();
486
+ if (seen.has(key))
487
+ return false;
488
+ seen.add(key);
489
+ }
490
+ return true;
491
+ }, { message: 'Poll options must be different from each other', path: ['options'] });
492
+ /** Cast or change a vote. The server upserts on (poll, voter), so voting
493
+ * twice replaces rather than doubles. */
494
+ export const castVoteBodySchema = z.object({
495
+ optionIndices: z
496
+ .array(z
497
+ .number()
498
+ .int()
499
+ .min(0)
500
+ .max(POLL_MAX_OPTIONS - 1))
501
+ .min(1)
502
+ .max(POLL_MAX_OPTIONS),
503
+ });
504
+ export const createCommentBodySchema = z.object({
505
+ text: z.string().trim().min(1).max(COMMENT_MAX_BODY_CHARS),
506
+ /** Null for a top-level comment. */
507
+ parentCommentId: objectIdSchema.nullable(),
508
+ });
509
+ export const updateCommentBodySchema = z.object({
510
+ text: z.string().trim().min(1).max(COMMENT_MAX_BODY_CHARS),
511
+ });
512
+ /** Set or clear a reaction. `null` clears it; at most one per viewer per item. */
513
+ export const setReactionBodySchema = z.object({
514
+ reaction: reactionTypeSchema.nullable(),
515
+ });
516
+ // ─── Engagement responses ────────────────────────────────────────────────────
517
+ /**
518
+ * Returned by the reaction endpoint so the card can render the authoritative
519
+ * result without a follow-up read. Without the fresh counts a client has to
520
+ * guess the new total, and two quick taps leave it showing a number the server
521
+ * never had.
522
+ */
523
+ export const setReactionResponseSchema = z.object({
524
+ contentKind: contentKindSchema,
525
+ contentId: objectIdSchema,
526
+ reaction: reactionTypeSchema.nullable(),
527
+ reactionCounts: reactionCountsSchema,
528
+ });
529
+ // ─── Reporting ───────────────────────────────────────────────────────────────
530
+ /**
531
+ * Why a member reported something.
532
+ *
533
+ * ⚠️ Stored on every report row, so this is data, not a label: removing a value
534
+ * orphans reports already filed under it, and the counts nobody can recover are
535
+ * exactly the ones a moderation review needs. Append only.
536
+ *
537
+ * ⚠️ A REASON THAT IS MISSING DOES NOT DISAPPEAR, it lands in `other`. Whatever
538
+ * is not named here becomes an undifferentiated pile that no aggregate can see
539
+ * a pattern in, which is the one thing report categories exist for. Worth being
540
+ * deliberate about the absences rather than discovering them later.
541
+ */
542
+ export const REPORT_REASON_VALUES = [
543
+ 'spam',
544
+ 'harassment',
545
+ 'misinformation',
546
+ 'off_topic',
547
+ 'impersonation',
548
+ 'other',
549
+ ];
550
+ export const reportReasonSchema = z.enum(REPORT_REASON_VALUES);
551
+ /**
552
+ * What a member sends to report a post, poll or comment.
553
+ *
554
+ * The target is the URL's, not the body's: a report is filed against a specific
555
+ * thing at a specific address, and taking the target from the body would let a
556
+ * caller report one item while the route thinks it is another.
557
+ *
558
+ * `note` is free text and optional, which is the pressure valve for everything
559
+ * the enum does not name. ⚠️ It is written by a member, so it is untrusted at
560
+ * render: a moderation queue displays it, and a moderation queue is a screen
561
+ * staff read quickly.
562
+ */
563
+ export const createReportBodySchema = z.object({
564
+ reason: reportReasonSchema,
565
+ note: z.string().trim().max(1000).optional(),
566
+ });
567
+ /**
568
+ * The answer to filing one.
569
+ *
570
+ * `alreadyReported` distinguishes "we have taken this" from "you already told
571
+ * us", because one report per member per target means a second press is a
572
+ * no-op, and a silent no-op reads as a failure to somebody who pressed twice
573
+ * deliberately. It is NOT a count: how many OTHER people reported an item is
574
+ * moderation's business and telling a reporter would turn the count into a
575
+ * score anyone could farm.
576
+ */
577
+ export const createReportResponseSchema = z.object({
578
+ contentKind: contentKindSchema,
579
+ contentId: objectIdSchema,
580
+ alreadyReported: z.boolean(),
581
+ });
582
+ /** The bookmark endpoint is a toggle and returns the state it settled on. */
583
+ export const toggleBookmarkResponseSchema = z.object({
584
+ contentKind: contentKindSchema,
585
+ contentId: objectIdSchema,
586
+ bookmarked: z.boolean(),
587
+ });
588
+ /** A vote returns the whole poll: counts, totals and the viewer's own choices
589
+ * all move together, and reassembling them client-side drifts. */
590
+ export const castVoteResponseSchema = z.object({
591
+ poll: feedPollSchema,
592
+ });
593
+ //# sourceMappingURL=feed.js.map