@openpeepshq/core 0.1.33 → 0.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +36 -33
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +17 -12
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +164 -140
  14. package/dist/analytics/report.d.ts +22 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +82 -25
  18. package/dist/backups/metadata.d.ts +2 -3
  19. package/dist/backups/metadata.js +6 -2
  20. package/dist/config/db.js +2 -4
  21. package/dist/config/defaults/capabilities.js +13 -2
  22. package/dist/config/defaults/community.js +8 -3
  23. package/dist/config/defaults/core.d.ts +1 -1
  24. package/dist/config/defaults/core.js +16 -8
  25. package/dist/config/index.d.ts +22 -0
  26. package/dist/config/index.js +15 -11
  27. package/dist/db/explorer/query.js +9 -8
  28. package/dist/db/explorer/sql.js +8 -8
  29. package/dist/db/helpers.d.ts +1 -0
  30. package/dist/db/helpers.js +25 -7
  31. package/dist/db/index.d.ts +1 -1
  32. package/dist/db/index.js +1 -0
  33. package/dist/db/init.js +2 -3
  34. package/dist/db/migration/importCollections.d.ts +14 -9
  35. package/dist/db/migration/importCollections.js +121 -174
  36. package/dist/db/migration/shared.d.ts +2 -33
  37. package/dist/db/migration/shared.js +17 -87
  38. package/dist/db/pg/client.js +4 -7
  39. package/dist/db/pg/collections.d.ts +2 -2
  40. package/dist/db/pg/collections.js +2 -2
  41. package/dist/db/pg/filters/index.js +1 -1
  42. package/dist/db/pg/filters/posts.d.ts +12 -0
  43. package/dist/db/pg/filters/posts.js +30 -4
  44. package/dist/db/pg/filters/profiles.d.ts +1 -0
  45. package/dist/db/pg/filters/profiles.js +2 -1
  46. package/dist/db/pg/helpers.js +2 -14
  47. package/dist/db/pg/map/filters.js +40 -10
  48. package/dist/db/pg/map/helpers.js +5 -1
  49. package/dist/db/pg/map/index.js +46 -51
  50. package/dist/db/pg/map/mutations.js +65 -25
  51. package/dist/db/pg/map/registry.d.ts +5 -0
  52. package/dist/db/pg/map/registry.js +133 -56
  53. package/dist/db/pg/map/relations.js +76 -68
  54. package/dist/db/pg/map/search.js +15 -37
  55. package/dist/db/pg/mappers.js +13 -7
  56. package/dist/db/pg/migrate.d.ts +1 -2
  57. package/dist/db/pg/migrate.js +8 -9
  58. package/dist/db/pg/queries/activity.js +5 -5
  59. package/dist/db/pg/queries/derived.js +8 -12
  60. package/dist/db/pg/queries/sorts.d.ts +1 -0
  61. package/dist/db/pg/queries/sorts.js +4 -0
  62. package/dist/db/pg/schema/documents.d.ts +279 -41
  63. package/dist/db/pg/schema/documents.js +136 -22
  64. package/dist/db/pg/schema/edges.d.ts +116 -7
  65. package/dist/db/pg/schema/edges.js +9 -2
  66. package/dist/db/pg/schema/index.d.ts +362 -15
  67. package/dist/db/pg/schema/index.js +5 -1
  68. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  69. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  70. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  71. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  72. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  73. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  74. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  75. package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
  76. package/dist/db/pg/sql/meta/_journal.json +49 -0
  77. package/dist/db/replaceOrigin.js +1 -1
  78. package/dist/email/queueStats.js +8 -11
  79. package/dist/email/render.js +14 -3
  80. package/dist/email/send.js +19 -17
  81. package/dist/email/smtpTest.js +10 -6
  82. package/dist/errors/index.js +1 -1
  83. package/dist/events/index.d.ts +4 -0
  84. package/dist/events/index.js +1 -0
  85. package/dist/events/once.js +2 -4
  86. package/dist/federation/activities.d.ts +17 -0
  87. package/dist/federation/activities.js +25 -0
  88. package/dist/federation/identity.d.ts +16 -0
  89. package/dist/federation/identity.js +52 -0
  90. package/dist/federation/index.d.ts +4 -0
  91. package/dist/federation/index.js +3 -0
  92. package/dist/federation/profiles.d.ts +3 -0
  93. package/dist/federation/profiles.js +14 -0
  94. package/dist/groups/finders.d.ts +2 -1
  95. package/dist/groups/helpers.d.ts +18 -0
  96. package/dist/groups/helpers.js +1 -2
  97. package/dist/groups/mapping.d.ts +4 -2
  98. package/dist/groups/mutations.js +1 -1
  99. package/dist/hashtags/finders.d.ts +6 -3
  100. package/dist/hashtags/finders.js +2 -0
  101. package/dist/hashtags/helpers.d.ts +8 -0
  102. package/dist/hashtags/helpers.js +4 -0
  103. package/dist/hashtags/index.d.ts +2 -0
  104. package/dist/hashtags/index.js +2 -0
  105. package/dist/hashtags/mutations.d.ts +3 -0
  106. package/dist/hashtags/mutations.js +13 -1
  107. package/dist/i18n/index.d.ts +1 -1
  108. package/dist/i18n/index.js +3 -1
  109. package/dist/i18n/pluginLocales.d.ts +6 -0
  110. package/dist/i18n/pluginLocales.js +15 -0
  111. package/dist/inviteLinks/mutations.js +2 -3
  112. package/dist/jams/export.d.ts +19 -0
  113. package/dist/jams/export.js +58 -0
  114. package/dist/jams/finders.js +4 -1
  115. package/dist/jams/health.d.ts +10 -0
  116. package/dist/jams/health.js +50 -0
  117. package/dist/jams/helpers.d.ts +2 -2
  118. package/dist/jams/helpers.js +6 -2
  119. package/dist/jams/index.d.ts +2 -0
  120. package/dist/jams/index.js +25 -18
  121. package/dist/jams/jobs.js +2 -3
  122. package/dist/jams/livekit.d.ts +49 -4
  123. package/dist/jams/livekit.js +62 -45
  124. package/dist/jams/mapping.d.ts +3 -3
  125. package/dist/jams/mutations.d.ts +1 -1
  126. package/dist/jams/recording.d.ts +10 -0
  127. package/dist/jams/recording.js +33 -1
  128. package/dist/jams/token.d.ts +13 -1
  129. package/dist/jams/token.js +25 -18
  130. package/dist/jams/waitingRoom.js +1 -1
  131. package/dist/jobs/index.d.ts +1 -0
  132. package/dist/jobs/index.js +9 -3
  133. package/dist/jobs/jobDetail.js +6 -12
  134. package/dist/jobs/jobLog.js +2 -3
  135. package/dist/lib/streams.js +4 -39
  136. package/dist/lib/zodDeepPartial.d.ts +1 -1
  137. package/dist/lib/zodDeepPartial.js +1 -1
  138. package/dist/log/index.js +13 -29
  139. package/dist/media/index.d.ts +1 -1
  140. package/dist/media/index.js +73 -12
  141. package/dist/media/jobs.js +1 -2
  142. package/dist/media/openpeeps/index.js +11 -46
  143. package/dist/media/processing.js +25 -11
  144. package/dist/media/streaming.js +5 -5
  145. package/dist/media/streamingCleanupJobs.js +1 -2
  146. package/dist/media/streamingJobs.js +3 -4
  147. package/dist/media/streamingPrewarm.js +7 -11
  148. package/dist/mediaAttachments/index.js +6 -2
  149. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  150. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  151. package/dist/notifications/defaultNotifications/follow/index.js +15 -18
  152. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  153. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  154. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  155. package/dist/notifications/defaultNotifications/index.js +4 -0
  156. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  157. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  158. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  159. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  160. package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
  161. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  162. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  163. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  164. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  165. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
  166. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  167. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  168. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  169. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  170. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  171. package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
  172. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  173. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
  174. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  175. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  176. package/dist/notifications/fcmCredential.js +1 -1
  177. package/dist/notifications/finders.js +1 -1
  178. package/dist/notifications/helpers.js +13 -10
  179. package/dist/notifications/jobs.js +10 -5
  180. package/dist/notifications/mutations.js +8 -1
  181. package/dist/notifications/push.js +11 -16
  182. package/dist/performance/index.js +3 -3
  183. package/dist/plugins/helpers.js +3 -6
  184. package/dist/plugins/index.js +39 -4
  185. package/dist/plugins/install.d.ts +28 -9
  186. package/dist/plugins/install.js +302 -56
  187. package/dist/plugins/pluginAuth.d.ts +1 -1
  188. package/dist/plugins/pluginAuth.js +13 -10
  189. package/dist/plugins/state.js +2 -3
  190. package/dist/posts/activity.d.ts +9 -0
  191. package/dist/posts/activity.js +34 -0
  192. package/dist/posts/contextClosure.d.ts +1 -9
  193. package/dist/posts/contextClosure.js +14 -44
  194. package/dist/posts/conversationQueries.d.ts +7 -0
  195. package/dist/posts/conversationQueries.js +76 -4
  196. package/dist/posts/eventAgenda.d.ts +1 -0
  197. package/dist/posts/eventAgenda.js +17 -8
  198. package/dist/posts/eventOccurrenceJobs.js +7 -2
  199. package/dist/posts/eventOccurrences.d.ts +6 -0
  200. package/dist/posts/eventOccurrences.js +22 -1
  201. package/dist/posts/finders.d.ts +56 -9
  202. package/dist/posts/finders.js +84 -23
  203. package/dist/posts/helpers/filters.js +13 -9
  204. package/dist/posts/helpers/index.d.ts +179 -14
  205. package/dist/posts/helpers/index.js +70 -34
  206. package/dist/posts/index.d.ts +5 -2
  207. package/dist/posts/index.js +5 -2
  208. package/dist/posts/mapping.d.ts +765 -30
  209. package/dist/posts/mapping.js +74 -31
  210. package/dist/posts/mutations.d.ts +516 -3
  211. package/dist/posts/mutations.js +179 -41
  212. package/dist/posts/pollEnd.d.ts +3 -0
  213. package/dist/posts/pollEnd.js +4 -0
  214. package/dist/posts/pollEndJobs.d.ts +8 -0
  215. package/dist/posts/pollEndJobs.js +49 -0
  216. package/dist/posts/replyClosure.d.ts +10 -0
  217. package/dist/posts/replyClosure.js +43 -0
  218. package/dist/posts/rsvpConfirmationEmail.js +23 -15
  219. package/dist/posts/threadPreview.d.ts +8 -0
  220. package/dist/posts/threadPreview.js +44 -0
  221. package/dist/posts/unseenCounts.js +4 -1
  222. package/dist/processingStats/queries.js +6 -7
  223. package/dist/profileSettings/cache.js +21 -5
  224. package/dist/profileSettings/mapping.d.ts +2 -0
  225. package/dist/profiles/activityQueries.d.ts +5 -0
  226. package/dist/profiles/activityQueries.js +85 -0
  227. package/dist/profiles/activitySummary.d.ts +3 -0
  228. package/dist/profiles/activitySummary.js +82 -0
  229. package/dist/profiles/blocks.d.ts +12 -0
  230. package/dist/profiles/blocks.js +73 -0
  231. package/dist/profiles/cache.d.ts +1 -0
  232. package/dist/profiles/cache.js +30 -10
  233. package/dist/profiles/export.js +30 -39
  234. package/dist/profiles/finders.d.ts +2 -1
  235. package/dist/profiles/finders.js +15 -8
  236. package/dist/profiles/helpers.d.ts +2 -0
  237. package/dist/profiles/index.d.ts +2 -0
  238. package/dist/profiles/index.js +2 -0
  239. package/dist/profiles/mapping.d.ts +10 -5
  240. package/dist/profiles/mapping.js +13 -1
  241. package/dist/profiles/mutations.d.ts +8 -4
  242. package/dist/profiles/mutations.js +31 -4
  243. package/dist/redis/connection.d.ts +2 -0
  244. package/dist/redis/connection.js +25 -6
  245. package/dist/reports/helpers.js +7 -3
  246. package/dist/roles/index.d.ts +1 -1
  247. package/dist/roles/index.js +1 -1
  248. package/dist/roles/mapping.d.ts +1 -0
  249. package/dist/roles/mutations.js +85 -3
  250. package/dist/search/finders.js +15 -3
  251. package/dist/search/helpers.js +1 -1
  252. package/dist/search/mapping.d.ts +1 -1
  253. package/dist/search/mapping.js +6 -2
  254. package/dist/sentry/index.js +9 -11
  255. package/dist/seo/index.d.ts +50 -0
  256. package/dist/seo/index.js +145 -0
  257. package/dist/seo/route.d.ts +18 -0
  258. package/dist/seo/route.js +19 -0
  259. package/dist/server/index.d.ts +19 -0
  260. package/dist/server/index.js +31 -14
  261. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  262. package/dist/server/stablePublicServerInfo.js +37 -0
  263. package/dist/server/status.d.ts +25 -0
  264. package/dist/server/status.js +97 -0
  265. package/dist/session/index.js +2 -2
  266. package/dist/stats/finders.d.ts +1 -17681
  267. package/dist/stats/finders.js +22 -9
  268. package/dist/stats/helpers.js +4 -1
  269. package/dist/stats/mapping.d.ts +39 -2
  270. package/dist/stats/mapping.js +8 -4
  271. package/dist/stripe/cache.js +5 -6
  272. package/dist/stripe/connection.js +3 -4
  273. package/dist/stripe/helpers.js +15 -20
  274. package/package.json +5 -7
  275. package/dist/db/migration/detect.d.ts +0 -3
  276. package/dist/db/migration/detect.js +0 -33
  277. package/dist/db/migration/importPostgres.d.ts +0 -3
  278. package/dist/db/migration/importPostgres.js +0 -18
  279. package/dist/db/migration/transform.d.ts +0 -20
  280. package/dist/db/migration/transform.js +0 -232
  281. package/dist/db/migration/validate.d.ts +0 -18
  282. package/dist/db/migration/validate.js +0 -69
  283. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  284. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  285. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  286. package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
  287. package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
  288. package/dist/mastodon/index.d.ts +0 -4
  289. package/dist/mastodon/index.js +0 -51
  290. package/dist/mastodon/types.d.ts +0 -7579
  291. package/dist/mastodon/types.js +0 -523
  292. package/dist/mastodon/typescript.d.ts +0 -1578
  293. package/dist/mastodon/typescript.js +0 -1
  294. package/dist/migration/index.d.ts +0 -4
  295. package/dist/migration/index.js +0 -4
  296. package/dist/roles/defaults.d.ts +0 -2
  297. package/dist/roles/defaults.js +0 -95
@@ -7,14 +7,20 @@ import { analyticsCacheKey, getAnalyticsCache, setAnalyticsCache, } from './cach
7
7
  import { aggregateSeriesIntoBuckets, eachUtcDay, resolveAnalyticsRange, selectChartBuckets, } from './dateRange.js';
8
8
  import { metricCard, sumSeries, averageSeries } from './metrics.js';
9
9
  import { isPublicAnalyticsGroup } from './privacy.js';
10
- const POST_TYPE_KEYS = ['jam', 'article', 'note', 'poll', 'event'];
10
+ const POST_TYPE_KEYS = [
11
+ 'jam',
12
+ 'article',
13
+ 'note',
14
+ 'poll',
15
+ 'event',
16
+ 'resource',
17
+ ];
11
18
  const todayString = () => formatISO(startOfDay(new Date()), { representation: 'date' });
12
19
  const includesToday = (to) => to >= todayString();
13
20
  const utcDayStart = (day) => `${day}T00:00:00.000Z`;
14
21
  const exclusiveEnd = (day) => `${formatISO(addDays(parseISO(utcDayStart(day)), 1), { representation: 'date' })}T00:00:00.000Z`;
15
22
  const rollingMauFrom = (to) => formatISO(subDays(parseISO(utcDayStart(to)), 29), { representation: 'date' });
16
23
  const countDistinctActives = async (from, to) => {
17
- var _a, _b;
18
24
  const db = await database();
19
25
  const start = utcDayStart(from);
20
26
  const end = exclusiveEnd(to);
@@ -24,8 +30,9 @@ const countDistinctActives = async (from, to) => {
24
30
  where deleted_at is null
25
31
  and created_at >= ${start} and created_at < ${end}
26
32
  union
27
- select from_id from reactions
28
- where created_at >= ${start} and created_at < ${end}
33
+ select from_id from entries
34
+ where body->>'type' in ('reaction', 'unreaction')
35
+ and created_at >= ${start} and created_at < ${end}
29
36
  union
30
37
  select from_id from repost
31
38
  where created_at >= ${start} and created_at < ${end}
@@ -38,16 +45,15 @@ const countDistinctActives = async (from, to) => {
38
45
  ) active
39
46
  `);
40
47
  const rows = result.rows;
41
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
48
+ return Number(rows[0]?.c ?? 0);
42
49
  };
43
50
  /** Earliest day with compiled analytics — used to bound the `all` preset. */
44
51
  const earliestAnalyticsDay = async () => {
45
- var _a;
46
52
  const db = await database();
47
53
  const [row] = await db
48
54
  .select({ day: min(analyticsDailyTotals.day) })
49
55
  .from(analyticsDailyTotals);
50
- return (_a = row === null || row === void 0 ? void 0 : row.day) !== null && _a !== void 0 ? _a : null;
56
+ return row?.day ?? null;
51
57
  };
52
58
  const resolveQueryRange = async (query = {}) => {
53
59
  const range = resolveAnalyticsRange(query);
@@ -56,11 +62,14 @@ const resolveQueryRange = async (query = {}) => {
56
62
  const earliest = await earliestAnalyticsDay();
57
63
  if (!earliest || earliest <= range.from)
58
64
  return range;
59
- return Object.assign(Object.assign({}, resolveAnalyticsRange({ from: earliest, to: range.to })), { preset: 'all' });
65
+ return {
66
+ ...resolveAnalyticsRange({ from: earliest, to: range.to }),
67
+ preset: 'all',
68
+ };
60
69
  };
61
70
  const seriesFromTotals = (days, rows) => {
62
71
  const map = new Map(rows.map((r) => [r.day, r.value]));
63
- return days.map((day) => { var _a; return ({ day, value: (_a = map.get(day)) !== null && _a !== void 0 ? _a : 0 }); });
72
+ return days.map((day) => ({ day, value: map.get(day) ?? 0 }));
64
73
  };
65
74
  const loadTotalsSeries = async (from, to, column) => {
66
75
  const db = await database();
@@ -71,22 +80,51 @@ const loadTotalsSeries = async (from, to, column) => {
71
80
  .from(analyticsDailyTotals)
72
81
  .where(and(gte(analyticsDailyTotals.day, from), lte(analyticsDailyTotals.day, to)))
73
82
  .orderBy(asc(analyticsDailyTotals.day));
74
- return seriesFromTotals(days, rows.map((r) => { var _a; return ({ day: r.day, value: Number((_a = r.value) !== null && _a !== void 0 ? _a : 0) }); }));
83
+ return seriesFromTotals(days, rows.map((r) => ({ day: r.day, value: Number(r.value ?? 0) })));
75
84
  };
76
85
  const sumColumn = async (from, to, column) => sumSeries(await loadTotalsSeries(from, to, column));
77
86
  const totalMembersAt = async (day) => {
78
- var _a, _b;
79
87
  const db = await database();
80
88
  const end = `${day}T23:59:59.999Z`;
81
89
  const result = await db.execute(sql `
82
90
  select count(*)::int as c from profiles
83
- where deleted_at is null and created_at <= ${end}
91
+ where deleted_at is null and type = 'local'
92
+ and created_at <= ${end}
93
+ `);
94
+ const rows = result.rows;
95
+ return Number(rows[0]?.c ?? 0);
96
+ };
97
+ const verifiedMembersAt = async (day) => {
98
+ const db = await database();
99
+ const end = `${day}T23:59:59.999Z`;
100
+ const result = await db.execute(sql `
101
+ select count(*)::int as c from profiles p
102
+ join controls c on c.to_id = p.id::text
103
+ join accounts a on a.id::text = c.from_id
104
+ where p.deleted_at is null and p.type = 'local'
105
+ and a.deleted_at is null
106
+ and a.email_validated = true
107
+ and p.created_at <= ${end}
84
108
  `);
85
109
  const rows = result.rows;
86
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
110
+ return Number(rows[0]?.c ?? 0);
111
+ };
112
+ const unverifiedMembersAt = async (day) => {
113
+ const db = await database();
114
+ const end = `${day}T23:59:59.999Z`;
115
+ const result = await db.execute(sql `
116
+ select count(*)::int as c from profiles p
117
+ join controls c on c.to_id = p.id::text
118
+ join accounts a on a.id::text = c.from_id
119
+ where p.deleted_at is null and p.type = 'local'
120
+ and a.deleted_at is null
121
+ and a.email_validated = false
122
+ and p.created_at <= ${end}
123
+ `);
124
+ const rows = result.rows;
125
+ return Number(rows[0]?.c ?? 0);
87
126
  };
88
127
  const totalPostsAt = async (day) => {
89
- var _a, _b;
90
128
  const db = await database();
91
129
  const end = `${day}T23:59:59.999Z`;
92
130
  const result = await db.execute(sql `
@@ -96,10 +134,9 @@ const totalPostsAt = async (day) => {
96
134
  and created_at <= ${end}
97
135
  `);
98
136
  const rows = result.rows;
99
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
137
+ return Number(rows[0]?.c ?? 0);
100
138
  };
101
139
  const latestCompiledAt = async (from, to) => {
102
- var _a, _b;
103
140
  const db = await database();
104
141
  const rows = await db
105
142
  .select({ compiledAt: analyticsDailyTotals.compiledAt })
@@ -107,10 +144,10 @@ const latestCompiledAt = async (from, to) => {
107
144
  .where(and(gte(analyticsDailyTotals.day, from), lte(analyticsDailyTotals.day, to)))
108
145
  .orderBy(desc(analyticsDailyTotals.compiledAt))
109
146
  .limit(1);
110
- return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.compiledAt) !== null && _b !== void 0 ? _b : null;
147
+ return rows[0]?.compiledAt ?? null;
111
148
  };
112
149
  const groupVisibility = (body) => isPublicAnalyticsGroup(body) ? 'public' : 'private';
113
- const groupDisplayName = (body, handle) => { var _a, _b, _c; return (_c = (_b = (_a = body.name) !== null && _a !== void 0 ? _a : body.displayName) !== null && _b !== void 0 ? _b : handle) !== null && _c !== void 0 ? _c : undefined; };
150
+ const groupDisplayName = (body, handle) => body.name ?? body.displayName ?? handle ?? undefined;
114
151
  const enrichGroupRows = async (rows, from, to) => {
115
152
  if (rows.length === 0)
116
153
  return [];
@@ -144,21 +181,17 @@ const enrichGroupRows = async (rows, from, to) => {
144
181
  from groups g
145
182
  where g.id::text in (${sql.join(ids.map((id) => sql `${id}`), sql `, `)})
146
183
  `);
147
- const metaById = new Map(metaResult.rows.map((r) => {
148
- var _a, _b, _c;
149
- return [
150
- r.group_id,
151
- {
152
- members: Number((_a = r.members) !== null && _a !== void 0 ? _a : 0),
153
- growth: Number((_b = r.growth) !== null && _b !== void 0 ? _b : 0),
154
- activeMembers: Number((_c = r.active_members) !== null && _c !== void 0 ? _c : 0),
155
- },
156
- ];
157
- }));
184
+ const metaById = new Map(metaResult.rows.map((r) => [
185
+ r.group_id,
186
+ {
187
+ members: Number(r.members ?? 0),
188
+ growth: Number(r.growth ?? 0),
189
+ activeMembers: Number(r.active_members ?? 0),
190
+ },
191
+ ]));
158
192
  return rows.map((r) => {
159
- var _a, _b, _c;
160
- const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
161
- const meta = (_b = metaById.get(r.groupId)) !== null && _b !== void 0 ? _b : {
193
+ const body = (r.body ?? {});
194
+ const meta = metaById.get(r.groupId) ?? {
162
195
  members: 0,
163
196
  growth: 0,
164
197
  activeMembers: 0,
@@ -168,7 +201,7 @@ const enrichGroupRows = async (rows, from, to) => {
168
201
  : Math.round(((r.likes + r.comments) / r.uniqueViewers) * 1000) / 10;
169
202
  return {
170
203
  groupId: r.groupId,
171
- handle: (_c = r.handle) !== null && _c !== void 0 ? _c : undefined,
204
+ handle: r.handle ?? undefined,
172
205
  name: groupDisplayName(body, r.handle),
173
206
  posts: r.posts,
174
207
  likes: r.likes,
@@ -205,11 +238,10 @@ const topGroups = async (from, to, limit = 6) => {
205
238
  + coalesce(${sum(analyticsDailyByGroup.comments)}, 0)`))
206
239
  .limit(limit);
207
240
  return enrichGroupRows(rows.map((r) => {
208
- var _a, _b, _c, _d;
209
- const postsCount = Number((_a = r.posts) !== null && _a !== void 0 ? _a : 0);
210
- const likesCount = Number((_b = r.likes) !== null && _b !== void 0 ? _b : 0);
211
- const commentsCount = Number((_c = r.comments) !== null && _c !== void 0 ? _c : 0);
212
- const viewers = Number((_d = r.uniqueViewers) !== null && _d !== void 0 ? _d : 0);
241
+ const postsCount = Number(r.posts ?? 0);
242
+ const likesCount = Number(r.likes ?? 0);
243
+ const commentsCount = Number(r.comments ?? 0);
244
+ const viewers = Number(r.uniqueViewers ?? 0);
213
245
  return {
214
246
  groupId: r.groupId,
215
247
  handle: r.handle,
@@ -224,7 +256,6 @@ const topGroups = async (from, to, limit = 6) => {
224
256
  };
225
257
  /** Top groups by new-member joins in range, with bucketed join series. */
226
258
  const groupGrowthOverTime = async (from, to, limit = 6) => {
227
- var _a;
228
259
  const db = await database();
229
260
  const start = `${from}T00:00:00.000Z`;
230
261
  const end = `${to}T23:59:59.999Z`;
@@ -245,12 +276,11 @@ const groupGrowthOverTime = async (from, to, limit = 6) => {
245
276
  `);
246
277
  const topRows = topResult.rows;
247
278
  const series = topRows.map((r, i) => {
248
- var _a, _b;
249
- const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
279
+ const body = (r.body ?? {});
250
280
  return {
251
281
  key: `g${i}`,
252
282
  groupId: r.group_id,
253
- name: (_b = groupDisplayName(body, r.handle)) !== null && _b !== void 0 ? _b : r.group_id.slice(0, 8),
283
+ name: groupDisplayName(body, r.handle) ?? r.group_id.slice(0, 8),
254
284
  };
255
285
  });
256
286
  if (series.length === 0) {
@@ -274,17 +304,16 @@ const groupGrowthOverTime = async (from, to, limit = 6) => {
274
304
  const key = idToKey.get(row.group_id);
275
305
  if (!key)
276
306
  continue;
277
- byDayGroup.set(`${row.day}:${key}`, Number((_a = row.c) !== null && _a !== void 0 ? _a : 0));
307
+ byDayGroup.set(`${row.day}:${key}`, Number(row.c ?? 0));
278
308
  }
279
309
  const { buckets } = selectChartBuckets(from, to);
280
310
  const overTime = buckets.map((bucket) => {
281
- var _a;
282
311
  const values = {};
283
312
  for (const s of series)
284
313
  values[s.key] = 0;
285
314
  for (const day of eachUtcDay(bucket.from, bucket.to)) {
286
315
  for (const s of series) {
287
- values[s.key] += (_a = byDayGroup.get(`${day}:${s.key}`)) !== null && _a !== void 0 ? _a : 0;
316
+ values[s.key] += byDayGroup.get(`${day}:${s.key}`) ?? 0;
288
317
  }
289
318
  }
290
319
  return { day: bucket.key, label: bucket.label, values };
@@ -306,6 +335,7 @@ const loadPostsByTypeDaily = async (from, to) => {
306
335
  when type = 'question' then 'poll'
307
336
  when type = 'article' then 'article'
308
337
  when type = 'event' then 'event'
338
+ when type = 'resource' then 'resource'
309
339
  else 'note'
310
340
  end as kind,
311
341
  count(*)::int as c
@@ -317,17 +347,13 @@ const loadPostsByTypeDaily = async (from, to) => {
317
347
  group by 1, 2
318
348
  order by 1
319
349
  `);
320
- return result.rows.map((r) => {
321
- var _a;
322
- return ({
323
- day: r.day,
324
- kind: r.kind,
325
- count: Number((_a = r.c) !== null && _a !== void 0 ? _a : 0),
326
- });
327
- });
350
+ return result.rows.map((r) => ({
351
+ day: r.day,
352
+ kind: r.kind,
353
+ count: Number(r.c ?? 0),
354
+ }));
328
355
  };
329
356
  const totalGroupsAt = async (day) => {
330
- var _a, _b;
331
357
  const db = await database();
332
358
  const end = `${day}T23:59:59.999Z`;
333
359
  const result = await db.execute(sql `
@@ -335,7 +361,7 @@ const totalGroupsAt = async (day) => {
335
361
  where deleted_at is null and created_at <= ${end}
336
362
  `);
337
363
  const rows = result.rows;
338
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
364
+ return Number(rows[0]?.c ?? 0);
339
365
  };
340
366
  const topMembers = async (from, to, limit = 10) => {
341
367
  const db = await database();
@@ -348,8 +374,9 @@ const topMembers = async (from, to, limit = 10) => {
348
374
  and visibility <> 'direct'
349
375
  and created_at >= ${start} and created_at <= ${end}
350
376
  union all
351
- select from_id from reactions
352
- where created_at >= ${start} and created_at <= ${end}
377
+ select from_id from entries
378
+ where body->>'type' in ('reaction', 'unreaction')
379
+ and created_at >= ${start} and created_at <= ${end}
353
380
  union all
354
381
  select from_id from reply_to
355
382
  where created_at >= ${start} and created_at <= ${end}
@@ -392,19 +419,16 @@ const topMembers = async (from, to, limit = 10) => {
392
419
  join profiles p on p.id::text = s.profile_id
393
420
  where p.created_at is not null
394
421
  `);
395
- return result.rows.map((r) => {
396
- var _a, _b, _c, _d, _e, _f;
397
- return ({
398
- profileId: r.profile_id,
399
- handle: (_a = r.handle) !== null && _a !== void 0 ? _a : r.profile_id.slice(0, 8),
400
- displayName: (_e = (_c = (_b = r.body) === null || _b === void 0 ? void 0 : _b.displayName) !== null && _c !== void 0 ? _c : (_d = r.body) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : undefined,
401
- role: r.role,
402
- joinedAt: typeof r.created_at === 'string'
403
- ? r.created_at
404
- : new Date(r.created_at).toISOString(),
405
- contributions: Number((_f = r.contributions) !== null && _f !== void 0 ? _f : 0),
406
- });
407
- });
422
+ return result.rows.map((r) => ({
423
+ profileId: r.profile_id,
424
+ handle: r.handle ?? r.profile_id.slice(0, 8),
425
+ displayName: r.body?.displayName ?? r.body?.name ?? undefined,
426
+ role: r.role,
427
+ joinedAt: typeof r.created_at === 'string'
428
+ ? r.created_at
429
+ : new Date(r.created_at).toISOString(),
430
+ contributions: Number(r.contributions ?? 0),
431
+ }));
408
432
  };
409
433
  /**
410
434
  * Top posts must not expose DM content or private-group posts (snippets +
@@ -440,25 +464,26 @@ const topPostsByViews = async (from, to, limit = 10) => {
440
464
  .orderBy(desc(sum(analyticsPostViewsDaily.uniqueViewers)))
441
465
  .limit(limit);
442
466
  return rows.map((r) => {
443
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
444
- const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
445
- const content = (_f = (_d = (_c = (_b = body.title) !== null && _b !== void 0 ? _b : body.name) !== null && _c !== void 0 ? _c : body.content) !== null && _d !== void 0 ? _d : (_e = body.data) === null || _e === void 0 ? void 0 : _e.content) !== null && _f !== void 0 ? _f : '';
467
+ const body = (r.body ?? {});
468
+ const content = body.title ?? body.name ?? body.content ?? body.data?.content ?? '';
446
469
  const postType = r.type === 'event' && body.jam != null
447
470
  ? 'jam'
448
471
  : r.type === 'question'
449
472
  ? 'poll'
450
- : ((_g = r.type) !== null && _g !== void 0 ? _g : 'note');
451
- const profileBody = ((_h = r.profileBody) !== null && _h !== void 0 ? _h : {});
473
+ : r.type === 'resource'
474
+ ? 'resource'
475
+ : (r.type ?? 'note');
476
+ const profileBody = (r.profileBody ?? {});
452
477
  return {
453
478
  postId: r.postId,
454
479
  snippet: typeof content === 'string'
455
480
  ? content.slice(0, 120) || undefined
456
481
  : undefined,
457
- authorHandle: (_j = r.handle) !== null && _j !== void 0 ? _j : undefined,
458
- authorDisplayName: (_l = (_k = profileBody.displayName) !== null && _k !== void 0 ? _k : profileBody.name) !== null && _l !== void 0 ? _l : undefined,
482
+ authorHandle: r.handle ?? undefined,
483
+ authorDisplayName: profileBody.displayName ?? profileBody.name ?? undefined,
459
484
  postType,
460
- uniqueViewers: Number((_m = r.uniqueViewers) !== null && _m !== void 0 ? _m : 0),
461
- viewEvents: Number((_o = r.viewEvents) !== null && _o !== void 0 ? _o : 0),
485
+ uniqueViewers: Number(r.uniqueViewers ?? 0),
486
+ viewEvents: Number(r.viewEvents ?? 0),
462
487
  };
463
488
  });
464
489
  };
@@ -473,9 +498,10 @@ const withCache = async (section, from, to, build) => {
473
498
  };
474
499
  export const getAnalyticsOverview = async (query = {}) => {
475
500
  const range = await resolveQueryRange(query);
476
- return withCache('overview-v6', range.from, range.to, async () => {
477
- 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([
501
+ // Unique people in the window — summing daily rollups would count a
502
+ // member once per day they were active.
503
+ return withCache('overview-v7', range.from, range.to, async () => {
504
+ 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
505
  loadTotalsSeries(range.from, range.to, 'activeMembers'),
480
506
  loadTotalsSeries(range.from, range.to, 'posts'),
481
507
  loadTotalsSeries(range.from, range.to, 'likes'),
@@ -489,13 +515,17 @@ export const getAnalyticsOverview = async (query = {}) => {
489
515
  totalMembersAt(range.to),
490
516
  totalGroupsAt(range.to),
491
517
  totalPostsAt(range.to),
492
- sumColumn(range.previousFrom, range.previousTo, 'activeMembers'),
518
+ countDistinctActives(range.from, range.to),
519
+ countDistinctActives(range.previousFrom, range.previousTo),
493
520
  sumColumn(range.previousFrom, range.previousTo, 'posts'),
494
521
  totalMembersAt(range.previousTo),
495
522
  totalGroupsAt(range.previousTo),
496
523
  totalPostsAt(range.previousTo),
524
+ verifiedMembersAt(range.to),
525
+ unverifiedMembersAt(range.to),
526
+ verifiedMembersAt(range.previousTo),
527
+ unverifiedMembersAt(range.previousTo),
497
528
  ]);
498
- const activeMembers = sumSeries(activeMembersSeries);
499
529
  const totalPosts = sumSeries(postsSeries);
500
530
  const { buckets } = selectChartBuckets(range.from, range.to);
501
531
  const typeTotals = Object.fromEntries(POST_TYPE_KEYS.map((k) => [k, 0]));
@@ -505,12 +535,11 @@ export const getAnalyticsOverview = async (query = {}) => {
505
535
  ? row.kind
506
536
  : 'note';
507
537
  typeTotals[kind] += row.count;
508
- const dayMap = (_a = dailyByType.get(row.day)) !== null && _a !== void 0 ? _a : {};
509
- dayMap[kind] = ((_b = dayMap[kind]) !== null && _b !== void 0 ? _b : 0) + row.count;
538
+ const dayMap = dailyByType.get(row.day) ?? {};
539
+ dayMap[kind] = (dayMap[kind] ?? 0) + row.count;
510
540
  dailyByType.set(row.day, dayMap);
511
541
  }
512
542
  const postsOverTime = buckets.map((bucket) => {
513
- var _a;
514
543
  const point = {
515
544
  day: bucket.key,
516
545
  label: bucket.label,
@@ -519,13 +548,14 @@ export const getAnalyticsOverview = async (query = {}) => {
519
548
  note: 0,
520
549
  poll: 0,
521
550
  event: 0,
551
+ resource: 0,
522
552
  };
523
553
  for (const day of eachUtcDay(bucket.from, bucket.to)) {
524
554
  const dayMap = dailyByType.get(day);
525
555
  if (!dayMap)
526
556
  continue;
527
557
  for (const key of POST_TYPE_KEYS) {
528
- point[key] += (_a = dayMap[key]) !== null && _a !== void 0 ? _a : 0;
558
+ point[key] += dayMap[key] ?? 0;
529
559
  }
530
560
  }
531
561
  return point;
@@ -536,8 +566,7 @@ export const getAnalyticsOverview = async (query = {}) => {
536
566
  }));
537
567
  const activeUsersSeries = aggregateSeriesIntoBuckets(activeMembersSeries, buckets);
538
568
  const engagementRateSeries = postsSeries.map((p, i) => {
539
- var _a, _b, _c, _d;
540
- const engagements = ((_b = (_a = likesSeries[i]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = commentsSeries[i]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
569
+ const engagements = (likesSeries[i]?.value ?? 0) + (commentsSeries[i]?.value ?? 0);
541
570
  const postCount = p.value;
542
571
  return {
543
572
  day: p.day,
@@ -547,11 +576,13 @@ export const getAnalyticsOverview = async (query = {}) => {
547
576
  };
548
577
  });
549
578
  return {
550
- range: Object.assign(Object.assign({}, range), { compiledAt }),
579
+ range: { ...range, compiledAt },
551
580
  metrics: {
552
581
  totalPosts: metricCard('totalPosts', totalPosts, prevPosts, postsSeries),
553
582
  allTimePosts: metricCard('allTimePosts', allTimePosts, prevAllTimePosts),
554
583
  totalMembers: metricCard('totalMembers', totalMembers, prevTotalMembers),
584
+ verifiedMembers: metricCard('verifiedMembers', verifiedMembers, prevVerifiedMembers),
585
+ unverifiedMembers: metricCard('unverifiedMembers', unverifiedMembers, prevUnverifiedMembers),
555
586
  activeMembers: metricCard('activeMembers', activeMembers, prevActive, activeMembersSeries),
556
587
  totalGroups: metricCard('totalGroups', totalGroups, prevTotalGroups),
557
588
  },
@@ -601,25 +632,19 @@ export const getAnalyticsGrowth = async (query = {}) => {
601
632
  const dauMau = mau === 0 ? 0 : Math.round((dau / mau) * 1000) / 10;
602
633
  const prevDauMau = prevMau === 0 ? 0 : Math.round((prevDau / prevMau) * 1000) / 10;
603
634
  const byDay = new Map(newMembersSeries.map((p) => [p.day, p.value]));
604
- const signupsByDay = eachUtcDay(range.from, range.to).map((day) => {
605
- var _a;
606
- return ({
607
- day,
608
- value: (_a = byDay.get(day)) !== null && _a !== void 0 ? _a : 0,
609
- });
610
- });
611
- const recentSignups = recentRows.rows.map((r) => {
612
- var _a;
613
- return ({
614
- profileId: String(r.id),
615
- handle: r.handle,
616
- displayName: (_a = r.body) === null || _a === void 0 ? void 0 : _a.displayName,
617
- joinedAt: r.created_at,
618
- channel: r.channel,
619
- });
620
- });
635
+ const signupsByDay = eachUtcDay(range.from, range.to).map((day) => ({
636
+ day,
637
+ value: byDay.get(day) ?? 0,
638
+ }));
639
+ const recentSignups = recentRows.rows.map((r) => ({
640
+ profileId: String(r.id),
641
+ handle: r.handle,
642
+ displayName: r.body?.displayName,
643
+ joinedAt: r.created_at,
644
+ channel: r.channel,
645
+ }));
621
646
  return {
622
- range: Object.assign(Object.assign({}, range), { compiledAt }),
647
+ range: { ...range, compiledAt },
623
648
  metrics: {
624
649
  newSignups: metricCard('newSignups', newSignups, prevNew, newMembersSeries),
625
650
  dau: metricCard('dau', dau, prevDau, activeMembersSeries),
@@ -659,20 +684,17 @@ export const getAnalyticsEngagement = async (query = {}) => {
659
684
  const bookmarksByBucket = aggregateSeriesIntoBuckets(bookmarksSeries, buckets);
660
685
  const dmsByBucket = aggregateSeriesIntoBuckets(dmsSeries, buckets);
661
686
  const impressionsByPeriod = aggregateSeriesIntoBuckets(impressionsSeries, buckets);
662
- const engagementOverTime = buckets.map((bucket, i) => {
663
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
664
- return ({
665
- day: bucket.key,
666
- label: bucket.label,
667
- likes: (_b = (_a = likesByBucket[i]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0,
668
- comments: (_d = (_c = commentsByBucket[i]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0,
669
- reposts: (_f = (_e = repostsByBucket[i]) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0,
670
- bookmarks: (_h = (_g = bookmarksByBucket[i]) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0,
671
- dms: (_k = (_j = dmsByBucket[i]) === null || _j === void 0 ? void 0 : _j.value) !== null && _k !== void 0 ? _k : 0,
672
- });
673
- });
687
+ const engagementOverTime = buckets.map((bucket, i) => ({
688
+ day: bucket.key,
689
+ label: bucket.label,
690
+ likes: likesByBucket[i]?.value ?? 0,
691
+ comments: commentsByBucket[i]?.value ?? 0,
692
+ reposts: repostsByBucket[i]?.value ?? 0,
693
+ bookmarks: bookmarksByBucket[i]?.value ?? 0,
694
+ dms: dmsByBucket[i]?.value ?? 0,
695
+ }));
674
696
  return {
675
- range: Object.assign(Object.assign({}, range), { compiledAt }),
697
+ range: { ...range, compiledAt },
676
698
  metrics: {
677
699
  likes: metricCard('likes', sumSeries(likesSeries), prevLikes, likesSeries),
678
700
  comments: metricCard('comments', sumSeries(commentsSeries), prevComments, commentsSeries),
@@ -705,24 +727,21 @@ export const getAnalyticsRetention = async (query = {}) => {
705
727
  const avg = (key) => {
706
728
  if (rates.length === 0)
707
729
  return 0;
708
- return (Math.round((rates.reduce((a, r) => { var _a; return a + Number((_a = r[key]) !== null && _a !== void 0 ? _a : 0); }, 0) / rates.length) *
730
+ return (Math.round((rates.reduce((a, r) => a + Number(r[key] ?? 0), 0) / rates.length) *
709
731
  10) / 10);
710
732
  };
711
733
  return {
712
- range: Object.assign(Object.assign({}, range), { compiledAt }),
734
+ range: { ...range, compiledAt },
713
735
  metrics: {
714
736
  day1: metricCard('day1', avg('1'), 0),
715
737
  day7: metricCard('day7', avg('7'), 0),
716
738
  day30: metricCard('day30', avg('30'), 0),
717
739
  },
718
- cohorts: cohortRows.map((c) => {
719
- var _a;
720
- return ({
721
- cohortWeek: c.cohortWeek,
722
- cohortSize: c.cohortSize,
723
- rates: ((_a = c.rates) !== null && _a !== void 0 ? _a : {}),
724
- });
725
- }),
740
+ cohorts: cohortRows.map((c) => ({
741
+ cohortWeek: c.cohortWeek,
742
+ cohortSize: c.cohortSize,
743
+ rates: (c.rates ?? {}),
744
+ })),
726
745
  retentionByGroup: groups,
727
746
  };
728
747
  });
@@ -730,23 +749,28 @@ export const getAnalyticsRetention = async (query = {}) => {
730
749
  export const exportAnalyticsCsv = async (query = {}) => {
731
750
  const overview = await getAnalyticsOverview(query);
732
751
  const lines = [
733
- 'bucket,label,active_members,posts,jams,articles,notes,polls,events',
752
+ 'bucket,label,active_members,posts,jams,articles,notes,polls,events,resources',
734
753
  ...overview.activeUsersSeries.map((p, i) => {
735
- var _a, _b, _c, _d, _e;
736
754
  const posts = overview.postsOverTime[i];
737
755
  const postTotal = posts
738
- ? posts.jam + posts.article + posts.note + posts.poll + posts.event
756
+ ? posts.jam +
757
+ posts.article +
758
+ posts.note +
759
+ posts.poll +
760
+ posts.event +
761
+ posts.resource
739
762
  : 0;
740
763
  return [
741
764
  p.day,
742
765
  p.label,
743
766
  p.value,
744
767
  postTotal,
745
- (_a = posts === null || posts === void 0 ? void 0 : posts.jam) !== null && _a !== void 0 ? _a : 0,
746
- (_b = posts === null || posts === void 0 ? void 0 : posts.article) !== null && _b !== void 0 ? _b : 0,
747
- (_c = posts === null || posts === void 0 ? void 0 : posts.note) !== null && _c !== void 0 ? _c : 0,
748
- (_d = posts === null || posts === void 0 ? void 0 : posts.poll) !== null && _d !== void 0 ? _d : 0,
749
- (_e = posts === null || posts === void 0 ? void 0 : posts.event) !== null && _e !== void 0 ? _e : 0,
768
+ posts?.jam ?? 0,
769
+ posts?.article ?? 0,
770
+ posts?.note ?? 0,
771
+ posts?.poll ?? 0,
772
+ posts?.event ?? 0,
773
+ posts?.resource ?? 0,
750
774
  ].join(',');
751
775
  }),
752
776
  ];
@@ -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;
@@ -72,9 +92,10 @@ export declare const buildAnalyticsBoardReport: (query?: AnalyticsDateQuery) =>
72
92
  note: number;
73
93
  poll: number;
74
94
  event: number;
95
+ resource: number;
75
96
  }[];
76
97
  postTypes: {
77
- type: "poll" | "note" | "event" | "article" | "jam";
98
+ type: "resource" | "poll" | "note" | "event" | "article" | "jam";
78
99
  count: number;
79
100
  }[];
80
101
  activeUsersSeries: {
@@ -112,15 +112,14 @@ export const buildSimplePdf = (text) => {
112
112
  return Buffer.from(pdf);
113
113
  };
114
114
  export const sendMonthlyAnalyticsReport = async (overridePeriod) => {
115
- var _a, _b;
116
115
  const settings = await getAnalyticsReportSettings();
117
116
  if (!settings.enabled || settings.recipients.length === 0) {
118
117
  log.info('Monthly analytics report skipped (disabled or no recipients)');
119
118
  return { sent: false, recipients: [] };
120
119
  }
121
120
  const previousMonth = subMonths(new Date(), 1);
122
- const from = (_a = overridePeriod === null || overridePeriod === void 0 ? void 0 : overridePeriod.from) !== null && _a !== void 0 ? _a : dayString(startOfMonth(previousMonth));
123
- const to = (_b = overridePeriod === null || overridePeriod === void 0 ? void 0 : overridePeriod.to) !== null && _b !== void 0 ? _b : dayString(endOfMonth(previousMonth));
121
+ const from = overridePeriod?.from ?? dayString(startOfMonth(previousMonth));
122
+ const to = overridePeriod?.to ?? dayString(endOfMonth(previousMonth));
124
123
  const { text, pdf } = await buildAnalyticsBoardReport({ from, to });
125
124
  const filename = `analytics-${from}-${to}.pdf`;
126
125
  const db = await database();