@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
@@ -10,6 +10,8 @@ import { assignRole, unassignRole } from '../profiles/mutations.js';
10
10
  import { hash } from 'bcrypt';
11
11
  import { profilesMapping } from '../profiles/mapping.js';
12
12
  import { assertProfileCapacity } from '../profiles/capacity.js';
13
+ import { localActorScalars } from '../federation/identity.js';
14
+ import { uuidv7 } from 'uuidv7';
13
15
  import { findRoleByKey } from '../roles/index.js';
14
16
  import { log, normalizeEmailAddress, sendEmailValidationMail, sendWelcomeEmail, } from './helpers.js';
15
17
  import { findAccountByEmail } from './finders.js';
@@ -19,6 +21,26 @@ import { conflict } from '../errors/index.js';
19
21
  import { connector } from '../db/helpers.js';
20
22
  import { hub } from '../events/index.js';
21
23
  import { deletePushSubscription, listPushSubscriptionsByAccount, } from '../pushSubscriptions/index.js';
24
+ const applyCommunityRoleChanges = async (profile, changes) => {
25
+ for (const roleKey of changes.add) {
26
+ const role = await findRoleByKey(roleKey);
27
+ if (role) {
28
+ await assignRole(profile, role);
29
+ }
30
+ else {
31
+ log.error(`Role ${roleKey} missing`);
32
+ }
33
+ }
34
+ for (const roleKey of changes.remove) {
35
+ const role = await findRoleByKey(roleKey);
36
+ if (role) {
37
+ await unassignRole(profile, role);
38
+ }
39
+ else {
40
+ log.error(`Role ${roleKey} missing`);
41
+ }
42
+ }
43
+ };
22
44
  export const createAccount = async (accountCreationData) => {
23
45
  const { db } = await allpeepDb();
24
46
  const coreConfig = await config();
@@ -57,16 +79,13 @@ export const createAccount = async (accountCreationData) => {
57
79
  let profile;
58
80
  if (accountCreationData.profile) {
59
81
  await assertProfileCapacity();
60
- const { handle, displayName, avatar } = accountCreationData.profile;
61
- profile = await profilesMapping.create(db, {
62
- handle,
82
+ const { handle, displayName, avatar, bot } = accountCreationData.profile;
83
+ const profileId = uuidv7();
84
+ profile = await profilesMapping.create(db, Object.assign(Object.assign(Object.assign({ id: profileId, handle,
63
85
  displayName,
64
- avatar,
65
- activityPub: {
86
+ avatar }, (bot === true ? { bot: true } : {})), { activityPub: {
66
87
  domain: coreConfig.activityPub.defaultDomain,
67
- },
68
- type: 'local',
69
- });
88
+ }, type: 'local' }), localActorScalars(profileId, coreConfig.activityPub.defaultDomain)));
70
89
  if (firstAccount && profile) {
71
90
  const ownerRole = await findRoleByKey('owner');
72
91
  if (ownerRole) {
@@ -78,15 +97,11 @@ export const createAccount = async (accountCreationData) => {
78
97
  }
79
98
  else {
80
99
  await hub.emit('profileCreated', profile);
81
- const registrationRoleKeys = communityConf.roles.onRegistration.add;
82
- for (const roleKey of registrationRoleKeys) {
83
- const role = await findRoleByKey(roleKey);
84
- if (role) {
85
- await assignRole(profile, role);
86
- }
87
- else {
88
- log.error(`Role ${roleKey} missing`);
89
- }
100
+ await applyCommunityRoleChanges(profile, communityConf.roles.onRegistration);
101
+ // Authorized/SSO creates skip the validation email, so apply the
102
+ // same promotion humans get after confirming.
103
+ if (emailValidated) {
104
+ await applyCommunityRoleChanges(profile, communityConf.roles.onEmailValidation);
90
105
  }
91
106
  }
92
107
  if (inviteCode) {
@@ -175,24 +190,7 @@ export const validateEmail = async (token) => {
175
190
  await accountsMapping.update(db, account.id, { emailValidated: true });
176
191
  await accountsCache.del(account.id);
177
192
  await accountsCache.del(account.email);
178
- for (const roleKey of communityConf.roles.onEmailValidation.add) {
179
- const role = await findRoleByKey(roleKey);
180
- if (role) {
181
- await assignRole(account.profiles[0], role);
182
- }
183
- else {
184
- log.error(`Role ${roleKey} missing`);
185
- }
186
- }
187
- for (const roleKey of communityConf.roles.onEmailValidation.remove) {
188
- const role = await findRoleByKey(roleKey);
189
- if (role) {
190
- await unassignRole(account.profiles[0], role);
191
- }
192
- else {
193
- log.error(`Role ${roleKey} missing`);
194
- }
195
- }
193
+ await applyCommunityRoleChanges(account.profiles[0], communityConf.roles.onEmailValidation);
196
194
  return true;
197
195
  }
198
196
  }
@@ -24,14 +24,16 @@ export const compileAnalyticsDay = async (day) => {
24
24
  const now = new Date().toISOString();
25
25
  const newMembers = await countScalar(db, sql `select count(*)::int as c from profiles
26
26
  where deleted_at is null
27
+ and type = 'local'
27
28
  and created_at >= ${start} and created_at < ${end}`);
28
29
  const posts = await countScalar(db, sql `select count(*)::int as c from posts
29
30
  where deleted_at is null and visibility <> 'direct'
30
31
  and created_at >= ${start} and created_at < ${end}`);
31
32
  const replies = await countScalar(db, sql `select count(*)::int as c from reply_to
32
33
  where created_at >= ${start} and created_at < ${end}`);
33
- const likes = await countScalar(db, sql `select count(*)::int as c from reactions
34
- where created_at >= ${start} and created_at < ${end}`);
34
+ const likes = await countScalar(db, sql `select count(*)::int as c from entries
35
+ where body->>'type' = 'reaction'
36
+ and created_at >= ${start} and created_at < ${end}`);
35
37
  const reposts = await countScalar(db, sql `select count(*)::int as c from repost
36
38
  where created_at >= ${start} and created_at < ${end}`);
37
39
  const bookmarks = await countScalar(db, sql `select count(*)::int as c from bookmarks
@@ -55,8 +57,9 @@ export const compileAnalyticsDay = async (day) => {
55
57
  where deleted_at is null
56
58
  and created_at >= ${start} and created_at < ${end}
57
59
  union
58
- select from_id from reactions
59
- where created_at >= ${start} and created_at < ${end}
60
+ select from_id from entries
61
+ where body->>'type' in ('reaction', 'unreaction')
62
+ and created_at >= ${start} and created_at < ${end}
60
63
  union
61
64
  select from_id from repost
62
65
  where created_at >= ${start} and created_at < ${end}
@@ -129,10 +132,11 @@ export const compileAnalyticsDay = async (day) => {
129
132
  update analytics_daily_by_group g
130
133
  set
131
134
  likes = coalesce((
132
- select count(*)::int from reactions r
133
- join post_groups pg on pg.from_id = r.to_id
135
+ select count(*)::int from entries e
136
+ join post_groups pg on pg.from_id = e.to_id
134
137
  where pg.to_id = g.group_id
135
- and r.created_at >= ${start} and r.created_at < ${end}
138
+ and e.body->>'type' = 'reaction'
139
+ and e.created_at >= ${start} and e.created_at < ${end}
136
140
  ), 0),
137
141
  comments = coalesce((
138
142
  select count(*)::int from reply_to rt
@@ -164,8 +168,9 @@ export const compileAnalyticsDay = async (day) => {
164
168
  select created_at from posts
165
169
  where deleted_at is null and created_at >= ${start} and created_at < ${end}
166
170
  union all
167
- select created_at from reactions
168
- where created_at >= ${start} and created_at < ${end}
171
+ select created_at from entries
172
+ where body->>'type' in ('reaction', 'unreaction')
173
+ and created_at >= ${start} and created_at < ${end}
169
174
  union all
170
175
  select created_at from reply_to
171
176
  where created_at >= ${start} and created_at < ${end}
@@ -243,7 +248,8 @@ export const compileRetentionCohorts = async () => {
243
248
  from (
244
249
  select creator_id as profile_id, created_at from posts where deleted_at is null
245
250
  union all
246
- select from_id, created_at from reactions
251
+ select from_id, created_at from entries
252
+ where body->>'type' in ('reaction', 'unreaction')
247
253
  union all
248
254
  select from_id, created_at from reply_to
249
255
  union all
@@ -24,8 +24,9 @@ const countDistinctActives = async (from, to) => {
24
24
  where deleted_at is null
25
25
  and created_at >= ${start} and created_at < ${end}
26
26
  union
27
- select from_id from reactions
28
- where created_at >= ${start} and created_at < ${end}
27
+ select from_id from entries
28
+ where body->>'type' in ('reaction', 'unreaction')
29
+ and created_at >= ${start} and created_at < ${end}
29
30
  union
30
31
  select from_id from repost
31
32
  where created_at >= ${start} and created_at < ${end}
@@ -80,7 +81,40 @@ const totalMembersAt = async (day) => {
80
81
  const end = `${day}T23:59:59.999Z`;
81
82
  const result = await db.execute(sql `
82
83
  select count(*)::int as c from profiles
83
- where deleted_at is null and created_at <= ${end}
84
+ where deleted_at is null and type = 'local'
85
+ and created_at <= ${end}
86
+ `);
87
+ const rows = result.rows;
88
+ return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
89
+ };
90
+ const verifiedMembersAt = async (day) => {
91
+ var _a, _b;
92
+ const db = await database();
93
+ const end = `${day}T23:59:59.999Z`;
94
+ const result = await db.execute(sql `
95
+ select count(*)::int as c from profiles p
96
+ join controls c on c.to_id = p.id::text
97
+ join accounts a on a.id::text = c.from_id
98
+ where p.deleted_at is null and p.type = 'local'
99
+ and a.deleted_at is null
100
+ and a.email_validated = true
101
+ and p.created_at <= ${end}
102
+ `);
103
+ const rows = result.rows;
104
+ return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
105
+ };
106
+ const unverifiedMembersAt = async (day) => {
107
+ var _a, _b;
108
+ const db = await database();
109
+ const end = `${day}T23:59:59.999Z`;
110
+ const result = await db.execute(sql `
111
+ select count(*)::int as c from profiles p
112
+ join controls c on c.to_id = p.id::text
113
+ join accounts a on a.id::text = c.from_id
114
+ where p.deleted_at is null and p.type = 'local'
115
+ and a.deleted_at is null
116
+ and a.email_validated = false
117
+ and p.created_at <= ${end}
84
118
  `);
85
119
  const rows = result.rows;
86
120
  return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
@@ -348,8 +382,9 @@ const topMembers = async (from, to, limit = 10) => {
348
382
  and visibility <> 'direct'
349
383
  and created_at >= ${start} and created_at <= ${end}
350
384
  union all
351
- select from_id from reactions
352
- where created_at >= ${start} and created_at <= ${end}
385
+ select from_id from entries
386
+ where body->>'type' in ('reaction', 'unreaction')
387
+ and created_at >= ${start} and created_at <= ${end}
353
388
  union all
354
389
  select from_id from reply_to
355
390
  where created_at >= ${start} and created_at <= ${end}
@@ -473,9 +508,11 @@ const withCache = async (section, from, to, build) => {
473
508
  };
474
509
  export const getAnalyticsOverview = async (query = {}) => {
475
510
  const range = await resolveQueryRange(query);
476
- return withCache('overview-v6', range.from, range.to, async () => {
511
+ // Unique people in the window — summing daily rollups would count a
512
+ // member once per day they were active.
513
+ return withCache('overview-v7', range.from, range.to, async () => {
477
514
  var _a, _b;
478
- const [activeMembersSeries, postsSeries, likesSeries, commentsSeries, postsByTypeDaily, topGroupRows, groupGrowth, topPostRows, topMemberRows, compiledAt, totalMembers, totalGroups, allTimePosts, prevActive, prevPosts, prevTotalMembers, prevTotalGroups, prevAllTimePosts,] = await Promise.all([
515
+ const [activeMembersSeries, postsSeries, likesSeries, commentsSeries, postsByTypeDaily, topGroupRows, groupGrowth, topPostRows, topMemberRows, compiledAt, totalMembers, totalGroups, allTimePosts, activeMembers, prevActive, prevPosts, prevTotalMembers, prevTotalGroups, prevAllTimePosts, verifiedMembers, unverifiedMembers, prevVerifiedMembers, prevUnverifiedMembers,] = await Promise.all([
479
516
  loadTotalsSeries(range.from, range.to, 'activeMembers'),
480
517
  loadTotalsSeries(range.from, range.to, 'posts'),
481
518
  loadTotalsSeries(range.from, range.to, 'likes'),
@@ -489,13 +526,17 @@ export const getAnalyticsOverview = async (query = {}) => {
489
526
  totalMembersAt(range.to),
490
527
  totalGroupsAt(range.to),
491
528
  totalPostsAt(range.to),
492
- sumColumn(range.previousFrom, range.previousTo, 'activeMembers'),
529
+ countDistinctActives(range.from, range.to),
530
+ countDistinctActives(range.previousFrom, range.previousTo),
493
531
  sumColumn(range.previousFrom, range.previousTo, 'posts'),
494
532
  totalMembersAt(range.previousTo),
495
533
  totalGroupsAt(range.previousTo),
496
534
  totalPostsAt(range.previousTo),
535
+ verifiedMembersAt(range.to),
536
+ unverifiedMembersAt(range.to),
537
+ verifiedMembersAt(range.previousTo),
538
+ unverifiedMembersAt(range.previousTo),
497
539
  ]);
498
- const activeMembers = sumSeries(activeMembersSeries);
499
540
  const totalPosts = sumSeries(postsSeries);
500
541
  const { buckets } = selectChartBuckets(range.from, range.to);
501
542
  const typeTotals = Object.fromEntries(POST_TYPE_KEYS.map((k) => [k, 0]));
@@ -552,6 +593,8 @@ export const getAnalyticsOverview = async (query = {}) => {
552
593
  totalPosts: metricCard('totalPosts', totalPosts, prevPosts, postsSeries),
553
594
  allTimePosts: metricCard('allTimePosts', allTimePosts, prevAllTimePosts),
554
595
  totalMembers: metricCard('totalMembers', totalMembers, prevTotalMembers),
596
+ verifiedMembers: metricCard('verifiedMembers', verifiedMembers, prevVerifiedMembers),
597
+ unverifiedMembers: metricCard('unverifiedMembers', unverifiedMembers, prevUnverifiedMembers),
555
598
  activeMembers: metricCard('activeMembers', activeMembers, prevActive, activeMembersSeries),
556
599
  totalGroups: metricCard('totalGroups', totalGroups, prevTotalGroups),
557
600
  },
@@ -43,6 +43,26 @@ export declare const buildAnalyticsBoardReport: (query?: AnalyticsDateQuery) =>
43
43
  value: number;
44
44
  }[] | undefined;
45
45
  };
46
+ verifiedMembers: {
47
+ key: string;
48
+ value: number;
49
+ previousValue: number;
50
+ deltaPct: number | null;
51
+ series?: {
52
+ day: string;
53
+ value: number;
54
+ }[] | undefined;
55
+ };
56
+ unverifiedMembers: {
57
+ key: string;
58
+ value: number;
59
+ previousValue: number;
60
+ deltaPct: number | null;
61
+ series?: {
62
+ day: string;
63
+ value: number;
64
+ }[] | undefined;
65
+ };
46
66
  activeMembers: {
47
67
  key: string;
48
68
  value: number;
@@ -1,4 +1,4 @@
1
- import { access, cp, mkdir, mkdtemp, readdir, rm, writeFile, readFile, } from 'node:fs/promises';
1
+ import { access, cp, mkdir, mkdtemp, readdir, rm, writeFile, readFile, stat, } from 'node:fs/promises';
2
2
  import { constants, createWriteStream } from 'node:fs';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { emptyDir } from 'fs-extra';
@@ -7,16 +7,21 @@ import { tmpdir } from 'node:os';
7
7
  import archiver from 'archiver';
8
8
  import extract from 'extract-zip';
9
9
  import { collectionInfos } from '../db/index.js';
10
- import { communityConfig, config } from '../config/index.js';
11
- import { exportAllPostgresCollections, importAllArangoCollections, importAllPostgresCollections, } from '../db/migration/importCollections.js';
10
+ import { communityConfig, config, defaultConfig } from '../config/index.js';
11
+ import { exportAllPostgresCollections, importAllPostgresCollections, } from '../db/migration/importCollections.js';
12
12
  import { getLatestSchemaVersion } from '../db/pg/migrate.js';
13
13
  import { replaceOrigin } from '../db/replaceOrigin.js';
14
14
  import { logger } from '../log/index.js';
15
15
  import { setDefaultRoles } from '../roles/index.js';
16
+ import { backfillMissingEventOccurrences } from '../posts/eventOccurrences.js';
16
17
  import { serverRootUrl } from '../server/index.js';
17
- import { resolveBackupDatabaseType, } from './metadata.js';
18
+ import { linkHostPeerDependencies } from '../plugins/index.js';
19
+ import { resolveBackupDatabaseType } from './metadata.js';
18
20
  export { resolveBackupDatabaseType } from './metadata.js';
19
21
  const log = logger('core:backups');
22
+ const pathExists = (p) => access(p)
23
+ .then(() => true)
24
+ .catch(() => false);
20
25
  /** Safety net if extraction stalls (normal 1 GiB restore finishes in a few minutes). */
21
26
  const EXTRACT_TIMEOUT_MS = 30 * 60 * 1000;
22
27
  const extractWithUnzipCli = (zipPath, tempDir) => {
@@ -104,6 +109,41 @@ const zipDirectory = (sourceDir, zipPath) => new Promise((resolve, reject) => {
104
109
  archive.directory(sourceDir, false);
105
110
  void archive.finalize();
106
111
  });
112
+ /**
113
+ * Peer-dependency symlinks in a restored plugin were created against the host
114
+ * packages of the image the backup came from. Re-anchor them to the current
115
+ * host tree so restored plugins resolve even after an image update.
116
+ */
117
+ const relinkRestoredPlugins = async (pluginsPath) => {
118
+ var _a, _b;
119
+ const namespaces = await readdir(pluginsPath).catch(() => []);
120
+ for (const namespace of namespaces) {
121
+ const namespaceDir = join(pluginsPath, namespace);
122
+ if (!(await stat(namespaceDir)
123
+ .then((s) => s.isDirectory())
124
+ .catch(() => false))) {
125
+ continue;
126
+ }
127
+ const names = await readdir(namespaceDir).catch(() => []);
128
+ for (const name of names) {
129
+ const pluginDir = join(namespaceDir, name);
130
+ let pkg;
131
+ try {
132
+ pkg = JSON.parse(await readFile(join(pluginDir, 'package.json'), 'utf8'));
133
+ }
134
+ catch (_c) {
135
+ continue;
136
+ }
137
+ const peers = Object.keys((_a = pkg.peerDependencies) !== null && _a !== void 0 ? _a : {});
138
+ if (peers.length === 0)
139
+ continue;
140
+ const linked = await linkHostPeerDependencies(pluginDir, peers);
141
+ if (!linked.success) {
142
+ log.warn(`Restored plugin ${(_b = pkg.name) !== null && _b !== void 0 ? _b : pluginDir} peer re-link failed: ${linked.error}`);
143
+ }
144
+ }
145
+ }
146
+ };
107
147
  const withTimeout = (promise, ms, message, onTimeout) => {
108
148
  let timeoutId;
109
149
  return Promise.race([
@@ -138,8 +178,7 @@ const assertBackupExtracted = async (tempDir) => {
138
178
  await access(metadataPath, constants.F_OK);
139
179
  }
140
180
  catch (_a) {
141
- // Legacy Arango JSONL templates (e.g. test-backup.zip) omit metadata.json.
142
- log.warn(`Backup has no metadata.json under ${tempDir}; treating as legacy Arango JSONL`);
181
+ throw new Error('Backup invalid: missing metadata.json (Postgres JSONL archives only)');
143
182
  }
144
183
  try {
145
184
  await access(collectionsPath, constants.F_OK);
@@ -154,15 +193,14 @@ const assertBackupExtracted = async (tempDir) => {
154
193
  }
155
194
  log.info(`Found ${jsonlFiles.length} collection backup files in archive`);
156
195
  };
157
- const restoreDatabaseFromBackup = async (collectionsDir, databaseType, schemaVersion) => {
158
- log.info('Restoring %s database from JSONL collections', databaseType);
159
- const { total } = databaseType === 'postgres'
160
- ? await importAllPostgresCollections(collectionsDir, schemaVersion)
161
- : await importAllArangoCollections(collectionsDir);
196
+ const restoreDatabaseFromBackup = async (collectionsDir, schemaVersion) => {
197
+ log.info('Restoring postgres database from JSONL collections');
198
+ const { total } = await importAllPostgresCollections(collectionsDir, schemaVersion);
162
199
  if (total === 0) {
163
200
  throw new Error('Backup restore completed with zero rows; archive may be empty or corrupt');
164
201
  }
165
- log.info('Restored %d database rows from backup', total);
202
+ const backfilled = await backfillMissingEventOccurrences();
203
+ log.info('Restored %d database rows from backup; indexed %d events', total, backfilled);
166
204
  };
167
205
  export const createBackup = async () => {
168
206
  try {
@@ -187,6 +225,14 @@ export const createBackup = async () => {
187
225
  await cp(coreConfig.logs.local.path, logsDir, {
188
226
  recursive: true,
189
227
  });
228
+ // Admin-installed plugins, so restores and moves carry them with the
229
+ // instance. Missing (e.g. fresh installs) is not an error.
230
+ const pluginsPath = defaultConfig.plugins.path;
231
+ if (await pathExists(pluginsPath)) {
232
+ const backupPluginsDir = join(backupDir, 'plugins');
233
+ await mkdir(backupPluginsDir);
234
+ await cp(pluginsPath, backupPluginsDir, { recursive: true });
235
+ }
190
236
  await writeFile(join(metaDir, 'collectionInfos.json'), JSON.stringify(collectionInfos, null, 2));
191
237
  await writeFile(join(backupDir, 'metadata.json'), JSON.stringify({
192
238
  databaseType: 'postgres',
@@ -244,7 +290,7 @@ export const restoreBackups = async (zipFilePath) => {
244
290
  const backupMetadata = await readFile(join(tempDir, 'metadata.json'), 'utf-8')
245
291
  .then(JSON.parse)
246
292
  .catch(() => undefined);
247
- const databaseType = resolveBackupDatabaseType(backupMetadata);
293
+ resolveBackupDatabaseType(backupMetadata);
248
294
  log.info(`Emptying media directory ${coreConfig.media.storage.params.path}`);
249
295
  await emptyDir(coreConfig.media.storage.params.path);
250
296
  log.info(`Copying media from backup to ${coreConfig.media.storage.params.path}`);
@@ -257,12 +303,26 @@ export const restoreBackups = async (zipFilePath) => {
257
303
  await cp(join(tempDir, 'logs'), coreConfig.logs.local.path, {
258
304
  recursive: true,
259
305
  });
260
- await restoreDatabaseFromBackup(collectionsDir, databaseType, backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.schemaVersion);
306
+ // Older images never archived plugins; never wipe a live plugins tree for
307
+ // such a backup.
308
+ const pluginsPath = defaultConfig.plugins.path;
309
+ const backupPluginsDir = join(tempDir, 'plugins');
310
+ if (await pathExists(backupPluginsDir)) {
311
+ log.info(`Emptying plugins directory ${pluginsPath}`);
312
+ await emptyDir(pluginsPath);
313
+ log.info(`Copying plugins from backup to ${pluginsPath}`);
314
+ await cp(backupPluginsDir, pluginsPath, { recursive: true });
315
+ await relinkRestoredPlugins(pluginsPath);
316
+ }
317
+ else {
318
+ log.info('Backup contains no plugins; leaving existing plugins in place.');
319
+ }
320
+ await restoreDatabaseFromBackup(collectionsDir, backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.schemaVersion);
261
321
  // Repoint the backup's absolute URLs at this server's full origin (scheme +
262
322
  // host + port). Matching by the backup hostname means a prod backup on
263
323
  // `https://host` restores cleanly onto `http://localhost:5174` without
264
324
  // stranding the old scheme/port.
265
325
  await replaceOrigin((_a = backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.config) === null || _a === void 0 ? void 0 : _a.hostname, await serverRootUrl());
266
- log.info(`Restored ${databaseType} backup (hostname was ${(_c = (_b = backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.config) === null || _b === void 0 ? void 0 : _b.hostname) !== null && _c !== void 0 ? _c : 'unknown'})`);
326
+ log.info(`Restored postgres backup (hostname was ${(_c = (_b = backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.config) === null || _b === void 0 ? void 0 : _b.hostname) !== null && _c !== void 0 ? _c : 'unknown'})`);
267
327
  await setDefaultRoles();
268
328
  };
@@ -1,16 +1,15 @@
1
- export type BackupDatabaseType = 'arango' | 'postgres';
1
+ export type BackupDatabaseType = 'postgres';
2
2
  export type BackupMetadata = {
3
3
  databaseType?: BackupDatabaseType;
4
4
  /** When this backup archive was created (ISO-8601). */
5
5
  createdAt?: string;
6
6
  /**
7
7
  * Drizzle journal tag the database was on when the backup was created
8
- * (e.g. `0007_shallow_oracle`). Omitted on legacy Arango archives.
8
+ * (e.g. `0007_shallow_oracle`).
9
9
  */
10
10
  schemaVersion?: string;
11
11
  config?: {
12
12
  hostname?: string;
13
13
  };
14
14
  };
15
- /** Legacy Arango backups omit databaseType; treat them as Arango JSONL. */
16
15
  export declare const resolveBackupDatabaseType: (metadata?: BackupMetadata) => BackupDatabaseType;
@@ -1,2 +1,6 @@
1
- /** Legacy Arango backups omit databaseType; treat them as Arango JSONL. */
2
- export const resolveBackupDatabaseType = (metadata) => (metadata === null || metadata === void 0 ? void 0 : metadata.databaseType) === 'postgres' ? 'postgres' : 'arango';
1
+ export const resolveBackupDatabaseType = (metadata) => {
2
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.databaseType) === 'postgres') {
3
+ return 'postgres';
4
+ }
5
+ throw new Error('Backup is not a Postgres JSONL archive (missing metadata.json databaseType: "postgres")');
6
+ };
@@ -35,8 +35,19 @@ export const defaultCapabilitiesConfig = {
35
35
  ],
36
36
  },
37
37
  self: { add: ['core-profiles-update', ...postCapabilities] },
38
- blocked: { remove: ['*'] },
39
- blockedBy: { remove: ['*'] },
38
+ blocked: {
39
+ remove: [
40
+ 'core-posts-*',
41
+ 'core-profiles-read',
42
+ 'core-profiles-follow',
43
+ 'core-profiles-unfollow',
44
+ 'core-profiles-requestFollow',
45
+ 'core-profiles-block',
46
+ 'core-profiles-mute',
47
+ 'core-profiles-unmute',
48
+ ],
49
+ },
50
+ 'blocked-by': { remove: ['*'] },
40
51
  },
41
52
  report: {
42
53
  reporter: { add: ['core-reports-read'] },
@@ -7,14 +7,18 @@ export const defaultCommunityConfig = {
7
7
  light: {
8
8
  primaryHex: '#15678a',
9
9
  logoSmall: '/img/logo-small.png',
10
- defaultProfileAvatar: '/img/default-avatar.png',
10
+ // No defaultProfileAvatar — profiles without a custom avatar fall back
11
+ // to letter initials in the Avatar component.
11
12
  defaultGroupAvatar: '/img/default-group-avatar.svg',
12
13
  backgroundAuth: '/img/background-auth.png',
13
14
  },
14
15
  dark: {
15
- primaryHex: '#15678a',
16
+ // Lighter than the light-mode primary so it stays readable on the
17
+ // near-black dark background.
18
+ primaryHex: '#38aee1',
16
19
  logoSmall: '/img/logo-small-white.png',
17
- defaultProfileAvatar: '/img/default-avatar.png',
20
+ // No defaultProfileAvatar — profiles without a custom avatar fall back
21
+ // to letter initials in the Avatar component.
18
22
  defaultGroupAvatar: '/img/default-group-avatar.svg',
19
23
  backgroundAuth: '/img/background-auth.png',
20
24
  },
@@ -1,2 +1,2 @@
1
- import type { CoreConfig } from '@openpeepshq/common/types';
1
+ import { type CoreConfig } from '@openpeepshq/common/types';
2
2
  export declare const defaultConfig: CoreConfig;
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_MAX_MEDIA_UPLOAD_MB, } from '@openpeepshq/common/types';
1
2
  import db from './db.js';
2
3
  import redis from './redis.js';
3
4
  import { readEnvInteger, resolveJwtSecret } from '../helpers.js';
@@ -31,6 +32,7 @@ export const defaultConfig = {
31
32
  },
32
33
  logs,
33
34
  media: {
35
+ maxUploadMb: DEFAULT_MAX_MEDIA_UPLOAD_MB,
34
36
  storage: {
35
37
  driver: 'openpeeps',
36
38
  params: {
@@ -65,6 +67,7 @@ export const defaultConfig = {
65
67
  },
66
68
  federation: {
67
69
  active: false,
70
+ allowedHosts: [],
68
71
  },
69
72
  activityPub: {
70
73
  defaultDomain: process.env.ACTIVITY_PUB_DEFAULT_DOMAIN || 'localhost',
@@ -51,6 +51,7 @@ export declare const config: <T = {
51
51
  };
52
52
  };
53
53
  media: {
54
+ maxUploadMb: number;
54
55
  storage: {
55
56
  driver: "openpeeps";
56
57
  params: {
@@ -84,6 +85,7 @@ export declare const config: <T = {
84
85
  };
85
86
  federation: {
86
87
  active: boolean;
88
+ allowedHosts: string[];
87
89
  };
88
90
  activityPub: {
89
91
  defaultDomain: string;
@@ -118,6 +120,10 @@ export declare const config: <T = {
118
120
  tokenUrl: string;
119
121
  userinfoUrl: string;
120
122
  clientId: string;
123
+ kind?: "oidc" | "github" | "gitlab" | "gitlab-selfhosted" | "google" | "entra" | "auth0" | "keycloak" | "authentik" | "okta" | "discord" | "pocketid" | undefined;
124
+ instanceUrl?: string | undefined;
125
+ tenant?: string | undefined;
126
+ emailsUrl?: string | undefined;
121
127
  jwksUri?: string | undefined;
122
128
  clientSecret?: string | undefined;
123
129
  scope?: string | undefined;
@@ -201,6 +207,13 @@ export declare const communityConfig: () => Promise<{
201
207
  };
202
208
  icon?: string | undefined;
203
209
  mobileIcon?: string | undefined;
210
+ primaryHex?: string | undefined;
211
+ logoFull?: string | undefined;
212
+ logoSmall?: string | undefined;
213
+ defaultProfileAvatar?: string | undefined;
214
+ defaultGroupAvatar?: string | undefined;
215
+ backgroundAuth?: string | undefined;
216
+ background?: string | undefined;
204
217
  };
205
218
  info: {
206
219
  name: string;
@@ -219,6 +232,8 @@ export declare const communityConfig: () => Promise<{
219
232
  settings: {
220
233
  openRegistrations: boolean;
221
234
  defaultLanguage?: string | undefined;
235
+ defaultTimeZone?: string | undefined;
236
+ defaultFeedFormat?: "threaded" | "linear" | undefined;
222
237
  };
223
238
  roles: {
224
239
  onRegistration: {
@@ -277,6 +292,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
277
292
  };
278
293
  };
279
294
  media: {
295
+ maxUploadMb: number;
280
296
  storage: {
281
297
  driver: "openpeeps";
282
298
  params: {
@@ -310,6 +326,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
310
326
  };
311
327
  federation: {
312
328
  active: boolean;
329
+ allowedHosts: string[];
313
330
  };
314
331
  activityPub: {
315
332
  defaultDomain: string;
@@ -344,6 +361,10 @@ export declare const sanitizedConfigWithDefaults: <T = {
344
361
  tokenUrl: string;
345
362
  userinfoUrl: string;
346
363
  clientId: string;
364
+ kind?: "oidc" | "github" | "gitlab" | "gitlab-selfhosted" | "google" | "entra" | "auth0" | "keycloak" | "authentik" | "okta" | "discord" | "pocketid" | undefined;
365
+ instanceUrl?: string | undefined;
366
+ tenant?: string | undefined;
367
+ emailsUrl?: string | undefined;
347
368
  jwksUri?: string | undefined;
348
369
  clientSecret?: string | undefined;
349
370
  scope?: string | undefined;