@openpeepshq/core 0.1.34 → 0.1.35

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 (165) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/index.d.ts +1 -0
  23. package/dist/config/index.js +9 -11
  24. package/dist/db/explorer/query.js +9 -8
  25. package/dist/db/explorer/sql.js +8 -8
  26. package/dist/db/helpers.js +15 -5
  27. package/dist/db/migration/importCollections.js +15 -18
  28. package/dist/db/migration/shared.js +15 -35
  29. package/dist/db/pg/client.js +4 -7
  30. package/dist/db/pg/filters/index.js +1 -1
  31. package/dist/db/pg/filters/posts.d.ts +2 -0
  32. package/dist/db/pg/filters/posts.js +2 -0
  33. package/dist/db/pg/helpers.js +2 -14
  34. package/dist/db/pg/map/filters.js +8 -8
  35. package/dist/db/pg/map/helpers.js +5 -1
  36. package/dist/db/pg/map/index.js +46 -51
  37. package/dist/db/pg/map/mutations.js +56 -21
  38. package/dist/db/pg/map/registry.js +87 -50
  39. package/dist/db/pg/map/relations.js +67 -63
  40. package/dist/db/pg/map/search.js +15 -37
  41. package/dist/db/pg/mappers.js +13 -7
  42. package/dist/db/pg/migrate.js +2 -3
  43. package/dist/db/pg/queries/activity.js +2 -2
  44. package/dist/db/pg/queries/derived.js +8 -12
  45. package/dist/db/pg/schema/documents.js +119 -18
  46. package/dist/db/pg/schema/edges.js +7 -1
  47. package/dist/db/pg/schema/index.js +5 -1
  48. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  49. package/dist/db/pg/sql/meta/_journal.json +8 -1
  50. package/dist/db/replaceOrigin.js +1 -1
  51. package/dist/email/queueStats.js +8 -11
  52. package/dist/email/render.js +7 -4
  53. package/dist/email/send.js +19 -17
  54. package/dist/email/smtpTest.js +10 -6
  55. package/dist/errors/index.js +1 -1
  56. package/dist/events/once.js +2 -4
  57. package/dist/federation/activities.js +1 -2
  58. package/dist/groups/helpers.js +1 -2
  59. package/dist/groups/mutations.js +1 -1
  60. package/dist/hashtags/finders.js +2 -2
  61. package/dist/inviteLinks/mutations.js +2 -3
  62. package/dist/jams/export.js +5 -7
  63. package/dist/jams/finders.js +4 -1
  64. package/dist/jams/health.d.ts +6 -4
  65. package/dist/jams/health.js +15 -11
  66. package/dist/jams/helpers.js +6 -2
  67. package/dist/jams/index.js +2 -2
  68. package/dist/jams/jobs.js +1 -2
  69. package/dist/jams/livekit.js +8 -8
  70. package/dist/jams/recording.js +1 -1
  71. package/dist/jams/token.js +13 -17
  72. package/dist/jobs/index.js +7 -6
  73. package/dist/jobs/jobDetail.js +5 -6
  74. package/dist/jobs/jobLog.js +2 -3
  75. package/dist/lib/streams.js +4 -39
  76. package/dist/lib/zodDeepPartial.d.ts +1 -1
  77. package/dist/lib/zodDeepPartial.js +1 -1
  78. package/dist/log/index.js +13 -29
  79. package/dist/media/index.js +50 -4
  80. package/dist/media/jobs.js +1 -2
  81. package/dist/media/openpeeps/index.js +11 -46
  82. package/dist/media/processing.js +7 -4
  83. package/dist/media/streaming.js +5 -5
  84. package/dist/media/streamingCleanupJobs.js +1 -2
  85. package/dist/media/streamingJobs.js +3 -4
  86. package/dist/media/streamingPrewarm.js +7 -11
  87. package/dist/mediaAttachments/index.js +6 -2
  88. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  89. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  90. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  91. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  92. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  93. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  94. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  95. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  96. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  97. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  98. package/dist/notifications/defaultNotifications/newGroupPost/index.js +6 -7
  99. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  100. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  101. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  102. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  103. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  104. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  105. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  106. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  107. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  108. package/dist/notifications/fcmCredential.js +1 -1
  109. package/dist/notifications/finders.js +1 -1
  110. package/dist/notifications/helpers.js +13 -10
  111. package/dist/notifications/jobs.js +10 -7
  112. package/dist/notifications/mutations.js +4 -1
  113. package/dist/notifications/push.js +11 -16
  114. package/dist/performance/index.js +3 -3
  115. package/dist/plugins/helpers.js +3 -6
  116. package/dist/plugins/index.js +2 -3
  117. package/dist/plugins/install.js +31 -17
  118. package/dist/plugins/pluginAuth.js +3 -4
  119. package/dist/plugins/state.js +2 -3
  120. package/dist/posts/activity.js +1 -2
  121. package/dist/posts/contextClosure.js +1 -2
  122. package/dist/posts/conversationQueries.js +2 -4
  123. package/dist/posts/eventAgenda.js +8 -5
  124. package/dist/posts/eventOccurrences.js +2 -2
  125. package/dist/posts/finders.d.ts +42 -2
  126. package/dist/posts/finders.js +21 -9
  127. package/dist/posts/helpers/filters.js +2 -3
  128. package/dist/posts/helpers/index.d.ts +152 -0
  129. package/dist/posts/helpers/index.js +43 -27
  130. package/dist/posts/mapping.d.ts +546 -14
  131. package/dist/posts/mapping.js +60 -18
  132. package/dist/posts/mutations.d.ts +76 -0
  133. package/dist/posts/mutations.js +46 -31
  134. package/dist/posts/pollEnd.js +3 -6
  135. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  136. package/dist/posts/threadPreview.js +1 -1
  137. package/dist/processingStats/queries.js +6 -7
  138. package/dist/profileSettings/cache.js +1 -2
  139. package/dist/profiles/activitySummary.js +23 -28
  140. package/dist/profiles/cache.js +15 -8
  141. package/dist/profiles/export.js +30 -39
  142. package/dist/profiles/finders.js +7 -5
  143. package/dist/profiles/mutations.js +3 -5
  144. package/dist/redis/connection.js +1 -1
  145. package/dist/reports/helpers.js +7 -3
  146. package/dist/roles/mutations.js +20 -21
  147. package/dist/search/finders.js +15 -3
  148. package/dist/search/helpers.js +1 -1
  149. package/dist/sentry/index.js +9 -11
  150. package/dist/seo/index.d.ts +50 -0
  151. package/dist/seo/index.js +145 -0
  152. package/dist/seo/route.d.ts +18 -0
  153. package/dist/seo/route.js +19 -0
  154. package/dist/server/index.d.ts +1 -0
  155. package/dist/server/index.js +16 -11
  156. package/dist/server/status.js +6 -7
  157. package/dist/session/index.js +2 -2
  158. package/dist/stats/finders.js +13 -4
  159. package/dist/stats/helpers.js +4 -1
  160. package/dist/stats/mapping.d.ts +39 -1
  161. package/dist/stats/mapping.js +9 -2
  162. package/dist/stripe/cache.js +5 -6
  163. package/dist/stripe/connection.js +3 -4
  164. package/dist/stripe/helpers.js +15 -20
  165. package/package.json +5 -6
@@ -18,19 +18,26 @@ export const clearProfileCache = async (profile) => {
18
18
  publicProfilesCache.del(`all:${profile.id}`),
19
19
  ]);
20
20
  };
21
- const withEmptyFollowGraphs = (profile) => {
22
- var _a, _b, _c, _d, _e, _f;
23
- return (Object.assign(Object.assign({}, profile), { roles: (_a = profile.roles) !== null && _a !== void 0 ? _a : [], followers: [], following: [], controllers: (_b = profile.controllers) !== null && _b !== void 0 ? _b : [], memberships: (_c = profile.memberships) !== null && _c !== void 0 ? _c : [], profileStats: (_d = profile.profileStats) !== null && _d !== void 0 ? _d : {
24
- followersCount: 0,
25
- followingCount: 0,
26
- }, blockingIds: (_e = profile.blockingIds) !== null && _e !== void 0 ? _e : [], blockedByIds: (_f = profile.blockedByIds) !== null && _f !== void 0 ? _f : [] }));
27
- };
21
+ const withEmptyFollowGraphs = (profile) => ({
22
+ ...profile,
23
+ roles: profile.roles ?? [],
24
+ followers: [],
25
+ following: [],
26
+ controllers: profile.controllers ?? [],
27
+ memberships: profile.memberships ?? [],
28
+ profileStats: profile.profileStats ?? {
29
+ followersCount: 0,
30
+ followingCount: 0,
31
+ },
32
+ blockingIds: profile.blockingIds ?? [],
33
+ blockedByIds: profile.blockedByIds ?? [],
34
+ });
28
35
  const withBlockIds = async (profile) => {
29
36
  if (!profile)
30
37
  return undefined;
31
38
  const { db } = await allpeepDb();
32
39
  const { blockingIds, blockedByIds } = await loadBlockIds(db, profile.id);
33
- return Object.assign(Object.assign({}, profile), { blockingIds, blockedByIds });
40
+ return { ...profile, blockingIds, blockedByIds };
34
41
  };
35
42
  export const getProfile = async (id, ignoreSoftDelete = false) => profilesCache.wrap(id, () => allpeepDb()
36
43
  .then(({ db }) => ignoreSoftDelete
@@ -9,14 +9,11 @@ const emptyStats = () => ({
9
9
  reactionsCount: 0,
10
10
  lastSeen: null,
11
11
  });
12
- const toMemberExportStats = (row) => {
13
- var _a, _b, _c;
14
- return ({
15
- postsCount: (_a = row === null || row === void 0 ? void 0 : row.postsCount) !== null && _a !== void 0 ? _a : 0,
16
- reactionsCount: (_b = row === null || row === void 0 ? void 0 : row.reactionsCount) !== null && _b !== void 0 ? _b : 0,
17
- lastSeen: (_c = row === null || row === void 0 ? void 0 : row.lastSeen) !== null && _c !== void 0 ? _c : null,
18
- });
19
- };
12
+ const toMemberExportStats = (row) => ({
13
+ postsCount: row?.postsCount ?? 0,
14
+ reactionsCount: row?.reactionsCount ?? 0,
15
+ lastSeen: row?.lastSeen ?? null,
16
+ });
20
17
  export const listMembersForExport = async () => {
21
18
  const { db } = await allpeepDb();
22
19
  const [profiles, statsRows] = await Promise.all([
@@ -24,22 +21,19 @@ export const listMembersForExport = async () => {
24
21
  membersExportMapping.filter(guestFilter).all(db),
25
22
  ]);
26
23
  const statsById = new Map(statsRows.map((row) => [row.id, toMemberExportStats(row)]));
27
- return profiles.map((profile) => {
28
- var _a;
29
- return (Object.assign(Object.assign({}, profile), ((_a = statsById.get(profile.id)) !== null && _a !== void 0 ? _a : emptyStats())));
30
- });
24
+ return profiles.map((profile) => ({
25
+ ...profile,
26
+ ...(statsById.get(profile.id) ?? emptyStats()),
27
+ }));
31
28
  };
32
29
  const formatCustomFields = (fields) => formatMemberExportCustomFields(fields);
33
30
  const formatEmailVerified = (controllers) => {
34
- var _a;
35
- const validated = (_a = controllers[0]) === null || _a === void 0 ? void 0 : _a.emailValidated;
31
+ const validated = controllers[0]?.emailValidated;
36
32
  return validated == null ? '' : validated ? 'yes' : 'no';
37
33
  };
38
- const formatGroups = (memberships) => {
39
- var _a;
40
- return (_a = memberships === null || memberships === void 0 ? void 0 : memberships.map((membership) => membership.group.displayName).join('; ')) !== null && _a !== void 0 ? _a : '';
41
- };
42
- const formatRoles = (roles) => { var _a; return (_a = roles === null || roles === void 0 ? void 0 : roles.map((role) => role.displayName || role.key).join('; ')) !== null && _a !== void 0 ? _a : ''; };
34
+ const formatGroups = (memberships) => memberships?.map((membership) => membership.group.displayName).join('; ') ??
35
+ '';
36
+ const formatRoles = (roles) => roles?.map((role) => role.displayName || role.key).join('; ') ?? '';
43
37
  const memberExportHeaders = [
44
38
  'Email',
45
39
  'Email Verified',
@@ -61,25 +55,22 @@ export const exportMembersCsv = async () => {
61
55
  const members = await listMembersForExport();
62
56
  return [
63
57
  toCsvRow([...memberExportHeaders]),
64
- ...members.map((member) => {
65
- var _a, _b, _c, _d, _e, _f, _g;
66
- return toCsvRow([
67
- (_b = (_a = member.controllers[0]) === null || _a === void 0 ? void 0 : _a.email) !== null && _b !== void 0 ? _b : '',
68
- formatEmailVerified(member.controllers),
69
- member.createdAt,
70
- member.handle,
71
- (_c = member.displayName) !== null && _c !== void 0 ? _c : '',
72
- formatRoles(member.roles),
73
- (_d = member.bio) !== null && _d !== void 0 ? _d : '',
74
- (_f = (_e = member.location) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : '',
75
- formatCustomFields(member.fields),
76
- formatGroups(member.memberships),
77
- (_g = member.lastSeen) !== null && _g !== void 0 ? _g : '',
78
- member.postsCount,
79
- member.reactionsCount,
80
- member.profileStats.followersCount,
81
- member.profileStats.followingCount,
82
- ]);
83
- }),
58
+ ...members.map((member) => toCsvRow([
59
+ member.controllers[0]?.email ?? '',
60
+ formatEmailVerified(member.controllers),
61
+ member.createdAt,
62
+ member.handle,
63
+ member.displayName ?? '',
64
+ formatRoles(member.roles),
65
+ member.bio ?? '',
66
+ member.location?.text ?? '',
67
+ formatCustomFields(member.fields),
68
+ formatGroups(member.memberships),
69
+ member.lastSeen ?? '',
70
+ member.postsCount,
71
+ member.reactionsCount,
72
+ member.profileStats.followersCount,
73
+ member.profileStats.followingCount,
74
+ ])),
84
75
  ].join('\n');
85
76
  };
@@ -32,13 +32,15 @@ export const follows = (follower, followed) => allpeepDb().then(({ db }) => foll
32
32
  export const listGroupMembers = (group) => allpeepDb()
33
33
  .then(({ db }) => groupsMapping.relationsFrom(group, membersRelation).all(db))
34
34
  .then((members) => Promise.all(members
35
- .filter((m) => { var _a; return (_a = m.profile) === null || _a === void 0 ? void 0 : _a.id; })
36
- .map(async (m) => (Object.assign(Object.assign({}, m), { profile: (await getProfile(m.profile.id)) })))))
35
+ .filter((m) => m.profile?.id)
36
+ .map(async (m) => ({
37
+ ...m,
38
+ profile: (await getProfile(m.profile.id)),
39
+ }))))
37
40
  .then((members) => members.filter((m) => !!m.profile));
38
41
  export const listCommonGroups = async (profile1, profile2) => {
39
- var _a, _b;
40
42
  const groups = await listGroups({ profile: profile1, scopes: [] });
41
- const profile1GroupIds = new Set(((_a = profile1.memberships) === null || _a === void 0 ? void 0 : _a.map((m) => m.group.id)) || []);
42
- const profile2GroupIds = new Set(((_b = profile2.memberships) === null || _b === void 0 ? void 0 : _b.map((m) => m.group.id)) || []);
43
+ const profile1GroupIds = new Set(profile1.memberships?.map((m) => m.group.id) || []);
44
+ const profile2GroupIds = new Set(profile2.memberships?.map((m) => m.group.id) || []);
43
45
  return groups.filter((group) => profile1GroupIds.has(group.id) && profile2GroupIds.has(group.id));
44
46
  };
@@ -11,13 +11,12 @@ import { deleteBlock, dropFollowsBetween, insertBlock, listBlockingIds, } from '
11
11
  import { localActorScalars } from '../federation/identity.js';
12
12
  import { uuidv7 } from 'uuidv7';
13
13
  export const createProfile = async (data, controllingAccount) => {
14
- var _a;
15
14
  await assertProfileCapacity();
16
15
  const db = await allpeepDb().then((db) => db.db);
17
16
  const id = uuidv7();
18
- const domain = (_a = data.activityPub) === null || _a === void 0 ? void 0 : _a.domain;
17
+ const domain = data.activityPub?.domain;
19
18
  const actor = data.type === 'local' && domain ? localActorScalars(id, domain) : {};
20
- const profile = await profilesMapping.create(db, Object.assign(Object.assign(Object.assign({}, data), { id }), actor));
19
+ const profile = await profilesMapping.create(db, { ...data, id, ...actor });
21
20
  if (controllingAccount) {
22
21
  await giveControl(db, controllingAccount, profile);
23
22
  await accountsCache.del(controllingAccount.id);
@@ -50,11 +49,10 @@ export const pinPostOnProfile = async (profile, pinnedPostId) => {
50
49
  return updated;
51
50
  };
52
51
  export const deleteProfile = async (profileId) => {
53
- var _a, _b;
54
52
  const db = await allpeepDb().then((db) => db.db);
55
53
  const profileToDelete = await getProfile(profileId);
56
54
  if (profileToDelete) {
57
- await Promise.all((_b = (_a = profileToDelete.controllers) === null || _a === void 0 ? void 0 : _a.map((account) => accountsCache.del(account.id))) !== null && _b !== void 0 ? _b : []);
55
+ await Promise.all(profileToDelete.controllers?.map((account) => accountsCache.del(account.id)) ?? []);
58
56
  if (profileToDelete.following && profileToDelete.following.length > 0) {
59
57
  await Promise.all(profileToDelete.following.map((followed) => profilesCache.del(followed.id)));
60
58
  }
@@ -21,7 +21,7 @@ export const closeRedisConnections = async () => {
21
21
  try {
22
22
  await conn.disconnect();
23
23
  }
24
- catch (_a) {
24
+ catch {
25
25
  // already closed
26
26
  }
27
27
  }));
@@ -3,9 +3,13 @@ import { collectionInfos } from '../db/index.js';
3
3
  import { tombstoneProfileWithMetaIfDeleted } from '@openpeepshq/common/lib';
4
4
  import { transformPost } from '../posts/index.js';
5
5
  export const transformReport = async (report) => {
6
- var _a;
7
- const rawPosts = ((_a = report.reportedPosts) !== null && _a !== void 0 ? _a : []);
8
- return Object.assign(Object.assign({}, report), { reporterProfile: tombstoneProfileWithMetaIfDeleted(report.reporterProfile), reportedProfile: tombstoneProfileWithMetaIfDeleted(report.reportedProfile), reportedPosts: await Promise.all(rawPosts.map((post) => transformPost(post))) });
6
+ const rawPosts = (report.reportedPosts ?? []);
7
+ return {
8
+ ...report,
9
+ reporterProfile: tombstoneProfileWithMetaIfDeleted(report.reporterProfile),
10
+ reportedProfile: tombstoneProfileWithMetaIfDeleted(report.reportedProfile),
11
+ reportedPosts: await Promise.all(rawPosts.map((post) => transformPost(post))),
12
+ };
9
13
  };
10
14
  export const transformReports = async (reports) => Promise.all(reports.map(transformReport));
11
15
  export const createdReportConnector = connector(collectionInfos.profilesCollection, collectionInfos.reportsCollection, collectionInfos.createdReportCollection);
@@ -15,11 +15,8 @@ export const createRole = (roleData) => allpeepDb().then(async ({ db }) => {
15
15
  }
16
16
  return rolesMapping.create(db, roleData);
17
17
  });
18
- const capabilitiesMatchFactory = (capabilities, factoryRole) => {
19
- var _a, _b;
20
- return capabilitySetsEqual(capabilities === null || capabilities === void 0 ? void 0 : capabilities.add, (_a = factoryRole.capabilities) === null || _a === void 0 ? void 0 : _a.add) &&
21
- capabilitySetsEqual(capabilities === null || capabilities === void 0 ? void 0 : capabilities.remove, (_b = factoryRole.capabilities) === null || _b === void 0 ? void 0 : _b.remove);
22
- };
18
+ const capabilitiesMatchFactory = (capabilities, factoryRole) => capabilitySetsEqual(capabilities?.add, factoryRole.capabilities?.add) &&
19
+ capabilitySetsEqual(capabilities?.remove, factoryRole.capabilities?.remove);
23
20
  /**
24
21
  * Effective default flag for a write: an explicit `true` wins, and
25
22
  * capabilities that exactly match the system defaults re-adopt the role as a
@@ -28,15 +25,18 @@ const capabilitiesMatchFactory = (capabilities, factoryRole) => {
28
25
  * the current defaults version when the write does not set one explicitly.
29
26
  */
30
27
  const withDefaultAdoption = (existingRole, roleData) => {
31
- var _a;
32
- const factoryRole = defaultRoles.find((role) => { var _a; return role.key === ((_a = roleData.key) !== null && _a !== void 0 ? _a : existingRole === null || existingRole === void 0 ? void 0 : existingRole.key); });
28
+ const factoryRole = defaultRoles.find((role) => role.key === (roleData.key ?? existingRole?.key));
33
29
  if (!factoryRole)
34
30
  return roleData;
35
- const matchesFactory = capabilitiesMatchFactory((_a = roleData.capabilities) !== null && _a !== void 0 ? _a : existingRole === null || existingRole === void 0 ? void 0 : existingRole.capabilities, factoryRole);
31
+ const matchesFactory = capabilitiesMatchFactory(roleData.capabilities ?? existingRole?.capabilities, factoryRole);
36
32
  const isDefault = roleData.default === true || matchesFactory;
37
- return Object.assign(Object.assign(Object.assign({}, roleData), { default: isDefault }), (matchesFactory && roleData.baseVersion === undefined
38
- ? { baseVersion: currentRoleDefaults.version }
39
- : {}));
33
+ return {
34
+ ...roleData,
35
+ default: isDefault,
36
+ ...(matchesFactory && roleData.baseVersion === undefined
37
+ ? { baseVersion: currentRoleDefaults.version }
38
+ : {}),
39
+ };
40
40
  };
41
41
  /**
42
42
  * Applies the base→current delta of the system defaults to a capability
@@ -45,16 +45,16 @@ const withDefaultAdoption = (existingRole, roleData) => {
45
45
  */
46
46
  const applyCapabilityDelta = (capabilities, base, current) => {
47
47
  const delta = (list, from, to) => {
48
- const removed = (from !== null && from !== void 0 ? from : []).filter((c) => !(to !== null && to !== void 0 ? to : []).includes(c));
49
- const added = (to !== null && to !== void 0 ? to : []).filter((c) => !(from !== null && from !== void 0 ? from : []).includes(c));
48
+ const removed = (from ?? []).filter((c) => !(to ?? []).includes(c));
49
+ const added = (to ?? []).filter((c) => !(from ?? []).includes(c));
50
50
  return [
51
- ...(list !== null && list !== void 0 ? list : []).filter((c) => !removed.includes(c)),
52
- ...added.filter((c) => !(list !== null && list !== void 0 ? list : []).includes(c)),
51
+ ...(list ?? []).filter((c) => !removed.includes(c)),
52
+ ...added.filter((c) => !(list ?? []).includes(c)),
53
53
  ];
54
54
  };
55
55
  return {
56
- add: delta(capabilities === null || capabilities === void 0 ? void 0 : capabilities.add, base === null || base === void 0 ? void 0 : base.add, current === null || current === void 0 ? void 0 : current.add),
57
- remove: delta(capabilities === null || capabilities === void 0 ? void 0 : capabilities.remove, base === null || base === void 0 ? void 0 : base.remove, current === null || current === void 0 ? void 0 : current.remove),
56
+ add: delta(capabilities?.add, base?.add, current?.add),
57
+ remove: delta(capabilities?.remove, base?.remove, current?.remove),
58
58
  };
59
59
  };
60
60
  /**
@@ -64,17 +64,16 @@ const applyCapabilityDelta = (capabilities, base, current) => {
64
64
  * role untouched — the anchor only moves when capabilities actually change.
65
65
  */
66
66
  const rebaseRoleToCurrentDefaults = (existingRole, factoryRole) => {
67
- var _a, _b, _c;
68
67
  const baseVersion = existingRole.baseVersion;
69
68
  if (!baseVersion || baseVersion === currentRoleDefaults.version) {
70
69
  return null;
71
70
  }
72
- const baseRole = (_a = findRoleDefaultsVersion(baseVersion)) === null || _a === void 0 ? void 0 : _a.roles.find((role) => role.key === factoryRole.key);
71
+ const baseRole = findRoleDefaultsVersion(baseVersion)?.roles.find((role) => role.key === factoryRole.key);
73
72
  if (!baseRole)
74
73
  return null;
75
74
  const capabilities = applyCapabilityDelta(existingRole.capabilities, baseRole.capabilities, factoryRole.capabilities);
76
- const unchanged = capabilitySetsEqual((_b = existingRole.capabilities) === null || _b === void 0 ? void 0 : _b.add, capabilities.add) &&
77
- capabilitySetsEqual((_c = existingRole.capabilities) === null || _c === void 0 ? void 0 : _c.remove, capabilities.remove);
75
+ const unchanged = capabilitySetsEqual(existingRole.capabilities?.add, capabilities.add) &&
76
+ capabilitySetsEqual(existingRole.capabilities?.remove, capabilities.remove);
78
77
  if (unchanged)
79
78
  return null;
80
79
  return { capabilities, baseVersion: currentRoleDefaults.version };
@@ -36,15 +36,27 @@ export const searchPosts = async (query, authData, limitOffset = { offset: 0, li
36
36
  const profile = requireProfile(authData);
37
37
  const { db } = await allpeepDb();
38
38
  const mapping = postSearchMapping(profile, query);
39
- return filterAndTransform(mapping, db, Object.assign({ transform: transformPostWithScore(profile), filter: await canReadPostFilter(authData) }, limitOffset));
39
+ return filterAndTransform(mapping, db, {
40
+ transform: transformPostWithScore(profile),
41
+ filter: await canReadPostFilter(authData),
42
+ ...limitOffset,
43
+ });
40
44
  });
41
45
  export const searchEvents = async (query, authData, limitOffset = { offset: 0, limit: 15 }) => {
42
46
  const profile = requireProfile(authData);
43
- return filterAndTransform(eventSearchMapping(profile, query), (await allpeepDb()).db, Object.assign({ transform: transformPostWithScore(profile), filter: await canReadPostFilter(authData) }, limitOffset));
47
+ return filterAndTransform(eventSearchMapping(profile, query), (await allpeepDb()).db, {
48
+ transform: transformPostWithScore(profile),
49
+ filter: await canReadPostFilter(authData),
50
+ ...limitOffset,
51
+ });
44
52
  };
45
53
  export const searchJams = async (query, authData, limitOffset = { offset: 0, limit: 15 }) => {
46
54
  const profile = requireProfile(authData);
47
- return filterAndTransform(jamSearchMapping(profile, query), (await allpeepDb()).db, Object.assign({ transform: transformPostWithScore(profile), filter: await canReadPostFilter(authData) }, limitOffset));
55
+ return filterAndTransform(jamSearchMapping(profile, query), (await allpeepDb()).db, {
56
+ transform: transformPostWithScore(profile),
57
+ filter: await canReadPostFilter(authData),
58
+ ...limitOffset,
59
+ });
48
60
  };
49
61
  export const searchResultCounts = async (query, authData) => {
50
62
  const profile = requireProfile(authData);
@@ -1 +1 @@
1
- export const queryParamsToLimit = (query) => { var _a, _b; return (query === null || query === void 0 ? void 0 : query.offset) ? [query.offset, (_a = query === null || query === void 0 ? void 0 : query.limit) !== null && _a !== void 0 ? _a : 15] : ((_b = query === null || query === void 0 ? void 0 : query.limit) !== null && _b !== void 0 ? _b : 15); };
1
+ export const queryParamsToLimit = (query) => query?.offset ? [query.offset, query?.limit ?? 15] : (query?.limit ?? 15);
@@ -10,7 +10,6 @@ export const SERVICE_TAG = 'service';
10
10
  * Strip scheme/port from `server.host` / `SERVER_HOST` for Sentry tags.
11
11
  */
12
12
  export const normalizeServerHostname = (host) => {
13
- var _a;
14
13
  const trimmed = host.trim();
15
14
  if (!trimmed)
16
15
  return 'unknown';
@@ -18,8 +17,8 @@ export const normalizeServerHostname = (host) => {
18
17
  const serverUrl = trimmed.includes('://') ? trimmed : `http://${trimmed}`;
19
18
  return new URL(serverUrl).hostname || 'unknown';
20
19
  }
21
- catch (_b) {
22
- return ((_a = trimmed.split('/')[0]) === null || _a === void 0 ? void 0 : _a.split(':')[0]) || 'unknown';
20
+ catch {
21
+ return trimmed.split('/')[0]?.split(':')[0] || 'unknown';
23
22
  }
24
23
  };
25
24
  export const getCommunityHostname = () => communityHostname;
@@ -30,14 +29,13 @@ export const getSentryService = () => serviceName;
30
29
  * — never fall back to `NODE_ENV` (Docker images always set that to production).
31
30
  */
32
31
  export const resolveSentryEnvironment = (explicit) => {
33
- var _a, _b;
34
- const fromExplicit = explicit === null || explicit === void 0 ? void 0 : explicit.trim();
32
+ const fromExplicit = explicit?.trim();
35
33
  if (fromExplicit)
36
34
  return fromExplicit;
37
- const fromSentryEnv = (_a = process.env.SENTRY_ENVIRONMENT) === null || _a === void 0 ? void 0 : _a.trim();
35
+ const fromSentryEnv = process.env.SENTRY_ENVIRONMENT?.trim();
38
36
  if (fromSentryEnv)
39
37
  return fromSentryEnv;
40
- const fromEnvironment = (_b = process.env.ENVIRONMENT) === null || _b === void 0 ? void 0 : _b.trim();
38
+ const fromEnvironment = process.env.ENVIRONMENT?.trim();
41
39
  if (fromEnvironment)
42
40
  return fromEnvironment;
43
41
  return 'local';
@@ -56,7 +54,6 @@ export const applyCommunitySentryTags = () => {
56
54
  * Always records hostname/service for local diagnostics even when Sentry is off.
57
55
  */
58
56
  export const initSentry = (options = {}) => {
59
- var _a, _b, _c, _d;
60
57
  if (options.hostname !== undefined) {
61
58
  communityHostname = normalizeServerHostname(options.hostname);
62
59
  }
@@ -76,8 +73,8 @@ export const initSentry = (options = {}) => {
76
73
  }
77
74
  return;
78
75
  }
79
- const dsn = (_a = options.dsn) !== null && _a !== void 0 ? _a : process.env.SENTRY_DSN;
80
- const enabled = (_b = options.enabled) !== null && _b !== void 0 ? _b : (Boolean(dsn) && process.env.SENTRY_ENABLED !== '0');
76
+ const dsn = options.dsn ?? process.env.SENTRY_DSN;
77
+ const enabled = options.enabled ?? (Boolean(dsn) && process.env.SENTRY_ENABLED !== '0');
81
78
  if (!enabled || !dsn) {
82
79
  log.info({
83
80
  communityHostname,
@@ -86,7 +83,8 @@ export const initSentry = (options = {}) => {
86
83
  initialized = true;
87
84
  return;
88
85
  }
89
- const tracesSampleRate = (_c = options.tracesSampleRate) !== null && _c !== void 0 ? _c : Number((_d = process.env.SENTRY_TRACES_SAMPLE_RATE) !== null && _d !== void 0 ? _d : '0.1');
86
+ const tracesSampleRate = options.tracesSampleRate ??
87
+ Number(process.env.SENTRY_TRACES_SAMPLE_RATE ?? '0.1');
90
88
  const environment = resolveSentryEnvironment(options.environment);
91
89
  Sentry.init({
92
90
  dsn,
@@ -0,0 +1,50 @@
1
+ /** A sitemap row: app-relative path plus modification time, when known. */
2
+ export type CrawlableEntry = {
3
+ path: string;
4
+ updatedAt?: string | null;
5
+ };
6
+ /** What a content page should be titled and summarised as, for crawlers. */
7
+ export type CrawlableMeta = {
8
+ title: string;
9
+ description: string;
10
+ /** Post routes only: the extra facts DiscussionForumPosting needs. */
11
+ kind?: 'post';
12
+ datePublished?: string;
13
+ dateModified?: string;
14
+ authorName?: string;
15
+ };
16
+ /**
17
+ * Metadata plus whether the route could render at all, so the server can answer
18
+ * 404 for a content path that will never show anything to a crawler instead of
19
+ * a 200 community shell.
20
+ */
21
+ export type SpaMeta = {
22
+ meta: CrawlableMeta | null;
23
+ notFound: boolean;
24
+ };
25
+ export { seoRoute, type SeoRoute, type SeoRouteKind } from './route';
26
+ /** Publicly readable pages, newest first. Events are posts and have no route of
27
+ * their own, so they are covered by the post paths.
28
+ *
29
+ * Profiles are opt-in: a crawled profile page is cached by search engines long
30
+ * after the member leaves. `listProfiles` applies no privacy filter — it is the
31
+ * same list `/members` shows — so enabling this exposes exactly the profiles an
32
+ * anonymous visitor can already browse.
33
+ */
34
+ export declare const crawlableEntries: ({ indexProfiles, }: {
35
+ indexProfiles: boolean;
36
+ }) => Promise<CrawlableEntry[]>;
37
+ /**
38
+ * Metadata for a content route, plus whether it can render at all, so a shared
39
+ * post is not described to every crawler as the community homepage and an
40
+ * unknown id is not served as a 200. Negatives are cached as well: a bot
41
+ * probing unknown ids should not turn each request into a query. Profile
42
+ * metadata additionally requires the `indexProfiles` flag.
43
+ */
44
+ export declare const spaMetaForPath: (pathname: string, { indexProfiles }: {
45
+ indexProfiles: boolean;
46
+ }) => Promise<SpaMeta>;
47
+ /** Convenience wrapper for callers that only need the metadata itself. */
48
+ export declare const metaForPath: (pathname: string, options: {
49
+ indexProfiles: boolean;
50
+ }) => Promise<CrawlableMeta | null>;
@@ -0,0 +1,145 @@
1
+ import { capabilitiesConfig } from '../config/index.js';
2
+ import { findGroupByHandle, listGroups } from '../groups/index.js';
3
+ import { findPost, listPosts } from '../posts/index.js';
4
+ import { canReadPost } from '../posts/helpers/filters.js';
5
+ import { findProfileByHandle, listProfiles } from '../profiles/index.js';
6
+ import { getSharedConnection } from '../redis/index.js';
7
+ import { seoRoute } from './route.js';
8
+ export { seoRoute } from './route.js';
9
+ /**
10
+ * Per entity kind. `listPosts` runs each row through `transformPost`, which
11
+ * hydrates reactions, mentions and thread previews we never render here, so the
12
+ * cap is what keeps a crawler sweep from turning into a full content scan.
13
+ */
14
+ const PER_KIND_LIMIT = 1_000;
15
+ // Versioned because the cached shape gained `notFound` and later the
16
+ // JSON-LD fields: an old entry must never be read as the new one during a
17
+ // rolling restart.
18
+ const META_CACHE_PREFIX = 'seo:meta:v3:';
19
+ const META_TTL_SECONDS = 5 * 60;
20
+ /**
21
+ * An anonymous visitor: no profile, no scopes. That is the whole access rule.
22
+ * `listPosts` filters with `canReadPost(config, authData)` after querying and
23
+ * `canSeeGroupFilter` falls through to `groupFilters.publiclyReadable()`, so
24
+ * reusing those guards — instead of writing a sitemap-specific visibility check —
25
+ * means any later change to what anonymous visitors may read applies here
26
+ * automatically. Soft-deleted documents are excluded by the map layer.
27
+ */
28
+ const ANONYMOUS = { scopes: [] };
29
+ const byNewest = (a, b) => (b.updatedAt ?? '').localeCompare(a.updatedAt ?? '');
30
+ /** Collapse whitespace and clip to something a search snippet can use. */
31
+ const excerpt = (value, fallback) => {
32
+ const text = (value ?? '').replace(/\s+/g, ' ').trim();
33
+ if (!text)
34
+ return fallback;
35
+ return text.length > 155 ? `${text.slice(0, 152).trimEnd()}...` : text;
36
+ };
37
+ /** Publicly readable pages, newest first. Events are posts and have no route of
38
+ * their own, so they are covered by the post paths.
39
+ *
40
+ * Profiles are opt-in: a crawled profile page is cached by search engines long
41
+ * after the member leaves. `listProfiles` applies no privacy filter — it is the
42
+ * same list `/members` shows — so enabling this exposes exactly the profiles an
43
+ * anonymous visitor can already browse.
44
+ */
45
+ export const crawlableEntries = async ({ indexProfiles, }) => {
46
+ const [posts, groups, profiles] = await Promise.all([
47
+ listPosts(ANONYMOUS, { limit: PER_KIND_LIMIT }),
48
+ listGroups(ANONYMOUS),
49
+ indexProfiles ? listProfiles() : Promise.resolve([]),
50
+ ]);
51
+ const entities = [
52
+ ...posts.map((post) => ({
53
+ path: `/posts/${post.id}`,
54
+ updatedAt: post.updatedAt,
55
+ })),
56
+ ...groups.slice(0, PER_KIND_LIMIT).map((group) => ({
57
+ path: `/groups/@${group.handle}`,
58
+ updatedAt: group.updatedAt,
59
+ })),
60
+ ...profiles.slice(0, PER_KIND_LIMIT).map((profile) => ({
61
+ path: `/@${profile.handle}`,
62
+ updatedAt: profile.updatedAt,
63
+ })),
64
+ ].sort(byNewest);
65
+ // A crawler arriving only through the sitemap otherwise never learns the
66
+ // homepage exists; no lastmod, the root has no single modification time.
67
+ return [{ path: '/' }, ...entities];
68
+ };
69
+ const resolveMeta = async (pathname, indexProfiles) => {
70
+ const route = seoRoute(pathname, { indexProfiles });
71
+ if (!route)
72
+ return { meta: null, notFound: false };
73
+ if (route.kind === 'post') {
74
+ const post = await findPost(route.handle);
75
+ // findPost has no visibility gate of its own — `toFilteredPostsList` applies
76
+ // it for lists — so the read rule is re-applied here rather than trusted.
77
+ if (!post ||
78
+ !(await canReadPost(await capabilitiesConfig(), ANONYMOUS)(post)))
79
+ return { meta: null, notFound: true };
80
+ const body = 'content' in post.data
81
+ ? post.data.content
82
+ : 'name' in post.data
83
+ ? post.data.name
84
+ : '';
85
+ const heading = 'title' in post.data && post.data.title
86
+ ? post.data.title
87
+ : excerpt(body, post.profile?.displayName ?? 'Post');
88
+ return {
89
+ meta: {
90
+ title: heading,
91
+ description: excerpt(body, heading),
92
+ kind: 'post',
93
+ datePublished: post.createdAt,
94
+ dateModified: post.updatedAt,
95
+ authorName: post.profile?.displayName ||
96
+ (post.profile?.handle ? `@${post.profile.handle}` : undefined),
97
+ },
98
+ notFound: false,
99
+ };
100
+ }
101
+ if (route.kind === 'group') {
102
+ const group = await findGroupByHandle(route.handle);
103
+ // Groups have no visibility column; this mirrors
104
+ // `groupFilters.publiclyReadable()`, which reads the same capability.
105
+ if (!group?.capabilities?.none?.add?.includes('core-groups-read'))
106
+ return { meta: null, notFound: true };
107
+ const groupTitle = group.displayName || `@${group.handle}`;
108
+ return {
109
+ meta: {
110
+ title: groupTitle,
111
+ description: excerpt(group.description, groupTitle),
112
+ },
113
+ notFound: false,
114
+ };
115
+ }
116
+ const profile = await findProfileByHandle(route.handle);
117
+ if (!profile)
118
+ return { meta: null, notFound: true };
119
+ return {
120
+ meta: {
121
+ title: profile.displayName || `@${profile.handle}`,
122
+ description: excerpt(profile.bio, `@${profile.handle}`),
123
+ },
124
+ notFound: false,
125
+ };
126
+ };
127
+ /**
128
+ * Metadata for a content route, plus whether it can render at all, so a shared
129
+ * post is not described to every crawler as the community homepage and an
130
+ * unknown id is not served as a 200. Negatives are cached as well: a bot
131
+ * probing unknown ids should not turn each request into a query. Profile
132
+ * metadata additionally requires the `indexProfiles` flag.
133
+ */
134
+ export const spaMetaForPath = async (pathname, { indexProfiles }) => {
135
+ const redis = await getSharedConnection();
136
+ const key = `${META_CACHE_PREFIX}${pathname}`;
137
+ const cached = await redis.get(key);
138
+ if (cached)
139
+ return JSON.parse(cached);
140
+ const resolved = await resolveMeta(pathname, indexProfiles);
141
+ await redis.set(key, JSON.stringify(resolved), { EX: META_TTL_SECONDS });
142
+ return resolved;
143
+ };
144
+ /** Convenience wrapper for callers that only need the metadata itself. */
145
+ export const metaForPath = async (pathname, options) => (await spaMetaForPath(pathname, options)).meta;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Pure parsing of the content routes the crawler layer recognises. Kept free of
3
+ * data-layer imports so the rules are unit-testable and so this can be loaded
4
+ * where opening a database connection would be wrong.
5
+ */
6
+ export type SeoRouteKind = 'post' | 'group' | 'profile';
7
+ export type SeoRoute = {
8
+ kind: SeoRouteKind;
9
+ handle: string;
10
+ };
11
+ /**
12
+ * A trailing slash addresses the same page as the bare path; `webNavigator`
13
+ * never emits one, so the canonical spelling has none. Tolerating it here stops
14
+ * `/posts/x/` from silently falling back to community-wide metadata.
15
+ */
16
+ export declare const seoRoute: (pathname: string, { indexProfiles }: {
17
+ indexProfiles: boolean;
18
+ }) => SeoRoute | null;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A trailing slash addresses the same page as the bare path; `webNavigator`
3
+ * never emits one, so the canonical spelling has none. Tolerating it here stops
4
+ * `/posts/x/` from silently falling back to community-wide metadata.
5
+ */
6
+ export const seoRoute = (pathname, { indexProfiles }) => {
7
+ const post = /^\/posts\/([\w-]+)\/?$/.exec(pathname)?.[1];
8
+ if (post)
9
+ return { kind: 'post', handle: post };
10
+ // Group and profile handles carry the leading @ in real URLs, and the web
11
+ // client also accepts it absent, so both spellings resolve.
12
+ const group = /^\/groups\/@?([^/]+?)\/?$/.exec(pathname)?.[1];
13
+ if (group)
14
+ return { kind: 'group', handle: group };
15
+ if (!indexProfiles)
16
+ return null;
17
+ const profile = /^\/@([^/]+?)\/?$/.exec(pathname)?.[1];
18
+ return profile ? { kind: 'profile', handle: profile } : null;
19
+ };
@@ -72,6 +72,7 @@ export declare const serverInfo: () => Promise<{
72
72
  defaultLanguage?: string | undefined;
73
73
  defaultTimeZone?: string | undefined;
74
74
  defaultFeedFormat?: "threaded" | "linear" | undefined;
75
+ indexProfiles?: boolean | undefined;
75
76
  };
76
77
  roles: {
77
78
  onRegistration: {