@openpeepshq/common 0.1.44 → 0.1.46

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 (77) hide show
  1. package/dist/lib/adminSections.d.ts +4 -0
  2. package/dist/lib/adminSections.js +5 -0
  3. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  4. package/dist/lib/capabilitiesHelpers.js +21 -13
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +138 -2
  7. package/dist/lib/eventRecurrence.d.ts +32 -0
  8. package/dist/lib/eventRecurrence.js +284 -0
  9. package/dist/lib/eventTime.d.ts +29 -0
  10. package/dist/lib/eventTime.js +143 -0
  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.d.ts +63 -41
  18. package/dist/lib/groupHelpers.js +155 -45
  19. package/dist/lib/groupTemplateHelpers.d.ts +16 -0
  20. package/dist/lib/groupTemplateHelpers.js +51 -0
  21. package/dist/lib/index.d.ts +11 -0
  22. package/dist/lib/index.js +11 -0
  23. package/dist/lib/jamHelpers.d.ts +38 -3
  24. package/dist/lib/jamHelpers.js +93 -8
  25. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  26. package/dist/lib/legacyThemeRoot.js +10 -0
  27. package/dist/lib/markdownHelpers.d.ts +22 -0
  28. package/dist/lib/markdownHelpers.js +73 -3
  29. package/dist/lib/postHelpers.d.ts +164 -9
  30. package/dist/lib/postHelpers.js +353 -11
  31. package/dist/lib/profileHelpers.d.ts +11 -0
  32. package/dist/lib/profileHelpers.js +31 -0
  33. package/dist/lib/pushHelpers.d.ts +3 -1
  34. package/dist/lib/pushHelpers.js +13 -0
  35. package/dist/lib/reactions.d.ts +17 -0
  36. package/dist/lib/reactions.js +37 -0
  37. package/dist/lib/scopeHelpers.d.ts +31 -2
  38. package/dist/lib/scopeHelpers.js +37 -3
  39. package/dist/lib/ssoLoginUrl.d.ts +24 -0
  40. package/dist/lib/ssoLoginUrl.js +75 -0
  41. package/dist/lib/ssoProviders.d.ts +72 -0
  42. package/dist/lib/ssoProviders.js +370 -0
  43. package/dist/lib/text.d.ts +2 -0
  44. package/dist/lib/text.js +2 -0
  45. package/dist/lib/timeZone.d.ts +9 -0
  46. package/dist/lib/timeZone.js +44 -0
  47. package/dist/lib/tokenHelpers.d.ts +5 -0
  48. package/dist/lib/tokenHelpers.js +19 -0
  49. package/dist/types/analytics.d.ts +20 -0
  50. package/dist/types/analytics.js +4 -0
  51. package/dist/types/api.d.ts +42669 -10689
  52. package/dist/types/api.js +94 -16
  53. package/dist/types/auth.d.ts +22 -13
  54. package/dist/types/capabilities.d.ts +26 -5
  55. package/dist/types/capabilities.js +95 -1
  56. package/dist/types/config.d.ts +93 -6
  57. package/dist/types/config.js +56 -5
  58. package/dist/types/db.d.ts +1911 -248
  59. package/dist/types/db.js +17 -3
  60. package/dist/types/export.d.ts +120 -0
  61. package/dist/types/export.js +7 -0
  62. package/dist/types/index.d.ts +2 -0
  63. package/dist/types/index.js +2 -0
  64. package/dist/types/internal.d.ts +8313 -2675
  65. package/dist/types/internal.js +16 -1
  66. package/dist/types/models.d.ts +343 -16
  67. package/dist/types/models.js +98 -7
  68. package/dist/types/notifications.d.ts +1 -0
  69. package/dist/types/plugins.d.ts +43 -1
  70. package/dist/types/plugins.js +75 -1
  71. package/dist/types/roleDefaults.d.ts +31 -0
  72. package/dist/types/roleDefaults.js +110 -0
  73. package/dist/types/stats.d.ts +54359 -4718
  74. package/dist/types/stats.js +30 -0
  75. package/dist/types/utils.d.ts +2 -0
  76. package/dist/types/utils.js +1 -3
  77. package/package.json +1 -1
@@ -1,5 +1,7 @@
1
- import { visibilityTypeValues, } from '../types/index.js';
1
+ import { POLL_OPTION_MAX_LENGTH, visibilityTypeValues, } from '../types/index.js';
2
2
  import { canModerateJam } from './jamHelpers.js';
3
+ import { defaultRsvpRecurrenceId, effectiveEventTimes, isRecurringEvent, listRsvpOccurrences, normalizeRecurrenceId, sameRecurrenceId, } from './eventRecurrence.js';
4
+ import { formatEventWhen } from './eventTime.js';
3
5
  import { checkGroupCapabilities, checkPostCapabilities, checkRoleCapabilities, } from './capabilitiesHelpers.js';
4
6
  import { scopeMatches } from './scopeHelpers.js';
5
7
  import { countBy, dateSorter, groupBy, transformValues } from './utils.js';
@@ -13,6 +15,77 @@ export const buildThreads = (posts) => posts
13
15
  .filter((p) => !posts.find((p2) => p2.id === p.inReplyToId))
14
16
  .map((post) => buildThread(post, posts))
15
17
  .sort(dateSorter());
18
+ const parentIdOf = (post) => { var _a, _b; return (_a = post.inReplyToId) !== null && _a !== void 0 ? _a : (_b = post.replyTo) === null || _b === void 0 ? void 0 : _b.id; };
19
+ export const buildThreadPreview = (rootId, replies) => {
20
+ var _a;
21
+ const sorted = [...replies].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id));
22
+ if (!sorted.length)
23
+ return [];
24
+ const ids = new Set(sorted.map((post) => post.id));
25
+ const parent = new Map(sorted.map((post) => [post.id, post.id]));
26
+ const find = (id) => {
27
+ var _a;
28
+ const current = (_a = parent.get(id)) !== null && _a !== void 0 ? _a : id;
29
+ if (current !== id) {
30
+ const root = find(current);
31
+ parent.set(id, root);
32
+ return root;
33
+ }
34
+ return id;
35
+ };
36
+ const union = (a, b) => {
37
+ const ra = find(a);
38
+ const rb = find(b);
39
+ if (ra !== rb)
40
+ parent.set(ra, rb);
41
+ };
42
+ for (const post of sorted) {
43
+ const parentId = parentIdOf(post);
44
+ if (parentId && ids.has(parentId))
45
+ union(post.id, parentId);
46
+ }
47
+ const grouped = new Map();
48
+ for (const post of sorted) {
49
+ const key = find(post.id);
50
+ const list = (_a = grouped.get(key)) !== null && _a !== void 0 ? _a : [];
51
+ list.push(post);
52
+ grouped.set(key, list);
53
+ }
54
+ return [...grouped.values()]
55
+ .map((posts) => {
56
+ var _a, _b;
57
+ const start = (_a = posts.find((post) => {
58
+ const parentId = parentIdOf(post);
59
+ return !parentId || !ids.has(parentId);
60
+ })) !== null && _a !== void 0 ? _a : posts[0];
61
+ const ordered = [];
62
+ const used = new Set();
63
+ let current = start;
64
+ while (current && !used.has(current.id)) {
65
+ ordered.push(current);
66
+ used.add(current.id);
67
+ current = posts.find((post) => parentIdOf(post) === (current === null || current === void 0 ? void 0 : current.id) && !used.has(post.id));
68
+ }
69
+ for (const post of posts) {
70
+ if (!used.has(post.id))
71
+ ordered.push(post);
72
+ }
73
+ const startParentId = parentIdOf(start);
74
+ const ancestor = startParentId && startParentId !== rootId
75
+ ? ((_b = start.replyTo) !== null && _b !== void 0 ? _b : undefined)
76
+ : undefined;
77
+ const skippedAncestor = !!(ancestor &&
78
+ ancestor.inReplyToId &&
79
+ ancestor.inReplyToId !== rootId);
80
+ return { skippedAncestor, ancestor, posts: ordered };
81
+ })
82
+ .sort((a, b) => {
83
+ var _a, _b, _c, _d, _e, _f, _g, _h;
84
+ const aKey = (_d = (_b = (_a = a.ancestor) === null || _a === void 0 ? void 0 : _a.createdAt) !== null && _b !== void 0 ? _b : (_c = a.posts[0]) === null || _c === void 0 ? void 0 : _c.createdAt) !== null && _d !== void 0 ? _d : '';
85
+ const bKey = (_h = (_f = (_e = b.ancestor) === null || _e === void 0 ? void 0 : _e.createdAt) !== null && _f !== void 0 ? _f : (_g = b.posts[0]) === null || _g === void 0 ? void 0 : _g.createdAt) !== null && _h !== void 0 ? _h : '';
86
+ return aKey.localeCompare(bKey);
87
+ });
88
+ };
16
89
  export const getReactionCount = (post) => {
17
90
  return countBy(post.reactions, (r) => r.reaction);
18
91
  };
@@ -32,6 +105,8 @@ export const resolvePollOptionContents = (options, fallbackLabel) => options.map
32
105
  const trimmed = text.trim();
33
106
  return trimmed.length > 0 ? trimmed : fallbackLabel(index);
34
107
  });
108
+ /** Longer choices are rejected by `questionSchema`, so block submit instead. */
109
+ export const pollOptionsWithinLimit = (options) => options.every((text) => text.trim().length <= POLL_OPTION_MAX_LENGTH);
35
110
  export const collectVotes = (post) => {
36
111
  if (post.type !== 'question') {
37
112
  return {
@@ -57,16 +132,224 @@ export const collectVotes = (post) => {
57
132
  voteCounts,
58
133
  };
59
134
  };
60
- const latestRsvpPerProfile = (rsvps) => {
61
- const rsvpsByProfile = groupBy(rsvps, (r) => r.profile.id);
135
+ const latestRsvpPerProfile = (rsvps, recurrenceId) => {
136
+ const scoped = rsvps.filter((rsvp) => {
137
+ if (recurrenceId) {
138
+ if (rsvp.recurrenceId) {
139
+ return sameRecurrenceId(rsvp.recurrenceId, recurrenceId);
140
+ }
141
+ return true;
142
+ }
143
+ return true;
144
+ });
145
+ const rsvpsByProfile = groupBy(scoped, (r) => r.profile.id);
62
146
  return Object.values(rsvpsByProfile).map((profileRsvps) => {
63
- const sorted = profileRsvps.sort(dateSorter());
147
+ const instanceRsvps = recurrenceId
148
+ ? profileRsvps.filter((rsvp) => sameRecurrenceId(rsvp.recurrenceId, recurrenceId))
149
+ : [];
150
+ const seriesRsvps = recurrenceId
151
+ ? profileRsvps.filter((rsvp) => !rsvp.recurrenceId)
152
+ : profileRsvps;
153
+ const pool = recurrenceId && instanceRsvps.length > 0 ? instanceRsvps : seriesRsvps;
154
+ const sorted = pool.sort(dateSorter());
64
155
  return sorted[sorted.length - 1];
65
156
  });
66
157
  };
67
- export const calculateEffectiveRsvps = (post) => latestRsvpPerProfile(post.rsvps || []);
68
- export const getEffectiveRsvp = (post, profileId) => calculateEffectiveRsvps(post).find((r) => r.profile.id === profileId);
69
- export const countYesRsvps = (post) => calculateEffectiveRsvps(post).filter((r) => r.response === 'yes').length;
158
+ export const calculateEffectiveRsvps = (post, recurrenceId) => latestRsvpPerProfile(post.rsvps || [], recurrenceId).filter((rsvp) => !!rsvp);
159
+ export const getEffectiveRsvp = (post, profileId, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).find((r) => r.profile.id === profileId);
160
+ export const countYesRsvps = (post, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).filter((r) => r.response === 'yes').length;
161
+ export const countSeriesYesRsvps = (post) => {
162
+ var _a;
163
+ return ((_a = post.rsvps) !== null && _a !== void 0 ? _a : []).filter((r) => !r.recurrenceId && r.response === 'yes')
164
+ .length;
165
+ };
166
+ const attendingResponse = (response) => response === 'yes' || response === 'tentative';
167
+ /** Current roster: attending guests, plus organizer removals that can be restored. */
168
+ export const listedRsvps = (rsvps) => rsvps.filter((rsvp) => rsvp.response === 'yes' ||
169
+ rsvp.response === 'tentative' ||
170
+ rsvp.response === 'removed');
171
+ export const isRsvpCancelNotice = (data) => {
172
+ if (!data || typeof data !== 'object')
173
+ return false;
174
+ const notice = data;
175
+ return (typeof notice.series === 'boolean' &&
176
+ Array.isArray(notice.occurrenceIds) &&
177
+ notice.occurrenceIds.every((id) => typeof id === 'string'));
178
+ };
179
+ export const rsvpCancelNotice = (post, profileId, response, occurrenceIds) => {
180
+ var _a, _b;
181
+ if (response !== 'no')
182
+ return undefined;
183
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
184
+ if (!event)
185
+ return undefined;
186
+ if (occurrenceIds === null || occurrenceIds === void 0 ? void 0 : occurrenceIds.length) {
187
+ const canceled = occurrenceIds.filter((id) => { var _a; return attendingResponse((_a = getEffectiveRsvp(post, profileId, id)) === null || _a === void 0 ? void 0 : _a.response); });
188
+ if (!canceled.length)
189
+ return undefined;
190
+ return { occurrenceIds: canceled, series: false };
191
+ }
192
+ if (attendingResponse((_b = getEffectiveRsvp(post, profileId)) === null || _b === void 0 ? void 0 : _b.response)) {
193
+ return { occurrenceIds: [], series: isRecurringEvent(event) };
194
+ }
195
+ if (!event.recurrence)
196
+ return undefined;
197
+ const canceled = instanceRsvpIdsForProfile(post, profileId).filter((id) => { var _a; return attendingResponse((_a = getEffectiveRsvp(post, profileId, id)) === null || _a === void 0 ? void 0 : _a.response); });
198
+ if (!canceled.length)
199
+ return undefined;
200
+ return { occurrenceIds: canceled, series: false };
201
+ };
202
+ const instanceRsvpKey = (profileId, recurrenceId) => `${profileId}|${normalizeRecurrenceId(recurrenceId)}`;
203
+ /** Attending → no transitions, newest first. Later re-RSVPs do not erase them. */
204
+ export const listRsvpCancellations = (post) => {
205
+ var _a, _b;
206
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
207
+ const recurring = event ? isRecurringEvent(event) : false;
208
+ const seriesResponse = new Map();
209
+ const instanceResponse = new Map();
210
+ const records = [];
211
+ for (const rsvp of [...((_b = post.rsvps) !== null && _b !== void 0 ? _b : [])].sort(dateSorter())) {
212
+ const profileId = rsvp.profile.id;
213
+ if (rsvp.response === 'no') {
214
+ if (rsvp.recurrenceId) {
215
+ const key = instanceRsvpKey(profileId, rsvp.recurrenceId);
216
+ const previous = instanceResponse.has(key)
217
+ ? instanceResponse.get(key)
218
+ : seriesResponse.get(profileId);
219
+ if (attendingResponse(previous)) {
220
+ records.push({
221
+ profile: rsvp.profile,
222
+ recurrenceId: rsvp.recurrenceId,
223
+ canceledAt: rsvp.createdAt,
224
+ series: false,
225
+ });
226
+ }
227
+ }
228
+ else if (attendingResponse(seriesResponse.get(profileId))) {
229
+ records.push({
230
+ profile: rsvp.profile,
231
+ canceledAt: rsvp.createdAt,
232
+ series: recurring,
233
+ });
234
+ }
235
+ }
236
+ if (rsvp.recurrenceId) {
237
+ instanceResponse.set(instanceRsvpKey(profileId, rsvp.recurrenceId), rsvp.response);
238
+ }
239
+ else {
240
+ seriesResponse.set(profileId, rsvp.response);
241
+ }
242
+ }
243
+ return records.reverse();
244
+ };
245
+ export const rsvpCancelWhenLabels = (post, notice) => {
246
+ var _a;
247
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
248
+ if (!event || notice.series)
249
+ return { series: notice.series, labels: [] };
250
+ const format = (start, end) => formatEventWhen(start, {
251
+ end,
252
+ timeZone: event.timeZone,
253
+ allDay: event.wholeDay,
254
+ });
255
+ if (!notice.occurrenceIds.length) {
256
+ return { series: false, labels: [format(event.start, event.end)] };
257
+ }
258
+ return {
259
+ series: false,
260
+ labels: notice.occurrenceIds.map((id) => {
261
+ const times = effectiveEventTimes(event, id);
262
+ return format(times.start, times.end);
263
+ }),
264
+ };
265
+ };
266
+ export const instanceRsvpIdsForProfile = (post, profileId) => {
267
+ var _a;
268
+ const ids = new Set();
269
+ for (const rsvp of (_a = post.rsvps) !== null && _a !== void 0 ? _a : []) {
270
+ if (rsvp.profile.id !== profileId || !rsvp.recurrenceId)
271
+ continue;
272
+ ids.add(normalizeRecurrenceId(rsvp.recurrenceId));
273
+ }
274
+ return [...ids];
275
+ };
276
+ export const overlaySeriesRsvpEntries = (response, instanceIds) => [
277
+ { response },
278
+ ...instanceIds.map((recurrenceId) => ({ response, recurrenceId })),
279
+ ];
280
+ export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) => {
281
+ var _a;
282
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
283
+ const maxAttendees = event === null || event === void 0 ? void 0 : event.maxAttendees;
284
+ if (!event || !maxAttendees || !event.recurrence)
285
+ return false;
286
+ const occurrences = listRsvpOccurrences(event, now);
287
+ // When there are no upcoming occurrences (e.g. a live jam whose current
288
+ // occurrence started before `now`), fall back to the series-level count.
289
+ if (occurrences.length === 0) {
290
+ const current = getEffectiveRsvp(post, profileId);
291
+ if ((current === null || current === void 0 ? void 0 : current.response) !== 'yes' &&
292
+ countSeriesYesRsvps(post) >= maxAttendees) {
293
+ return true;
294
+ }
295
+ return false;
296
+ }
297
+ return occurrences.some((occurrence) => {
298
+ const current = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
299
+ if ((current === null || current === void 0 ? void 0 : current.response) === 'yes')
300
+ return false;
301
+ return countYesRsvps(post, occurrence.recurrenceId) >= maxAttendees;
302
+ });
303
+ };
304
+ export const occurrenceHasCapacity = (post, recurrenceId, profileId) => {
305
+ var _a;
306
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
307
+ if (!(event === null || event === void 0 ? void 0 : event.maxAttendees))
308
+ return true;
309
+ if (profileId) {
310
+ const current = getEffectiveRsvp(post, profileId, recurrenceId);
311
+ if ((current === null || current === void 0 ? void 0 : current.response) === 'yes')
312
+ return true;
313
+ }
314
+ return countYesRsvps(post, recurrenceId) < event.maxAttendees;
315
+ };
316
+ /** Series Register stays enabled while any upcoming date still has a seat. */
317
+ export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date()) => {
318
+ var _a;
319
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
320
+ if (!event)
321
+ return false;
322
+ if (!event.recurrence) {
323
+ return occurrenceHasCapacity(post, undefined, profileId);
324
+ }
325
+ return listRsvpOccurrences(event, now).some((occurrence) => occurrenceHasCapacity(post, occurrence.recurrenceId, profileId));
326
+ };
327
+ /**
328
+ * Series-page RSVP for the Register/Cancel CTA: prefer the default/next date,
329
+ * then any attending instance so a partial RSVP still shows Cancel.
330
+ */
331
+ export const displayRsvpForProfile = (post, profileId, options) => {
332
+ var _a;
333
+ const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
334
+ const scopedId = (options === null || options === void 0 ? void 0 : options.lockToOccurrence)
335
+ ? options.recurrenceId
336
+ : event
337
+ ? defaultRsvpRecurrenceId(event, options === null || options === void 0 ? void 0 : options.recurrenceId, options === null || options === void 0 ? void 0 : options.now)
338
+ : options === null || options === void 0 ? void 0 : options.recurrenceId;
339
+ const scoped = getEffectiveRsvp(post, profileId, scopedId);
340
+ if (options === null || options === void 0 ? void 0 : options.lockToOccurrence)
341
+ return scoped;
342
+ if (scoped && scoped.response !== 'no')
343
+ return scoped;
344
+ if (event === null || event === void 0 ? void 0 : event.recurrence) {
345
+ for (const occurrence of listRsvpOccurrences(event, options === null || options === void 0 ? void 0 : options.now)) {
346
+ const instance = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
347
+ if (instance && instance.response !== 'no')
348
+ return instance;
349
+ }
350
+ }
351
+ return scoped;
352
+ };
70
353
  export const isCapacityEvent = (event) => !!event.maxAttendees;
71
354
  export const parseEventMaxAttendeesInput = (raw) => {
72
355
  const trimmed = raw.trim();
@@ -88,7 +371,7 @@ export const normalizeEventDataForSave = (event) => {
88
371
  }
89
372
  return { ...event, maxAttendees: Math.trunc(maxAttendees) };
90
373
  };
91
- /** ArangoDB may store null when capacity was cleared; strip for validation/output. */
374
+ /** Null capacity means it was cleared; strip for validation/output. */
92
375
  export const normalizeEventDataFromDb = (event) => {
93
376
  if (event.maxAttendees != null) {
94
377
  return event;
@@ -104,7 +387,7 @@ export const eventDataForDbUpdate = (previous, normalized) => {
104
387
  };
105
388
  export const canManageEventRsvps = (profile, post) => !!(profile &&
106
389
  (post.profile.id === profile.id || canModerateJam(profile, post)));
107
- export const getJamCapacityJoinBlock = (post, profile) => {
390
+ export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
108
391
  var _a;
109
392
  const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
110
393
  if (!(event === null || event === void 0 ? void 0 : event.maxAttendees) || !(profile === null || profile === void 0 ? void 0 : profile.id)) {
@@ -113,14 +396,14 @@ export const getJamCapacityJoinBlock = (post, profile) => {
113
396
  if (canModerateJam(profile, post)) {
114
397
  return { blocked: false };
115
398
  }
116
- const myRsvp = getEffectiveRsvp(post, profile.id);
399
+ const myRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
117
400
  if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'yes') {
118
401
  return { blocked: false };
119
402
  }
120
403
  if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'removed') {
121
404
  return { blocked: true, reason: 'removed' };
122
405
  }
123
- if (countYesRsvps(post) >= event.maxAttendees) {
406
+ if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
124
407
  return { blocked: true, reason: 'full' };
125
408
  }
126
409
  return { blocked: true, reason: 'rsvp-required' };
@@ -161,3 +444,62 @@ export const canCreatePostTypeWithVisibility = (authData, type, visibility) => {
161
444
  });
162
445
  };
163
446
  export const canCreatePostType = (authData, type) => visibilityTypeValues.some((visibility) => canCreatePostTypeWithVisibility(authData, type, visibility));
447
+ /**
448
+ * Whether Reply / Repost / Like should look live. Non-members of a group
449
+ * post stay fully disabled (existing feed rule). Each action also follows
450
+ * the capability the matching write endpoint actually checks: feed replies
451
+ * and reposts need create-*, likes need core-posts-react.
452
+ */
453
+ export const getPostActionAvailability = (authData, post, config) => {
454
+ var _a, _b, _c;
455
+ const isGroupPost = !!post.groupId || !!post.group;
456
+ const membershipExists = !!((_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships) === null || _b === void 0 ? void 0 : _b.some((m) => { var _a; return m.group.id === ((_a = post.group) === null || _a === void 0 ? void 0 : _a.id) || m.group.id === post.groupId; }));
457
+ if (isGroupPost && !membershipExists) {
458
+ return { canReply: false, canRepost: false, canReact: false };
459
+ }
460
+ const canReply = checkPostCapabilities(authData, ['core-posts-reply'], post, config)
461
+ .success &&
462
+ canCreatePost(authData, 'note', post.visibility, (_c = post.group) !== null && _c !== void 0 ? _c : undefined);
463
+ const canReact = checkPostCapabilities(authData, ['core-posts-react'], post, config).success;
464
+ const canRepost = post.group
465
+ ? checkGroupCapabilities(authData, [`core-posts-create-${post.type}`], post.group).success
466
+ : canCreatePost(authData, post.type, post.visibility);
467
+ return { canReply, canRepost, canReact };
468
+ };
469
+ /** Sentinel handle for block-hidden reply tombstones (no name/handle leak). */
470
+ export const HIDDEN_AUTHOR_HANDLE = 'hidden';
471
+ export const toHiddenPost = (post) => ({
472
+ ...post,
473
+ hidden: true,
474
+ data: {
475
+ ...post.data,
476
+ ...('content' in post.data ? { content: '' } : {}),
477
+ },
478
+ profile: {
479
+ ...post.profile,
480
+ displayName: undefined,
481
+ handle: HIDDEN_AUTHOR_HANDLE,
482
+ avatar: null,
483
+ header: null,
484
+ bio: undefined,
485
+ },
486
+ });
487
+ export const isHiddenPost = (post) => !!post.hidden;
488
+ const participantIds = (post) => {
489
+ var _a, _b, _c;
490
+ const ids = new Set(((_a = post.audience) !== null && _a !== void 0 ? _a : []).map((member) => member.id).filter(Boolean));
491
+ const creatorId = (_b = post.creatorId) !== null && _b !== void 0 ? _b : (_c = post.profile) === null || _c === void 0 ? void 0 : _c.id;
492
+ if (creatorId)
493
+ ids.add(creatorId);
494
+ return ids;
495
+ };
496
+ export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
497
+ if (!viewer || post.visibility !== 'direct')
498
+ return false;
499
+ const blocked = blockedIds instanceof Set ? blockedIds : new Set(blockedIds !== null && blockedIds !== void 0 ? blockedIds : []);
500
+ if (!blocked.size)
501
+ return false;
502
+ const others = participantIds(post);
503
+ others.delete(viewer.id);
504
+ return others.size === 1 && blocked.has([...others][0]);
505
+ };
@@ -39,3 +39,14 @@ export declare const sortProfiles: (profiles: PublicProfile[]) => PublicProfile[
39
39
  export declare const isStripeActive: (sub: StripeSubscriptionData | undefined | null) => boolean;
40
40
  export declare const getStripeCustomerId: (profileSettings: ProfileSettings) => string | undefined;
41
41
  export declare const isOwnerProfile: (profile: ProfileWithMeta) => boolean;
42
+ type BlockIdProfile = {
43
+ blockingIds?: string[] | null;
44
+ blockedByIds?: string[] | null;
45
+ };
46
+ export declare const blockedPairIds: (profile?: BlockIdProfile | null) => string[];
47
+ export declare const isBlockedPair: (profile: BlockIdProfile | undefined | null, otherId: string | undefined | null) => boolean;
48
+ export declare const viewerBlockedTarget: (profile: BlockIdProfile | undefined | null, otherId: string | undefined | null) => boolean;
49
+ export declare const targetBlockedViewer: (profile: BlockIdProfile | undefined | null, otherId: string | undefined | null) => boolean;
50
+ export declare const sharesControllingAccount: (a: Pick<ProfileWithMeta, "controllers">, b: Pick<ProfileWithMeta, "controllers">) => boolean;
51
+ export declare const toBlockedProfileStub: (profile: Pick<ProfileWithMeta, "id" | "type" | "createdAt" | "updatedAt" | "handle" | "displayName">) => PublicProfile;
52
+ export {};
@@ -28,6 +28,8 @@ export const toPublicDeletedProfile = (profile) => ({
28
28
  memberships: [],
29
29
  fields: undefined,
30
30
  profileStats: undefined,
31
+ pinnedPostId: undefined,
32
+ roles: [],
31
33
  });
32
34
  export const anonymizeProfileIfDeleted = (profile) => {
33
35
  if (!profile)
@@ -58,6 +60,9 @@ export const toDeletedProfileWithMeta = (profile) => ({
58
60
  controllers: [],
59
61
  memberships: [],
60
62
  profileStats: { followersCount: 0, followingCount: 0 },
63
+ blockingIds: [],
64
+ blockedByIds: [],
65
+ followedHashtags: [],
61
66
  });
62
67
  /** Tombstone a `ProfileWithMeta` only when it is soft-deleted. */
63
68
  export const tombstoneProfileWithMetaIfDeleted = (profile) => profile && isDeletedProfile(profile)
@@ -102,3 +107,29 @@ export const getStripeCustomerId = (profileSettings) => { var _a; return (_a = p
102
107
  export const isOwnerProfile = (profile) => {
103
108
  return profile === null || profile === void 0 ? void 0 : profile.roles.some((role) => role.key === 'owner');
104
109
  };
110
+ export const blockedPairIds = (profile) => {
111
+ var _a, _b;
112
+ return [
113
+ ...new Set([
114
+ ...((_a = profile === null || profile === void 0 ? void 0 : profile.blockingIds) !== null && _a !== void 0 ? _a : []),
115
+ ...((_b = profile === null || profile === void 0 ? void 0 : profile.blockedByIds) !== null && _b !== void 0 ? _b : []),
116
+ ]),
117
+ ];
118
+ };
119
+ export const isBlockedPair = (profile, otherId) => !!otherId && blockedPairIds(profile).includes(otherId);
120
+ export const viewerBlockedTarget = (profile, otherId) => { var _a; return !!otherId && ((_a = profile === null || profile === void 0 ? void 0 : profile.blockingIds) !== null && _a !== void 0 ? _a : []).includes(otherId); };
121
+ export const targetBlockedViewer = (profile, otherId) => { var _a; return !!otherId && ((_a = profile === null || profile === void 0 ? void 0 : profile.blockedByIds) !== null && _a !== void 0 ? _a : []).includes(otherId); };
122
+ export const sharesControllingAccount = (a, b) => {
123
+ var _a, _b;
124
+ const otherIds = new Set(((_a = b.controllers) !== null && _a !== void 0 ? _a : []).map((account) => account.id));
125
+ return ((_b = a.controllers) !== null && _b !== void 0 ? _b : []).some((account) => otherIds.has(account.id));
126
+ };
127
+ export const toBlockedProfileStub = (profile) => ({
128
+ id: profile.id,
129
+ type: profile.type,
130
+ createdAt: profile.createdAt,
131
+ updatedAt: profile.updatedAt,
132
+ handle: profile.handle,
133
+ displayName: profile.displayName,
134
+ blockedByMe: true,
135
+ });
@@ -1,4 +1,6 @@
1
- import type { PushSubscription } from '../types';
1
+ import type { PushSubscription, PushSubscriptionData } from '../types';
2
2
  export declare const pushSubscriptionDeviceName: (subscription: PushSubscription) => string | undefined;
3
+ /** Identity used to send a push. Duplicate keys mean duplicate notifications. */
4
+ export declare const pushSubscriptionDeliveryKey: (subscription: PushSubscriptionData) => string;
3
5
  export declare const pushSubscriptionEndpoint: (subscription: PushSubscription) => string | undefined;
4
6
  export declare const pushSubscriptionIsMobile: (subscription: PushSubscription) => boolean;
@@ -1,4 +1,17 @@
1
1
  export const pushSubscriptionDeviceName = (subscription) => 'deviceName' in subscription ? subscription.deviceName : undefined;
2
+ /** Identity used to send a push. Duplicate keys mean duplicate notifications. */
3
+ export const pushSubscriptionDeliveryKey = (subscription) => {
4
+ switch (subscription.type) {
5
+ case 'web':
6
+ return `web:${subscription.endpoint}`;
7
+ case 'webhook':
8
+ return `webhook:${subscription.url}`;
9
+ case 'apn':
10
+ return `apn:${subscription.apnToken}`;
11
+ case 'fcm':
12
+ return `fcm:${subscription.fcmToken}`;
13
+ }
14
+ };
2
15
  export const pushSubscriptionEndpoint = (subscription) => 'endpoint' in subscription ? subscription.endpoint : undefined;
3
16
  export const pushSubscriptionIsMobile = (subscription) => {
4
17
  var _a;
@@ -0,0 +1,17 @@
1
+ export declare const AP_LIKE_REACTION = "\uD83D\uDC4D";
2
+ export declare const AP_DISLIKE_REACTION = "\uD83D\uDC4E";
3
+ export declare const activityPubActivityForReaction: (reaction: string) => "Like" | "Dislike" | null;
4
+ export type ReactionLogEntry = {
5
+ type: string;
6
+ createdAt: string;
7
+ data?: unknown;
8
+ profile: {
9
+ id: string;
10
+ };
11
+ };
12
+ /** Latest reaction/unreaction per (profile, emoji) wins. */
13
+ export declare const currentReactionsFromEntries: <T extends ReactionLogEntry>(entries: readonly T[]) => Array<{
14
+ reaction: string;
15
+ profile: T["profile"];
16
+ }>;
17
+ export declare const isReactionHistoryEntry: (type: string) => type is "reaction" | "unreaction";
@@ -0,0 +1,37 @@
1
+ export const AP_LIKE_REACTION = '👍';
2
+ export const AP_DISLIKE_REACTION = '👎';
3
+ export const activityPubActivityForReaction = (reaction) => {
4
+ if (reaction === AP_LIKE_REACTION)
5
+ return 'Like';
6
+ if (reaction === AP_DISLIKE_REACTION)
7
+ return 'Dislike';
8
+ return null;
9
+ };
10
+ const reactionFromData = (data) => {
11
+ if (!data || typeof data !== 'object' || !('reaction' in data)) {
12
+ return undefined;
13
+ }
14
+ const reaction = data.reaction;
15
+ return typeof reaction === 'string' && reaction.length > 0
16
+ ? reaction
17
+ : undefined;
18
+ };
19
+ /** Latest reaction/unreaction per (profile, emoji) wins. */
20
+ export const currentReactionsFromEntries = (entries) => {
21
+ const latest = new Map();
22
+ const sorted = [...entries].filter((entry) => entry.type === 'reaction' || entry.type === 'unreaction');
23
+ sorted.sort((a, b) => (a.createdAt < b.createdAt ? -1 : 1));
24
+ for (const entry of sorted) {
25
+ const reaction = reactionFromData(entry.data);
26
+ if (!reaction)
27
+ continue;
28
+ latest.set(`${entry.profile.id}\0${reaction}`, { entry, reaction });
29
+ }
30
+ return [...latest.values()]
31
+ .filter(({ entry }) => entry.type === 'reaction')
32
+ .map(({ entry, reaction }) => ({
33
+ reaction,
34
+ profile: entry.profile,
35
+ }));
36
+ };
37
+ export const isReactionHistoryEntry = (type) => type === 'reaction' || type === 'unreaction';
@@ -8,8 +8,21 @@ export declare const scopeMatches: ({ scopes, requiredScope, }: {
8
8
  requiredScope: Scope;
9
9
  }) => boolean;
10
10
  export declare const getPublicPostReadScope: (postId: string) => Scope;
11
- /** Public posts are readable without auth; grant read scope for that post id. */
12
- export declare const withPublicPostReadScopes: (authData: AuthorizationData, post: Pick<PublicPost, "id" | "visibility">, neededCapabilities: string[]) => AuthorizationData;
11
+ /**
12
+ * Posts with `public` visibility — and posts in groups that grant the needed
13
+ * *-read caps to `none` — are readable without auth; grant read scope for
14
+ * that post id (same pattern as {@link withPublicGroupReadScopes}).
15
+ */
16
+ export declare const withPublicPostReadScopes: (authData: AuthorizationData, post: Pick<PublicPost, "id" | "visibility"> & {
17
+ /** Only the group's `none` capabilities matter for the public check. */
18
+ group?: {
19
+ capabilities?: {
20
+ none?: {
21
+ add?: string[];
22
+ };
23
+ } | null;
24
+ } | null;
25
+ }, neededCapabilities: string[]) => AuthorizationData;
13
26
  export declare const getPublicGroupReadScope: (groupId: string) => Scope;
14
27
  /**
15
28
  * Groups that grant the needed *-read caps to relationship `none` are readable
@@ -23,3 +36,19 @@ export declare const withPublicGroupReadScopes: (authData: AuthorizationData, gr
23
36
  };
24
37
  } | null;
25
38
  }, neededCapabilities: string[]) => AuthorizationData;
39
+ export declare const getPublicProfileReadScope: (profileId: string) => Scope;
40
+ /**
41
+ * Profiles whose capabilities config grants the needed *-read caps to
42
+ * relationship `none` are readable without auth (same pattern as
43
+ * {@link withPublicGroupReadScopes}). Community-wide `publicContent` is
44
+ * still enforced by `ensureAccess` on the profile endpoints.
45
+ */
46
+ export declare const withPublicProfileReadScopes: (authData: AuthorizationData, profile: {
47
+ id: string;
48
+ }, neededCapabilities: string[], config: {
49
+ profile?: {
50
+ none?: {
51
+ add?: string[];
52
+ };
53
+ } | null;
54
+ }) => AuthorizationData;
@@ -45,11 +45,19 @@ export const getPublicPostReadScope = (postId) => ({
45
45
  scopeLevel: 'read',
46
46
  resource: { type: 'posts', id: postId },
47
47
  });
48
- /** Public posts are readable without auth; grant read scope for that post id. */
48
+ /**
49
+ * Posts with `public` visibility — and posts in groups that grant the needed
50
+ * *-read caps to `none` — are readable without auth; grant read scope for
51
+ * that post id (same pattern as {@link withPublicGroupReadScopes}).
52
+ */
49
53
  export const withPublicPostReadScopes = (authData, post, neededCapabilities) => {
50
54
  var _a;
51
- if (post.visibility !== 'public' ||
52
- !neededCapabilities.every((c) => c.endsWith('-read'))) {
55
+ if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
56
+ return authData;
57
+ }
58
+ const publicGroupPost = post.visibility === 'group' &&
59
+ neededCapabilities.every((c) => { var _a, _b, _c, _d, _e; return (_e = (_d = (_c = (_b = (_a = post.group) === null || _a === void 0 ? void 0 : _a.capabilities) === null || _b === void 0 ? void 0 : _b.none) === null || _c === void 0 ? void 0 : _c.add) === null || _d === void 0 ? void 0 : _d.includes(c)) !== null && _e !== void 0 ? _e : false; });
60
+ if (post.visibility !== 'public' && !publicGroupPost) {
53
61
  return authData;
54
62
  }
55
63
  const publicReadScope = getPublicPostReadScope(post.id);
@@ -83,3 +91,29 @@ export const withPublicGroupReadScopes = (authData, group, neededCapabilities) =
83
91
  }
84
92
  return { ...authData, scopes: [...scopes, publicReadScope] };
85
93
  };
94
+ export const getPublicProfileReadScope = (profileId) => ({
95
+ scopeLevel: 'read',
96
+ resource: { type: 'profiles', id: profileId },
97
+ });
98
+ /**
99
+ * Profiles whose capabilities config grants the needed *-read caps to
100
+ * relationship `none` are readable without auth (same pattern as
101
+ * {@link withPublicGroupReadScopes}). Community-wide `publicContent` is
102
+ * still enforced by `ensureAccess` on the profile endpoints.
103
+ */
104
+ export const withPublicProfileReadScopes = (authData, profile, neededCapabilities, config) => {
105
+ var _a, _b, _c, _d;
106
+ if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
107
+ return authData;
108
+ }
109
+ const noneAdd = (_c = (_b = (_a = config.profile) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : [];
110
+ if (!neededCapabilities.every((c) => noneAdd.includes(c))) {
111
+ return authData;
112
+ }
113
+ const publicReadScope = getPublicProfileReadScope(profile.id);
114
+ const scopes = (_d = authData.scopes) !== null && _d !== void 0 ? _d : [];
115
+ if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
116
+ return authData;
117
+ }
118
+ return { ...authData, scopes: [...scopes, publicReadScope] };
119
+ };