@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
@@ -23,7 +23,7 @@ export declare const collectVotes: (post: PublicPost) => {
23
23
  votes: AnswerWithPublicProfile[];
24
24
  };
25
25
  export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?: string) => {
26
- response: "no" | "yes" | "tentative" | "removed";
26
+ response: "no" | "yes" | "tentative" | "removed" | "waitlist";
27
27
  profile: {
28
28
  id: string;
29
29
  type: "local" | "guest" | "federated";
@@ -84,9 +84,11 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
84
84
  };
85
85
  createdAt: string;
86
86
  recurrenceId?: string | undefined;
87
+ waitlistJoinedAt?: string | undefined;
88
+ offerExpiresAt?: string | undefined;
87
89
  }[];
88
90
  export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, recurrenceId?: string) => {
89
- response: "no" | "yes" | "tentative" | "removed";
91
+ response: "no" | "yes" | "tentative" | "removed" | "waitlist";
90
92
  profile: {
91
93
  id: string;
92
94
  type: "local" | "guest" | "federated";
@@ -147,12 +149,14 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
147
149
  };
148
150
  createdAt: string;
149
151
  recurrenceId?: string | undefined;
152
+ waitlistJoinedAt?: string | undefined;
153
+ offerExpiresAt?: string | undefined;
150
154
  } | undefined;
151
155
  export declare const countYesRsvps: (post: PublicPost, recurrenceId?: string) => number;
152
156
  export declare const countSeriesYesRsvps: (post: PublicPost) => number;
153
157
  /** Current roster: attending guests, plus organizer removals that can be restored. */
154
158
  export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
155
- response: "no" | "yes" | "tentative" | "removed";
159
+ response: "no" | "yes" | "tentative" | "removed" | "waitlist";
156
160
  profile: {
157
161
  id: string;
158
162
  type: "local" | "guest" | "federated";
@@ -213,6 +217,8 @@ export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
213
217
  };
214
218
  createdAt: string;
215
219
  recurrenceId?: string | undefined;
220
+ waitlistJoinedAt?: string | undefined;
221
+ offerExpiresAt?: string | undefined;
216
222
  }[];
217
223
  /** Set only when a member leaves an attending RSVP. A second "no" stays unset. */
218
224
  export type RsvpCancelNotice = {
@@ -249,15 +255,20 @@ export declare const displayRsvpForProfile: (post: PublicPost, profileId: string
249
255
  now?: Date;
250
256
  }) => PublicRsvp | undefined;
251
257
  export declare const isCapacityEvent: (event: Event) => boolean;
258
+ export declare const DEFAULT_WAITLIST_OFFER_MINUTES = 60;
259
+ export declare const MAX_WAITLIST_OFFER_MINUTES: number;
252
260
  export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
261
+ export declare const normalizeWaitlistOfferMinutes: (value: number | null | undefined) => number | undefined;
262
+ export declare const parseEventWaitlistOfferMinutesInput: (raw: string) => number | undefined;
253
263
  export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
254
264
  export declare const normalizeEventDataForSave: <T extends Event>(event: T) => T;
255
265
  /** Null capacity means it was cleared; strip for validation/output. */
256
266
  export declare const normalizeEventDataFromDb: <T extends Event>(event: T) => T;
257
267
  export declare const normalizePostDataFromDb: (data: PostDataUnion) => PostDataUnion;
258
- /** Nested `data` updates send null to remove maxAttendees. */
259
- export type EventDbUpdate = Omit<Event, 'maxAttendees'> & {
268
+ /** Nested `data` updates send null to remove cleared capacity fields. */
269
+ export type EventDbUpdate = Omit<Event, 'maxAttendees' | 'waitlistOfferMinutes'> & {
260
270
  maxAttendees?: number | null;
271
+ waitlistOfferMinutes?: number | null;
261
272
  };
262
273
  export declare const eventDataForDbUpdate: (previous: Event | undefined, normalized: Event) => EventDbUpdate;
263
274
  export declare const canManageEventRsvps: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
@@ -296,8 +307,19 @@ export declare const toHiddenPost: <T extends {
296
307
  export declare const isHiddenPost: (post: {
297
308
  hidden?: boolean;
298
309
  }) => boolean;
310
+ export declare const participantIds: (post: Pick<PublicPost, "audience" | "profile"> & {
311
+ creatorId?: string;
312
+ }) => Set<string>;
313
+ /** Direct message between exactly two participants. */
314
+ export declare const isOneToOneDm: (post: Pick<PublicPost, "visibility" | "audience" | "profile"> & {
315
+ creatorId?: string;
316
+ }) => boolean;
299
317
  export declare const isOneToOneWithBlocked: (post: Pick<PublicPost, "visibility" | "audience" | "profile"> & {
300
318
  creatorId?: string;
301
319
  }, viewer: {
302
320
  id: string;
303
321
  } | undefined | null, blockedIds?: Set<string> | string[]) => boolean;
322
+ /** First usable text field of a post, whitespace-collapsed and truncated. */
323
+ export declare const messagePreviewText: (message: PublicPost, maxLength?: number) => string;
324
+ /** Display names of a post's audience minus the viewer, comma-joined. */
325
+ export declare const conversationLabel: (message: PublicPost, viewerId?: string) => string;
@@ -5,6 +5,7 @@ import { formatEventWhen } from './eventTime.js';
5
5
  import { checkGroupCapabilities, checkPostCapabilities, checkRoleCapabilities, } from './capabilitiesHelpers.js';
6
6
  import { scopeMatches } from './scopeHelpers.js';
7
7
  import { countBy, dateSorter, groupBy, transformValues } from './utils.js';
8
+ import { truncateText } from './text.js';
8
9
  const buildThread = (rootPost, postList) => ({
9
10
  ...rootPost,
10
11
  children: postList
@@ -315,6 +316,11 @@ export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date(
315
316
  */
316
317
  export const displayRsvpForProfile = (post, profileId, options) => {
317
318
  const event = post.data?.type === 'event' ? post.data : undefined;
319
+ // One-time events have no occurrences. Older claims stamped the start time
320
+ // onto some RSVPs; a newer unscoped waitlist must still be the current one.
321
+ if (event && !event.recurrence) {
322
+ return getEffectiveRsvp(post, profileId);
323
+ }
318
324
  const scopedId = options?.lockToOccurrence
319
325
  ? options.recurrenceId
320
326
  : event
@@ -335,6 +341,8 @@ export const displayRsvpForProfile = (post, profileId, options) => {
335
341
  return scoped;
336
342
  };
337
343
  export const isCapacityEvent = (event) => !!event.maxAttendees;
344
+ export const DEFAULT_WAITLIST_OFFER_MINUTES = 60;
345
+ export const MAX_WAITLIST_OFFER_MINUTES = 7 * 24 * 60;
338
346
  export const parseEventMaxAttendeesInput = (raw) => {
339
347
  const trimmed = raw.trim();
340
348
  if (!trimmed)
@@ -342,8 +350,22 @@ export const parseEventMaxAttendeesInput = (raw) => {
342
350
  const parsed = Number.parseInt(trimmed, 10);
343
351
  return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
344
352
  };
353
+ export const normalizeWaitlistOfferMinutes = (value) => {
354
+ if (value == null || !Number.isFinite(value))
355
+ return undefined;
356
+ const minutes = Math.trunc(value);
357
+ if (minutes < 1 || minutes > MAX_WAITLIST_OFFER_MINUTES)
358
+ return undefined;
359
+ return minutes;
360
+ };
361
+ export const parseEventWaitlistOfferMinutesInput = (raw) => {
362
+ const trimmed = raw.trim();
363
+ if (!trimmed)
364
+ return undefined;
365
+ return normalizeWaitlistOfferMinutes(Number.parseInt(trimmed, 10));
366
+ };
345
367
  export const withoutEventMaxAttendees = (event) => {
346
- const { maxAttendees: _, ...rest } = event;
368
+ const { maxAttendees: _, waitlistOfferMinutes: __, ...rest } = event;
347
369
  return rest;
348
370
  };
349
371
  export const normalizeEventDataForSave = (event) => {
@@ -353,21 +375,34 @@ export const normalizeEventDataForSave = (event) => {
353
375
  maxAttendees < 1) {
354
376
  return withoutEventMaxAttendees(event);
355
377
  }
356
- return { ...event, maxAttendees: Math.trunc(maxAttendees) };
378
+ const minutes = normalizeWaitlistOfferMinutes(event.waitlistOfferMinutes);
379
+ const { waitlistOfferMinutes: _, ...rest } = event;
380
+ return {
381
+ ...rest,
382
+ maxAttendees: Math.trunc(maxAttendees),
383
+ ...(minutes != null ? { waitlistOfferMinutes: minutes } : {}),
384
+ };
357
385
  };
358
386
  /** Null capacity means it was cleared; strip for validation/output. */
359
387
  export const normalizeEventDataFromDb = (event) => {
360
- if (event.maxAttendees != null) {
361
- return event;
362
- }
363
- return withoutEventMaxAttendees(event);
388
+ const { maxAttendees, waitlistOfferMinutes, ...rest } = event;
389
+ return {
390
+ ...rest,
391
+ ...(maxAttendees != null ? { maxAttendees } : {}),
392
+ ...(waitlistOfferMinutes != null ? { waitlistOfferMinutes } : {}),
393
+ };
364
394
  };
365
395
  export const normalizePostDataFromDb = (data) => data.type === 'event' ? normalizeEventDataFromDb(data) : data;
366
396
  export const eventDataForDbUpdate = (previous, normalized) => {
397
+ let next = normalized;
367
398
  if (previous?.maxAttendees != null && !('maxAttendees' in normalized)) {
368
- return { ...normalized, maxAttendees: null };
399
+ next = { ...next, maxAttendees: null };
400
+ }
401
+ if (previous?.waitlistOfferMinutes != null &&
402
+ !('waitlistOfferMinutes' in normalized)) {
403
+ next = { ...next, waitlistOfferMinutes: null };
369
404
  }
370
- return normalized;
405
+ return next;
371
406
  };
372
407
  export const canManageEventRsvps = (profile, post) => !!(profile &&
373
408
  (post.profile.id === profile.id || canModerateJam(profile, post)));
@@ -389,6 +424,13 @@ export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
389
424
  if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
390
425
  return { blocked: true, reason: 'full' };
391
426
  }
427
+ // A freed seat stays reserved for the waitlist unless this profile holds the offer.
428
+ const waiting = calculateEffectiveRsvps(post, recurrenceId).filter((rsvp) => rsvp.response === 'waitlist' && rsvp.profile.type !== 'federated');
429
+ const mine = waiting.find((rsvp) => rsvp.profile.id === profile.id);
430
+ const offerOpen = !!mine?.offerExpiresAt && Date.parse(mine.offerExpiresAt) > Date.now();
431
+ if (waiting.length > 0 && !offerOpen) {
432
+ return { blocked: true, reason: 'full' };
433
+ }
392
434
  return { blocked: true, reason: 'rsvp-required' };
393
435
  };
394
436
  export const canDeletePost = (authData, post, config) => checkPostCapabilities(authData, ['core-posts-delete'], post, config).success;
@@ -458,13 +500,15 @@ export const toHiddenPost = (post) => ({
458
500
  },
459
501
  });
460
502
  export const isHiddenPost = (post) => !!post.hidden;
461
- const participantIds = (post) => {
503
+ export const participantIds = (post) => {
462
504
  const ids = new Set((post.audience ?? []).map((member) => member.id).filter(Boolean));
463
505
  const creatorId = post.creatorId ?? post.profile?.id;
464
506
  if (creatorId)
465
507
  ids.add(creatorId);
466
508
  return ids;
467
509
  };
510
+ /** Direct message between exactly two participants. */
511
+ export const isOneToOneDm = (post) => post.visibility === 'direct' && participantIds(post).size === 2;
468
512
  export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
469
513
  if (!viewer || post.visibility !== 'direct')
470
514
  return false;
@@ -475,3 +519,22 @@ export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
475
519
  others.delete(viewer.id);
476
520
  return others.size === 1 && blocked.has([...others][0]);
477
521
  };
522
+ /** First usable text field of a post, whitespace-collapsed and truncated. */
523
+ export const messagePreviewText = (message, maxLength = 160) => {
524
+ const data = message.data;
525
+ if (!data || typeof data !== 'object')
526
+ return '';
527
+ const text = 'content' in data && typeof data.content === 'string' && data.content
528
+ ? data.content
529
+ : 'name' in data && typeof data.name === 'string'
530
+ ? data.name
531
+ : 'title' in data && typeof data.title === 'string'
532
+ ? data.title
533
+ : '';
534
+ return truncateText(text.replace(/\s+/g, ' ').trim(), maxLength);
535
+ };
536
+ /** Display names of a post's audience minus the viewer, comma-joined. */
537
+ export const conversationLabel = (message, viewerId) => (message.audience ?? [])
538
+ .filter((profile) => profile.id !== viewerId)
539
+ .map((profile) => profile.displayName || `@${profile.handle}`)
540
+ .join(', ');
@@ -1,12 +1,22 @@
1
1
  import type { GroupWithMeta, InviteLinkWithMeta, ProfileSettings, ProfileWithMeta, PublicProfile, StripeSubscriptionData } from '../types';
2
2
  export declare const PROFILE_DISPLAY_NAME_MAX_LENGTH = 30;
3
- /** Public sentinel shown for soft-deleted authors (API + clients). */
4
- export declare const DELETED_AUTHOR_DISPLAY_NAME = "Deleted author";
3
+ /** Public sentinel shown for soft-deleted profiles (API + clients). */
4
+ export declare const DELETED_AUTHOR_DISPLAY_NAME = "Deleted Profile";
5
5
  export declare const DELETED_AUTHOR_HANDLE = "deleted";
6
6
  export declare const clampProfileDisplayName: (displayName: string | undefined | null) => string | undefined;
7
7
  export declare const isDeletedProfile: (profile: {
8
8
  deletedAt?: string | null;
9
9
  } | undefined | null) => boolean;
10
+ type DeletedProfileIdentity = {
11
+ deletedAt?: string | null;
12
+ displayName?: unknown;
13
+ handle?: unknown;
14
+ };
15
+ /**
16
+ * Deleted rows keep their original handle (the column is unique) and may have
17
+ * no display name. Public hydration fills in the sentinel when it is missing.
18
+ */
19
+ export declare const withDeletedProfileIdentity: <T extends DeletedProfileIdentity>(profile: T) => T;
10
20
  /**
11
21
  * Strip PII from a soft-deleted profile for public API / UI surfaces.
12
22
  * Keeps id + timestamps (including deletedAt) so clients can detect the state.
@@ -1,7 +1,7 @@
1
1
  const containsIgnoreCase = (candidate, query) => candidate.toLowerCase().indexOf(query.toLowerCase()) > -1;
2
2
  export const PROFILE_DISPLAY_NAME_MAX_LENGTH = 30;
3
- /** Public sentinel shown for soft-deleted authors (API + clients). */
4
- export const DELETED_AUTHOR_DISPLAY_NAME = 'Deleted author';
3
+ /** Public sentinel shown for soft-deleted profiles (API + clients). */
4
+ export const DELETED_AUTHOR_DISPLAY_NAME = 'Deleted Profile';
5
5
  export const DELETED_AUTHOR_HANDLE = 'deleted';
6
6
  export const clampProfileDisplayName = (displayName) => {
7
7
  if (!displayName)
@@ -10,6 +10,23 @@ export const clampProfileDisplayName = (displayName) => {
10
10
  return clamped || undefined;
11
11
  };
12
12
  export const isDeletedProfile = (profile) => !!profile?.deletedAt;
13
+ /**
14
+ * Deleted rows keep their original handle (the column is unique) and may have
15
+ * no display name. Public hydration fills in the sentinel when it is missing.
16
+ */
17
+ export const withDeletedProfileIdentity = (profile) => {
18
+ if (!isDeletedProfile(profile))
19
+ return profile;
20
+ if (profile.displayName === DELETED_AUTHOR_DISPLAY_NAME &&
21
+ profile.handle === DELETED_AUTHOR_HANDLE) {
22
+ return profile;
23
+ }
24
+ return {
25
+ ...profile,
26
+ displayName: DELETED_AUTHOR_DISPLAY_NAME,
27
+ handle: DELETED_AUTHOR_HANDLE,
28
+ };
29
+ };
13
30
  /**
14
31
  * Strip PII from a soft-deleted profile for public API / UI surfaces.
15
32
  * Keeps id + timestamps (including deletedAt) so clients can detect the state.
@@ -1,4 +1,6 @@
1
- import type { MediaAttachmentData, ResourceKind } from '../types/models';
1
+ import { RESOURCE_TITLE_MAX_LENGTH, type MediaAttachmentData, type ResourceKind, type VisibilityType } from '../types/models';
2
+ export { RESOURCE_TITLE_MAX_LENGTH };
3
+ export declare const isValidResourceUrl: (url: string | undefined) => boolean;
2
4
  export declare const RESOURCE_KINDS: readonly ["video", "file", "gallery", "audio", "link"];
3
5
  export declare const attachmentMediaKind: (att: Pick<MediaAttachmentData, "type" | "meta">) => "image" | "video" | "audio" | "file";
4
6
  export declare const resourceHasRequiredMedia: (resource: {
@@ -6,6 +8,32 @@ export declare const resourceHasRequiredMedia: (resource: {
6
8
  url?: string;
7
9
  attachments?: MediaAttachmentData[];
8
10
  }) => boolean;
11
+ export declare const RESOURCE_FORM_ISSUES: readonly ["title", "titleLength", "url", "media", "audience", "group"];
12
+ export type ResourceFormIssue = (typeof RESOURCE_FORM_ISSUES)[number];
13
+ export declare const resourceFormIssues: (input: {
14
+ title?: string;
15
+ resourceKind: ResourceKind;
16
+ url?: string;
17
+ attachments?: MediaAttachmentData[];
18
+ visibility?: string | null;
19
+ audience?: readonly unknown[] | null;
20
+ groupId?: string | null;
21
+ }) => ResourceFormIssue[];
22
+ /**
23
+ * Draft visibility the profile may actually post with. A group-only author
24
+ * starts on Specific Group; a single postable group is preselected. Pass
25
+ * `postableGroupIds: null` while memberships are still loading so an existing
26
+ * group choice is not cleared.
27
+ */
28
+ export declare const resourceVisibilityForCapabilities: (input: {
29
+ visibility?: string | null;
30
+ groupId?: string | null;
31
+ allowed: readonly VisibilityType[];
32
+ postableGroupIds: readonly string[] | null;
33
+ }) => {
34
+ visibility: VisibilityType;
35
+ groupId?: string;
36
+ };
9
37
  export type CategoryNode = {
10
38
  name: string;
11
39
  path: string[];
@@ -1,3 +1,14 @@
1
+ import { z } from 'zod';
2
+ import { RESOURCE_TITLE_MAX_LENGTH, visibilityTypeValues, } from '../types/models.js';
3
+ export { RESOURCE_TITLE_MAX_LENGTH };
4
+ /** Matches `resourcePostSchema.url` (`z.url()`), after trimming. */
5
+ const resourceUrlSchema = z.url();
6
+ export const isValidResourceUrl = (url) => {
7
+ const trimmed = url?.trim() ?? '';
8
+ if (!trimmed)
9
+ return false;
10
+ return resourceUrlSchema.safeParse(trimmed).success;
11
+ };
1
12
  export const RESOURCE_KINDS = [
2
13
  'video',
3
14
  'file',
@@ -17,8 +28,9 @@ export const attachmentMediaKind = (att) => {
17
28
  return 'file';
18
29
  };
19
30
  export const resourceHasRequiredMedia = (resource) => {
20
- if (resource.resourceKind === 'link')
21
- return Boolean(resource.url);
31
+ if (resource.resourceKind === 'link') {
32
+ return isValidResourceUrl(resource.url);
33
+ }
22
34
  const need = resource.resourceKind === 'gallery'
23
35
  ? 'image'
24
36
  : resource.resourceKind === 'video'
@@ -28,6 +40,66 @@ export const resourceHasRequiredMedia = (resource) => {
28
40
  : 'file';
29
41
  return (resource.attachments ?? []).some((att) => attachmentMediaKind(att) === need);
30
42
  };
43
+ export const RESOURCE_FORM_ISSUES = [
44
+ 'title',
45
+ 'titleLength',
46
+ 'url',
47
+ 'media',
48
+ 'audience',
49
+ 'group',
50
+ ];
51
+ export const resourceFormIssues = (input) => {
52
+ const issues = [];
53
+ if (!input.title?.trim())
54
+ issues.push('title');
55
+ else if (input.title.length > RESOURCE_TITLE_MAX_LENGTH) {
56
+ issues.push('titleLength');
57
+ }
58
+ if (input.resourceKind === 'link') {
59
+ if (!isValidResourceUrl(input.url))
60
+ issues.push('url');
61
+ }
62
+ else if (!resourceHasRequiredMedia(input)) {
63
+ issues.push('media');
64
+ }
65
+ if (input.visibility === 'direct' && !input.audience?.length) {
66
+ issues.push('audience');
67
+ }
68
+ if (input.visibility === 'group' && !input.groupId) {
69
+ issues.push('group');
70
+ }
71
+ return issues;
72
+ };
73
+ const isVisibility = (value) => !!value && visibilityTypeValues.includes(value);
74
+ /**
75
+ * Draft visibility the profile may actually post with. A group-only author
76
+ * starts on Specific Group; a single postable group is preselected. Pass
77
+ * `postableGroupIds: null` while memberships are still loading so an existing
78
+ * group choice is not cleared.
79
+ */
80
+ export const resourceVisibilityForCapabilities = (input) => {
81
+ const current = isVisibility(input.visibility) ? input.visibility : 'local';
82
+ const fallback = input.allowed[0];
83
+ if (!fallback) {
84
+ return { visibility: current, groupId: input.groupId ?? undefined };
85
+ }
86
+ const keep = input.allowed.includes(current) ? current : fallback;
87
+ if (keep !== 'group')
88
+ return { visibility: keep };
89
+ if (input.postableGroupIds == null) {
90
+ return { visibility: 'group', groupId: input.groupId ?? undefined };
91
+ }
92
+ const kept = input.groupId && input.postableGroupIds.includes(input.groupId)
93
+ ? input.groupId
94
+ : undefined;
95
+ return {
96
+ visibility: 'group',
97
+ groupId: kept ??
98
+ (input.postableGroupIds.length === 1
99
+ ? input.postableGroupIds[0]
100
+ : undefined),
101
+ };
102
+ };
31
103
  export const categoryTreeFromPaths = (paths) => {
32
104
  const root = [];
33
105
  for (const path of paths) {
package/dist/lib/utils.js CHANGED
@@ -111,25 +111,25 @@ export const formatTimeStamp = (timestamp, startDate) => {
111
111
  };
112
112
  const getMode = (config, profileSettings, systemTheme) => {
113
113
  if (profileSettings) {
114
- if (profileSettings.theme === "system") {
114
+ if (profileSettings.theme === 'system') {
115
115
  return systemTheme;
116
116
  }
117
- else if (profileSettings?.theme === "dark") {
118
- return "dark";
117
+ else if (profileSettings?.theme === 'dark') {
118
+ return 'dark';
119
119
  }
120
- else if (profileSettings?.theme === "light") {
121
- return "light";
120
+ else if (profileSettings?.theme === 'light') {
121
+ return 'light';
122
122
  }
123
123
  }
124
124
  return config.theme.base === 'OpenpeepsDark' ? 'dark' : 'light';
125
125
  };
126
- export const getTheme = (config, profileSettings, systemTheme = getSystemTheme()) => getMode(config, profileSettings, systemTheme) === 'dark' ?
127
- { ...config.theme.dark, dark: true } :
128
- { ...config.theme.light, dark: false };
126
+ export const getTheme = (config, profileSettings, systemTheme = getSystemTheme()) => getMode(config, profileSettings, systemTheme) === 'dark'
127
+ ? { ...config.theme.dark, dark: true }
128
+ : { ...config.theme.light, dark: false };
129
129
  export const getSystemTheme = () => {
130
- if (typeof window !== "undefined" && window.matchMedia) {
131
- const systemIsDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
132
- return systemIsDark ? "dark" : "light";
130
+ if (typeof window !== 'undefined' && window.matchMedia) {
131
+ const systemIsDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
132
+ return systemIsDark ? 'dark' : 'light';
133
133
  }
134
134
  return 'light';
135
135
  };
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ export declare const livekitDiagnosisCheckIdSchema: z.ZodEnum<{
3
+ url: "url";
4
+ apiKey: "apiKey";
5
+ apiSecret: "apiSecret";
6
+ reachable: "reachable";
7
+ }>;
8
+ export declare const livekitDiagnosisSchema: z.ZodObject<{
9
+ connected: z.ZodBoolean;
10
+ recordingEnabled: z.ZodBoolean;
11
+ url: z.ZodOptional<z.ZodString>;
12
+ error: z.ZodOptional<z.ZodString>;
13
+ checks: z.ZodArray<z.ZodObject<{
14
+ id: z.ZodEnum<{
15
+ url: "url";
16
+ apiKey: "apiKey";
17
+ apiSecret: "apiSecret";
18
+ reachable: "reachable";
19
+ }>;
20
+ ok: z.ZodBoolean;
21
+ }, z.core.$strip>>;
22
+ }, z.core.$strip>;
23
+ export type LivekitDiagnosis = z.infer<typeof livekitDiagnosisSchema>;
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ export const livekitDiagnosisCheckIdSchema = z.enum([
3
+ 'url',
4
+ 'apiKey',
5
+ 'apiSecret',
6
+ 'reachable',
7
+ ]);
8
+ export const livekitDiagnosisSchema = z.object({
9
+ connected: z.boolean(),
10
+ recordingEnabled: z.boolean(),
11
+ url: z.string().optional(),
12
+ /** Last probe failure. Credentials are redacted before this is returned. */
13
+ error: z.string().optional(),
14
+ checks: z.array(z.object({
15
+ id: livekitDiagnosisCheckIdSchema,
16
+ ok: z.boolean(),
17
+ })),
18
+ });
@@ -0,0 +1,41 @@
1
+ import { z } from 'zod';
2
+ export declare const storedMediaStatusSchema: z.ZodEnum<{
3
+ unseen: "unseen";
4
+ referenced: "referenced";
5
+ pending: "pending";
6
+ due: "due";
7
+ }>;
8
+ export type StoredMediaStatus = z.infer<typeof storedMediaStatusSchema>;
9
+ export declare const storedMediaFileSchema: z.ZodObject<{
10
+ storageId: z.ZodString;
11
+ size: z.ZodNumber;
12
+ modifiedAt: z.ZodString;
13
+ status: z.ZodEnum<{
14
+ unseen: "unseen";
15
+ referenced: "referenced";
16
+ pending: "pending";
17
+ due: "due";
18
+ }>;
19
+ unreferencedSince: z.ZodNullable<z.ZodString>;
20
+ deletesAt: z.ZodNullable<z.ZodString>;
21
+ url: z.ZodString;
22
+ }, z.core.$strip>;
23
+ export type StoredMediaFile = z.infer<typeof storedMediaFileSchema>;
24
+ export declare const storedMediaListSchema: z.ZodObject<{
25
+ files: z.ZodArray<z.ZodObject<{
26
+ storageId: z.ZodString;
27
+ size: z.ZodNumber;
28
+ modifiedAt: z.ZodString;
29
+ status: z.ZodEnum<{
30
+ unseen: "unseen";
31
+ referenced: "referenced";
32
+ pending: "pending";
33
+ due: "due";
34
+ }>;
35
+ unreferencedSince: z.ZodNullable<z.ZodString>;
36
+ deletesAt: z.ZodNullable<z.ZodString>;
37
+ url: z.ZodString;
38
+ }, z.core.$strip>>;
39
+ graceMs: z.ZodNumber;
40
+ }, z.core.$strip>;
41
+ export type StoredMediaList = z.infer<typeof storedMediaListSchema>;
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ export const storedMediaStatusSchema = z.enum([
3
+ 'referenced',
4
+ 'pending',
5
+ 'due',
6
+ 'unseen',
7
+ ]);
8
+ export const storedMediaFileSchema = z.object({
9
+ storageId: z.string(),
10
+ size: z.number(),
11
+ modifiedAt: z.string(),
12
+ status: storedMediaStatusSchema,
13
+ unreferencedSince: z.string().nullable(),
14
+ deletesAt: z.string().nullable(),
15
+ url: z.string(),
16
+ });
17
+ export const storedMediaListSchema = z.object({
18
+ files: z.array(storedMediaFileSchema),
19
+ graceMs: z.number(),
20
+ });