@openpeepshq/core 0.1.33 → 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 (297) 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 +36 -33
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +17 -12
  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 +164 -140
  14. package/dist/analytics/report.d.ts +22 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +82 -25
  18. package/dist/backups/metadata.d.ts +2 -3
  19. package/dist/backups/metadata.js +6 -2
  20. package/dist/config/db.js +2 -4
  21. package/dist/config/defaults/capabilities.js +13 -2
  22. package/dist/config/defaults/community.js +8 -3
  23. package/dist/config/defaults/core.d.ts +1 -1
  24. package/dist/config/defaults/core.js +16 -8
  25. package/dist/config/index.d.ts +22 -0
  26. package/dist/config/index.js +15 -11
  27. package/dist/db/explorer/query.js +9 -8
  28. package/dist/db/explorer/sql.js +8 -8
  29. package/dist/db/helpers.d.ts +1 -0
  30. package/dist/db/helpers.js +25 -7
  31. package/dist/db/index.d.ts +1 -1
  32. package/dist/db/index.js +1 -0
  33. package/dist/db/init.js +2 -3
  34. package/dist/db/migration/importCollections.d.ts +14 -9
  35. package/dist/db/migration/importCollections.js +121 -174
  36. package/dist/db/migration/shared.d.ts +2 -33
  37. package/dist/db/migration/shared.js +17 -87
  38. package/dist/db/pg/client.js +4 -7
  39. package/dist/db/pg/collections.d.ts +2 -2
  40. package/dist/db/pg/collections.js +2 -2
  41. package/dist/db/pg/filters/index.js +1 -1
  42. package/dist/db/pg/filters/posts.d.ts +12 -0
  43. package/dist/db/pg/filters/posts.js +30 -4
  44. package/dist/db/pg/filters/profiles.d.ts +1 -0
  45. package/dist/db/pg/filters/profiles.js +2 -1
  46. package/dist/db/pg/helpers.js +2 -14
  47. package/dist/db/pg/map/filters.js +40 -10
  48. package/dist/db/pg/map/helpers.js +5 -1
  49. package/dist/db/pg/map/index.js +46 -51
  50. package/dist/db/pg/map/mutations.js +65 -25
  51. package/dist/db/pg/map/registry.d.ts +5 -0
  52. package/dist/db/pg/map/registry.js +133 -56
  53. package/dist/db/pg/map/relations.js +76 -68
  54. package/dist/db/pg/map/search.js +15 -37
  55. package/dist/db/pg/mappers.js +13 -7
  56. package/dist/db/pg/migrate.d.ts +1 -2
  57. package/dist/db/pg/migrate.js +8 -9
  58. package/dist/db/pg/queries/activity.js +5 -5
  59. package/dist/db/pg/queries/derived.js +8 -12
  60. package/dist/db/pg/queries/sorts.d.ts +1 -0
  61. package/dist/db/pg/queries/sorts.js +4 -0
  62. package/dist/db/pg/schema/documents.d.ts +279 -41
  63. package/dist/db/pg/schema/documents.js +136 -22
  64. package/dist/db/pg/schema/edges.d.ts +116 -7
  65. package/dist/db/pg/schema/edges.js +9 -2
  66. package/dist/db/pg/schema/index.d.ts +362 -15
  67. package/dist/db/pg/schema/index.js +5 -1
  68. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  69. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  70. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  71. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  72. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  73. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  74. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  75. package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
  76. package/dist/db/pg/sql/meta/_journal.json +49 -0
  77. package/dist/db/replaceOrigin.js +1 -1
  78. package/dist/email/queueStats.js +8 -11
  79. package/dist/email/render.js +14 -3
  80. package/dist/email/send.js +19 -17
  81. package/dist/email/smtpTest.js +10 -6
  82. package/dist/errors/index.js +1 -1
  83. package/dist/events/index.d.ts +4 -0
  84. package/dist/events/index.js +1 -0
  85. package/dist/events/once.js +2 -4
  86. package/dist/federation/activities.d.ts +17 -0
  87. package/dist/federation/activities.js +25 -0
  88. package/dist/federation/identity.d.ts +16 -0
  89. package/dist/federation/identity.js +52 -0
  90. package/dist/federation/index.d.ts +4 -0
  91. package/dist/federation/index.js +3 -0
  92. package/dist/federation/profiles.d.ts +3 -0
  93. package/dist/federation/profiles.js +14 -0
  94. package/dist/groups/finders.d.ts +2 -1
  95. package/dist/groups/helpers.d.ts +18 -0
  96. package/dist/groups/helpers.js +1 -2
  97. package/dist/groups/mapping.d.ts +4 -2
  98. package/dist/groups/mutations.js +1 -1
  99. package/dist/hashtags/finders.d.ts +6 -3
  100. package/dist/hashtags/finders.js +2 -0
  101. package/dist/hashtags/helpers.d.ts +8 -0
  102. package/dist/hashtags/helpers.js +4 -0
  103. package/dist/hashtags/index.d.ts +2 -0
  104. package/dist/hashtags/index.js +2 -0
  105. package/dist/hashtags/mutations.d.ts +3 -0
  106. package/dist/hashtags/mutations.js +13 -1
  107. package/dist/i18n/index.d.ts +1 -1
  108. package/dist/i18n/index.js +3 -1
  109. package/dist/i18n/pluginLocales.d.ts +6 -0
  110. package/dist/i18n/pluginLocales.js +15 -0
  111. package/dist/inviteLinks/mutations.js +2 -3
  112. package/dist/jams/export.d.ts +19 -0
  113. package/dist/jams/export.js +58 -0
  114. package/dist/jams/finders.js +4 -1
  115. package/dist/jams/health.d.ts +10 -0
  116. package/dist/jams/health.js +50 -0
  117. package/dist/jams/helpers.d.ts +2 -2
  118. package/dist/jams/helpers.js +6 -2
  119. package/dist/jams/index.d.ts +2 -0
  120. package/dist/jams/index.js +25 -18
  121. package/dist/jams/jobs.js +2 -3
  122. package/dist/jams/livekit.d.ts +49 -4
  123. package/dist/jams/livekit.js +62 -45
  124. package/dist/jams/mapping.d.ts +3 -3
  125. package/dist/jams/mutations.d.ts +1 -1
  126. package/dist/jams/recording.d.ts +10 -0
  127. package/dist/jams/recording.js +33 -1
  128. package/dist/jams/token.d.ts +13 -1
  129. package/dist/jams/token.js +25 -18
  130. package/dist/jams/waitingRoom.js +1 -1
  131. package/dist/jobs/index.d.ts +1 -0
  132. package/dist/jobs/index.js +9 -3
  133. package/dist/jobs/jobDetail.js +6 -12
  134. package/dist/jobs/jobLog.js +2 -3
  135. package/dist/lib/streams.js +4 -39
  136. package/dist/lib/zodDeepPartial.d.ts +1 -1
  137. package/dist/lib/zodDeepPartial.js +1 -1
  138. package/dist/log/index.js +13 -29
  139. package/dist/media/index.d.ts +1 -1
  140. package/dist/media/index.js +73 -12
  141. package/dist/media/jobs.js +1 -2
  142. package/dist/media/openpeeps/index.js +11 -46
  143. package/dist/media/processing.js +25 -11
  144. package/dist/media/streaming.js +5 -5
  145. package/dist/media/streamingCleanupJobs.js +1 -2
  146. package/dist/media/streamingJobs.js +3 -4
  147. package/dist/media/streamingPrewarm.js +7 -11
  148. package/dist/mediaAttachments/index.js +6 -2
  149. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  150. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  151. package/dist/notifications/defaultNotifications/follow/index.js +15 -18
  152. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  153. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  154. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  155. package/dist/notifications/defaultNotifications/index.js +4 -0
  156. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  157. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  158. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  159. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  160. package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
  161. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  162. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  163. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  164. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  165. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
  166. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  167. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  168. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  169. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  170. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  171. package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
  172. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  173. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
  174. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  175. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  176. package/dist/notifications/fcmCredential.js +1 -1
  177. package/dist/notifications/finders.js +1 -1
  178. package/dist/notifications/helpers.js +13 -10
  179. package/dist/notifications/jobs.js +10 -5
  180. package/dist/notifications/mutations.js +8 -1
  181. package/dist/notifications/push.js +11 -16
  182. package/dist/performance/index.js +3 -3
  183. package/dist/plugins/helpers.js +3 -6
  184. package/dist/plugins/index.js +39 -4
  185. package/dist/plugins/install.d.ts +28 -9
  186. package/dist/plugins/install.js +302 -56
  187. package/dist/plugins/pluginAuth.d.ts +1 -1
  188. package/dist/plugins/pluginAuth.js +13 -10
  189. package/dist/plugins/state.js +2 -3
  190. package/dist/posts/activity.d.ts +9 -0
  191. package/dist/posts/activity.js +34 -0
  192. package/dist/posts/contextClosure.d.ts +1 -9
  193. package/dist/posts/contextClosure.js +14 -44
  194. package/dist/posts/conversationQueries.d.ts +7 -0
  195. package/dist/posts/conversationQueries.js +76 -4
  196. package/dist/posts/eventAgenda.d.ts +1 -0
  197. package/dist/posts/eventAgenda.js +17 -8
  198. package/dist/posts/eventOccurrenceJobs.js +7 -2
  199. package/dist/posts/eventOccurrences.d.ts +6 -0
  200. package/dist/posts/eventOccurrences.js +22 -1
  201. package/dist/posts/finders.d.ts +56 -9
  202. package/dist/posts/finders.js +84 -23
  203. package/dist/posts/helpers/filters.js +13 -9
  204. package/dist/posts/helpers/index.d.ts +179 -14
  205. package/dist/posts/helpers/index.js +70 -34
  206. package/dist/posts/index.d.ts +5 -2
  207. package/dist/posts/index.js +5 -2
  208. package/dist/posts/mapping.d.ts +765 -30
  209. package/dist/posts/mapping.js +74 -31
  210. package/dist/posts/mutations.d.ts +516 -3
  211. package/dist/posts/mutations.js +179 -41
  212. package/dist/posts/pollEnd.d.ts +3 -0
  213. package/dist/posts/pollEnd.js +4 -0
  214. package/dist/posts/pollEndJobs.d.ts +8 -0
  215. package/dist/posts/pollEndJobs.js +49 -0
  216. package/dist/posts/replyClosure.d.ts +10 -0
  217. package/dist/posts/replyClosure.js +43 -0
  218. package/dist/posts/rsvpConfirmationEmail.js +23 -15
  219. package/dist/posts/threadPreview.d.ts +8 -0
  220. package/dist/posts/threadPreview.js +44 -0
  221. package/dist/posts/unseenCounts.js +4 -1
  222. package/dist/processingStats/queries.js +6 -7
  223. package/dist/profileSettings/cache.js +21 -5
  224. package/dist/profileSettings/mapping.d.ts +2 -0
  225. package/dist/profiles/activityQueries.d.ts +5 -0
  226. package/dist/profiles/activityQueries.js +85 -0
  227. package/dist/profiles/activitySummary.d.ts +3 -0
  228. package/dist/profiles/activitySummary.js +82 -0
  229. package/dist/profiles/blocks.d.ts +12 -0
  230. package/dist/profiles/blocks.js +73 -0
  231. package/dist/profiles/cache.d.ts +1 -0
  232. package/dist/profiles/cache.js +30 -10
  233. package/dist/profiles/export.js +30 -39
  234. package/dist/profiles/finders.d.ts +2 -1
  235. package/dist/profiles/finders.js +15 -8
  236. package/dist/profiles/helpers.d.ts +2 -0
  237. package/dist/profiles/index.d.ts +2 -0
  238. package/dist/profiles/index.js +2 -0
  239. package/dist/profiles/mapping.d.ts +10 -5
  240. package/dist/profiles/mapping.js +13 -1
  241. package/dist/profiles/mutations.d.ts +8 -4
  242. package/dist/profiles/mutations.js +31 -4
  243. package/dist/redis/connection.d.ts +2 -0
  244. package/dist/redis/connection.js +25 -6
  245. package/dist/reports/helpers.js +7 -3
  246. package/dist/roles/index.d.ts +1 -1
  247. package/dist/roles/index.js +1 -1
  248. package/dist/roles/mapping.d.ts +1 -0
  249. package/dist/roles/mutations.js +85 -3
  250. package/dist/search/finders.js +15 -3
  251. package/dist/search/helpers.js +1 -1
  252. package/dist/search/mapping.d.ts +1 -1
  253. package/dist/search/mapping.js +6 -2
  254. package/dist/sentry/index.js +9 -11
  255. package/dist/seo/index.d.ts +50 -0
  256. package/dist/seo/index.js +145 -0
  257. package/dist/seo/route.d.ts +18 -0
  258. package/dist/seo/route.js +19 -0
  259. package/dist/server/index.d.ts +19 -0
  260. package/dist/server/index.js +31 -14
  261. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  262. package/dist/server/stablePublicServerInfo.js +37 -0
  263. package/dist/server/status.d.ts +25 -0
  264. package/dist/server/status.js +97 -0
  265. package/dist/session/index.js +2 -2
  266. package/dist/stats/finders.d.ts +1 -17681
  267. package/dist/stats/finders.js +22 -9
  268. package/dist/stats/helpers.js +4 -1
  269. package/dist/stats/mapping.d.ts +39 -2
  270. package/dist/stats/mapping.js +8 -4
  271. package/dist/stripe/cache.js +5 -6
  272. package/dist/stripe/connection.js +3 -4
  273. package/dist/stripe/helpers.js +15 -20
  274. package/package.json +5 -7
  275. package/dist/db/migration/detect.d.ts +0 -3
  276. package/dist/db/migration/detect.js +0 -33
  277. package/dist/db/migration/importPostgres.d.ts +0 -3
  278. package/dist/db/migration/importPostgres.js +0 -18
  279. package/dist/db/migration/transform.d.ts +0 -20
  280. package/dist/db/migration/transform.js +0 -232
  281. package/dist/db/migration/validate.d.ts +0 -18
  282. package/dist/db/migration/validate.js +0 -69
  283. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  284. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  285. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  286. package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
  287. package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
  288. package/dist/mastodon/index.d.ts +0 -4
  289. package/dist/mastodon/index.js +0 -51
  290. package/dist/mastodon/types.d.ts +0 -7579
  291. package/dist/mastodon/types.js +0 -523
  292. package/dist/mastodon/typescript.d.ts +0 -1578
  293. package/dist/mastodon/typescript.js +0 -1
  294. package/dist/migration/index.d.ts +0 -4
  295. package/dist/migration/index.js +0 -4
  296. package/dist/roles/defaults.d.ts +0 -2
  297. package/dist/roles/defaults.js +0 -95
@@ -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
+ };
@@ -1,3 +1,4 @@
1
+ export { SERVER_INFO_BUCKET_MS, roundDownUptimeSeconds, stablePublicServerInfo, } from './stablePublicServerInfo';
1
2
  export type DurationType = 'yesterday' | 'today' | 'last7Days' | 'last30Days' | 'last90Days';
2
3
  /** Infer http vs https for absolute URLs (OIDC redirects, emails, media). */
3
4
  export declare const protocolForServerHost: (host: string, envProtocol?: string | undefined) => "http" | "https";
@@ -7,6 +8,13 @@ export declare const serverInfo: () => Promise<{
7
8
  version: string;
8
9
  environment: string;
9
10
  publicContent: boolean;
11
+ startedAt: string;
12
+ uptimeSeconds: number;
13
+ disk: {
14
+ folderBytes: number;
15
+ freeBytes: number;
16
+ totalBytes: number;
17
+ } | null;
10
18
  lastAccessed: string | null;
11
19
  communityConfig: {
12
20
  theme: {
@@ -37,6 +45,13 @@ export declare const serverInfo: () => Promise<{
37
45
  };
38
46
  icon?: string | undefined;
39
47
  mobileIcon?: string | undefined;
48
+ primaryHex?: string | undefined;
49
+ logoFull?: string | undefined;
50
+ logoSmall?: string | undefined;
51
+ defaultProfileAvatar?: string | undefined;
52
+ defaultGroupAvatar?: string | undefined;
53
+ backgroundAuth?: string | undefined;
54
+ background?: string | undefined;
40
55
  };
41
56
  info: {
42
57
  name: string;
@@ -55,6 +70,9 @@ export declare const serverInfo: () => Promise<{
55
70
  settings: {
56
71
  openRegistrations: boolean;
57
72
  defaultLanguage?: string | undefined;
73
+ defaultTimeZone?: string | undefined;
74
+ defaultFeedFormat?: "threaded" | "linear" | undefined;
75
+ indexProfiles?: boolean | undefined;
58
76
  };
59
77
  roles: {
60
78
  onRegistration: {
@@ -97,6 +115,7 @@ export declare const serverInfo: () => Promise<{
97
115
  };
98
116
  };
99
117
  };
118
+ build?: string | undefined;
100
119
  maxProfiles?: number | undefined;
101
120
  sso?: {
102
121
  generic: {
@@ -1,9 +1,12 @@
1
1
  import { sql } from 'drizzle-orm';
2
- import { publicSsoInfo } from '@openpeepshq/common/lib';
2
+ import { publicSsoInfo, withLegacyThemeRoot } from '@openpeepshq/common/lib';
3
3
  import { communityConfig, config } from '../config/index.js';
4
4
  import { database } from '../db/index.js';
5
5
  import { normalizeComputedDatetime } from '../db/pg/mappers.js';
6
6
  import { postSeen } from '../db/pg/schema/index.js';
7
+ import { diskUsage, processStartedAt } from './status.js';
8
+ import { roundDownUptimeSeconds } from './stablePublicServerInfo.js';
9
+ export { SERVER_INFO_BUCKET_MS, roundDownUptimeSeconds, stablePublicServerInfo, } from './stablePublicServerInfo.js';
7
10
  /** Infer http vs https for absolute URLs (OIDC redirects, emails, media). */
8
11
  export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PROTOCOL) => {
9
12
  if (envProtocol === 'http' || envProtocol === 'https') {
@@ -24,22 +27,36 @@ export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PRO
24
27
  export const serverProtocol = async () => protocolForServerHost((await config()).server.host);
25
28
  export const serverRootUrl = async () => `${await serverProtocol()}://${(await config()).server.host}`;
26
29
  const lastAccessedFromPostViews = async () => {
27
- var _a;
28
30
  const db = await database();
29
31
  const rows = await db
30
32
  .select({ last: sql `max(${postSeen.createdAt})` })
31
33
  .from(postSeen);
32
- return normalizeComputedDatetime((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.last);
34
+ return normalizeComputedDatetime(rows[0]?.last);
33
35
  };
34
36
  export const serverInfo = () => config().then(async (coreConfig) => {
35
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36
- return ({
37
+ const [lastAccessed, disk, community] = await Promise.all([
38
+ lastAccessedFromPostViews(),
39
+ diskUsage(coreConfig.media.storage.params.path),
40
+ communityConfig(),
41
+ ]);
42
+ return {
37
43
  version: coreConfig.version,
44
+ build: process.env.BUILD?.trim() || undefined,
38
45
  environment: coreConfig.environment,
39
46
  publicContent: coreConfig.server.publicContent,
40
- lastAccessed: await lastAccessedFromPostViews(),
47
+ startedAt: processStartedAt,
48
+ uptimeSeconds: roundDownUptimeSeconds(Math.floor(process.uptime())),
49
+ disk,
50
+ lastAccessed,
41
51
  maxProfiles: coreConfig.server.maxProfiles || undefined,
42
- communityConfig: Object.assign(Object.assign({}, (await communityConfig())), { settings: Object.assign(Object.assign({}, (await communityConfig()).settings), { openRegistrations: !!coreConfig.server.signUpsOpen }) }),
52
+ communityConfig: {
53
+ ...community,
54
+ theme: withLegacyThemeRoot(community.theme),
55
+ settings: {
56
+ ...community.settings,
57
+ openRegistrations: !!coreConfig.server.signUpsOpen,
58
+ },
59
+ },
43
60
  jams: {
44
61
  livekit: {
45
62
  url: coreConfig.jams.livekit.url,
@@ -53,19 +70,19 @@ export const serverInfo = () => config().then(async (coreConfig) => {
53
70
  publicKey: coreConfig.vapid.publicKey,
54
71
  },
55
72
  sentryConfig: {
56
- enabled: !!((_b = (_a = coreConfig.services) === null || _a === void 0 ? void 0 : _a.sentry) === null || _b === void 0 ? void 0 : _b.enabled) &&
57
- !!((_d = (_c = coreConfig.services) === null || _c === void 0 ? void 0 : _c.sentry) === null || _d === void 0 ? void 0 : _d.dsn),
58
- dsn: (_f = (_e = coreConfig.services) === null || _e === void 0 ? void 0 : _e.sentry) === null || _f === void 0 ? void 0 : _f.dsn,
59
- replayEnabled: !!((_h = (_g = coreConfig.services) === null || _g === void 0 ? void 0 : _g.sentry) === null || _h === void 0 ? void 0 : _h.replayEnabled) &&
60
- !!((_k = (_j = coreConfig.services) === null || _j === void 0 ? void 0 : _j.sentry) === null || _k === void 0 ? void 0 : _k.dsn),
73
+ enabled: !!coreConfig.services?.sentry?.enabled &&
74
+ !!coreConfig.services?.sentry?.dsn,
75
+ dsn: coreConfig.services?.sentry?.dsn,
76
+ replayEnabled: !!coreConfig.services?.sentry?.replayEnabled &&
77
+ !!coreConfig.services?.sentry?.dsn,
61
78
  },
62
79
  payments: {
63
80
  stripe: {
64
81
  paidMembership: {
65
- enabled: !!((_o = (_m = (_l = coreConfig.payments) === null || _l === void 0 ? void 0 : _l.stripe) === null || _m === void 0 ? void 0 : _m.paidMembership) === null || _o === void 0 ? void 0 : _o.enabled),
82
+ enabled: !!coreConfig.payments?.stripe?.paidMembership?.enabled,
66
83
  },
67
84
  },
68
85
  },
69
86
  sso: publicSsoInfo(coreConfig.sso),
70
- });
87
+ };
71
88
  });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Shipped RN clients remount auth when /server/info identity changes.
3
+ * Round volatile clocks down to the current 10-minute wall-clock bucket
4
+ * so successive JSON payloads stay deep-equal.
5
+ */
6
+ export declare const SERVER_INFO_BUCKET_MS: number;
7
+ export declare const roundDownTo: (value: number, step: number) => number;
8
+ export declare const serverInfoBucketStart: (now?: number) => number;
9
+ export declare const roundDownUptimeSeconds: (uptimeSeconds: number) => number;
10
+ export declare const createStableLoader: <T>(bucketMs?: number) => {
11
+ get: (load: () => Promise<T>, now?: number) => Promise<T>;
12
+ reset: () => void;
13
+ };
14
+ export declare const stablePublicServerInfo: {
15
+ get: (load: () => Promise<unknown>, now?: number) => Promise<unknown>;
16
+ reset: () => void;
17
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Shipped RN clients remount auth when /server/info identity changes.
3
+ * Round volatile clocks down to the current 10-minute wall-clock bucket
4
+ * so successive JSON payloads stay deep-equal.
5
+ */
6
+ export const SERVER_INFO_BUCKET_MS = 10 * 60 * 1000;
7
+ export const roundDownTo = (value, step) => Math.floor(value / step) * step;
8
+ export const serverInfoBucketStart = (now = Date.now()) => roundDownTo(now, SERVER_INFO_BUCKET_MS);
9
+ export const roundDownUptimeSeconds = (uptimeSeconds) => roundDownTo(Math.max(0, uptimeSeconds), SERVER_INFO_BUCKET_MS / 1000);
10
+ export const createStableLoader = (bucketMs = SERVER_INFO_BUCKET_MS) => {
11
+ let snapshot = null;
12
+ let inflight = null;
13
+ const get = async (load, now = Date.now()) => {
14
+ const bucket = roundDownTo(now, bucketMs);
15
+ if (snapshot && snapshot.at === bucket) {
16
+ return snapshot.value;
17
+ }
18
+ if (inflight) {
19
+ return inflight;
20
+ }
21
+ inflight = load()
22
+ .then((value) => {
23
+ snapshot = { at: bucket, value };
24
+ return value;
25
+ })
26
+ .finally(() => {
27
+ inflight = null;
28
+ });
29
+ return inflight;
30
+ };
31
+ const reset = () => {
32
+ snapshot = null;
33
+ inflight = null;
34
+ };
35
+ return { get, reset };
36
+ };
37
+ export const stablePublicServerInfo = createStableLoader();
@@ -0,0 +1,25 @@
1
+ import os from 'node:os';
2
+ import type { HostResourceStats } from '@openpeepshq/common/types';
3
+ export declare const processStartedAt: string;
4
+ export type MediaDiskUsage = {
5
+ folderBytes: number;
6
+ totalBytes: number;
7
+ freeBytes: number;
8
+ };
9
+ /** Sum of regular files under dir. Skips unreadable entries. */
10
+ export declare const folderSize: (dir: string) => Promise<number>;
11
+ /** Media-folder byte size plus free space on that volume. Null if unreadable. */
12
+ export declare const diskUsage: (mediaPath: string) => Promise<MediaDiskUsage | null>;
13
+ export type CpuTimes = {
14
+ idle: number;
15
+ total: number;
16
+ };
17
+ export declare const cpuTimes: (cpus?: Array<{
18
+ times: os.CpuInfo["times"];
19
+ }>) => CpuTimes;
20
+ export declare const cpuUsedPercent: (previous: CpuTimes, next: CpuTimes) => number;
21
+ export declare const memoryUsage: (totalBytes?: number, freeBytes?: number) => {
22
+ usedBytes: number;
23
+ totalBytes: number;
24
+ } | null;
25
+ export declare const hostResources: (wait?: (ms: number) => Promise<void>) => Promise<HostResourceStats>;
@@ -0,0 +1,97 @@
1
+ import { readdir, stat, statfs } from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ export const processStartedAt = new Date(Date.now() - process.uptime() * 1000).toISOString();
5
+ const FOLDER_SIZE_CACHE_MS = 30_000;
6
+ let folderSizeCache = null;
7
+ /** Sum of regular files under dir. Skips unreadable entries. */
8
+ export const folderSize = async (dir) => {
9
+ let total = 0;
10
+ let entries;
11
+ try {
12
+ entries = await readdir(dir, { withFileTypes: true });
13
+ }
14
+ catch {
15
+ return 0;
16
+ }
17
+ for (const entry of entries) {
18
+ const full = path.join(dir, entry.name);
19
+ try {
20
+ if (entry.isSymbolicLink())
21
+ continue;
22
+ if (entry.isDirectory()) {
23
+ total += await folderSize(full);
24
+ continue;
25
+ }
26
+ if (entry.isFile()) {
27
+ total += (await stat(full)).size;
28
+ }
29
+ }
30
+ catch {
31
+ // Skip entries we cannot stat (permissions, races).
32
+ }
33
+ }
34
+ return total;
35
+ };
36
+ const cachedFolderSize = async (mediaPath) => {
37
+ const now = Date.now();
38
+ if (folderSizeCache &&
39
+ folderSizeCache.mediaPath === mediaPath &&
40
+ now - folderSizeCache.at < FOLDER_SIZE_CACHE_MS) {
41
+ return folderSizeCache.bytes;
42
+ }
43
+ const bytes = await folderSize(mediaPath);
44
+ folderSizeCache = { mediaPath, at: now, bytes };
45
+ return bytes;
46
+ };
47
+ /** Media-folder byte size plus free space on that volume. Null if unreadable. */
48
+ export const diskUsage = async (mediaPath) => {
49
+ try {
50
+ const stats = await statfs(mediaPath);
51
+ const blockSize = Number(stats.bsize);
52
+ const totalBytes = Number(stats.blocks) * blockSize;
53
+ const freeBytes = Number(stats.bavail) * blockSize;
54
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0)
55
+ return null;
56
+ const folderBytes = await cachedFolderSize(mediaPath);
57
+ return { folderBytes, totalBytes, freeBytes };
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ };
63
+ export const cpuTimes = (cpus = os.cpus()) => {
64
+ let idle = 0;
65
+ let total = 0;
66
+ for (const cpu of cpus) {
67
+ const times = cpu.times;
68
+ idle += times.idle;
69
+ total += times.user + times.nice + times.sys + times.idle + times.irq;
70
+ }
71
+ return { idle, total };
72
+ };
73
+ export const cpuUsedPercent = (previous, next) => {
74
+ const idleDelta = next.idle - previous.idle;
75
+ const totalDelta = next.total - previous.total;
76
+ if (totalDelta <= 0)
77
+ return 0;
78
+ return Math.min(100, Math.max(0, (1 - idleDelta / totalDelta) * 100));
79
+ };
80
+ export const memoryUsage = (totalBytes = os.totalmem(), freeBytes = os.freemem()) => {
81
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0)
82
+ return null;
83
+ const usedBytes = Math.max(0, Math.min(totalBytes, totalBytes - Math.max(0, freeBytes)));
84
+ return { usedBytes, totalBytes };
85
+ };
86
+ const CPU_SAMPLE_MS = 50;
87
+ export const hostResources = async (wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) => {
88
+ const memory = memoryUsage();
89
+ const previous = cpuTimes();
90
+ await wait(CPU_SAMPLE_MS);
91
+ const cpuPercent = Math.round(cpuUsedPercent(previous, cpuTimes()) * 10) / 10;
92
+ return {
93
+ memoryUsedBytes: memory?.usedBytes ?? 0,
94
+ memoryTotalBytes: memory?.totalBytes ?? 0,
95
+ cpuUsedPercent: cpuPercent,
96
+ };
97
+ };
@@ -50,9 +50,9 @@ export const getSessionPresence = async (profileId) => {
50
50
  const connections = Object.entries(raw).flatMap(([connectionId, value]) => {
51
51
  try {
52
52
  const parsed = JSON.parse(value);
53
- return [Object.assign({ connectionId }, parsed)];
53
+ return [{ connectionId, ...parsed }];
54
54
  }
55
- catch (_a) {
55
+ catch {
56
56
  return [];
57
57
  }
58
58
  });