@openpeepshq/common 0.4.0 → 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.
Files changed (69) hide show
  1. package/dist/lib/adminSections.d.ts +4 -0
  2. package/dist/lib/adminSections.js +5 -0
  3. package/dist/lib/attachmentHelpers.js +5 -1
  4. package/dist/lib/capabilitiesHelpers.d.ts +9 -0
  5. package/dist/lib/capabilitiesHelpers.js +9 -0
  6. package/dist/lib/csvHelpers.d.ts +2 -0
  7. package/dist/lib/csvHelpers.js +13 -0
  8. package/dist/lib/eventRecurrence.d.ts +9 -0
  9. package/dist/lib/eventRecurrence.js +17 -9
  10. package/dist/lib/eventWaitlist.d.ts +58 -0
  11. package/dist/lib/eventWaitlist.js +217 -0
  12. package/dist/lib/index.d.ts +1 -0
  13. package/dist/lib/index.js +1 -0
  14. package/dist/lib/markdownHelpers.d.ts +12 -3
  15. package/dist/lib/markdownHelpers.js +115 -6
  16. package/dist/lib/postHelpers.d.ts +27 -5
  17. package/dist/lib/postHelpers.js +72 -9
  18. package/dist/lib/profileHelpers.d.ts +12 -2
  19. package/dist/lib/profileHelpers.js +19 -2
  20. package/dist/lib/resources.d.ts +29 -1
  21. package/dist/lib/resources.js +74 -2
  22. package/dist/lib/utils.js +11 -11
  23. package/dist/types/admin-livekit.d.ts +23 -0
  24. package/dist/types/admin-livekit.js +18 -0
  25. package/dist/types/admin-media.d.ts +41 -0
  26. package/dist/types/admin-media.js +20 -0
  27. package/dist/types/api.d.ts +19945 -3526
  28. package/dist/types/api.js +15 -9
  29. package/dist/types/capabilities.d.ts +2 -2
  30. package/dist/types/capabilities.js +3 -0
  31. package/dist/types/config.d.ts +3 -0
  32. package/dist/types/config.js +6 -0
  33. package/dist/types/db.d.ts +65 -22
  34. package/dist/types/forbiddenHandles.d.ts +28 -0
  35. package/dist/types/forbiddenHandles.js +75 -0
  36. package/dist/types/index.d.ts +2 -0
  37. package/dist/types/index.js +2 -0
  38. package/dist/types/internal.d.ts +163 -44
  39. package/dist/types/models.d.ts +28 -14
  40. package/dist/types/models.js +27 -28
  41. package/dist/types/notifications.d.ts +2 -0
  42. package/dist/types/notifications.js +4 -2
  43. package/dist/types/roleDefaults.js +109 -95
  44. package/dist/types/stats.d.ts +348 -108
  45. package/package.json +7 -6
  46. package/src/lib/adminSections.ts +5 -0
  47. package/src/lib/attachmentHelpers.ts +18 -12
  48. package/src/lib/capabilitiesHelpers.ts +15 -0
  49. package/src/lib/csvHelpers.ts +19 -3
  50. package/src/lib/eventRecurrence.ts +19 -10
  51. package/src/lib/eventWaitlist.ts +325 -0
  52. package/src/lib/index.ts +1 -0
  53. package/src/lib/markdownHelpers.ts +121 -7
  54. package/src/lib/postHelpers.ts +101 -11
  55. package/src/lib/profileHelpers.ts +31 -2
  56. package/src/lib/resources.ts +105 -2
  57. package/src/lib/utils.ts +40 -31
  58. package/src/types/admin-livekit.ts +24 -0
  59. package/src/types/admin-media.ts +29 -0
  60. package/src/types/api.ts +19 -9
  61. package/src/types/auth.ts +2 -2
  62. package/src/types/capabilities.ts +3 -0
  63. package/src/types/config.ts +6 -0
  64. package/src/types/forbiddenHandles.ts +103 -0
  65. package/src/types/index.ts +2 -0
  66. package/src/types/models.ts +53 -33
  67. package/src/types/notifications.ts +7 -7
  68. package/src/types/roleDefaults.ts +115 -96
  69. package/src/types/stripe.ts +3 -1
@@ -35,6 +35,7 @@ import {
35
35
  } from './capabilitiesHelpers';
36
36
  import { scopeMatches } from './scopeHelpers';
37
37
  import { countBy, dateSorter, groupBy, transformValues } from './utils';
38
+ import { truncateText } from './text';
38
39
 
39
40
  const buildThread = (rootPost: PublicPost, postList: PublicPost[]): Thread => ({
40
41
  ...rootPost,
@@ -498,6 +499,11 @@ export const displayRsvpForProfile = (
498
499
  },
499
500
  ): PublicRsvp | undefined => {
500
501
  const event = post.data?.type === 'event' ? post.data : undefined;
502
+ // One-time events have no occurrences. Older claims stamped the start time
503
+ // onto some RSVPs; a newer unscoped waitlist must still be the current one.
504
+ if (event && !event.recurrence) {
505
+ return getEffectiveRsvp(post, profileId);
506
+ }
501
507
  const scopedId = options?.lockToOccurrence
502
508
  ? options.recurrenceId
503
509
  : event
@@ -521,6 +527,9 @@ export const displayRsvpForProfile = (
521
527
 
522
528
  export const isCapacityEvent = (event: Event) => !!event.maxAttendees;
523
529
 
530
+ export const DEFAULT_WAITLIST_OFFER_MINUTES = 60;
531
+ export const MAX_WAITLIST_OFFER_MINUTES = 7 * 24 * 60;
532
+
524
533
  export const parseEventMaxAttendeesInput = (
525
534
  raw: string,
526
535
  ): number | undefined => {
@@ -530,8 +539,25 @@ export const parseEventMaxAttendeesInput = (
530
539
  return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
531
540
  };
532
541
 
542
+ export const normalizeWaitlistOfferMinutes = (
543
+ value: number | null | undefined,
544
+ ): number | undefined => {
545
+ if (value == null || !Number.isFinite(value)) return undefined;
546
+ const minutes = Math.trunc(value);
547
+ if (minutes < 1 || minutes > MAX_WAITLIST_OFFER_MINUTES) return undefined;
548
+ return minutes;
549
+ };
550
+
551
+ export const parseEventWaitlistOfferMinutesInput = (
552
+ raw: string,
553
+ ): number | undefined => {
554
+ const trimmed = raw.trim();
555
+ if (!trimmed) return undefined;
556
+ return normalizeWaitlistOfferMinutes(Number.parseInt(trimmed, 10));
557
+ };
558
+
533
559
  export const withoutEventMaxAttendees = <T extends Event>(event: T): T => {
534
- const { maxAttendees: _, ...rest } = event;
560
+ const { maxAttendees: _, waitlistOfferMinutes: __, ...rest } = event;
535
561
  return rest as T;
536
562
  };
537
563
 
@@ -544,33 +570,52 @@ export const normalizeEventDataForSave = <T extends Event>(event: T): T => {
544
570
  ) {
545
571
  return withoutEventMaxAttendees(event);
546
572
  }
547
- return { ...event, maxAttendees: Math.trunc(maxAttendees) };
573
+ const minutes = normalizeWaitlistOfferMinutes(event.waitlistOfferMinutes);
574
+ const { waitlistOfferMinutes: _, ...rest } = event;
575
+ return {
576
+ ...rest,
577
+ maxAttendees: Math.trunc(maxAttendees),
578
+ ...(minutes != null ? { waitlistOfferMinutes: minutes } : {}),
579
+ } as T;
548
580
  };
549
581
 
550
582
  /** Null capacity means it was cleared; strip for validation/output. */
551
583
  export const normalizeEventDataFromDb = <T extends Event>(event: T): T => {
552
- if (event.maxAttendees != null) {
553
- return event;
554
- }
555
- return withoutEventMaxAttendees(event);
584
+ const { maxAttendees, waitlistOfferMinutes, ...rest } = event;
585
+ return {
586
+ ...rest,
587
+ ...(maxAttendees != null ? { maxAttendees } : {}),
588
+ ...(waitlistOfferMinutes != null ? { waitlistOfferMinutes } : {}),
589
+ } as T;
556
590
  };
557
591
 
558
592
  export const normalizePostDataFromDb = (data: PostDataUnion): PostDataUnion =>
559
593
  data.type === 'event' ? normalizeEventDataFromDb(data) : data;
560
594
 
561
- /** Nested `data` updates send null to remove maxAttendees. */
562
- export type EventDbUpdate = Omit<Event, 'maxAttendees'> & {
595
+ /** Nested `data` updates send null to remove cleared capacity fields. */
596
+ export type EventDbUpdate = Omit<
597
+ Event,
598
+ 'maxAttendees' | 'waitlistOfferMinutes'
599
+ > & {
563
600
  maxAttendees?: number | null;
601
+ waitlistOfferMinutes?: number | null;
564
602
  };
565
603
 
566
604
  export const eventDataForDbUpdate = (
567
605
  previous: Event | undefined,
568
606
  normalized: Event,
569
607
  ): EventDbUpdate => {
608
+ let next: EventDbUpdate = normalized;
570
609
  if (previous?.maxAttendees != null && !('maxAttendees' in normalized)) {
571
- return { ...normalized, maxAttendees: null };
610
+ next = { ...next, maxAttendees: null };
611
+ }
612
+ if (
613
+ previous?.waitlistOfferMinutes != null &&
614
+ !('waitlistOfferMinutes' in normalized)
615
+ ) {
616
+ next = { ...next, waitlistOfferMinutes: null };
572
617
  }
573
- return normalized;
618
+ return next;
574
619
  };
575
620
 
576
621
  export const canManageEventRsvps = (
@@ -610,6 +655,16 @@ export const getJamCapacityJoinBlock = (
610
655
  if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
611
656
  return { blocked: true, reason: 'full' };
612
657
  }
658
+ // A freed seat stays reserved for the waitlist unless this profile holds the offer.
659
+ const waiting = calculateEffectiveRsvps(post, recurrenceId).filter(
660
+ (rsvp) => rsvp.response === 'waitlist' && rsvp.profile.type !== 'federated',
661
+ );
662
+ const mine = waiting.find((rsvp) => rsvp.profile.id === profile.id);
663
+ const offerOpen =
664
+ !!mine?.offerExpiresAt && Date.parse(mine.offerExpiresAt) > Date.now();
665
+ if (waiting.length > 0 && !offerOpen) {
666
+ return { blocked: true, reason: 'full' };
667
+ }
613
668
  return { blocked: true, reason: 'rsvp-required' };
614
669
  };
615
670
 
@@ -754,7 +809,7 @@ export const toHiddenPost = <
754
809
  export const isHiddenPost = (post: { hidden?: boolean }): boolean =>
755
810
  !!post.hidden;
756
811
 
757
- const participantIds = (
812
+ export const participantIds = (
758
813
  post: Pick<PublicPost, 'audience' | 'profile'> & { creatorId?: string },
759
814
  ): Set<string> => {
760
815
  const ids = new Set(
@@ -765,6 +820,13 @@ const participantIds = (
765
820
  return ids;
766
821
  };
767
822
 
823
+ /** Direct message between exactly two participants. */
824
+ export const isOneToOneDm = (
825
+ post: Pick<PublicPost, 'visibility' | 'audience' | 'profile'> & {
826
+ creatorId?: string;
827
+ },
828
+ ): boolean => post.visibility === 'direct' && participantIds(post).size === 2;
829
+
768
830
  export const isOneToOneWithBlocked = (
769
831
  post: Pick<PublicPost, 'visibility' | 'audience' | 'profile'> & {
770
832
  creatorId?: string;
@@ -780,3 +842,31 @@ export const isOneToOneWithBlocked = (
780
842
  others.delete(viewer.id);
781
843
  return others.size === 1 && blocked.has([...others][0]!);
782
844
  };
845
+
846
+ /** First usable text field of a post, whitespace-collapsed and truncated. */
847
+ export const messagePreviewText = (
848
+ message: PublicPost,
849
+ maxLength = 160,
850
+ ): string => {
851
+ const data = message.data;
852
+ if (!data || typeof data !== 'object') return '';
853
+ const text =
854
+ 'content' in data && typeof data.content === 'string' && data.content
855
+ ? data.content
856
+ : 'name' in data && typeof data.name === 'string'
857
+ ? data.name
858
+ : 'title' in data && typeof data.title === 'string'
859
+ ? data.title
860
+ : '';
861
+ return truncateText(text.replace(/\s+/g, ' ').trim(), maxLength);
862
+ };
863
+
864
+ /** Display names of a post's audience minus the viewer, comma-joined. */
865
+ export const conversationLabel = (
866
+ message: PublicPost,
867
+ viewerId?: string,
868
+ ): string =>
869
+ (message.audience ?? [])
870
+ .filter((profile) => profile.id !== viewerId)
871
+ .map((profile) => profile.displayName || `@${profile.handle}`)
872
+ .join(', ');
@@ -12,8 +12,8 @@ const containsIgnoreCase = (candidate: string, query: string) =>
12
12
 
13
13
  export const PROFILE_DISPLAY_NAME_MAX_LENGTH = 30;
14
14
 
15
- /** Public sentinel shown for soft-deleted authors (API + clients). */
16
- export const DELETED_AUTHOR_DISPLAY_NAME = 'Deleted author';
15
+ /** Public sentinel shown for soft-deleted profiles (API + clients). */
16
+ export const DELETED_AUTHOR_DISPLAY_NAME = 'Deleted Profile';
17
17
  export const DELETED_AUTHOR_HANDLE = 'deleted';
18
18
 
19
19
  export const clampProfileDisplayName = (
@@ -28,6 +28,35 @@ export const isDeletedProfile = (
28
28
  profile: { deletedAt?: string | null } | undefined | null,
29
29
  ): boolean => !!profile?.deletedAt;
30
30
 
31
+ // `handle`/`displayName` arrive from untyped DB rows (`rowToModel`),
32
+ // so the hydration helper must accept `unknown`, not just `string | null`.
33
+ type DeletedProfileIdentity = {
34
+ deletedAt?: string | null;
35
+ displayName?: unknown;
36
+ handle?: unknown;
37
+ };
38
+
39
+ /**
40
+ * Deleted rows keep their original handle (the column is unique) and may have
41
+ * no display name. Public hydration fills in the sentinel when it is missing.
42
+ */
43
+ export const withDeletedProfileIdentity = <T extends DeletedProfileIdentity>(
44
+ profile: T,
45
+ ): T => {
46
+ if (!isDeletedProfile(profile)) return profile;
47
+ if (
48
+ profile.displayName === DELETED_AUTHOR_DISPLAY_NAME &&
49
+ profile.handle === DELETED_AUTHOR_HANDLE
50
+ ) {
51
+ return profile;
52
+ }
53
+ return {
54
+ ...profile,
55
+ displayName: DELETED_AUTHOR_DISPLAY_NAME,
56
+ handle: DELETED_AUTHOR_HANDLE,
57
+ };
58
+ };
59
+
31
60
  /**
32
61
  * Strip PII from a soft-deleted profile for public API / UI surfaces.
33
62
  * Keeps id + timestamps (including deletedAt) so clients can detect the state.
@@ -1,4 +1,22 @@
1
- import type { MediaAttachmentData, ResourceKind } from '../types/models';
1
+ import { z } from 'zod';
2
+ import {
3
+ RESOURCE_TITLE_MAX_LENGTH,
4
+ visibilityTypeValues,
5
+ type MediaAttachmentData,
6
+ type ResourceKind,
7
+ type VisibilityType,
8
+ } from '../types/models';
9
+
10
+ export { RESOURCE_TITLE_MAX_LENGTH };
11
+
12
+ /** Matches `resourcePostSchema.url` (`z.url()`), after trimming. */
13
+ const resourceUrlSchema = z.url();
14
+
15
+ export const isValidResourceUrl = (url: string | undefined): boolean => {
16
+ const trimmed = url?.trim() ?? '';
17
+ if (!trimmed) return false;
18
+ return resourceUrlSchema.safeParse(trimmed).success;
19
+ };
2
20
 
3
21
  export const RESOURCE_KINDS = [
4
22
  'video',
@@ -24,7 +42,9 @@ export const resourceHasRequiredMedia = (resource: {
24
42
  url?: string;
25
43
  attachments?: MediaAttachmentData[];
26
44
  }): boolean => {
27
- if (resource.resourceKind === 'link') return Boolean(resource.url);
45
+ if (resource.resourceKind === 'link') {
46
+ return isValidResourceUrl(resource.url);
47
+ }
28
48
  const need =
29
49
  resource.resourceKind === 'gallery'
30
50
  ? 'image'
@@ -38,6 +58,89 @@ export const resourceHasRequiredMedia = (resource: {
38
58
  );
39
59
  };
40
60
 
61
+ export const RESOURCE_FORM_ISSUES = [
62
+ 'title',
63
+ 'titleLength',
64
+ 'url',
65
+ 'media',
66
+ 'audience',
67
+ 'group',
68
+ ] as const;
69
+
70
+ export type ResourceFormIssue = (typeof RESOURCE_FORM_ISSUES)[number];
71
+
72
+ export const resourceFormIssues = (input: {
73
+ title?: string;
74
+ resourceKind: ResourceKind;
75
+ url?: string;
76
+ attachments?: MediaAttachmentData[];
77
+ visibility?: string | null;
78
+ audience?: readonly unknown[] | null;
79
+ groupId?: string | null;
80
+ }): ResourceFormIssue[] => {
81
+ const issues: ResourceFormIssue[] = [];
82
+ if (!input.title?.trim()) issues.push('title');
83
+ else if (input.title.length > RESOURCE_TITLE_MAX_LENGTH) {
84
+ issues.push('titleLength');
85
+ }
86
+ if (input.resourceKind === 'link') {
87
+ if (!isValidResourceUrl(input.url)) issues.push('url');
88
+ } else if (!resourceHasRequiredMedia(input)) {
89
+ issues.push('media');
90
+ }
91
+ if (input.visibility === 'direct' && !input.audience?.length) {
92
+ issues.push('audience');
93
+ }
94
+ if (input.visibility === 'group' && !input.groupId) {
95
+ issues.push('group');
96
+ }
97
+ return issues;
98
+ };
99
+
100
+ const isVisibility = (
101
+ value: string | null | undefined,
102
+ ): value is VisibilityType =>
103
+ !!value && (visibilityTypeValues as readonly string[]).includes(value);
104
+
105
+ /**
106
+ * Draft visibility the profile may actually post with. A group-only author
107
+ * starts on Specific Group; a single postable group is preselected. Pass
108
+ * `postableGroupIds: null` while memberships are still loading so an existing
109
+ * group choice is not cleared.
110
+ */
111
+ export const resourceVisibilityForCapabilities = (input: {
112
+ visibility?: string | null;
113
+ groupId?: string | null;
114
+ allowed: readonly VisibilityType[];
115
+ postableGroupIds: readonly string[] | null;
116
+ }): { visibility: VisibilityType; groupId?: string } => {
117
+ const current = isVisibility(input.visibility) ? input.visibility : 'local';
118
+ const fallback = input.allowed[0];
119
+ if (!fallback) {
120
+ return { visibility: current, groupId: input.groupId ?? undefined };
121
+ }
122
+
123
+ const keep = input.allowed.includes(current) ? current : fallback;
124
+ if (keep !== 'group') return { visibility: keep };
125
+
126
+ if (input.postableGroupIds == null) {
127
+ return { visibility: 'group', groupId: input.groupId ?? undefined };
128
+ }
129
+
130
+ const kept =
131
+ input.groupId && input.postableGroupIds.includes(input.groupId)
132
+ ? input.groupId
133
+ : undefined;
134
+ return {
135
+ visibility: 'group',
136
+ groupId:
137
+ kept ??
138
+ (input.postableGroupIds.length === 1
139
+ ? input.postableGroupIds[0]
140
+ : undefined),
141
+ };
142
+ };
143
+
41
144
  export type CategoryNode = {
42
145
  name: string;
43
146
  path: string[];
package/src/lib/utils.ts CHANGED
@@ -64,8 +64,8 @@ export const asyncFilter = async <T>(
64
64
 
65
65
  export const passThroughUndefined =
66
66
  <Input, Output>(func: (input: Input) => Output) =>
67
- (input: Input | undefined) =>
68
- input && func(input);
67
+ (input: Input | undefined) =>
68
+ input && func(input);
69
69
 
70
70
  export const countBy = <T, V extends string | number | symbol>(
71
71
  arr: T[],
@@ -93,8 +93,8 @@ export const groupBy = <T, V extends string | number | symbol>(
93
93
 
94
94
  export const dateSorter =
95
95
  <T extends { createdAt: string }>(): ((v0: T, v1: T) => number) =>
96
- (v0: T, v1: T) =>
97
- Date.parse(v0.createdAt) - Date.parse(v1.createdAt);
96
+ (v0: T, v1: T) =>
97
+ Date.parse(v0.createdAt) - Date.parse(v1.createdAt);
98
98
 
99
99
  export const getUniqueBy = <T, V = string>(
100
100
  arr: T[],
@@ -135,11 +135,11 @@ export const deepSet = <T>(
135
135
  const keys = Array.isArray(path)
136
136
  ? path
137
137
  : path
138
- .replace(/(\w)\[/g, '$1.[')
139
- .split('.')
140
- .map((k) =>
141
- k.includes('[') ? parseInt(k.substring(1, k.length - 1)) : k,
142
- );
138
+ .replace(/(\w)\[/g, '$1.[')
139
+ .split('.')
140
+ .map((k) =>
141
+ k.includes('[') ? parseInt(k.substring(1, k.length - 1)) : k,
142
+ );
143
143
 
144
144
  let subObject: unknown = obj;
145
145
  for (let i = 0; i < keys.length; i++) {
@@ -150,9 +150,9 @@ export const deepSet = <T>(
150
150
  // @ts-expect-error deepset is not really typeable
151
151
  subObject[currentKey] = subObject[currentKey]
152
152
  ? // @ts-expect-error deepset is not really typeable
153
- subObject[currentKey]
153
+ subObject[currentKey]
154
154
  : // @ts-expect-error deepset is not really typeable
155
- isNaN(nextKey)
155
+ isNaN(nextKey)
156
156
  ? {}
157
157
  : [];
158
158
  } else {
@@ -203,35 +203,41 @@ export const formatTimeStamp = (
203
203
  return new Date(timestamp * 1000).toLocaleDateString();
204
204
  };
205
205
 
206
- const getMode = (config: CommunityConfig, profileSettings: ProfileSettings | undefined, systemTheme: 'dark' | 'light'): 'dark' | 'light' => {
206
+ const getMode = (
207
+ config: CommunityConfig,
208
+ profileSettings: ProfileSettings | undefined,
209
+ systemTheme: 'dark' | 'light',
210
+ ): 'dark' | 'light' => {
207
211
  if (profileSettings) {
208
- if (profileSettings.theme === "system") {
212
+ if (profileSettings.theme === 'system') {
209
213
  return systemTheme;
210
- } else if (profileSettings?.theme === "dark") {
211
- return "dark";
212
- } else if (profileSettings?.theme === "light") {
213
- return "light";
214
+ } else if (profileSettings?.theme === 'dark') {
215
+ return 'dark';
216
+ } else if (profileSettings?.theme === 'light') {
217
+ return 'light';
214
218
  }
215
219
  }
216
220
  return config.theme.base === 'OpenpeepsDark' ? 'dark' : 'light';
217
- }
221
+ };
218
222
 
219
223
  export const getTheme = (
220
224
  config: CommunityConfig,
221
225
  profileSettings?: ProfileSettings,
222
- systemTheme: 'dark' | 'light' = getSystemTheme()
226
+ systemTheme: 'dark' | 'light' = getSystemTheme(),
223
227
  ) =>
224
- getMode(config, profileSettings, systemTheme) === 'dark' ?
225
- { ...config.theme.dark, dark: true } :
226
- { ...config.theme.light, dark: false };
228
+ getMode(config, profileSettings, systemTheme) === 'dark'
229
+ ? { ...config.theme.dark, dark: true }
230
+ : { ...config.theme.light, dark: false };
227
231
 
228
232
  export const getSystemTheme = () => {
229
- if (typeof window !== "undefined" && window.matchMedia) {
230
- const systemIsDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
231
- return systemIsDark ? "dark" : "light"
233
+ if (typeof window !== 'undefined' && window.matchMedia) {
234
+ const systemIsDark = window.matchMedia(
235
+ '(prefers-color-scheme: dark)',
236
+ ).matches;
237
+ return systemIsDark ? 'dark' : 'light';
232
238
  }
233
239
  return 'light';
234
- }
240
+ };
235
241
 
236
242
  export const getProfileAvatar = (
237
243
  profile: PublicProfile | undefined | null,
@@ -252,7 +258,8 @@ export const getGroupAvatar = (
252
258
  };
253
259
 
254
260
  export const extractDateFromUUIDv7 = (uuidV7: string): string => {
255
- const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
261
+ const UUID_REGEX =
262
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
256
263
  if (!UUID_REGEX.test(uuidV7)) {
257
264
  throw new Error('Invalid UUID format');
258
265
  }
@@ -271,13 +278,15 @@ export const extractDateFromUUIDv7 = (uuidV7: string): string => {
271
278
 
272
279
  const pad = (num: number, size: number): string => {
273
280
  let s = String(num);
274
- while (s.length < size) { s = '0' + s; }
281
+ while (s.length < size) {
282
+ s = '0' + s;
283
+ }
275
284
  return s;
276
285
  };
277
286
 
278
287
  return (
279
288
  date.getUTCFullYear().toString() +
280
- pad(date.getUTCMonth() + 1, 2) + // months are zero‑based
289
+ pad(date.getUTCMonth() + 1, 2) + // months are zero‑based
281
290
  pad(date.getUTCDate(), 2) +
282
291
  pad(date.getUTCHours(), 2) +
283
292
  pad(date.getUTCMinutes(), 2)
@@ -292,7 +301,7 @@ export const formatSize = (bytes: number) => {
292
301
 
293
302
  export const hasVisibilityChanged = (
294
303
  previousAudienceSetting: AudienceSetting,
295
- newAudienceSetting: AudienceSetting
304
+ newAudienceSetting: AudienceSetting,
296
305
  ): boolean => {
297
306
  if (previousAudienceSetting.visibility !== newAudienceSetting.visibility) {
298
307
  return true;
@@ -319,4 +328,4 @@ export const hasVisibilityChanged = (
319
328
  }
320
329
 
321
330
  return false;
322
- };
331
+ };
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+
3
+ export const livekitDiagnosisCheckIdSchema = z.enum([
4
+ 'url',
5
+ 'apiKey',
6
+ 'apiSecret',
7
+ 'reachable',
8
+ ]);
9
+
10
+ export const livekitDiagnosisSchema = z.object({
11
+ connected: z.boolean(),
12
+ recordingEnabled: z.boolean(),
13
+ url: z.string().optional(),
14
+ /** Last probe failure. Credentials are redacted before this is returned. */
15
+ error: z.string().optional(),
16
+ checks: z.array(
17
+ z.object({
18
+ id: livekitDiagnosisCheckIdSchema,
19
+ ok: z.boolean(),
20
+ }),
21
+ ),
22
+ });
23
+
24
+ export type LivekitDiagnosis = z.infer<typeof livekitDiagnosisSchema>;
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+
3
+ export const storedMediaStatusSchema = z.enum([
4
+ 'referenced',
5
+ 'pending',
6
+ 'due',
7
+ 'unseen',
8
+ ]);
9
+
10
+ export type StoredMediaStatus = z.infer<typeof storedMediaStatusSchema>;
11
+
12
+ export const storedMediaFileSchema = z.object({
13
+ storageId: z.string(),
14
+ size: z.number(),
15
+ modifiedAt: z.string(),
16
+ status: storedMediaStatusSchema,
17
+ unreferencedSince: z.string().nullable(),
18
+ deletesAt: z.string().nullable(),
19
+ url: z.string(),
20
+ });
21
+
22
+ export type StoredMediaFile = z.infer<typeof storedMediaFileSchema>;
23
+
24
+ export const storedMediaListSchema = z.object({
25
+ files: z.array(storedMediaFileSchema),
26
+ graceMs: z.number(),
27
+ });
28
+
29
+ export type StoredMediaList = z.infer<typeof storedMediaListSchema>;
package/src/types/api.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  accessTokenSchema,
10
10
  accountInteractionsSchema,
11
11
  accountNameSchema,
12
+ federatedHandleSchema,
12
13
  accountSchema,
13
14
  answerSchema,
14
15
  applicationDataSchema,
@@ -76,7 +77,7 @@ export const publicProfileSchema = z.object({
76
77
  createdAt: z.string().datetime(),
77
78
  updatedAt: z.string().datetime(),
78
79
  deletedAt: z.string().datetime().nullable().optional(),
79
- handle: accountNameSchema,
80
+ handle: federatedHandleSchema,
80
81
  avatar: z.string().url().nullable().optional(),
81
82
  header: z.string().url().nullable().optional(),
82
83
  displayName: z.string().max(30).optional(),
@@ -661,14 +662,15 @@ export const updateProfileRequestSchema = profileDataSchema
661
662
  })
662
663
  .superRefine((value, ctx) => {
663
664
  if (value.handle === undefined || value.type === 'federated') return;
664
- if (!accountNameSchema.safeParse(value.handle).success) {
665
- ctx.addIssue({
666
- code: 'custom',
667
- path: ['handle'],
668
- message:
669
- 'Handle must be 1–16 characters: letters, numbers, underscores, or hyphens (no spaces or punctuation)',
670
- });
671
- }
665
+ const result = accountNameSchema.safeParse(value.handle);
666
+ if (result.success) return;
667
+ ctx.addIssue({
668
+ code: 'custom',
669
+ path: ['handle'],
670
+ message:
671
+ result.error.issues[0]?.message ??
672
+ 'Handle must be 1–16 characters: letters, numbers, underscores, or hyphens (no spaces or punctuation)',
673
+ });
672
674
  });
673
675
  export type UpdateProfileRequest = z.infer<typeof updateProfileRequestSchema>;
674
676
 
@@ -782,6 +784,14 @@ export const searchResultCountsSchema = z.object({
782
784
  });
783
785
  export type SearchResultCounts = z.infer<typeof searchResultCountsSchema>;
784
786
 
787
+ export const directMessageSearchHitSchema = z.object({
788
+ conversationId: z.uuid(),
789
+ message: publicPostSchema,
790
+ });
791
+ export type DirectMessageSearchHit = z.infer<
792
+ typeof directMessageSearchHitSchema
793
+ >;
794
+
785
795
  // Plain object schema — used as API contract & in OpenAPI generation. Cross-
786
796
  // field validation lives on `postCreationDataFormSchema` below to keep this
787
797
  // schema introspectable by zod-to-openapi (which can't walk zod-4 `.refine()`
package/src/types/auth.ts CHANGED
@@ -17,6 +17,6 @@ export const authorizationDataSchema = z.object({
17
17
  account: accountWithMetaSchema.optional(),
18
18
  service: z.string().optional(),
19
19
  scopes: z.array(scopeSchema),
20
- })
20
+ });
21
21
 
22
- export type AuthorizationData = z.infer<typeof authorizationDataSchema>;
22
+ export type AuthorizationData = z.infer<typeof authorizationDataSchema>;
@@ -216,6 +216,8 @@ export const roleCapabilities = [
216
216
  'core-roles-read',
217
217
  'core-roles-update',
218
218
  'core-maintenance-restart',
219
+ 'core-media-read',
220
+ 'core-media-delete',
219
221
  'core-inviteLinks-create',
220
222
  'core-inviteLinks-read',
221
223
  'core-inviteLinks-update',
@@ -249,6 +251,7 @@ export const roleCapabilityEditorKeys = [
249
251
  'core-inviteLinks-*',
250
252
  'core-logs-*',
251
253
  'core-maintenance-*',
254
+ 'core-media-*',
252
255
  'core-plugins-*',
253
256
  'core-profiles-*',
254
257
  'core-posts-create-*',
@@ -10,6 +10,7 @@ import {
10
10
  } from './capabilities';
11
11
  import { postCapabilities } from './capabilities';
12
12
  import { postRelationships } from './capabilities';
13
+ import { additionalForbiddenHandlesSchema } from './forbiddenHandles';
13
14
 
14
15
  export const passwordPlaceHolder = '*********';
15
16
 
@@ -410,6 +411,11 @@ export const communityConfigSchemaFactory = (_sanitize?: boolean) =>
410
411
  /** Adds member profile pages to the sitemap. Off by default: a crawled
411
412
  * profile is cached by search engines long after the member leaves. */
412
413
  indexProfiles: z.boolean().optional(),
414
+ /**
415
+ * Usernames this community blocks in addition to the built-in list.
416
+ * Built-in names are not stored here and cannot be removed.
417
+ */
418
+ additionalForbiddenHandles: additionalForbiddenHandlesSchema.optional(),
413
419
  }),
414
420
  roles: z.object({
415
421
  onRegistration: z.object({