@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.
- package/dist/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +82 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +31 -14
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -7
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- 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
|
+
};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -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: {
|
package/dist/server/index.js
CHANGED
|
@@ -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(
|
|
34
|
+
return normalizeComputedDatetime(rows[0]?.last);
|
|
33
35
|
};
|
|
34
36
|
export const serverInfo = () => config().then(async (coreConfig) => {
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
47
|
+
startedAt: processStartedAt,
|
|
48
|
+
uptimeSeconds: roundDownUptimeSeconds(Math.floor(process.uptime())),
|
|
49
|
+
disk,
|
|
50
|
+
lastAccessed,
|
|
41
51
|
maxProfiles: coreConfig.server.maxProfiles || undefined,
|
|
42
|
-
communityConfig:
|
|
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: !!
|
|
57
|
-
!!
|
|
58
|
-
dsn:
|
|
59
|
-
replayEnabled: !!
|
|
60
|
-
!!
|
|
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: !!
|
|
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
|
+
};
|
package/dist/session/index.js
CHANGED
|
@@ -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 [
|
|
53
|
+
return [{ connectionId, ...parsed }];
|
|
54
54
|
}
|
|
55
|
-
catch
|
|
55
|
+
catch {
|
|
56
56
|
return [];
|
|
57
57
|
}
|
|
58
58
|
});
|