@openpeepshq/common 0.1.46 → 0.3.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 (83) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.js +30 -40
  3. package/dist/lib/csvHelpers.js +1 -1
  4. package/dist/lib/eventIcs.js +26 -32
  5. package/dist/lib/eventRecurrence.d.ts +17 -0
  6. package/dist/lib/eventRecurrence.js +75 -18
  7. package/dist/lib/eventTime.js +9 -11
  8. package/dist/lib/groupHelpers.js +13 -34
  9. package/dist/lib/groupTemplateHelpers.js +6 -10
  10. package/dist/lib/jamHelpers.js +6 -9
  11. package/dist/lib/markdownHelpers.d.ts +37 -0
  12. package/dist/lib/markdownHelpers.js +151 -3
  13. package/dist/lib/postHelpers.js +70 -97
  14. package/dist/lib/profileHelpers.js +17 -24
  15. package/dist/lib/pushHelpers.js +3 -4
  16. package/dist/lib/scopeHelpers.js +6 -9
  17. package/dist/lib/ssoLoginUrl.js +4 -6
  18. package/dist/lib/ssoProviders.js +35 -39
  19. package/dist/lib/tokenHelpers.js +5 -5
  20. package/dist/lib/utils.js +6 -7
  21. package/dist/types/admin-db.js +1 -1
  22. package/dist/types/api.d.ts +1 -0
  23. package/dist/types/api.js +1 -1
  24. package/dist/types/config.d.ts +3 -0
  25. package/dist/types/config.js +3 -0
  26. package/dist/types/models.js +1 -1
  27. package/dist/types/plugins.js +2 -2
  28. package/dist/zod.d.ts +1 -0
  29. package/dist/zod.js +1 -0
  30. package/package.json +36 -6
  31. package/src/index.ts +4 -0
  32. package/src/lib/adminSections.ts +84 -0
  33. package/src/lib/attachmentHelpers.ts +14 -0
  34. package/src/lib/capabilitiesHelpers.ts +532 -0
  35. package/src/lib/colors.ts +20 -0
  36. package/src/lib/csvHelpers.ts +31 -0
  37. package/src/lib/eventIcs.ts +265 -0
  38. package/src/lib/eventRecurrence.ts +495 -0
  39. package/src/lib/eventTime.ts +206 -0
  40. package/src/lib/federationHosts.ts +22 -0
  41. package/src/lib/feedCursor.ts +27 -0
  42. package/src/lib/feedFormat.ts +24 -0
  43. package/src/lib/groupHelpers.ts +421 -0
  44. package/src/lib/groupTemplateHelpers.ts +83 -0
  45. package/src/lib/index.ts +29 -0
  46. package/src/lib/jamHelpers.ts +164 -0
  47. package/src/lib/legacyThemeRoot.ts +14 -0
  48. package/src/lib/markdownHelpers.ts +290 -0
  49. package/src/lib/mediaDimensions.ts +21 -0
  50. package/src/lib/postHelpers.ts +783 -0
  51. package/src/lib/profileHelpers.ts +220 -0
  52. package/src/lib/pushHelpers.ts +34 -0
  53. package/src/lib/reactions.ts +52 -0
  54. package/src/lib/reportHelpers.ts +7 -0
  55. package/src/lib/scopeHelpers.ts +176 -0
  56. package/src/lib/ssoLoginUrl.ts +93 -0
  57. package/src/lib/ssoProviders.ts +472 -0
  58. package/src/lib/text.ts +26 -0
  59. package/src/lib/timeZone.ts +52 -0
  60. package/src/lib/tokenHelpers.ts +119 -0
  61. package/src/lib/utils.ts +322 -0
  62. package/src/types/admin-db.ts +74 -0
  63. package/src/types/admin-email.ts +55 -0
  64. package/src/types/admin-jobs.ts +17 -0
  65. package/src/types/admin-performance.ts +20 -0
  66. package/src/types/analytics.ts +318 -0
  67. package/src/types/api.ts +871 -0
  68. package/src/types/apple-app-site-association.ts +54 -0
  69. package/src/types/auth.ts +22 -0
  70. package/src/types/capabilities.ts +280 -0
  71. package/src/types/config.ts +546 -0
  72. package/src/types/db.ts +138 -0
  73. package/src/types/export.ts +10 -0
  74. package/src/types/index.ts +20 -0
  75. package/src/types/internal.ts +338 -0
  76. package/src/types/models.ts +939 -0
  77. package/src/types/notifications.ts +92 -0
  78. package/src/types/plugins.ts +150 -0
  79. package/src/types/roleDefaults.ts +132 -0
  80. package/src/types/stats.ts +195 -0
  81. package/src/types/stripe.ts +45 -0
  82. package/src/types/utils.ts +100 -0
  83. package/src/zod.ts +1 -0
@@ -15,17 +15,15 @@ export const buildThreads = (posts) => posts
15
15
  .filter((p) => !posts.find((p2) => p2.id === p.inReplyToId))
16
16
  .map((post) => buildThread(post, posts))
17
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; };
18
+ const parentIdOf = (post) => post.inReplyToId ?? post.replyTo?.id;
19
19
  export const buildThreadPreview = (rootId, replies) => {
20
- var _a;
21
20
  const sorted = [...replies].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id));
22
21
  if (!sorted.length)
23
22
  return [];
24
23
  const ids = new Set(sorted.map((post) => post.id));
25
24
  const parent = new Map(sorted.map((post) => [post.id, post.id]));
26
25
  const find = (id) => {
27
- var _a;
28
- const current = (_a = parent.get(id)) !== null && _a !== void 0 ? _a : id;
26
+ const current = parent.get(id) ?? id;
29
27
  if (current !== id) {
30
28
  const root = find(current);
31
29
  parent.set(id, root);
@@ -47,24 +45,23 @@ export const buildThreadPreview = (rootId, replies) => {
47
45
  const grouped = new Map();
48
46
  for (const post of sorted) {
49
47
  const key = find(post.id);
50
- const list = (_a = grouped.get(key)) !== null && _a !== void 0 ? _a : [];
48
+ const list = grouped.get(key) ?? [];
51
49
  list.push(post);
52
50
  grouped.set(key, list);
53
51
  }
54
52
  return [...grouped.values()]
55
53
  .map((posts) => {
56
- var _a, _b;
57
- const start = (_a = posts.find((post) => {
54
+ const start = posts.find((post) => {
58
55
  const parentId = parentIdOf(post);
59
56
  return !parentId || !ids.has(parentId);
60
- })) !== null && _a !== void 0 ? _a : posts[0];
57
+ }) ?? posts[0];
61
58
  const ordered = [];
62
59
  const used = new Set();
63
60
  let current = start;
64
61
  while (current && !used.has(current.id)) {
65
62
  ordered.push(current);
66
63
  used.add(current.id);
67
- current = posts.find((post) => parentIdOf(post) === (current === null || current === void 0 ? void 0 : current.id) && !used.has(post.id));
64
+ current = posts.find((post) => parentIdOf(post) === current?.id && !used.has(post.id));
68
65
  }
69
66
  for (const post of posts) {
70
67
  if (!used.has(post.id))
@@ -72,7 +69,7 @@ export const buildThreadPreview = (rootId, replies) => {
72
69
  }
73
70
  const startParentId = parentIdOf(start);
74
71
  const ancestor = startParentId && startParentId !== rootId
75
- ? ((_b = start.replyTo) !== null && _b !== void 0 ? _b : undefined)
72
+ ? (start.replyTo ?? undefined)
76
73
  : undefined;
77
74
  const skippedAncestor = !!(ancestor &&
78
75
  ancestor.inReplyToId &&
@@ -80,9 +77,8 @@ export const buildThreadPreview = (rootId, replies) => {
80
77
  return { skippedAncestor, ancestor, posts: ordered };
81
78
  })
82
79
  .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 : '';
80
+ const aKey = a.ancestor?.createdAt ?? a.posts[0]?.createdAt ?? '';
81
+ const bKey = b.ancestor?.createdAt ?? b.posts[0]?.createdAt ?? '';
86
82
  return aKey.localeCompare(bKey);
87
83
  });
88
84
  };
@@ -158,11 +154,8 @@ const latestRsvpPerProfile = (rsvps, recurrenceId) => {
158
154
  export const calculateEffectiveRsvps = (post, recurrenceId) => latestRsvpPerProfile(post.rsvps || [], recurrenceId).filter((rsvp) => !!rsvp);
159
155
  export const getEffectiveRsvp = (post, profileId, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).find((r) => r.profile.id === profileId);
160
156
  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
- };
157
+ export const countSeriesYesRsvps = (post) => (post.rsvps ?? []).filter((r) => !r.recurrenceId && r.response === 'yes')
158
+ .length;
166
159
  const attendingResponse = (response) => response === 'yes' || response === 'tentative';
167
160
  /** Current roster: attending guests, plus organizer removals that can be restored. */
168
161
  export const listedRsvps = (rsvps) => rsvps.filter((rsvp) => rsvp.response === 'yes' ||
@@ -177,24 +170,23 @@ export const isRsvpCancelNotice = (data) => {
177
170
  notice.occurrenceIds.every((id) => typeof id === 'string'));
178
171
  };
179
172
  export const rsvpCancelNotice = (post, profileId, response, occurrenceIds) => {
180
- var _a, _b;
181
173
  if (response !== 'no')
182
174
  return undefined;
183
- const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
175
+ const event = post.data?.type === 'event' ? post.data : undefined;
184
176
  if (!event)
185
177
  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); });
178
+ if (occurrenceIds?.length) {
179
+ const canceled = occurrenceIds.filter((id) => attendingResponse(getEffectiveRsvp(post, profileId, id)?.response));
188
180
  if (!canceled.length)
189
181
  return undefined;
190
182
  return { occurrenceIds: canceled, series: false };
191
183
  }
192
- if (attendingResponse((_b = getEffectiveRsvp(post, profileId)) === null || _b === void 0 ? void 0 : _b.response)) {
184
+ if (attendingResponse(getEffectiveRsvp(post, profileId)?.response)) {
193
185
  return { occurrenceIds: [], series: isRecurringEvent(event) };
194
186
  }
195
187
  if (!event.recurrence)
196
188
  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); });
189
+ const canceled = instanceRsvpIdsForProfile(post, profileId).filter((id) => attendingResponse(getEffectiveRsvp(post, profileId, id)?.response));
198
190
  if (!canceled.length)
199
191
  return undefined;
200
192
  return { occurrenceIds: canceled, series: false };
@@ -202,13 +194,12 @@ export const rsvpCancelNotice = (post, profileId, response, occurrenceIds) => {
202
194
  const instanceRsvpKey = (profileId, recurrenceId) => `${profileId}|${normalizeRecurrenceId(recurrenceId)}`;
203
195
  /** Attending → no transitions, newest first. Later re-RSVPs do not erase them. */
204
196
  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;
197
+ const event = post.data?.type === 'event' ? post.data : undefined;
207
198
  const recurring = event ? isRecurringEvent(event) : false;
208
199
  const seriesResponse = new Map();
209
200
  const instanceResponse = new Map();
210
201
  const records = [];
211
- for (const rsvp of [...((_b = post.rsvps) !== null && _b !== void 0 ? _b : [])].sort(dateSorter())) {
202
+ for (const rsvp of [...(post.rsvps ?? [])].sort(dateSorter())) {
212
203
  const profileId = rsvp.profile.id;
213
204
  if (rsvp.response === 'no') {
214
205
  if (rsvp.recurrenceId) {
@@ -243,8 +234,7 @@ export const listRsvpCancellations = (post) => {
243
234
  return records.reverse();
244
235
  };
245
236
  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;
237
+ const event = post.data?.type === 'event' ? post.data : undefined;
248
238
  if (!event || notice.series)
249
239
  return { series: notice.series, labels: [] };
250
240
  const format = (start, end) => formatEventWhen(start, {
@@ -264,9 +254,8 @@ export const rsvpCancelWhenLabels = (post, notice) => {
264
254
  };
265
255
  };
266
256
  export const instanceRsvpIdsForProfile = (post, profileId) => {
267
- var _a;
268
257
  const ids = new Set();
269
- for (const rsvp of (_a = post.rsvps) !== null && _a !== void 0 ? _a : []) {
258
+ for (const rsvp of post.rsvps ?? []) {
270
259
  if (rsvp.profile.id !== profileId || !rsvp.recurrenceId)
271
260
  continue;
272
261
  ids.add(normalizeRecurrenceId(rsvp.recurrenceId));
@@ -278,9 +267,8 @@ export const overlaySeriesRsvpEntries = (response, instanceIds) => [
278
267
  ...instanceIds.map((recurrenceId) => ({ response, recurrenceId })),
279
268
  ];
280
269
  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;
270
+ const event = post.data?.type === 'event' ? post.data : undefined;
271
+ const maxAttendees = event?.maxAttendees;
284
272
  if (!event || !maxAttendees || !event.recurrence)
285
273
  return false;
286
274
  const occurrences = listRsvpOccurrences(event, now);
@@ -288,7 +276,7 @@ export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) =>
288
276
  // occurrence started before `now`), fall back to the series-level count.
289
277
  if (occurrences.length === 0) {
290
278
  const current = getEffectiveRsvp(post, profileId);
291
- if ((current === null || current === void 0 ? void 0 : current.response) !== 'yes' &&
279
+ if (current?.response !== 'yes' &&
292
280
  countSeriesYesRsvps(post) >= maxAttendees) {
293
281
  return true;
294
282
  }
@@ -296,27 +284,25 @@ export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) =>
296
284
  }
297
285
  return occurrences.some((occurrence) => {
298
286
  const current = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
299
- if ((current === null || current === void 0 ? void 0 : current.response) === 'yes')
287
+ if (current?.response === 'yes')
300
288
  return false;
301
289
  return countYesRsvps(post, occurrence.recurrenceId) >= maxAttendees;
302
290
  });
303
291
  };
304
292
  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))
293
+ const event = post.data?.type === 'event' ? post.data : undefined;
294
+ if (!event?.maxAttendees)
308
295
  return true;
309
296
  if (profileId) {
310
297
  const current = getEffectiveRsvp(post, profileId, recurrenceId);
311
- if ((current === null || current === void 0 ? void 0 : current.response) === 'yes')
298
+ if (current?.response === 'yes')
312
299
  return true;
313
300
  }
314
301
  return countYesRsvps(post, recurrenceId) < event.maxAttendees;
315
302
  };
316
303
  /** Series Register stays enabled while any upcoming date still has a seat. */
317
304
  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;
305
+ const event = post.data?.type === 'event' ? post.data : undefined;
320
306
  if (!event)
321
307
  return false;
322
308
  if (!event.recurrence) {
@@ -329,20 +315,19 @@ export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date(
329
315
  * then any attending instance so a partial RSVP still shows Cancel.
330
316
  */
331
317
  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)
318
+ const event = post.data?.type === 'event' ? post.data : undefined;
319
+ const scopedId = options?.lockToOccurrence
335
320
  ? options.recurrenceId
336
321
  : 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;
322
+ ? defaultRsvpRecurrenceId(event, options?.recurrenceId, options?.now)
323
+ : options?.recurrenceId;
339
324
  const scoped = getEffectiveRsvp(post, profileId, scopedId);
340
- if (options === null || options === void 0 ? void 0 : options.lockToOccurrence)
325
+ if (options?.lockToOccurrence)
341
326
  return scoped;
342
327
  if (scoped && scoped.response !== 'no')
343
328
  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)) {
329
+ if (event?.recurrence) {
330
+ for (const occurrence of listRsvpOccurrences(event, options?.now)) {
346
331
  const instance = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
347
332
  if (instance && instance.response !== 'no')
348
333
  return instance;
@@ -380,7 +365,7 @@ export const normalizeEventDataFromDb = (event) => {
380
365
  };
381
366
  export const normalizePostDataFromDb = (data) => data.type === 'event' ? normalizeEventDataFromDb(data) : data;
382
367
  export const eventDataForDbUpdate = (previous, normalized) => {
383
- if ((previous === null || previous === void 0 ? void 0 : previous.maxAttendees) != null && !('maxAttendees' in normalized)) {
368
+ if (previous?.maxAttendees != null && !('maxAttendees' in normalized)) {
384
369
  return { ...normalized, maxAttendees: null };
385
370
  }
386
371
  return normalized;
@@ -388,19 +373,18 @@ export const eventDataForDbUpdate = (previous, normalized) => {
388
373
  export const canManageEventRsvps = (profile, post) => !!(profile &&
389
374
  (post.profile.id === profile.id || canModerateJam(profile, post)));
390
375
  export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
391
- var _a;
392
- const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
393
- if (!(event === null || event === void 0 ? void 0 : event.maxAttendees) || !(profile === null || profile === void 0 ? void 0 : profile.id)) {
376
+ const event = post.data?.type === 'event' ? post.data : undefined;
377
+ if (!event?.maxAttendees || !profile?.id) {
394
378
  return { blocked: false };
395
379
  }
396
380
  if (canModerateJam(profile, post)) {
397
381
  return { blocked: false };
398
382
  }
399
383
  const myRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
400
- if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'yes') {
384
+ if (myRsvp?.response === 'yes') {
401
385
  return { blocked: false };
402
386
  }
403
- if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'removed') {
387
+ if (myRsvp?.response === 'removed') {
404
388
  return { blocked: true, reason: 'removed' };
405
389
  }
406
390
  if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
@@ -409,40 +393,31 @@ export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
409
393
  return { blocked: true, reason: 'rsvp-required' };
410
394
  };
411
395
  export const canDeletePost = (authData, post, config) => checkPostCapabilities(authData, ['core-posts-delete'], post, config).success;
412
- export const canCreatePost = (authData, type, visibility, group) => {
413
- var _a;
414
- return visibility === 'group'
415
- ? !!group &&
416
- checkGroupCapabilities(authData, [`core-posts-create-${type}`], group)
417
- .success
418
- : checkRoleCapabilities((_a = authData.profile) === null || _a === void 0 ? void 0 : _a.roles, [
419
- `core-posts-create-${type}-${visibility}`,
420
- ]).success &&
421
- scopeMatches({
422
- scopes: authData.scopes,
423
- requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
424
- });
425
- };
426
- export const canCreatePostTypeInAnyGroup = (authData, type) => {
427
- var _a, _b;
428
- return scopeMatches({
429
- scopes: authData.scopes,
430
- requiredScope: { scopeLevel: 'write', resource: { type: 'groups' } },
431
- }) &&
432
- !!((_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships) === null || _b === void 0 ? void 0 : _b.some((m) => checkGroupCapabilities(authData, [`core-posts-create-${type}`], m.group).success));
433
- };
434
- export const canCreatePostTypeWithVisibility = (authData, type, visibility) => {
435
- var _a;
436
- return visibility === 'group'
437
- ? canCreatePostTypeInAnyGroup(authData, type)
438
- : checkRoleCapabilities((_a = authData.profile) === null || _a === void 0 ? void 0 : _a.roles, [
439
- `core-posts-create-${type}-${visibility}`,
440
- ]).success &&
441
- scopeMatches({
442
- scopes: authData.scopes,
443
- requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
444
- });
445
- };
396
+ export const canCreatePost = (authData, type, visibility, group) => visibility === 'group'
397
+ ? !!group &&
398
+ checkGroupCapabilities(authData, [`core-posts-create-${type}`], group)
399
+ .success
400
+ : checkRoleCapabilities(authData.profile?.roles, [
401
+ `core-posts-create-${type}-${visibility}`,
402
+ ]).success &&
403
+ scopeMatches({
404
+ scopes: authData.scopes,
405
+ requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
406
+ });
407
+ export const canCreatePostTypeInAnyGroup = (authData, type) => scopeMatches({
408
+ scopes: authData.scopes,
409
+ requiredScope: { scopeLevel: 'write', resource: { type: 'groups' } },
410
+ }) &&
411
+ !!authData.profile?.memberships?.some((m) => checkGroupCapabilities(authData, [`core-posts-create-${type}`], m.group).success);
412
+ export const canCreatePostTypeWithVisibility = (authData, type, visibility) => visibility === 'group'
413
+ ? canCreatePostTypeInAnyGroup(authData, type)
414
+ : checkRoleCapabilities(authData.profile?.roles, [
415
+ `core-posts-create-${type}-${visibility}`,
416
+ ]).success &&
417
+ scopeMatches({
418
+ scopes: authData.scopes,
419
+ requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
420
+ });
446
421
  export const canCreatePostType = (authData, type) => visibilityTypeValues.some((visibility) => canCreatePostTypeWithVisibility(authData, type, visibility));
447
422
  /**
448
423
  * Whether Reply / Repost / Like should look live. Non-members of a group
@@ -451,15 +426,14 @@ export const canCreatePostType = (authData, type) => visibilityTypeValues.some((
451
426
  * and reposts need create-*, likes need core-posts-react.
452
427
  */
453
428
  export const getPostActionAvailability = (authData, post, config) => {
454
- var _a, _b, _c;
455
429
  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; }));
430
+ const membershipExists = !!authData.profile?.memberships?.some((m) => m.group.id === post.group?.id || m.group.id === post.groupId);
457
431
  if (isGroupPost && !membershipExists) {
458
432
  return { canReply: false, canRepost: false, canReact: false };
459
433
  }
460
434
  const canReply = checkPostCapabilities(authData, ['core-posts-reply'], post, config)
461
435
  .success &&
462
- canCreatePost(authData, 'note', post.visibility, (_c = post.group) !== null && _c !== void 0 ? _c : undefined);
436
+ canCreatePost(authData, 'note', post.visibility, post.group ?? undefined);
463
437
  const canReact = checkPostCapabilities(authData, ['core-posts-react'], post, config).success;
464
438
  const canRepost = post.group
465
439
  ? checkGroupCapabilities(authData, [`core-posts-create-${post.type}`], post.group).success
@@ -486,9 +460,8 @@ export const toHiddenPost = (post) => ({
486
460
  });
487
461
  export const isHiddenPost = (post) => !!post.hidden;
488
462
  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;
463
+ const ids = new Set((post.audience ?? []).map((member) => member.id).filter(Boolean));
464
+ const creatorId = post.creatorId ?? post.profile?.id;
492
465
  if (creatorId)
493
466
  ids.add(creatorId);
494
467
  return ids;
@@ -496,7 +469,7 @@ const participantIds = (post) => {
496
469
  export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
497
470
  if (!viewer || post.visibility !== 'direct')
498
471
  return false;
499
- const blocked = blockedIds instanceof Set ? blockedIds : new Set(blockedIds !== null && blockedIds !== void 0 ? blockedIds : []);
472
+ const blocked = blockedIds instanceof Set ? blockedIds : new Set(blockedIds ?? []);
500
473
  if (!blocked.size)
501
474
  return false;
502
475
  const others = participantIds(post);
@@ -9,7 +9,7 @@ export const clampProfileDisplayName = (displayName) => {
9
9
  const clamped = displayName.slice(0, PROFILE_DISPLAY_NAME_MAX_LENGTH);
10
10
  return clamped || undefined;
11
11
  };
12
- export const isDeletedProfile = (profile) => !!(profile === null || profile === void 0 ? void 0 : profile.deletedAt);
12
+ export const isDeletedProfile = (profile) => !!profile?.deletedAt;
13
13
  /**
14
14
  * Strip PII from a soft-deleted profile for public API / UI surfaces.
15
15
  * Keeps id + timestamps (including deletedAt) so clients can detect the state.
@@ -68,7 +68,7 @@ export const toDeletedProfileWithMeta = (profile) => ({
68
68
  export const tombstoneProfileWithMetaIfDeleted = (profile) => profile && isDeletedProfile(profile)
69
69
  ? toDeletedProfileWithMeta(profile)
70
70
  : profile;
71
- export const profileName = (profile) => (profile === null || profile === void 0 ? void 0 : profile.displayName) || (profile === null || profile === void 0 ? void 0 : profile.handle);
71
+ export const profileName = (profile) => profile?.displayName || profile?.handle;
72
72
  export const matchesQuery = (profile, query, queryOptions = { handle: true, displayName: true }) => !!(profile &&
73
73
  (query.startsWith('@')
74
74
  ? profile.handle && containsIgnoreCase(profile.handle, query.substring(1))
@@ -81,7 +81,7 @@ export const matchesQuery = (profile, query, queryOptions = { handle: true, disp
81
81
  export const inviteLinkMatchesQuery = (inviteLink, query, queryOptions = { handle: true, displayName: true, slug: true, group: true }) => {
82
82
  const profile = inviteLink.profile;
83
83
  if (query.startsWith('@')) {
84
- return !!((profile === null || profile === void 0 ? void 0 : profile.handle) && containsIgnoreCase(profile.handle, query.substring(1)));
84
+ return !!(profile?.handle && containsIgnoreCase(profile.handle, query.substring(1)));
85
85
  }
86
86
  const groupMatches = queryOptions.group &&
87
87
  inviteLink.groups.some((group) => containsIgnoreCase(group.handle, query) ||
@@ -98,31 +98,24 @@ export const inviteLinkMatchesQuery = (inviteLink, query, queryOptions = { handl
98
98
  inviteLink.slug &&
99
99
  containsIgnoreCase(inviteLink.slug, query)))));
100
100
  };
101
- export const sortProfiles = (profiles) => {
102
- var _a;
103
- return (_a = profiles === null || profiles === void 0 ? void 0 : profiles.sort((a, b) => profileName(a).localeCompare(profileName(b)))) !== null && _a !== void 0 ? _a : [];
104
- };
105
- export const isStripeActive = (sub) => (sub === null || sub === void 0 ? void 0 : sub.status) === 'active' || (sub === null || sub === void 0 ? void 0 : sub.status) === 'trialing';
106
- export const getStripeCustomerId = (profileSettings) => { var _a; return (_a = profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.stripeSettings) === null || _a === void 0 ? void 0 : _a.customerId; };
101
+ export const sortProfiles = (profiles) => profiles?.sort((a, b) => profileName(a).localeCompare(profileName(b))) ?? [];
102
+ export const isStripeActive = (sub) => sub?.status === 'active' || sub?.status === 'trialing';
103
+ export const getStripeCustomerId = (profileSettings) => profileSettings?.stripeSettings?.customerId;
107
104
  export const isOwnerProfile = (profile) => {
108
- return profile === null || profile === void 0 ? void 0 : profile.roles.some((role) => role.key === 'owner');
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
- ];
105
+ return profile?.roles.some((role) => role.key === 'owner');
118
106
  };
107
+ export const blockedPairIds = (profile) => [
108
+ ...new Set([
109
+ ...(profile?.blockingIds ?? []),
110
+ ...(profile?.blockedByIds ?? []),
111
+ ]),
112
+ ];
119
113
  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); };
114
+ export const viewerBlockedTarget = (profile, otherId) => !!otherId && (profile?.blockingIds ?? []).includes(otherId);
115
+ export const targetBlockedViewer = (profile, otherId) => !!otherId && (profile?.blockedByIds ?? []).includes(otherId);
122
116
  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));
117
+ const otherIds = new Set((b.controllers ?? []).map((account) => account.id));
118
+ return (a.controllers ?? []).some((account) => otherIds.has(account.id));
126
119
  };
127
120
  export const toBlockedProfileStub = (profile) => ({
128
121
  id: profile.id,
@@ -13,7 +13,6 @@ export const pushSubscriptionDeliveryKey = (subscription) => {
13
13
  }
14
14
  };
15
15
  export const pushSubscriptionEndpoint = (subscription) => 'endpoint' in subscription ? subscription.endpoint : undefined;
16
- export const pushSubscriptionIsMobile = (subscription) => {
17
- var _a;
18
- return ((_a = pushSubscriptionDeviceName(subscription)) === null || _a === void 0 ? void 0 : _a.toLowerCase().match(/phone|android|mobile|ios/)) != null;
19
- };
16
+ export const pushSubscriptionIsMobile = (subscription) => pushSubscriptionDeviceName(subscription)
17
+ ?.toLowerCase()
18
+ .match(/phone|android|mobile|ios/) != null;
@@ -51,17 +51,16 @@ export const getPublicPostReadScope = (postId) => ({
51
51
  * that post id (same pattern as {@link withPublicGroupReadScopes}).
52
52
  */
53
53
  export const withPublicPostReadScopes = (authData, post, neededCapabilities) => {
54
- var _a;
55
54
  if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
56
55
  return authData;
57
56
  }
58
57
  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; });
58
+ neededCapabilities.every((c) => post.group?.capabilities?.none?.add?.includes(c) ?? false);
60
59
  if (post.visibility !== 'public' && !publicGroupPost) {
61
60
  return authData;
62
61
  }
63
62
  const publicReadScope = getPublicPostReadScope(post.id);
64
- const scopes = (_a = authData.scopes) !== null && _a !== void 0 ? _a : [];
63
+ const scopes = authData.scopes ?? [];
65
64
  if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
66
65
  return authData;
67
66
  }
@@ -76,16 +75,15 @@ export const getPublicGroupReadScope = (groupId) => ({
76
75
  * without auth (same pattern as {@link withPublicPostReadScopes}).
77
76
  */
78
77
  export const withPublicGroupReadScopes = (authData, group, neededCapabilities) => {
79
- var _a, _b, _c, _d;
80
78
  if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
81
79
  return authData;
82
80
  }
83
- const noneAdd = (_c = (_b = (_a = group.capabilities) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : [];
81
+ const noneAdd = group.capabilities?.none?.add ?? [];
84
82
  if (!neededCapabilities.every((c) => noneAdd.includes(c))) {
85
83
  return authData;
86
84
  }
87
85
  const publicReadScope = getPublicGroupReadScope(group.id);
88
- const scopes = (_d = authData.scopes) !== null && _d !== void 0 ? _d : [];
86
+ const scopes = authData.scopes ?? [];
89
87
  if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
90
88
  return authData;
91
89
  }
@@ -102,16 +100,15 @@ export const getPublicProfileReadScope = (profileId) => ({
102
100
  * still enforced by `ensureAccess` on the profile endpoints.
103
101
  */
104
102
  export const withPublicProfileReadScopes = (authData, profile, neededCapabilities, config) => {
105
- var _a, _b, _c, _d;
106
103
  if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
107
104
  return authData;
108
105
  }
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 : [];
106
+ const noneAdd = config.profile?.none?.add ?? [];
110
107
  if (!neededCapabilities.every((c) => noneAdd.includes(c))) {
111
108
  return authData;
112
109
  }
113
110
  const publicReadScope = getPublicProfileReadScope(profile.id);
114
- const scopes = (_d = authData.scopes) !== null && _d !== void 0 ? _d : [];
111
+ const scopes = authData.scopes ?? [];
115
112
  if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
116
113
  return authData;
117
114
  }
@@ -16,16 +16,15 @@ export const isAllowedSsoLoginUrl = (url) => {
16
16
  };
17
17
  export const oidcAuthorizePath = (id) => `/api/openpeeps/core/v1/sso/oidc/${encodeURIComponent(id)}/authorize`;
18
18
  export const ssoLoginDestinations = (sso) => {
19
- var _a, _b;
20
19
  const destinations = [];
21
- for (const provider of (_a = sso === null || sso === void 0 ? void 0 : sso.generic) !== null && _a !== void 0 ? _a : []) {
20
+ for (const provider of sso?.generic ?? []) {
22
21
  destinations.push({
23
22
  href: provider.loginLink,
24
23
  name: provider.name,
25
24
  testId: `auth-login-generic-${provider.id}`,
26
25
  });
27
26
  }
28
- for (const provider of (_b = sso === null || sso === void 0 ? void 0 : sso.oidc) !== null && _b !== void 0 ? _b : []) {
27
+ for (const provider of sso?.oidc ?? []) {
29
28
  destinations.push({
30
29
  href: oidcAuthorizePath(provider.id),
31
30
  name: provider.name,
@@ -35,7 +34,7 @@ export const ssoLoginDestinations = (sso) => {
35
34
  return destinations;
36
35
  };
37
36
  export const resolveOnlySsoView = (sso, searchParams) => {
38
- if (!(sso === null || sso === void 0 ? void 0 : sso.onlySSO) || searchParams.has(LOCAL_LOGIN_PARAM)) {
37
+ if (!sso?.onlySSO || searchParams.has(LOCAL_LOGIN_PARAM)) {
39
38
  return { mode: 'form' };
40
39
  }
41
40
  const destinations = ssoLoginDestinations(sso);
@@ -51,8 +50,7 @@ export const publicSsoInfo = (sso) => {
51
50
  name: provider.name,
52
51
  }));
53
52
  const generic = sso.generic.flatMap((provider) => {
54
- var _a;
55
- const loginLink = (_a = provider.loginLink) === null || _a === void 0 ? void 0 : _a.trim();
53
+ const loginLink = provider.loginLink?.trim();
56
54
  if (!loginLink || !isAllowedSsoLoginUrl(loginLink))
57
55
  return [];
58
56
  return [