@openpeepshq/core 0.1.33 → 0.1.34

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 (213) hide show
  1. package/dist/accounts/mutations.js +33 -35
  2. package/dist/analytics/compile.js +16 -10
  3. package/dist/analytics/read.js +52 -9
  4. package/dist/analytics/report.d.ts +20 -0
  5. package/dist/backups/index.js +75 -15
  6. package/dist/backups/metadata.d.ts +2 -3
  7. package/dist/backups/metadata.js +6 -2
  8. package/dist/config/defaults/capabilities.js +13 -2
  9. package/dist/config/defaults/community.js +7 -3
  10. package/dist/config/defaults/core.d.ts +1 -1
  11. package/dist/config/defaults/core.js +3 -0
  12. package/dist/config/index.d.ts +21 -0
  13. package/dist/config/index.js +7 -1
  14. package/dist/db/helpers.d.ts +1 -0
  15. package/dist/db/helpers.js +11 -3
  16. package/dist/db/index.d.ts +1 -1
  17. package/dist/db/index.js +1 -0
  18. package/dist/db/init.js +2 -3
  19. package/dist/db/migration/importCollections.d.ts +14 -9
  20. package/dist/db/migration/importCollections.js +114 -164
  21. package/dist/db/migration/shared.d.ts +2 -33
  22. package/dist/db/migration/shared.js +2 -52
  23. package/dist/db/pg/collections.d.ts +2 -2
  24. package/dist/db/pg/collections.js +2 -2
  25. package/dist/db/pg/filters/posts.d.ts +10 -0
  26. package/dist/db/pg/filters/posts.js +28 -4
  27. package/dist/db/pg/filters/profiles.d.ts +1 -0
  28. package/dist/db/pg/filters/profiles.js +2 -1
  29. package/dist/db/pg/map/filters.js +32 -2
  30. package/dist/db/pg/map/mutations.js +13 -8
  31. package/dist/db/pg/map/registry.d.ts +5 -0
  32. package/dist/db/pg/map/registry.js +64 -24
  33. package/dist/db/pg/map/relations.js +9 -5
  34. package/dist/db/pg/migrate.d.ts +1 -2
  35. package/dist/db/pg/migrate.js +6 -6
  36. package/dist/db/pg/queries/activity.js +3 -3
  37. package/dist/db/pg/queries/sorts.d.ts +1 -0
  38. package/dist/db/pg/queries/sorts.js +4 -0
  39. package/dist/db/pg/schema/documents.d.ts +279 -41
  40. package/dist/db/pg/schema/documents.js +21 -8
  41. package/dist/db/pg/schema/edges.d.ts +116 -7
  42. package/dist/db/pg/schema/edges.js +2 -1
  43. package/dist/db/pg/schema/index.d.ts +362 -15
  44. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  45. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  46. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  47. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  48. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  49. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  50. package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
  51. package/dist/db/pg/sql/meta/_journal.json +43 -1
  52. package/dist/email/render.js +11 -3
  53. package/dist/events/index.d.ts +4 -0
  54. package/dist/events/index.js +1 -0
  55. package/dist/federation/activities.d.ts +17 -0
  56. package/dist/federation/activities.js +26 -0
  57. package/dist/federation/identity.d.ts +16 -0
  58. package/dist/federation/identity.js +52 -0
  59. package/dist/federation/index.d.ts +4 -0
  60. package/dist/federation/index.js +3 -0
  61. package/dist/federation/profiles.d.ts +3 -0
  62. package/dist/federation/profiles.js +14 -0
  63. package/dist/groups/finders.d.ts +2 -1
  64. package/dist/groups/helpers.d.ts +18 -0
  65. package/dist/groups/mapping.d.ts +4 -2
  66. package/dist/hashtags/finders.d.ts +6 -3
  67. package/dist/hashtags/finders.js +2 -0
  68. package/dist/hashtags/helpers.d.ts +8 -0
  69. package/dist/hashtags/helpers.js +4 -0
  70. package/dist/hashtags/index.d.ts +2 -0
  71. package/dist/hashtags/index.js +2 -0
  72. package/dist/hashtags/mutations.d.ts +3 -0
  73. package/dist/hashtags/mutations.js +13 -1
  74. package/dist/i18n/index.d.ts +1 -1
  75. package/dist/i18n/index.js +3 -1
  76. package/dist/i18n/pluginLocales.d.ts +6 -0
  77. package/dist/i18n/pluginLocales.js +15 -0
  78. package/dist/jams/export.d.ts +19 -0
  79. package/dist/jams/export.js +60 -0
  80. package/dist/jams/health.d.ts +8 -0
  81. package/dist/jams/health.js +46 -0
  82. package/dist/jams/helpers.d.ts +2 -2
  83. package/dist/jams/index.d.ts +2 -0
  84. package/dist/jams/index.js +23 -16
  85. package/dist/jams/jobs.js +1 -1
  86. package/dist/jams/livekit.d.ts +49 -4
  87. package/dist/jams/livekit.js +56 -39
  88. package/dist/jams/mapping.d.ts +3 -3
  89. package/dist/jams/mutations.d.ts +1 -1
  90. package/dist/jams/recording.d.ts +10 -0
  91. package/dist/jams/recording.js +32 -0
  92. package/dist/jams/token.d.ts +13 -1
  93. package/dist/jams/token.js +18 -7
  94. package/dist/jams/waitingRoom.js +1 -1
  95. package/dist/jobs/index.d.ts +1 -0
  96. package/dist/jobs/index.js +6 -1
  97. package/dist/jobs/jobDetail.js +1 -6
  98. package/dist/media/index.d.ts +1 -1
  99. package/dist/media/index.js +23 -8
  100. package/dist/media/processing.js +18 -7
  101. package/dist/notifications/defaultNotifications/follow/index.js +2 -2
  102. package/dist/notifications/defaultNotifications/index.js +4 -0
  103. package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
  104. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  105. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  106. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  107. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
  108. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  109. package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
  110. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  111. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
  112. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  113. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  114. package/dist/notifications/jobs.js +3 -1
  115. package/dist/notifications/mutations.js +4 -0
  116. package/dist/plugins/index.js +37 -1
  117. package/dist/plugins/install.d.ts +28 -9
  118. package/dist/plugins/install.js +281 -49
  119. package/dist/plugins/pluginAuth.d.ts +1 -1
  120. package/dist/plugins/pluginAuth.js +10 -6
  121. package/dist/posts/activity.d.ts +9 -0
  122. package/dist/posts/activity.js +35 -0
  123. package/dist/posts/contextClosure.d.ts +1 -9
  124. package/dist/posts/contextClosure.js +15 -44
  125. package/dist/posts/conversationQueries.d.ts +7 -0
  126. package/dist/posts/conversationQueries.js +76 -2
  127. package/dist/posts/eventAgenda.d.ts +1 -0
  128. package/dist/posts/eventAgenda.js +10 -4
  129. package/dist/posts/eventOccurrenceJobs.js +7 -2
  130. package/dist/posts/eventOccurrences.d.ts +6 -0
  131. package/dist/posts/eventOccurrences.js +21 -0
  132. package/dist/posts/finders.d.ts +15 -8
  133. package/dist/posts/finders.js +67 -18
  134. package/dist/posts/helpers/filters.js +13 -8
  135. package/dist/posts/helpers/index.d.ts +27 -14
  136. package/dist/posts/helpers/index.js +34 -14
  137. package/dist/posts/index.d.ts +5 -2
  138. package/dist/posts/index.js +5 -2
  139. package/dist/posts/mapping.d.ts +216 -13
  140. package/dist/posts/mapping.js +14 -13
  141. package/dist/posts/mutations.d.ts +440 -3
  142. package/dist/posts/mutations.js +155 -32
  143. package/dist/posts/pollEnd.d.ts +3 -0
  144. package/dist/posts/pollEnd.js +7 -0
  145. package/dist/posts/pollEndJobs.d.ts +8 -0
  146. package/dist/posts/pollEndJobs.js +49 -0
  147. package/dist/posts/replyClosure.d.ts +10 -0
  148. package/dist/posts/replyClosure.js +43 -0
  149. package/dist/posts/rsvpConfirmationEmail.js +14 -16
  150. package/dist/posts/threadPreview.d.ts +8 -0
  151. package/dist/posts/threadPreview.js +44 -0
  152. package/dist/posts/unseenCounts.js +4 -1
  153. package/dist/profileSettings/cache.js +22 -5
  154. package/dist/profileSettings/mapping.d.ts +2 -0
  155. package/dist/profiles/activityQueries.d.ts +5 -0
  156. package/dist/profiles/activityQueries.js +85 -0
  157. package/dist/profiles/activitySummary.d.ts +3 -0
  158. package/dist/profiles/activitySummary.js +87 -0
  159. package/dist/profiles/blocks.d.ts +12 -0
  160. package/dist/profiles/blocks.js +73 -0
  161. package/dist/profiles/cache.d.ts +1 -0
  162. package/dist/profiles/cache.js +19 -6
  163. package/dist/profiles/finders.d.ts +2 -1
  164. package/dist/profiles/finders.js +8 -3
  165. package/dist/profiles/helpers.d.ts +2 -0
  166. package/dist/profiles/index.d.ts +2 -0
  167. package/dist/profiles/index.js +2 -0
  168. package/dist/profiles/mapping.d.ts +10 -5
  169. package/dist/profiles/mapping.js +13 -1
  170. package/dist/profiles/mutations.d.ts +8 -4
  171. package/dist/profiles/mutations.js +31 -2
  172. package/dist/redis/connection.d.ts +2 -0
  173. package/dist/redis/connection.js +25 -6
  174. package/dist/roles/index.d.ts +1 -1
  175. package/dist/roles/index.js +1 -1
  176. package/dist/roles/mapping.d.ts +1 -0
  177. package/dist/roles/mutations.js +86 -3
  178. package/dist/search/mapping.d.ts +1 -1
  179. package/dist/search/mapping.js +6 -2
  180. package/dist/server/index.d.ts +18 -0
  181. package/dist/server/index.js +24 -12
  182. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  183. package/dist/server/stablePublicServerInfo.js +37 -0
  184. package/dist/server/status.d.ts +25 -0
  185. package/dist/server/status.js +98 -0
  186. package/dist/stats/finders.d.ts +1 -17681
  187. package/dist/stats/finders.js +9 -5
  188. package/dist/stats/mapping.d.ts +0 -1
  189. package/dist/stats/mapping.js +0 -3
  190. package/package.json +4 -5
  191. package/dist/db/migration/detect.d.ts +0 -3
  192. package/dist/db/migration/detect.js +0 -33
  193. package/dist/db/migration/importPostgres.d.ts +0 -3
  194. package/dist/db/migration/importPostgres.js +0 -18
  195. package/dist/db/migration/transform.d.ts +0 -20
  196. package/dist/db/migration/transform.js +0 -232
  197. package/dist/db/migration/validate.d.ts +0 -18
  198. package/dist/db/migration/validate.js +0 -69
  199. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  200. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  201. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  202. package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
  203. package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
  204. package/dist/mastodon/index.d.ts +0 -4
  205. package/dist/mastodon/index.js +0 -51
  206. package/dist/mastodon/types.d.ts +0 -7579
  207. package/dist/mastodon/types.js +0 -523
  208. package/dist/mastodon/typescript.d.ts +0 -1578
  209. package/dist/mastodon/typescript.js +0 -1
  210. package/dist/migration/index.d.ts +0 -4
  211. package/dist/migration/index.js +0 -4
  212. package/dist/roles/defaults.d.ts +0 -2
  213. package/dist/roles/defaults.js +0 -95
@@ -1,4 +1,4 @@
1
1
  export * from './finders.js';
2
2
  export * from './mutations.js';
3
- export * from './defaults.js';
3
+ export { defaultRoles } from '@openpeepshq/common/types';
4
4
  export * from './mapping.js';
@@ -3,6 +3,7 @@ export declare const rolesMapping: import("../db/pg/map").Mapping<{
3
3
  key: string;
4
4
  default: boolean;
5
5
  displayName: string;
6
+ baseVersion?: string | undefined;
6
7
  description?: string | undefined;
7
8
  capabilities?: {
8
9
  add?: string[] | undefined;
@@ -1,5 +1,6 @@
1
- import { findRoleByKey } from './finders.js';
2
- import { defaultRoles } from './defaults.js';
1
+ import { currentRoleDefaults, defaultRoles, findRoleDefaultsVersion, } from '@openpeepshq/common/types';
2
+ import { capabilitySetsEqual } from '@openpeepshq/common/lib';
3
+ import { findRole, findRoleByKey } from './finders.js';
3
4
  import { allpeepDb } from '../db/index.js';
4
5
  import { conflict } from '../errors/index.js';
5
6
  import { rolesMapping } from './mapping.js';
@@ -14,8 +15,73 @@ export const createRole = (roleData) => allpeepDb().then(async ({ db }) => {
14
15
  }
15
16
  return rolesMapping.create(db, roleData);
16
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
+ };
23
+ /**
24
+ * Effective default flag for a write: an explicit `true` wins, and
25
+ * capabilities that exactly match the system defaults re-adopt the role as a
26
+ * default role even when the stored flag says otherwise — so future system
27
+ * default updates flow into it. Such an adoption also re-anchors the role to
28
+ * the current defaults version when the write does not set one explicitly.
29
+ */
30
+ 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); });
33
+ if (!factoryRole)
34
+ return roleData;
35
+ const matchesFactory = capabilitiesMatchFactory((_a = roleData.capabilities) !== null && _a !== void 0 ? _a : existingRole === null || existingRole === void 0 ? void 0 : existingRole.capabilities, factoryRole);
36
+ 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
+ : {}));
40
+ };
41
+ /**
42
+ * Applies the base→current delta of the system defaults to a capability
43
+ * list: capabilities the defaults gained are added, capabilities the
44
+ * defaults dropped are removed, everything else is kept.
45
+ */
46
+ const applyCapabilityDelta = (capabilities, base, current) => {
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));
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)),
53
+ ];
54
+ };
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),
58
+ };
59
+ };
60
+ /**
61
+ * Rebase patch for a customized built-in role anchored at an older defaults
62
+ * version, or null when nothing changed. The set delta is transitive, so a
63
+ * stale anchor still rebases correctly when intermediate versions left this
64
+ * role untouched — the anchor only moves when capabilities actually change.
65
+ */
66
+ const rebaseRoleToCurrentDefaults = (existingRole, factoryRole) => {
67
+ var _a, _b, _c;
68
+ const baseVersion = existingRole.baseVersion;
69
+ if (!baseVersion || baseVersion === currentRoleDefaults.version) {
70
+ return null;
71
+ }
72
+ const baseRole = (_a = findRoleDefaultsVersion(baseVersion)) === null || _a === void 0 ? void 0 : _a.roles.find((role) => role.key === factoryRole.key);
73
+ if (!baseRole)
74
+ return null;
75
+ 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);
78
+ if (unchanged)
79
+ return null;
80
+ return { capabilities, baseVersion: currentRoleDefaults.version };
81
+ };
17
82
  export const updateRole = (id, roleData) => allpeepDb().then(async ({ db }) => {
18
- const role = await rolesMapping.update(db, id, roleData);
83
+ const existingRole = await findRole(id);
84
+ const role = await rolesMapping.update(db, id, withDefaultAdoption(existingRole, roleData));
19
85
  await profilesCache.clear();
20
86
  return role;
21
87
  });
@@ -25,8 +91,25 @@ export const setDefaultRoles = async () => {
25
91
  if (!existingRole) {
26
92
  await createRole(role);
27
93
  }
94
+ else if (capabilitiesMatchFactory(existingRole.capabilities, role)) {
95
+ if (!existingRole.default) {
96
+ // Re-adopt roles that are exactly at the system defaults: only the
97
+ // flag and baseVersion are written, so the name and description are
98
+ // preserved.
99
+ await updateRole(existingRole.id, { default: true });
100
+ }
101
+ }
28
102
  else if (existingRole.default) {
103
+ // Default-flagged roles are system-managed: keep them in sync with the
104
+ // current factory so newly introduced capabilities reach them.
29
105
  await updateRole(existingRole.id, role);
30
106
  }
107
+ else {
108
+ // Customized built-in roles keep their edits; only merge in what the
109
+ // system defaults gained since their baseVersion.
110
+ const rebased = rebaseRoleToCurrentDefaults(existingRole, role);
111
+ if (rebased)
112
+ await updateRole(existingRole.id, rebased);
113
+ }
31
114
  }
32
115
  };
@@ -22,7 +22,7 @@ export declare const groupSearchMapping: (profile: ProfileWithMeta, query: strin
22
22
  };
23
23
  score: number;
24
24
  }>;
25
- export declare const profileSearchMapping: (_profile: ProfileWithMeta, query: string) => import("../db/pg/map").PgQueryResult<{
25
+ export declare const profileSearchMapping: (profile: ProfileWithMeta, query: string) => import("../db/pg/map").PgQueryResult<{
26
26
  data: ProfileWithMeta;
27
27
  score: number;
28
28
  }>;
@@ -1,15 +1,19 @@
1
+ import { blockedPairIds } from '@openpeepshq/common/lib';
1
2
  import { groupsMapping } from '../groups/index.js';
2
3
  import { canSeeGroupFilter } from '../groups/helpers.js';
3
4
  import { publicProfilesSearchMapping } from '../profiles/mapping.js';
4
5
  import { baseListPosts } from '../posts/finders.js';
5
- import { postFilters } from '../db/pg/filters/index.js';
6
+ import { postFilters, profileFilters } from '../db/pg/filters/index.js';
6
7
  export const groupSearchMapping = (profile, query) => groupsMapping.filter(canSeeGroupFilter(profile)).fulltextSearch({
7
8
  view: 'groupSearch',
8
9
  analyzer: 'text_en',
9
10
  fields: ['handle', 'displayName', 'description', 'rules'],
10
11
  query,
11
12
  });
12
- export const profileSearchMapping = (_profile, query) => publicProfilesSearchMapping.fulltextSearch({
13
+ export const profileSearchMapping = (profile, query) => publicProfilesSearchMapping
14
+ .filter(profileFilters.notGuest())
15
+ .filter(profileFilters.notIdIn(blockedPairIds(profile)))
16
+ .fulltextSearch({
13
17
  view: 'profileSearch',
14
18
  analyzer: 'text_en',
15
19
  fields: ['handle', 'displayName', 'bio', 'location.text', 'fields.value'],
@@ -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,8 @@ 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;
58
75
  };
59
76
  roles: {
60
77
  onRegistration: {
@@ -97,6 +114,7 @@ export declare const serverInfo: () => Promise<{
97
114
  };
98
115
  };
99
116
  };
117
+ build?: string | undefined;
100
118
  maxProfiles?: number | undefined;
101
119
  sso?: {
102
120
  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') {
@@ -32,14 +35,23 @@ const lastAccessedFromPostViews = async () => {
32
35
  return normalizeComputedDatetime((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.last);
33
36
  };
34
37
  export const serverInfo = () => config().then(async (coreConfig) => {
35
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36
- return ({
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
39
+ const [lastAccessed, disk, community] = await Promise.all([
40
+ lastAccessedFromPostViews(),
41
+ diskUsage(coreConfig.media.storage.params.path),
42
+ communityConfig(),
43
+ ]);
44
+ return {
37
45
  version: coreConfig.version,
46
+ build: ((_a = process.env.BUILD) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
38
47
  environment: coreConfig.environment,
39
48
  publicContent: coreConfig.server.publicContent,
40
- lastAccessed: await lastAccessedFromPostViews(),
49
+ startedAt: processStartedAt,
50
+ uptimeSeconds: roundDownUptimeSeconds(Math.floor(process.uptime())),
51
+ disk,
52
+ lastAccessed,
41
53
  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 }) }),
54
+ communityConfig: Object.assign(Object.assign({}, community), { theme: withLegacyThemeRoot(community.theme), settings: Object.assign(Object.assign({}, community.settings), { openRegistrations: !!coreConfig.server.signUpsOpen }) }),
43
55
  jams: {
44
56
  livekit: {
45
57
  url: coreConfig.jams.livekit.url,
@@ -53,19 +65,19 @@ export const serverInfo = () => config().then(async (coreConfig) => {
53
65
  publicKey: coreConfig.vapid.publicKey,
54
66
  },
55
67
  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),
68
+ enabled: !!((_c = (_b = coreConfig.services) === null || _b === void 0 ? void 0 : _b.sentry) === null || _c === void 0 ? void 0 : _c.enabled) &&
69
+ !!((_e = (_d = coreConfig.services) === null || _d === void 0 ? void 0 : _d.sentry) === null || _e === void 0 ? void 0 : _e.dsn),
70
+ dsn: (_g = (_f = coreConfig.services) === null || _f === void 0 ? void 0 : _f.sentry) === null || _g === void 0 ? void 0 : _g.dsn,
71
+ replayEnabled: !!((_j = (_h = coreConfig.services) === null || _h === void 0 ? void 0 : _h.sentry) === null || _j === void 0 ? void 0 : _j.replayEnabled) &&
72
+ !!((_l = (_k = coreConfig.services) === null || _k === void 0 ? void 0 : _k.sentry) === null || _l === void 0 ? void 0 : _l.dsn),
61
73
  },
62
74
  payments: {
63
75
  stripe: {
64
76
  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),
77
+ enabled: !!((_p = (_o = (_m = coreConfig.payments) === null || _m === void 0 ? void 0 : _m.stripe) === null || _o === void 0 ? void 0 : _o.paidMembership) === null || _p === void 0 ? void 0 : _p.enabled),
66
78
  },
67
79
  },
68
80
  },
69
81
  sso: publicSsoInfo(coreConfig.sso),
70
- });
82
+ };
71
83
  });
@@ -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,98 @@
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 = 30000;
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 (_a) {
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 (_b) {
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 (_a) {
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
+ var _a, _b;
89
+ const memory = memoryUsage();
90
+ const previous = cpuTimes();
91
+ await wait(CPU_SAMPLE_MS);
92
+ const cpuPercent = Math.round(cpuUsedPercent(previous, cpuTimes()) * 10) / 10;
93
+ return {
94
+ memoryUsedBytes: (_a = memory === null || memory === void 0 ? void 0 : memory.usedBytes) !== null && _a !== void 0 ? _a : 0,
95
+ memoryTotalBytes: (_b = memory === null || memory === void 0 ? void 0 : memory.totalBytes) !== null && _b !== void 0 ? _b : 0,
96
+ cpuUsedPercent: cpuPercent,
97
+ };
98
+ };