@openpeepshq/common 0.6.4 → 0.8.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.
@@ -741,9 +741,9 @@ export declare const visibilityTypeSchema: z.ZodEnum<{
741
741
  }>;
742
742
  export type VisibilityType = z.infer<typeof visibilityTypeSchema>;
743
743
  export declare const postTypeSchema: z.ZodEnum<{
744
- resource: "resource";
745
744
  note: "note";
746
745
  question: "question";
746
+ resource: "resource";
747
747
  event: "event";
748
748
  article: "article";
749
749
  }>;
@@ -933,6 +933,93 @@ export declare const questionSchema: z.ZodObject<{
933
933
  expiresAt: z.ZodOptional<z.ZodISODateTime>;
934
934
  }, z.core.$strip>;
935
935
  export type Question = z.infer<typeof questionSchema>;
936
+ export declare const noteInputSchema: z.ZodObject<{
937
+ type: z.ZodLiteral<"note">;
938
+ content: z.ZodOptional<z.ZodString>;
939
+ sensitive: z.ZodOptional<z.ZodBoolean>;
940
+ spoilerText: z.ZodOptional<z.ZodString>;
941
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
942
+ type: z.ZodString;
943
+ url: z.ZodURL;
944
+ previewUrl: z.ZodNullable<z.ZodURL>;
945
+ textUrl: z.ZodNull;
946
+ filename: z.ZodString;
947
+ meta: z.ZodObject<{
948
+ usage: z.ZodOptional<z.ZodString>;
949
+ focus: z.ZodOptional<z.ZodObject<{
950
+ x: z.ZodNumber;
951
+ y: z.ZodNumber;
952
+ }, z.core.$strip>>;
953
+ mimetype: z.ZodOptional<z.ZodString>;
954
+ size: z.ZodOptional<z.ZodNumber>;
955
+ }, z.core.$strip>;
956
+ description: z.ZodOptional<z.ZodString>;
957
+ blurhash: z.ZodOptional<z.ZodString>;
958
+ status: z.ZodOptional<z.ZodEnum<{
959
+ processing: "processing";
960
+ ready: "ready";
961
+ failed: "failed";
962
+ }>>;
963
+ error: z.ZodOptional<z.ZodString>;
964
+ }, z.core.$strip>>>;
965
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
966
+ shortcode: z.ZodString;
967
+ url: z.ZodURL;
968
+ staticUrl: z.ZodURL;
969
+ visibleInPicker: z.ZodBoolean;
970
+ category: z.ZodString;
971
+ }, z.core.$strip>>>;
972
+ language: z.ZodOptional<z.ZodEnum<{
973
+ [x: string]: string;
974
+ }>>;
975
+ }, z.core.$strip>;
976
+ export declare const questionInputSchema: z.ZodObject<{
977
+ content: z.ZodOptional<z.ZodString>;
978
+ sensitive: z.ZodOptional<z.ZodBoolean>;
979
+ spoilerText: z.ZodOptional<z.ZodString>;
980
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
981
+ type: z.ZodString;
982
+ url: z.ZodURL;
983
+ previewUrl: z.ZodNullable<z.ZodURL>;
984
+ textUrl: z.ZodNull;
985
+ filename: z.ZodString;
986
+ meta: z.ZodObject<{
987
+ usage: z.ZodOptional<z.ZodString>;
988
+ focus: z.ZodOptional<z.ZodObject<{
989
+ x: z.ZodNumber;
990
+ y: z.ZodNumber;
991
+ }, z.core.$strip>>;
992
+ mimetype: z.ZodOptional<z.ZodString>;
993
+ size: z.ZodOptional<z.ZodNumber>;
994
+ }, z.core.$strip>;
995
+ description: z.ZodOptional<z.ZodString>;
996
+ blurhash: z.ZodOptional<z.ZodString>;
997
+ status: z.ZodOptional<z.ZodEnum<{
998
+ processing: "processing";
999
+ ready: "ready";
1000
+ failed: "failed";
1001
+ }>>;
1002
+ error: z.ZodOptional<z.ZodString>;
1003
+ }, z.core.$strip>>>;
1004
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
1005
+ shortcode: z.ZodString;
1006
+ url: z.ZodURL;
1007
+ staticUrl: z.ZodURL;
1008
+ visibleInPicker: z.ZodBoolean;
1009
+ category: z.ZodString;
1010
+ }, z.core.$strip>>>;
1011
+ language: z.ZodOptional<z.ZodEnum<{
1012
+ [x: string]: string;
1013
+ }>>;
1014
+ type: z.ZodLiteral<"question">;
1015
+ options: z.ZodArray<z.ZodObject<{
1016
+ content: z.ZodString;
1017
+ type: z.ZodLiteral<"note">;
1018
+ }, z.core.$strip>>;
1019
+ multiple: z.ZodOptional<z.ZodBoolean>;
1020
+ votersVisible: z.ZodOptional<z.ZodBoolean>;
1021
+ expiresAt: z.ZodOptional<z.ZodISODateTime>;
1022
+ }, z.core.$strip>;
936
1023
  export declare const articleSchema: z.ZodObject<{
937
1024
  content: z.ZodOptional<z.ZodString>;
938
1025
  sensitive: z.ZodOptional<z.ZodBoolean>;
@@ -1475,11 +1562,294 @@ export declare const postDataUnionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1475
1562
  url: z.ZodOptional<z.ZodURL>;
1476
1563
  }, z.core.$strip>], "type">;
1477
1564
  export type PostDataUnion = z.infer<typeof postDataUnionSchema>;
1565
+ export declare const postDataInputUnionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1566
+ type: z.ZodLiteral<"note">;
1567
+ content: z.ZodOptional<z.ZodString>;
1568
+ sensitive: z.ZodOptional<z.ZodBoolean>;
1569
+ spoilerText: z.ZodOptional<z.ZodString>;
1570
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
1571
+ type: z.ZodString;
1572
+ url: z.ZodURL;
1573
+ previewUrl: z.ZodNullable<z.ZodURL>;
1574
+ textUrl: z.ZodNull;
1575
+ filename: z.ZodString;
1576
+ meta: z.ZodObject<{
1577
+ usage: z.ZodOptional<z.ZodString>;
1578
+ focus: z.ZodOptional<z.ZodObject<{
1579
+ x: z.ZodNumber;
1580
+ y: z.ZodNumber;
1581
+ }, z.core.$strip>>;
1582
+ mimetype: z.ZodOptional<z.ZodString>;
1583
+ size: z.ZodOptional<z.ZodNumber>;
1584
+ }, z.core.$strip>;
1585
+ description: z.ZodOptional<z.ZodString>;
1586
+ blurhash: z.ZodOptional<z.ZodString>;
1587
+ status: z.ZodOptional<z.ZodEnum<{
1588
+ processing: "processing";
1589
+ ready: "ready";
1590
+ failed: "failed";
1591
+ }>>;
1592
+ error: z.ZodOptional<z.ZodString>;
1593
+ }, z.core.$strip>>>;
1594
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
1595
+ shortcode: z.ZodString;
1596
+ url: z.ZodURL;
1597
+ staticUrl: z.ZodURL;
1598
+ visibleInPicker: z.ZodBoolean;
1599
+ category: z.ZodString;
1600
+ }, z.core.$strip>>>;
1601
+ language: z.ZodOptional<z.ZodEnum<{
1602
+ [x: string]: string;
1603
+ }>>;
1604
+ }, z.core.$strip>, z.ZodObject<{
1605
+ content: z.ZodOptional<z.ZodString>;
1606
+ sensitive: z.ZodOptional<z.ZodBoolean>;
1607
+ spoilerText: z.ZodOptional<z.ZodString>;
1608
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
1609
+ type: z.ZodString;
1610
+ url: z.ZodURL;
1611
+ previewUrl: z.ZodNullable<z.ZodURL>;
1612
+ textUrl: z.ZodNull;
1613
+ filename: z.ZodString;
1614
+ meta: z.ZodObject<{
1615
+ usage: z.ZodOptional<z.ZodString>;
1616
+ focus: z.ZodOptional<z.ZodObject<{
1617
+ x: z.ZodNumber;
1618
+ y: z.ZodNumber;
1619
+ }, z.core.$strip>>;
1620
+ mimetype: z.ZodOptional<z.ZodString>;
1621
+ size: z.ZodOptional<z.ZodNumber>;
1622
+ }, z.core.$strip>;
1623
+ description: z.ZodOptional<z.ZodString>;
1624
+ blurhash: z.ZodOptional<z.ZodString>;
1625
+ status: z.ZodOptional<z.ZodEnum<{
1626
+ processing: "processing";
1627
+ ready: "ready";
1628
+ failed: "failed";
1629
+ }>>;
1630
+ error: z.ZodOptional<z.ZodString>;
1631
+ }, z.core.$strip>>>;
1632
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
1633
+ shortcode: z.ZodString;
1634
+ url: z.ZodURL;
1635
+ staticUrl: z.ZodURL;
1636
+ visibleInPicker: z.ZodBoolean;
1637
+ category: z.ZodString;
1638
+ }, z.core.$strip>>>;
1639
+ language: z.ZodOptional<z.ZodEnum<{
1640
+ [x: string]: string;
1641
+ }>>;
1642
+ type: z.ZodLiteral<"question">;
1643
+ options: z.ZodArray<z.ZodObject<{
1644
+ content: z.ZodString;
1645
+ type: z.ZodLiteral<"note">;
1646
+ }, z.core.$strip>>;
1647
+ multiple: z.ZodOptional<z.ZodBoolean>;
1648
+ votersVisible: z.ZodOptional<z.ZodBoolean>;
1649
+ expiresAt: z.ZodOptional<z.ZodISODateTime>;
1650
+ }, z.core.$strip>, z.ZodObject<{
1651
+ content: z.ZodOptional<z.ZodString>;
1652
+ sensitive: z.ZodOptional<z.ZodBoolean>;
1653
+ spoilerText: z.ZodOptional<z.ZodString>;
1654
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
1655
+ type: z.ZodString;
1656
+ url: z.ZodURL;
1657
+ previewUrl: z.ZodNullable<z.ZodURL>;
1658
+ textUrl: z.ZodNull;
1659
+ filename: z.ZodString;
1660
+ meta: z.ZodObject<{
1661
+ usage: z.ZodOptional<z.ZodString>;
1662
+ focus: z.ZodOptional<z.ZodObject<{
1663
+ x: z.ZodNumber;
1664
+ y: z.ZodNumber;
1665
+ }, z.core.$strip>>;
1666
+ mimetype: z.ZodOptional<z.ZodString>;
1667
+ size: z.ZodOptional<z.ZodNumber>;
1668
+ }, z.core.$strip>;
1669
+ description: z.ZodOptional<z.ZodString>;
1670
+ blurhash: z.ZodOptional<z.ZodString>;
1671
+ status: z.ZodOptional<z.ZodEnum<{
1672
+ processing: "processing";
1673
+ ready: "ready";
1674
+ failed: "failed";
1675
+ }>>;
1676
+ error: z.ZodOptional<z.ZodString>;
1677
+ }, z.core.$strip>>>;
1678
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
1679
+ shortcode: z.ZodString;
1680
+ url: z.ZodURL;
1681
+ staticUrl: z.ZodURL;
1682
+ visibleInPicker: z.ZodBoolean;
1683
+ category: z.ZodString;
1684
+ }, z.core.$strip>>>;
1685
+ language: z.ZodOptional<z.ZodEnum<{
1686
+ [x: string]: string;
1687
+ }>>;
1688
+ type: z.ZodLiteral<"event">;
1689
+ name: z.ZodOptional<z.ZodString>;
1690
+ timeZone: z.ZodOptional<z.ZodString>;
1691
+ image: z.ZodOptional<z.ZodURL>;
1692
+ start: z.ZodISODateTime;
1693
+ end: z.ZodOptional<z.ZodISODateTime>;
1694
+ wholeDay: z.ZodBoolean;
1695
+ maxAttendees: z.ZodOptional<z.ZodNumber>;
1696
+ waitlistOfferMinutes: z.ZodOptional<z.ZodNumber>;
1697
+ attendeeListPublic: z.ZodOptional<z.ZodBoolean>;
1698
+ moderators: z.ZodOptional<z.ZodArray<z.ZodString>>;
1699
+ jam: z.ZodOptional<z.ZodObject<{
1700
+ moderators: z.ZodArray<z.ZodString>;
1701
+ speakers: z.ZodOptional<z.ZodArray<z.ZodString>>;
1702
+ presenters: z.ZodOptional<z.ZodArray<z.ZodString>>;
1703
+ audience: z.ZodOptional<z.ZodArray<z.ZodString>>;
1704
+ videoEnabled: z.ZodBoolean;
1705
+ type: z.ZodEnum<{
1706
+ "video-call": "video-call";
1707
+ }>;
1708
+ maxSpeakers: z.ZodOptional<z.ZodNumber>;
1709
+ maxPresenters: z.ZodOptional<z.ZodNumber>;
1710
+ maxAudience: z.ZodOptional<z.ZodNumber>;
1711
+ waitingRoom: z.ZodOptional<z.ZodBoolean>;
1712
+ }, z.core.$strip>>;
1713
+ physicalLocation: z.ZodOptional<z.ZodObject<{
1714
+ text: z.ZodString;
1715
+ coordinates: z.ZodOptional<z.ZodObject<{
1716
+ lat: z.ZodNumber;
1717
+ lng: z.ZodNumber;
1718
+ alt: z.ZodOptional<z.ZodNumber>;
1719
+ }, z.core.$strip>>;
1720
+ }, z.core.$strip>>;
1721
+ url: z.ZodOptional<z.ZodURL>;
1722
+ recurrence: z.ZodOptional<z.ZodObject<{
1723
+ freq: z.ZodEnum<{
1724
+ DAILY: "DAILY";
1725
+ WEEKLY: "WEEKLY";
1726
+ MONTHLY: "MONTHLY";
1727
+ }>;
1728
+ interval: z.ZodOptional<z.ZodNumber>;
1729
+ byDay: z.ZodOptional<z.ZodArray<z.ZodEnum<{
1730
+ MO: "MO";
1731
+ TU: "TU";
1732
+ WE: "WE";
1733
+ TH: "TH";
1734
+ FR: "FR";
1735
+ SA: "SA";
1736
+ SU: "SU";
1737
+ }>>>;
1738
+ until: z.ZodOptional<z.ZodISODateTime>;
1739
+ count: z.ZodOptional<z.ZodNumber>;
1740
+ }, z.core.$strip>>;
1741
+ exceptions: z.ZodOptional<z.ZodArray<z.ZodObject<{
1742
+ recurrenceId: z.ZodISODateTime;
1743
+ cancelled: z.ZodOptional<z.ZodBoolean>;
1744
+ start: z.ZodOptional<z.ZodISODateTime>;
1745
+ end: z.ZodOptional<z.ZodISODateTime>;
1746
+ physicalLocation: z.ZodOptional<z.ZodObject<{
1747
+ text: z.ZodString;
1748
+ coordinates: z.ZodOptional<z.ZodObject<{
1749
+ lat: z.ZodNumber;
1750
+ lng: z.ZodNumber;
1751
+ alt: z.ZodOptional<z.ZodNumber>;
1752
+ }, z.core.$strip>>;
1753
+ }, z.core.$strip>>;
1754
+ }, z.core.$strip>>>;
1755
+ }, z.core.$strip>, z.ZodObject<{
1756
+ content: z.ZodOptional<z.ZodString>;
1757
+ sensitive: z.ZodOptional<z.ZodBoolean>;
1758
+ spoilerText: z.ZodOptional<z.ZodString>;
1759
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
1760
+ type: z.ZodString;
1761
+ url: z.ZodURL;
1762
+ previewUrl: z.ZodNullable<z.ZodURL>;
1763
+ textUrl: z.ZodNull;
1764
+ filename: z.ZodString;
1765
+ meta: z.ZodObject<{
1766
+ usage: z.ZodOptional<z.ZodString>;
1767
+ focus: z.ZodOptional<z.ZodObject<{
1768
+ x: z.ZodNumber;
1769
+ y: z.ZodNumber;
1770
+ }, z.core.$strip>>;
1771
+ mimetype: z.ZodOptional<z.ZodString>;
1772
+ size: z.ZodOptional<z.ZodNumber>;
1773
+ }, z.core.$strip>;
1774
+ description: z.ZodOptional<z.ZodString>;
1775
+ blurhash: z.ZodOptional<z.ZodString>;
1776
+ status: z.ZodOptional<z.ZodEnum<{
1777
+ processing: "processing";
1778
+ ready: "ready";
1779
+ failed: "failed";
1780
+ }>>;
1781
+ error: z.ZodOptional<z.ZodString>;
1782
+ }, z.core.$strip>>>;
1783
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
1784
+ shortcode: z.ZodString;
1785
+ url: z.ZodURL;
1786
+ staticUrl: z.ZodURL;
1787
+ visibleInPicker: z.ZodBoolean;
1788
+ category: z.ZodString;
1789
+ }, z.core.$strip>>>;
1790
+ language: z.ZodOptional<z.ZodEnum<{
1791
+ [x: string]: string;
1792
+ }>>;
1793
+ type: z.ZodLiteral<"article">;
1794
+ image: z.ZodOptional<z.ZodURL>;
1795
+ title: z.ZodOptional<z.ZodString>;
1796
+ }, z.core.$strip>, z.ZodObject<{
1797
+ content: z.ZodOptional<z.ZodString>;
1798
+ sensitive: z.ZodOptional<z.ZodBoolean>;
1799
+ spoilerText: z.ZodOptional<z.ZodString>;
1800
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
1801
+ type: z.ZodString;
1802
+ url: z.ZodURL;
1803
+ previewUrl: z.ZodNullable<z.ZodURL>;
1804
+ textUrl: z.ZodNull;
1805
+ filename: z.ZodString;
1806
+ meta: z.ZodObject<{
1807
+ usage: z.ZodOptional<z.ZodString>;
1808
+ focus: z.ZodOptional<z.ZodObject<{
1809
+ x: z.ZodNumber;
1810
+ y: z.ZodNumber;
1811
+ }, z.core.$strip>>;
1812
+ mimetype: z.ZodOptional<z.ZodString>;
1813
+ size: z.ZodOptional<z.ZodNumber>;
1814
+ }, z.core.$strip>;
1815
+ description: z.ZodOptional<z.ZodString>;
1816
+ blurhash: z.ZodOptional<z.ZodString>;
1817
+ status: z.ZodOptional<z.ZodEnum<{
1818
+ processing: "processing";
1819
+ ready: "ready";
1820
+ failed: "failed";
1821
+ }>>;
1822
+ error: z.ZodOptional<z.ZodString>;
1823
+ }, z.core.$strip>>>;
1824
+ customEmojis: z.ZodOptional<z.ZodArray<z.ZodObject<{
1825
+ shortcode: z.ZodString;
1826
+ url: z.ZodURL;
1827
+ staticUrl: z.ZodURL;
1828
+ visibleInPicker: z.ZodBoolean;
1829
+ category: z.ZodString;
1830
+ }, z.core.$strip>>>;
1831
+ language: z.ZodOptional<z.ZodEnum<{
1832
+ [x: string]: string;
1833
+ }>>;
1834
+ type: z.ZodLiteral<"resource">;
1835
+ title: z.ZodString;
1836
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
1837
+ categoryPath: z.ZodOptional<z.ZodArray<z.ZodString>>;
1838
+ resourceKind: z.ZodEnum<{
1839
+ file: "file";
1840
+ link: "link";
1841
+ video: "video";
1842
+ gallery: "gallery";
1843
+ audio: "audio";
1844
+ }>;
1845
+ url: z.ZodOptional<z.ZodURL>;
1846
+ }, z.core.$strip>], "type">;
1847
+ export type PostDataInputUnion = z.infer<typeof postDataInputUnionSchema>;
1478
1848
  export declare const postDataSchema: z.ZodObject<{
1479
1849
  type: z.ZodEnum<{
1480
- resource: "resource";
1481
1850
  note: "note";
1482
1851
  question: "question";
1852
+ resource: "resource";
1483
1853
  event: "event";
1484
1854
  article: "article";
1485
1855
  }>;
@@ -1780,9 +2150,9 @@ export declare const postDataSchema: z.ZodObject<{
1780
2150
  export type PostData = z.infer<typeof postDataSchema>;
1781
2151
  export declare const postSchema: z.ZodObject<{
1782
2152
  type: z.ZodEnum<{
1783
- resource: "resource";
1784
2153
  note: "note";
1785
2154
  question: "question";
2155
+ resource: "resource";
1786
2156
  event: "event";
1787
2157
  article: "article";
1788
2158
  }>;
@@ -3,6 +3,7 @@ import validator from 'validator';
3
3
  import ISO6391 from 'iso-639-1';
4
4
  import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
5
5
  import { isEndBeforeStart } from '../lib/eventTime.js';
6
+ import { hasVisibleText, postContentWithinBudget } from '../lib/contentLength.js';
6
7
  import { groupRelationships } from './capabilities.js';
7
8
  import { capabilitiesSchema } from './config.js';
8
9
  import { HANDLE_RESERVED_MESSAGE, additionalForbiddenHandlesSchema, classifyAdditionalForbiddenHandle, collectAdditionalForbiddenHandles, forbiddenHandles, handleRegex, handleRegexBase, isDefaultForbiddenHandle, isForbiddenHandle, normalizeForbiddenHandle, } from './forbiddenHandles.js';
@@ -342,8 +343,7 @@ export const customEmojiSchema = z
342
343
  category: z.string(),
343
344
  })
344
345
  .openapi('CustomEmoji');
345
- export const noteSchema = z
346
- .object({
346
+ const noteBaseSchema = z.object({
347
347
  type: z.literal('note'),
348
348
  content: z.string().optional(),
349
349
  sensitive: z.boolean().optional(),
@@ -351,11 +351,29 @@ export const noteSchema = z
351
351
  attachments: z.array(mediaAttachmentDataSchema).optional(),
352
352
  customEmojis: z.array(customEmojiSchema).optional(),
353
353
  language: z.enum(ISO6391.getAllCodes()).optional(),
354
- })
355
- .openapi('Note');
354
+ });
355
+ // A note must carry something a reader can see: visible text or an
356
+ // attachment. Whitespace-only text renders nothing, so it is not enough.
357
+ const hasContentRefine = {
358
+ message: 'posts.form.contentRequired',
359
+ path: ['content'],
360
+ };
361
+ // Note/question carry the visible-text + raw budgets; the longer post
362
+ // flavors (article, resource, event) extend the base without them.
363
+ const contentBudgetRefine = {
364
+ message: 'posts.form.contentTooLong',
365
+ path: ['content'],
366
+ };
367
+ // The refines are write-side checks only: they must live on the input
368
+ // schemas the write endpoints validate against, not on the members of
369
+ // `postDataUnionSchema`. That union also validates API *responses*
370
+ // (`publicPostSchema`, reply/entry data), where a contentless note is
371
+ // legitimate — repost shells and system "left" notes have neither
372
+ // content nor attachments, and output validation must not reject them.
373
+ export const noteSchema = noteBaseSchema.openapi('Note');
356
374
  /** Poll choices are stored short so they fit the vote UI on small screens. */
357
375
  export const POLL_OPTION_MAX_LENGTH = 30;
358
- export const questionSchema = noteSchema
376
+ export const questionSchema = noteBaseSchema
359
377
  .extend({
360
378
  type: z.literal('question'),
361
379
  options: z
@@ -369,7 +387,13 @@ export const questionSchema = noteSchema
369
387
  expiresAt: z.iso.datetime().optional(),
370
388
  })
371
389
  .openapi('Question');
372
- export const articleSchema = noteSchema
390
+ export const noteInputSchema = noteBaseSchema
391
+ .refine((data) => hasVisibleText(data.content) || (data.attachments?.length ?? 0) > 0, hasContentRefine)
392
+ .refine((data) => postContentWithinBudget(data.content), contentBudgetRefine);
393
+ export const questionInputSchema = questionSchema
394
+ .refine((data) => hasVisibleText(data.content) || (data.attachments?.length ?? 0) > 0, hasContentRefine)
395
+ .refine((data) => postContentWithinBudget(data.content), contentBudgetRefine);
396
+ export const articleSchema = noteBaseSchema
373
397
  .extend({
374
398
  type: z.literal('article'),
375
399
  image: z.url().optional(),
@@ -378,7 +402,7 @@ export const articleSchema = noteSchema
378
402
  .openapi('Article');
379
403
  /** Resource titles are library headings, so they stay much shorter than the description. */
380
404
  export const RESOURCE_TITLE_MAX_LENGTH = 200;
381
- export const resourcePostSchema = noteSchema
405
+ export const resourcePostSchema = noteBaseSchema
382
406
  .extend({
383
407
  type: z.literal('resource'),
384
408
  title: z.string().max(RESOURCE_TITLE_MAX_LENGTH),
@@ -428,7 +452,7 @@ export const eventOccurrenceExceptionSchema = z
428
452
  path: ['end'],
429
453
  })
430
454
  .openapi('EventOccurrenceException');
431
- export const eventSchema = noteSchema
455
+ export const eventSchema = noteBaseSchema
432
456
  .extend({
433
457
  type: z.literal('event'),
434
458
  name: z.string().optional(),
@@ -460,6 +484,16 @@ export const postDataUnionSchema = z.discriminatedUnion('type', [
460
484
  articleSchema,
461
485
  resourcePostSchema,
462
486
  ]);
487
+ // Write-side union: the server POST/PUT endpoints validate *incoming*
488
+ // post payloads with this. The budget/requirement refines must not sit
489
+ // on the response-facing `postDataUnionSchema` members (see above).
490
+ export const postDataInputUnionSchema = z.discriminatedUnion('type', [
491
+ noteInputSchema,
492
+ questionInputSchema,
493
+ eventSchema,
494
+ articleSchema,
495
+ resourcePostSchema,
496
+ ]);
463
497
  export const postDataSchema = z.object({
464
498
  type: postTypeSchema,
465
499
  visibility: visibilityTypeSchema,