@openpeepshq/common 0.1.45 → 0.2.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 (126) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  3. package/dist/lib/capabilitiesHelpers.js +43 -38
  4. package/dist/lib/csvHelpers.js +1 -1
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +91 -15
  7. package/dist/lib/eventRecurrence.d.ts +19 -0
  8. package/dist/lib/eventRecurrence.js +82 -20
  9. package/dist/lib/eventTime.d.ts +7 -0
  10. package/dist/lib/eventTime.js +23 -9
  11. package/dist/lib/federationHosts.d.ts +3 -0
  12. package/dist/lib/federationHosts.js +17 -0
  13. package/dist/lib/feedCursor.d.ts +14 -0
  14. package/dist/lib/feedCursor.js +22 -0
  15. package/dist/lib/feedFormat.d.ts +12 -0
  16. package/dist/lib/feedFormat.js +14 -0
  17. package/dist/lib/groupHelpers.js +13 -34
  18. package/dist/lib/groupTemplateHelpers.js +6 -10
  19. package/dist/lib/index.d.ts +7 -0
  20. package/dist/lib/index.js +7 -0
  21. package/dist/lib/jamHelpers.d.ts +11 -2
  22. package/dist/lib/jamHelpers.js +43 -9
  23. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  24. package/dist/lib/legacyThemeRoot.js +10 -0
  25. package/dist/lib/markdownHelpers.d.ts +8 -0
  26. package/dist/lib/markdownHelpers.js +34 -6
  27. package/dist/lib/postHelpers.d.ts +142 -3
  28. package/dist/lib/postHelpers.js +323 -47
  29. package/dist/lib/profileHelpers.d.ts +11 -0
  30. package/dist/lib/profileHelpers.js +34 -10
  31. package/dist/lib/pushHelpers.js +3 -4
  32. package/dist/lib/reactions.d.ts +17 -0
  33. package/dist/lib/reactions.js +37 -0
  34. package/dist/lib/scopeHelpers.d.ts +31 -2
  35. package/dist/lib/scopeHelpers.js +39 -8
  36. package/dist/lib/ssoLoginUrl.js +4 -6
  37. package/dist/lib/ssoProviders.d.ts +72 -0
  38. package/dist/lib/ssoProviders.js +366 -0
  39. package/dist/lib/timeZone.d.ts +9 -0
  40. package/dist/lib/timeZone.js +44 -0
  41. package/dist/lib/tokenHelpers.js +5 -5
  42. package/dist/lib/utils.js +6 -7
  43. package/dist/types/admin-db.js +1 -1
  44. package/dist/types/analytics.d.ts +20 -0
  45. package/dist/types/analytics.js +4 -0
  46. package/dist/types/api.d.ts +41800 -11853
  47. package/dist/types/api.js +53 -5
  48. package/dist/types/auth.d.ts +20 -6
  49. package/dist/types/capabilities.d.ts +15 -1
  50. package/dist/types/capabilities.js +51 -0
  51. package/dist/types/config.d.ts +99 -0
  52. package/dist/types/config.js +56 -4
  53. package/dist/types/db.d.ts +1155 -164
  54. package/dist/types/db.js +14 -0
  55. package/dist/types/export.d.ts +120 -0
  56. package/dist/types/export.js +7 -0
  57. package/dist/types/index.d.ts +2 -0
  58. package/dist/types/index.js +2 -0
  59. package/dist/types/internal.d.ts +2577 -524
  60. package/dist/types/internal.js +6 -0
  61. package/dist/types/models.d.ts +63 -7
  62. package/dist/types/models.js +40 -3
  63. package/dist/types/plugins.d.ts +22 -0
  64. package/dist/types/plugins.js +66 -0
  65. package/dist/types/roleDefaults.d.ts +31 -0
  66. package/dist/types/roleDefaults.js +110 -0
  67. package/dist/types/stats.d.ts +54606 -6065
  68. package/dist/types/stats.js +30 -0
  69. package/dist/types/utils.d.ts +2 -0
  70. package/dist/types/utils.js +1 -3
  71. package/dist/zod.d.ts +1 -0
  72. package/dist/zod.js +1 -0
  73. package/package.json +36 -6
  74. package/src/index.ts +4 -0
  75. package/src/lib/adminSections.ts +84 -0
  76. package/src/lib/attachmentHelpers.ts +14 -0
  77. package/src/lib/capabilitiesHelpers.ts +532 -0
  78. package/src/lib/colors.ts +20 -0
  79. package/src/lib/csvHelpers.ts +31 -0
  80. package/src/lib/eventIcs.ts +265 -0
  81. package/src/lib/eventRecurrence.ts +495 -0
  82. package/src/lib/eventTime.ts +206 -0
  83. package/src/lib/federationHosts.ts +22 -0
  84. package/src/lib/feedCursor.ts +27 -0
  85. package/src/lib/feedFormat.ts +24 -0
  86. package/src/lib/groupHelpers.ts +421 -0
  87. package/src/lib/groupTemplateHelpers.ts +83 -0
  88. package/src/lib/index.ts +29 -0
  89. package/src/lib/jamHelpers.ts +164 -0
  90. package/src/lib/legacyThemeRoot.ts +14 -0
  91. package/src/lib/markdownHelpers.ts +122 -0
  92. package/src/lib/mediaDimensions.ts +21 -0
  93. package/src/lib/postHelpers.ts +783 -0
  94. package/src/lib/profileHelpers.ts +220 -0
  95. package/src/lib/pushHelpers.ts +34 -0
  96. package/src/lib/reactions.ts +52 -0
  97. package/src/lib/reportHelpers.ts +7 -0
  98. package/src/lib/scopeHelpers.ts +176 -0
  99. package/src/lib/ssoLoginUrl.ts +93 -0
  100. package/src/lib/ssoProviders.ts +472 -0
  101. package/src/lib/text.ts +26 -0
  102. package/src/lib/timeZone.ts +52 -0
  103. package/src/lib/tokenHelpers.ts +119 -0
  104. package/src/lib/utils.ts +322 -0
  105. package/src/types/admin-db.ts +74 -0
  106. package/src/types/admin-email.ts +55 -0
  107. package/src/types/admin-jobs.ts +17 -0
  108. package/src/types/admin-performance.ts +20 -0
  109. package/src/types/analytics.ts +318 -0
  110. package/src/types/api.ts +871 -0
  111. package/src/types/apple-app-site-association.ts +54 -0
  112. package/src/types/auth.ts +22 -0
  113. package/src/types/capabilities.ts +280 -0
  114. package/src/types/config.ts +546 -0
  115. package/src/types/db.ts +138 -0
  116. package/src/types/export.ts +10 -0
  117. package/src/types/index.ts +20 -0
  118. package/src/types/internal.ts +338 -0
  119. package/src/types/models.ts +939 -0
  120. package/src/types/notifications.ts +92 -0
  121. package/src/types/plugins.ts +150 -0
  122. package/src/types/roleDefaults.ts +132 -0
  123. package/src/types/stats.ts +195 -0
  124. package/src/types/stripe.ts +45 -0
  125. package/src/types/utils.ts +100 -0
  126. package/src/zod.ts +1 -0
@@ -53,9 +53,8 @@ const applyDuration = (start, durationMs) => {
53
53
  return toIso(new Date(start.getTime() + durationMs));
54
54
  };
55
55
  const exceptionById = (event) => {
56
- var _a;
57
56
  const map = new Map();
58
- for (const exception of (_a = event.exceptions) !== null && _a !== void 0 ? _a : []) {
57
+ for (const exception of event.exceptions ?? []) {
59
58
  map.set(normalizeRecurrenceId(exception.recurrenceId), exception);
60
59
  }
61
60
  return map;
@@ -77,13 +76,12 @@ const nextByFreq = (date, freq, interval) => {
77
76
  return addMonths(date, interval);
78
77
  };
79
78
  const generateRawStarts = (event, untilBound) => {
80
- var _a, _b, _c;
81
79
  const recurrence = event.recurrence;
82
80
  const dtstart = new Date(event.start);
83
81
  if (!recurrence) {
84
82
  return [dtstart];
85
83
  }
86
- const interval = (_a = recurrence.interval) !== null && _a !== void 0 ? _a : 1;
84
+ const interval = recurrence.interval ?? 1;
87
85
  const until = recurrence.until ? new Date(recurrence.until) : undefined;
88
86
  const hardStop = until && until < untilBound ? until : untilBound;
89
87
  const starts = [];
@@ -94,7 +92,7 @@ const generateRawStarts = (event, untilBound) => {
94
92
  return;
95
93
  starts.push(date);
96
94
  };
97
- if (recurrence.freq === 'WEEKLY' && ((_c = (_b = recurrence.byDay) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
95
+ if (recurrence.freq === 'WEEKLY' && (recurrence.byDay?.length ?? 0) > 0) {
98
96
  const byDays = new Set(recurrence.byDay);
99
97
  let cursor = dtstart;
100
98
  while (cursor.getTime() <= hardStop.getTime()) {
@@ -122,23 +120,22 @@ const generateRawStarts = (event, untilBound) => {
122
120
  return recurrence.count ? unique.slice(0, recurrence.count) : unique;
123
121
  };
124
122
  const decorateOccurrence = (originalStart, event, exceptions, durationMs) => {
125
- var _a, _b, _c;
126
123
  const recurrenceId = toIso(originalStart);
127
124
  const exception = exceptions.get(recurrenceId);
128
- if (exception === null || exception === void 0 ? void 0 : exception.cancelled) {
125
+ if (exception?.cancelled) {
129
126
  return {
130
127
  recurrenceId,
131
- start: (_a = exception.start) !== null && _a !== void 0 ? _a : recurrenceId,
132
- end: (_b = exception.end) !== null && _b !== void 0 ? _b : applyDuration(originalStart, durationMs),
128
+ start: exception.start ?? recurrenceId,
129
+ end: exception.end ?? applyDuration(originalStart, durationMs),
133
130
  cancelled: true,
134
131
  };
135
132
  }
136
- if (exception === null || exception === void 0 ? void 0 : exception.start) {
133
+ if (exception?.start) {
137
134
  const start = new Date(exception.start);
138
135
  return {
139
136
  recurrenceId,
140
137
  start: toIso(start),
141
- end: (_c = exception.end) !== null && _c !== void 0 ? _c : applyDuration(start, durationMs),
138
+ end: exception.end ?? applyDuration(start, durationMs),
142
139
  cancelled: false,
143
140
  };
144
141
  }
@@ -177,12 +174,79 @@ export const occurrencesForIndex = (event, now = new Date()) => {
177
174
  to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
178
175
  });
179
176
  };
180
- export const previewUpcomingOccurrences = (event, count = 3, now = new Date()) => expandEventOccurrences(event, {
177
+ export const listRsvpOccurrences = (event, now = new Date()) => expandEventOccurrences(event, {
181
178
  from: now,
182
179
  to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
183
- })
184
- .filter((occurrence) => !occurrence.cancelled)
185
- .slice(0, count);
180
+ }).filter((occurrence) => !occurrence.cancelled);
181
+ /** Matches the agenda: a missing end is one hour after start, not open forever. */
182
+ const IMPLIED_EVENT_DURATION_MS = 60 * 60 * 1000;
183
+ export const occurrenceHasEnded = (start, end, now = new Date()) => {
184
+ const startMs = new Date(start).getTime();
185
+ if (!Number.isFinite(startMs))
186
+ return false;
187
+ const explicitEnd = end ? new Date(end).getTime() : Number.NaN;
188
+ const endMs = Number.isFinite(explicitEnd)
189
+ ? explicitEnd
190
+ : startMs + IMPLIED_EVENT_DURATION_MS;
191
+ return endMs < now.getTime();
192
+ };
193
+ const findExpandedOccurrence = (event, recurrenceId) => {
194
+ const anchor = new Date(recurrenceId).getTime();
195
+ if (!Number.isFinite(anchor))
196
+ return undefined;
197
+ return expandEventOccurrences(event, {
198
+ from: new Date(anchor - OCCURRENCE_HORIZON_MS),
199
+ to: new Date(anchor + OCCURRENCE_HORIZON_MS),
200
+ }).find((occurrence) => sameRecurrenceId(occurrence.recurrenceId, recurrenceId));
201
+ };
202
+ const occurrenceClosed = (event, recurrenceId, now) => {
203
+ if (!event.recurrence) {
204
+ return occurrenceHasEnded(event.start, event.end, now);
205
+ }
206
+ const match = findExpandedOccurrence(event, recurrenceId);
207
+ if (!match || match.cancelled)
208
+ return true;
209
+ return occurrenceHasEnded(match.start, match.end, now);
210
+ };
211
+ /** False once the event, or the locked occurrence, is over. */
212
+ export const eventRsvpOpen = (event, options) => {
213
+ const now = options?.now ?? new Date();
214
+ if (options?.lockToOccurrence && options.recurrenceId) {
215
+ return !occurrenceClosed(event, options.recurrenceId, now);
216
+ }
217
+ if (!event.recurrence) {
218
+ return !occurrenceHasEnded(event.start, event.end, now);
219
+ }
220
+ return expandEventOccurrences(event, {
221
+ from: new Date(now.getTime() - OCCURRENCE_HORIZON_MS),
222
+ to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
223
+ }).some((occurrence) => !occurrence.cancelled &&
224
+ !occurrenceHasEnded(occurrence.start, occurrence.end, now));
225
+ };
226
+ /**
227
+ * True when every targeted time is already over. A series RSVP with no ids
228
+ * is past only when the series has nothing left open.
229
+ */
230
+ export const rsvpTargetsPastEvent = (event, target, now = new Date()) => {
231
+ const ids = target?.occurrenceIds?.length
232
+ ? target.occurrenceIds
233
+ : target?.recurrenceId
234
+ ? [target.recurrenceId]
235
+ : undefined;
236
+ if (!ids)
237
+ return !eventRsvpOpen(event, { now });
238
+ return ids.every((id) => !eventRsvpOpen(event, {
239
+ recurrenceId: id,
240
+ lockToOccurrence: true,
241
+ now,
242
+ }));
243
+ };
244
+ export const defaultRsvpRecurrenceId = (event, queryId, now = new Date()) => {
245
+ if (queryId)
246
+ return normalizeRecurrenceId(queryId);
247
+ return listRsvpOccurrences(event, now)[0]?.recurrenceId;
248
+ };
249
+ export const previewUpcomingOccurrences = (event, count = 3, now = new Date()) => listRsvpOccurrences(event, now).slice(0, count);
186
250
  export const effectiveEventTimes = (event, recurrenceId) => {
187
251
  if (!recurrenceId) {
188
252
  return { start: event.start, end: event.end };
@@ -198,9 +262,8 @@ export const effectiveEventTimes = (event, recurrenceId) => {
198
262
  return { start: match.start, end: match.end };
199
263
  };
200
264
  export const upsertEventException = (event, exception) => {
201
- var _a;
202
265
  const recurrenceId = normalizeRecurrenceId(exception.recurrenceId);
203
- const rest = ((_a = event.exceptions) !== null && _a !== void 0 ? _a : []).filter((existing) => !sameRecurrenceId(existing.recurrenceId, recurrenceId));
266
+ const rest = (event.exceptions ?? []).filter((existing) => !sameRecurrenceId(existing.recurrenceId, recurrenceId));
204
267
  return {
205
268
  ...event,
206
269
  exceptions: [...rest, { ...exception, recurrenceId }],
@@ -216,8 +279,7 @@ const formatWeekdayLabels = (days, t) => sortWeekdays(days)
216
279
  .map((day) => t(`events.form.repeat.day.${day}`, { defaultValue: day }))
217
280
  .join(', ');
218
281
  const formatRecurrencePattern = (recurrence, t, start) => {
219
- var _a, _b;
220
- const interval = (_a = recurrence.interval) !== null && _a !== void 0 ? _a : 1;
282
+ const interval = recurrence.interval ?? 1;
221
283
  if (recurrence.freq === 'DAILY') {
222
284
  return interval === 1
223
285
  ? t('events.repeat.daily', { defaultValue: 'Daily' })
@@ -234,7 +296,7 @@ const formatRecurrencePattern = (recurrence, t, start) => {
234
296
  count: interval,
235
297
  });
236
298
  }
237
- const days = ((_b = recurrence.byDay) === null || _b === void 0 ? void 0 : _b.length) && recurrence.byDay.length > 0
299
+ const days = recurrence.byDay?.length && recurrence.byDay.length > 0
238
300
  ? recurrence.byDay
239
301
  : start
240
302
  ? [weekdayFromDate(new Date(start))]
@@ -14,6 +14,13 @@ export declare const reinterpretIsoInTimeZone: (iso: string | undefined, fromTim
14
14
  export declare const utcIsoToWallClockDate: (iso: string, timeZone: string) => Date;
15
15
  /** Treat `date`'s local components as wall time in `timeZone`. */
16
16
  export declare const wallClockDateToUtcIso: (date: Date, timeZone: string) => string;
17
+ /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
18
+ export declare const eventTimeZoneOptions: (timeZone?: string | null) => Pick<Intl.DateTimeFormatOptions, "timeZone">;
19
+ /** Clock time in the event timezone, always including a short zone name. */
20
+ export declare const formatEventClockTime: (iso: string, options?: {
21
+ timeZone?: string | null;
22
+ locale?: string;
23
+ }) => string;
17
24
  export declare const formatEventWhen: (start: string, options?: {
18
25
  end?: string | null;
19
26
  timeZone?: string | null;
@@ -1,5 +1,6 @@
1
+ import { isIanaTimeZone } from './timeZone.js';
1
2
  const DATETIME_LOCAL_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/;
2
- const partNumber = (parts, type) => { var _a; return Number((_a = parts.find((part) => part.type === type)) === null || _a === void 0 ? void 0 : _a.value); };
3
+ const partNumber = (parts, type) => Number(parts.find((part) => part.type === type)?.value);
3
4
  /** Milliseconds to add to UTC to get wall time in `timeZone` at `utcMs`. */
4
5
  const tzOffsetMs = (utcMs, timeZone) => {
5
6
  const parts = new Intl.DateTimeFormat('en-US', {
@@ -22,7 +23,6 @@ const pad2 = (value) => String(value).padStart(2, '0');
22
23
  * and return a UTC ISO string.
23
24
  */
24
25
  export const zonedDateTimeToUtcIso = (local, timeZone) => {
25
- var _a;
26
26
  if (!local)
27
27
  return undefined;
28
28
  const match = DATETIME_LOCAL_RE.exec(local);
@@ -30,7 +30,7 @@ export const zonedDateTimeToUtcIso = (local, timeZone) => {
30
30
  const parsed = new Date(local);
31
31
  return Number.isNaN(parsed.getTime()) ? undefined : parsed.toISOString();
32
32
  }
33
- const utcGuess = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number((_a = match[6]) !== null && _a !== void 0 ? _a : 0));
33
+ const utcGuess = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6] ?? 0));
34
34
  try {
35
35
  const offset = tzOffsetMs(utcGuess, timeZone);
36
36
  const utcWithOffset = utcGuess - offset;
@@ -93,12 +93,26 @@ export const utcIsoToWallClockDate = (iso, timeZone) => {
93
93
  };
94
94
  /** Treat `date`'s local components as wall time in `timeZone`. */
95
95
  export const wallClockDateToUtcIso = (date, timeZone) => {
96
- var _a;
97
96
  const local = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
98
- return (_a = zonedDateTimeToUtcIso(local, timeZone)) !== null && _a !== void 0 ? _a : date.toISOString();
97
+ return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
98
+ };
99
+ /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
100
+ export const eventTimeZoneOptions = (timeZone) => {
101
+ const resolved = isIanaTimeZone(timeZone) ? timeZone : undefined;
102
+ return resolved ? { timeZone: resolved } : {};
103
+ };
104
+ /** Clock time in the event timezone, always including a short zone name. */
105
+ export const formatEventClockTime = (iso, options) => {
106
+ const timeZone = eventTimeZoneOptions(options?.timeZone).timeZone;
107
+ return new Date(iso).toLocaleTimeString(options?.locale, {
108
+ hour: '2-digit',
109
+ minute: '2-digit',
110
+ timeZoneName: 'short',
111
+ ...(timeZone ? { timeZone } : {}),
112
+ });
99
113
  };
100
114
  export const formatEventWhen = (start, options) => {
101
- const timeZone = (options === null || options === void 0 ? void 0 : options.timeZone) || undefined;
115
+ const timeZone = options?.timeZone || undefined;
102
116
  const dateOptions = {
103
117
  weekday: 'long',
104
118
  year: 'numeric',
@@ -106,7 +120,7 @@ export const formatEventWhen = (start, options) => {
106
120
  day: 'numeric',
107
121
  ...(timeZone ? { timeZone } : {}),
108
122
  };
109
- if (options === null || options === void 0 ? void 0 : options.allDay) {
123
+ if (options?.allDay) {
110
124
  const startLabel = new Date(start).toLocaleDateString(options.locale, dateOptions);
111
125
  if (!options.end)
112
126
  return startLabel;
@@ -119,8 +133,8 @@ export const formatEventWhen = (start, options) => {
119
133
  minute: '2-digit',
120
134
  ...(timeZone ? { timeZoneName: 'short' } : {}),
121
135
  };
122
- const startLabel = new Date(start).toLocaleString(options === null || options === void 0 ? void 0 : options.locale, dateTimeOptions);
123
- if (!(options === null || options === void 0 ? void 0 : options.end))
136
+ const startLabel = new Date(start).toLocaleString(options?.locale, dateTimeOptions);
137
+ if (!options?.end)
124
138
  return startLabel;
125
139
  const endLabel = new Date(options.end).toLocaleString(options.locale, dateTimeOptions);
126
140
  return `${startLabel} – ${endLabel}`;
@@ -0,0 +1,3 @@
1
+ /** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
2
+ export declare const hostMatchesAllowedPattern: (host: string, pattern: string) => boolean;
3
+ export declare const hostIsAllowed: (host: string, allowedHosts: readonly string[]) => boolean;
@@ -0,0 +1,17 @@
1
+ /** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
2
+ export const hostMatchesAllowedPattern = (host, pattern) => {
3
+ const normalizedHost = host.trim().toLowerCase().replace(/\.$/, '');
4
+ const normalizedPattern = pattern.trim().toLowerCase().replace(/\.$/, '');
5
+ if (!normalizedHost || !normalizedPattern)
6
+ return false;
7
+ if (normalizedPattern === '*')
8
+ return false;
9
+ if (normalizedPattern.startsWith('*.')) {
10
+ const suffix = normalizedPattern.slice(2);
11
+ if (!suffix.includes('.'))
12
+ return false;
13
+ return normalizedHost === suffix || normalizedHost.endsWith(`.${suffix}`);
14
+ }
15
+ return normalizedHost === normalizedPattern;
16
+ };
17
+ export const hostIsAllowed = (host, allowedHosts) => allowedHosts.some((pattern) => hostMatchesAllowedPattern(host, pattern));
@@ -0,0 +1,14 @@
1
+ export type FeedCursor = {
2
+ id: string;
3
+ lastActivityAt?: string;
4
+ };
5
+ /**
6
+ * Timeline feeds page by `(lastActivityAt DESC, id DESC)`. Encode both in
7
+ * `start` so a later bump cannot skip or duplicate rows across pages.
8
+ * Id-sorted feeds (profile, bookmarks, hashtags) still work: they read `id`.
9
+ */
10
+ export declare const encodeFeedCursor: (post: {
11
+ id?: string;
12
+ lastActivityAt?: string | null;
13
+ }) => string | undefined;
14
+ export declare const parseFeedCursor: (start?: string) => FeedCursor | undefined;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Timeline feeds page by `(lastActivityAt DESC, id DESC)`. Encode both in
3
+ * `start` so a later bump cannot skip or duplicate rows across pages.
4
+ * Id-sorted feeds (profile, bookmarks, hashtags) still work: they read `id`.
5
+ */
6
+ export const encodeFeedCursor = (post) => {
7
+ if (!post.id)
8
+ return undefined;
9
+ return post.lastActivityAt ? `${post.lastActivityAt}|${post.id}` : post.id;
10
+ };
11
+ export const parseFeedCursor = (start) => {
12
+ if (!start)
13
+ return undefined;
14
+ const sep = start.lastIndexOf('|');
15
+ if (sep <= 0)
16
+ return { id: start };
17
+ const lastActivityAt = start.slice(0, sep);
18
+ const id = start.slice(sep + 1);
19
+ if (!id)
20
+ return { id: start };
21
+ return { id, lastActivityAt };
22
+ };
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const FEED_FORMAT_OPTIONS: readonly ["threaded", "linear"];
3
+ export declare const feedFormatSchema: z.ZodEnum<{
4
+ threaded: "threaded";
5
+ linear: "linear";
6
+ }>;
7
+ export type FeedFormat = z.infer<typeof feedFormatSchema>;
8
+ export declare const DEFAULT_FEED_FORMAT: FeedFormat;
9
+ export declare const isFeedFormat: (value: string | null | undefined) => value is FeedFormat;
10
+ export declare const parseFeedFormat: (value?: string | null) => FeedFormat;
11
+ /** Profile default, then community default, then threaded. */
12
+ export declare const resolveFeedFormat: (profileFormat?: string | null, communityFormat?: string | null) => FeedFormat;
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ export const FEED_FORMAT_OPTIONS = ['threaded', 'linear'];
3
+ export const feedFormatSchema = z.enum(FEED_FORMAT_OPTIONS);
4
+ export const DEFAULT_FEED_FORMAT = 'threaded';
5
+ export const isFeedFormat = (value) => value === 'threaded' || value === 'linear';
6
+ export const parseFeedFormat = (value) => isFeedFormat(value) ? value : DEFAULT_FEED_FORMAT;
7
+ /** Profile default, then community default, then threaded. */
8
+ export const resolveFeedFormat = (profileFormat, communityFormat) => {
9
+ if (isFeedFormat(profileFormat))
10
+ return profileFormat;
11
+ if (isFeedFormat(communityFormat))
12
+ return communityFormat;
13
+ return DEFAULT_FEED_FORMAT;
14
+ };
@@ -1,13 +1,10 @@
1
1
  import { defaultGroupAdminCapabilityAdds, defaultGroupOwnerCapabilityAdds, defaultGroupRoles, } from '../types/capabilities.js';
2
2
  import { checkCapabilities, getGroupCapabilitiesByRoles, } from './capabilitiesHelpers.js';
3
3
  import { profileName } from './profileHelpers.js';
4
- const withModerator = (member) => {
5
- var _a, _b;
6
- return ({
7
- add: [...((_a = member.add) !== null && _a !== void 0 ? _a : []), 'core-posts-delete'],
8
- ...(((_b = member.remove) === null || _b === void 0 ? void 0 : _b.length) ? { remove: member.remove } : {}),
9
- });
10
- };
4
+ const withModerator = (member) => ({
5
+ add: [...(member.add ?? []), 'core-posts-delete'],
6
+ ...(member.remove?.length ? { remove: member.remove } : {}),
7
+ });
11
8
  const ownerCapabilities = {
12
9
  add: [...defaultGroupOwnerCapabilityAdds],
13
10
  };
@@ -15,7 +12,7 @@ const adminCapabilities = {
15
12
  add: [...defaultGroupAdminCapabilityAdds],
16
13
  };
17
14
  const containsIgnoreCase = (candidate, query) => candidate.toLowerCase().indexOf(query.toLowerCase()) > -1;
18
- export const groupName = (group) => (group === null || group === void 0 ? void 0 : group.displayName) || (group === null || group === void 0 ? void 0 : group.handle) || '';
15
+ export const groupName = (group) => group?.displayName || group?.handle || '';
19
16
  export const matchesGroupQuery = (group, query, queryOptions = { handle: true, displayName: true, description: false }) => (queryOptions.handle && containsIgnoreCase(group.handle, query)) ||
20
17
  (queryOptions.displayName &&
21
18
  group.displayName &&
@@ -23,15 +20,9 @@ export const matchesGroupQuery = (group, query, queryOptions = { handle: true, d
23
20
  (queryOptions.description &&
24
21
  group.description &&
25
22
  containsIgnoreCase(group.description, query));
26
- export const sortGroupMembers = (members) => {
27
- var _a;
28
- return (_a = members === null || members === void 0 ? void 0 : members.sort((a, b) => profileName(a.profile).localeCompare(profileName(b.profile)))) !== null && _a !== void 0 ? _a : [];
29
- };
30
- export const groupMembershipHasRole = (roles, role) => (roles !== null && roles !== void 0 ? roles : []).includes(role);
31
- export const actorIsGroupOwner = (profile, groupId) => {
32
- var _a, _b;
33
- return groupMembershipHasRole((_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === groupId)) === null || _b === void 0 ? void 0 : _b.roles, 'owner');
34
- };
23
+ export const sortGroupMembers = (members) => members?.sort((a, b) => profileName(a.profile).localeCompare(profileName(b.profile))) ?? [];
24
+ export const groupMembershipHasRole = (roles, role) => (roles ?? []).includes(role);
25
+ export const actorIsGroupOwner = (profile, groupId) => groupMembershipHasRole(profile.memberships?.find((m) => m.group.id === groupId)?.roles, 'owner');
35
26
  export const countGroupOwners = (members) => members.filter((m) => groupMembershipHasRole(m.roles, 'owner')).length;
36
27
  export const groupRoleChangeBlocked = ({ actorIsOwner, currentRoles, nextRoles, ownerCount, }) => {
37
28
  const wasOwner = groupMembershipHasRole(currentRoles, 'owner');
@@ -49,25 +40,13 @@ export const assignableGroupRoles = (actorIsOwner) => actorIsOwner
49
40
  ? [...defaultGroupRoles]
50
41
  : defaultGroupRoles.filter((role) => role !== 'owner');
51
42
  export const groupRolesForAssignment = (role) => (role === 'member' ? ['member'] : ['member', role]);
52
- export const canChangeMemberRole = (profile, group) => {
53
- var _a, _b, _c;
54
- return checkCapabilities(['core-groups-changeMemberRole'], getGroupCapabilitiesByRoles((_c = (_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [], group)).success;
55
- };
56
- export const canAddMember = (profile, group) => {
57
- var _a, _b, _c;
58
- return checkCapabilities(['core-groups-addMember'], getGroupCapabilitiesByRoles((_c = (_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [], group)).success;
59
- };
60
- export const canRemoveMember = (profile, group) => {
61
- var _a, _b, _c;
62
- return checkCapabilities(['core-groups-removeMember'], getGroupCapabilitiesByRoles((_c = (_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [], group)).success;
63
- };
43
+ export const canChangeMemberRole = (profile, group) => checkCapabilities(['core-groups-changeMemberRole'], getGroupCapabilitiesByRoles(profile.memberships?.find((m) => m.group.id === group.id)?.roles ?? [], group)).success;
44
+ export const canAddMember = (profile, group) => checkCapabilities(['core-groups-addMember'], getGroupCapabilitiesByRoles(profile.memberships?.find((m) => m.group.id === group.id)?.roles ?? [], group)).success;
45
+ export const canRemoveMember = (profile, group) => checkCapabilities(['core-groups-removeMember'], getGroupCapabilitiesByRoles(profile.memberships?.find((m) => m.group.id === group.id)?.roles ?? [], group)).success;
64
46
  export const isGroupDiscoverable = (group) => checkCapabilities(['core-groups-read'], getGroupCapabilitiesByRoles(['none'], group)).success;
65
47
  /** Posts are only readable by explicit group members (not public/local). */
66
- export const hasMemberOnlyPostsVisibility = (capabilities) => {
67
- var _a, _b, _c, _d;
68
- return !((_b = (_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.none) === null || _a === void 0 ? void 0 : _a.add) === null || _b === void 0 ? void 0 : _b.includes('core-posts-read')) &&
69
- !((_d = (_c = capabilities === null || capabilities === void 0 ? void 0 : capabilities.local) === null || _c === void 0 ? void 0 : _c.add) === null || _d === void 0 ? void 0 : _d.includes('core-posts-read'));
70
- };
48
+ export const hasMemberOnlyPostsVisibility = (capabilities) => !capabilities?.none?.add?.includes('core-posts-read') &&
49
+ !capabilities?.local?.add?.includes('core-posts-read');
71
50
  export const groupCapabilityTemplates = {
72
51
  defaultGroup: {
73
52
  name: 'defaultGroup',
@@ -14,19 +14,15 @@ const TEMPLATE_RELATIONSHIPS = [
14
14
  'admin',
15
15
  'owner',
16
16
  ];
17
- const normalizeBucket = (bucket) => {
18
- var _a, _b;
19
- return ({
20
- add: [...((_a = bucket === null || bucket === void 0 ? void 0 : bucket.add) !== null && _a !== void 0 ? _a : [])].sort(),
21
- remove: [...((_b = bucket === null || bucket === void 0 ? void 0 : bucket.remove) !== null && _b !== void 0 ? _b : [])].sort(),
22
- });
23
- };
17
+ const normalizeBucket = (bucket) => ({
18
+ add: [...(bucket?.add ?? [])].sort(),
19
+ remove: [...(bucket?.remove ?? [])].sort(),
20
+ });
24
21
  export const normalizeGroupCapabilitiesForMatch = (capabilities) => {
25
- var _a, _b;
26
22
  const normalized = {};
27
23
  for (const relationship of TEMPLATE_RELATIONSHIPS) {
28
- const bucket = capabilities === null || capabilities === void 0 ? void 0 : capabilities[relationship];
29
- if (!((_a = bucket === null || bucket === void 0 ? void 0 : bucket.add) === null || _a === void 0 ? void 0 : _a.length) && !((_b = bucket === null || bucket === void 0 ? void 0 : bucket.remove) === null || _b === void 0 ? void 0 : _b.length))
24
+ const bucket = capabilities?.[relationship];
25
+ if (!bucket?.add?.length && !bucket?.remove?.length)
30
26
  continue;
31
27
  normalized[relationship] = normalizeBucket(bucket);
32
28
  }
@@ -1,7 +1,10 @@
1
1
  export * from './utils';
2
+ export * from './legacyThemeRoot';
2
3
  export * from './profileHelpers';
3
4
  export * from './text';
4
5
  export * from './postHelpers';
6
+ export * from './feedCursor';
7
+ export * from './feedFormat';
5
8
  export * from './capabilitiesHelpers';
6
9
  export * from './adminSections';
7
10
  export * from './groupHelpers';
@@ -11,6 +14,7 @@ export * from './markdownHelpers';
11
14
  export * from './attachmentHelpers';
12
15
  export * from './eventIcs';
13
16
  export * from './eventTime';
17
+ export * from './timeZone';
14
18
  export * from './eventRecurrence';
15
19
  export * from './tokenHelpers';
16
20
  export * from './jamHelpers';
@@ -20,3 +24,6 @@ export * from './mediaDimensions';
20
24
  export * from './csvHelpers';
21
25
  export * from './reportHelpers';
22
26
  export * from './ssoLoginUrl';
27
+ export * from './ssoProviders';
28
+ export * from './federationHosts';
29
+ export * from './reactions';
package/dist/lib/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  export * from './utils.js';
2
+ export * from './legacyThemeRoot.js';
2
3
  export * from './profileHelpers.js';
3
4
  export * from './text.js';
4
5
  export * from './postHelpers.js';
6
+ export * from './feedCursor.js';
7
+ export * from './feedFormat.js';
5
8
  export * from './capabilitiesHelpers.js';
6
9
  export * from './adminSections.js';
7
10
  export * from './groupHelpers.js';
@@ -11,6 +14,7 @@ export * from './markdownHelpers.js';
11
14
  export * from './attachmentHelpers.js';
12
15
  export * from './eventIcs.js';
13
16
  export * from './eventTime.js';
17
+ export * from './timeZone.js';
14
18
  export * from './eventRecurrence.js';
15
19
  export * from './tokenHelpers.js';
16
20
  export * from './jamHelpers.js';
@@ -20,3 +24,6 @@ export * from './mediaDimensions.js';
20
24
  export * from './csvHelpers.js';
21
25
  export * from './reportHelpers.js';
22
26
  export * from './ssoLoginUrl.js';
27
+ export * from './ssoProviders.js';
28
+ export * from './federationHosts.js';
29
+ export * from './reactions.js';
@@ -8,7 +8,10 @@ export declare const uniquePostsById: <T extends {
8
8
  export declare const getJamUrl: (id: string, origin: string | undefined, occurrence?: string) => string;
9
9
  export declare const jamFromEvent: (event: PublicPost) => Jam | undefined;
10
10
  export declare const canModerateJam: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
11
- export declare const canAccessJamRecordings: (profile: PublicProfile | undefined, post: PublicPost) => boolean;
11
+ /** Host or jam moderator — same gate as the event Attendees tab. */
12
+ export declare const canViewJamAttendees: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
13
+ export declare const canAccessJamRecordings: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
14
+ export declare const jamRecordingAcceptsUpload: (status: string | undefined) => status is "requested" | "active" | "finalizing";
12
15
  export declare const isRtmpJamRecording: (recording: {
13
16
  kind?: string | null;
14
17
  }) => boolean;
@@ -25,7 +28,13 @@ export declare const assembleRtmpUrl: (url: string, streamKey: string) => string
25
28
  export declare const rtmpDestinationHost: (rtmpUrl: string) => string | undefined;
26
29
  export declare const toRtmpStreamResponse: (recording: JamRecording) => {
27
30
  id: string;
28
- status: "active" | "failed" | "requested" | "completed";
31
+ status: "active" | "failed" | "requested" | "finalizing" | "completed";
29
32
  destinationHost: string | undefined;
30
33
  egressId: string | undefined;
31
34
  };
35
+ /**
36
+ * Raised hands first, most recent raise first, so the person who just raised
37
+ * moves to the top of the people list and the top-left of the video grid.
38
+ * Everyone else keeps their relative order.
39
+ */
40
+ export declare const sortByRaisedHand: <T>(items: readonly T[], metadataOf: (item: T) => string | undefined) => T[];
@@ -2,9 +2,8 @@ import { normalizeRecurrenceId } from './eventRecurrence.js';
2
2
  export const jamRoomName = (postId, _recurrenceId) => postId;
3
3
  const UUID_PREFIX = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_.*)?$/i;
4
4
  export const postIdFromJamRoomName = (roomName) => {
5
- var _a;
6
5
  const match = roomName.match(UUID_PREFIX);
7
- return (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : roomName;
6
+ return match?.[1] ?? roomName;
8
7
  };
9
8
  /** Recurring jams use one LiveKit room per event; leftover occurrence rooms still collapse. */
10
9
  export const uniquePostsById = (posts) => {
@@ -30,30 +29,32 @@ export const getJamUrl = (id, origin, occurrence) => {
30
29
  return `${origin}/events/${id}/jam${query}`;
31
30
  };
32
31
  export const jamFromEvent = (event) => {
33
- var _a, _b;
34
- if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.jam)) {
32
+ if (event.data?.type === 'event' && event.data?.jam) {
35
33
  return event.data.jam;
36
34
  }
37
35
  return undefined;
38
36
  };
39
- export const canModerateJam = (profile, post) => { var _a, _b; return !!(profile && ((_b = (_a = jamFromEvent(post)) === null || _a === void 0 ? void 0 : _a.moderators) === null || _b === void 0 ? void 0 : _b.includes(profile.id))); };
37
+ export const canModerateJam = (profile, post) => !!(profile && jamFromEvent(post)?.moderators?.includes(profile.id));
38
+ /** Host or jam moderator — same gate as the event Attendees tab. */
39
+ export const canViewJamAttendees = (profile, post) => !!(profile &&
40
+ (post.profile.id === profile.id || canModerateJam(profile, post)));
40
41
  export const canAccessJamRecordings = (profile, post) => {
41
- var _a, _b, _c, _d;
42
42
  if (!profile) {
43
43
  return false;
44
44
  }
45
45
  if (post.profile.id === profile.id) {
46
46
  return true;
47
47
  }
48
- if (((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
48
+ if (post.data?.type !== 'event') {
49
49
  return false;
50
50
  }
51
51
  const event = post.data;
52
- if ((_b = event.moderators) === null || _b === void 0 ? void 0 : _b.includes(profile.id)) {
52
+ if (event.moderators?.includes(profile.id)) {
53
53
  return true;
54
54
  }
55
- return !!((_d = (_c = event.jam) === null || _c === void 0 ? void 0 : _c.moderators) === null || _d === void 0 ? void 0 : _d.includes(profile.id));
55
+ return !!event.jam?.moderators?.includes(profile.id);
56
56
  };
57
+ export const jamRecordingAcceptsUpload = (status) => status === 'requested' || status === 'active' || status === 'finalizing';
57
58
  export const isRtmpJamRecording = (recording) => recording.kind === 'rtmp';
58
59
  export const isFileJamRecording = (recording) => !isRtmpJamRecording(recording);
59
60
  export const pickActiveFileRecording = (recordings) => recordings.find(isFileJamRecording);
@@ -83,3 +84,36 @@ export const toRtmpStreamResponse = (recording) => ({
83
84
  destinationHost: recording.destinationHost,
84
85
  egressId: recording.egressId,
85
86
  });
87
+ /** Epoch ms from participant metadata when their hand is up. */
88
+ const raisedHandTimestamp = (metadata) => {
89
+ if (!metadata)
90
+ return undefined;
91
+ try {
92
+ const handRaised = JSON.parse(metadata)
93
+ .handRaised;
94
+ if (typeof handRaised !== 'string' || handRaised.length === 0) {
95
+ return undefined;
96
+ }
97
+ const timestamp = Date.parse(handRaised);
98
+ return Number.isNaN(timestamp) ? undefined : timestamp;
99
+ }
100
+ catch {
101
+ return undefined;
102
+ }
103
+ };
104
+ /**
105
+ * Raised hands first, most recent raise first, so the person who just raised
106
+ * moves to the top of the people list and the top-left of the video grid.
107
+ * Everyone else keeps their relative order.
108
+ */
109
+ export const sortByRaisedHand = (items, metadataOf) => [...items].sort((a, b) => {
110
+ const aRaised = raisedHandTimestamp(metadataOf(a));
111
+ const bRaised = raisedHandTimestamp(metadataOf(b));
112
+ if (aRaised === undefined && bRaised === undefined)
113
+ return 0;
114
+ if (aRaised === undefined)
115
+ return 1;
116
+ if (bRaised === undefined)
117
+ return -1;
118
+ return bRaised - aRaised;
119
+ });
@@ -0,0 +1,3 @@
1
+ import type { CommunityConfig } from '../types';
2
+ /** Copy light-mode fields onto theme root for pre-0.1.45 clients. */
3
+ export declare const withLegacyThemeRoot: (theme: CommunityConfig["theme"]) => CommunityConfig["theme"];
@@ -0,0 +1,10 @@
1
+ /** Copy light-mode fields onto theme root for pre-0.1.45 clients. */
2
+ export const withLegacyThemeRoot = (theme) => ({
3
+ primaryHex: theme.light.primaryHex,
4
+ logoSmall: theme.light.logoSmall,
5
+ defaultProfileAvatar: theme.light.defaultProfileAvatar,
6
+ defaultGroupAvatar: theme.light.defaultGroupAvatar,
7
+ backgroundAuth: theme.light.backgroundAuth,
8
+ background: theme.light.background,
9
+ ...theme,
10
+ });