@openpeepshq/core 0.1.34 → 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 (165) 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 +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  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 +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/index.d.ts +1 -0
  23. package/dist/config/index.js +9 -11
  24. package/dist/db/explorer/query.js +9 -8
  25. package/dist/db/explorer/sql.js +8 -8
  26. package/dist/db/helpers.js +15 -5
  27. package/dist/db/migration/importCollections.js +15 -18
  28. package/dist/db/migration/shared.js +15 -35
  29. package/dist/db/pg/client.js +4 -7
  30. package/dist/db/pg/filters/index.js +1 -1
  31. package/dist/db/pg/filters/posts.d.ts +2 -0
  32. package/dist/db/pg/filters/posts.js +2 -0
  33. package/dist/db/pg/helpers.js +2 -14
  34. package/dist/db/pg/map/filters.js +8 -8
  35. package/dist/db/pg/map/helpers.js +5 -1
  36. package/dist/db/pg/map/index.js +46 -51
  37. package/dist/db/pg/map/mutations.js +56 -21
  38. package/dist/db/pg/map/registry.js +87 -50
  39. package/dist/db/pg/map/relations.js +67 -63
  40. package/dist/db/pg/map/search.js +15 -37
  41. package/dist/db/pg/mappers.js +13 -7
  42. package/dist/db/pg/migrate.js +2 -3
  43. package/dist/db/pg/queries/activity.js +2 -2
  44. package/dist/db/pg/queries/derived.js +8 -12
  45. package/dist/db/pg/schema/documents.js +119 -18
  46. package/dist/db/pg/schema/edges.js +7 -1
  47. package/dist/db/pg/schema/index.js +5 -1
  48. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  49. package/dist/db/pg/sql/meta/_journal.json +8 -1
  50. package/dist/db/replaceOrigin.js +1 -1
  51. package/dist/email/queueStats.js +8 -11
  52. package/dist/email/render.js +7 -4
  53. package/dist/email/send.js +19 -17
  54. package/dist/email/smtpTest.js +10 -6
  55. package/dist/errors/index.js +1 -1
  56. package/dist/events/once.js +2 -4
  57. package/dist/federation/activities.js +1 -2
  58. package/dist/groups/helpers.js +1 -2
  59. package/dist/groups/mutations.js +1 -1
  60. package/dist/hashtags/finders.js +2 -2
  61. package/dist/inviteLinks/mutations.js +2 -3
  62. package/dist/jams/export.js +5 -7
  63. package/dist/jams/finders.js +4 -1
  64. package/dist/jams/health.d.ts +6 -4
  65. package/dist/jams/health.js +15 -11
  66. package/dist/jams/helpers.js +6 -2
  67. package/dist/jams/index.js +2 -2
  68. package/dist/jams/jobs.js +1 -2
  69. package/dist/jams/livekit.js +8 -8
  70. package/dist/jams/recording.js +1 -1
  71. package/dist/jams/token.js +13 -17
  72. package/dist/jobs/index.js +7 -6
  73. package/dist/jobs/jobDetail.js +5 -6
  74. package/dist/jobs/jobLog.js +2 -3
  75. package/dist/lib/streams.js +4 -39
  76. package/dist/lib/zodDeepPartial.d.ts +1 -1
  77. package/dist/lib/zodDeepPartial.js +1 -1
  78. package/dist/log/index.js +13 -29
  79. package/dist/media/index.js +50 -4
  80. package/dist/media/jobs.js +1 -2
  81. package/dist/media/openpeeps/index.js +11 -46
  82. package/dist/media/processing.js +7 -4
  83. package/dist/media/streaming.js +5 -5
  84. package/dist/media/streamingCleanupJobs.js +1 -2
  85. package/dist/media/streamingJobs.js +3 -4
  86. package/dist/media/streamingPrewarm.js +7 -11
  87. package/dist/mediaAttachments/index.js +6 -2
  88. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  89. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  90. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  91. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  92. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  93. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  94. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  95. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  96. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  97. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  98. package/dist/notifications/defaultNotifications/newGroupPost/index.js +6 -7
  99. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  100. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  101. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  102. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  103. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  104. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  105. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  106. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  107. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  108. package/dist/notifications/fcmCredential.js +1 -1
  109. package/dist/notifications/finders.js +1 -1
  110. package/dist/notifications/helpers.js +13 -10
  111. package/dist/notifications/jobs.js +10 -7
  112. package/dist/notifications/mutations.js +4 -1
  113. package/dist/notifications/push.js +11 -16
  114. package/dist/performance/index.js +3 -3
  115. package/dist/plugins/helpers.js +3 -6
  116. package/dist/plugins/index.js +2 -3
  117. package/dist/plugins/install.js +31 -17
  118. package/dist/plugins/pluginAuth.js +3 -4
  119. package/dist/plugins/state.js +2 -3
  120. package/dist/posts/activity.js +1 -2
  121. package/dist/posts/contextClosure.js +1 -2
  122. package/dist/posts/conversationQueries.js +2 -4
  123. package/dist/posts/eventAgenda.js +8 -5
  124. package/dist/posts/eventOccurrences.js +2 -2
  125. package/dist/posts/finders.d.ts +42 -2
  126. package/dist/posts/finders.js +21 -9
  127. package/dist/posts/helpers/filters.js +2 -3
  128. package/dist/posts/helpers/index.d.ts +152 -0
  129. package/dist/posts/helpers/index.js +43 -27
  130. package/dist/posts/mapping.d.ts +546 -14
  131. package/dist/posts/mapping.js +60 -18
  132. package/dist/posts/mutations.d.ts +76 -0
  133. package/dist/posts/mutations.js +46 -31
  134. package/dist/posts/pollEnd.js +3 -6
  135. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  136. package/dist/posts/threadPreview.js +1 -1
  137. package/dist/processingStats/queries.js +6 -7
  138. package/dist/profileSettings/cache.js +1 -2
  139. package/dist/profiles/activitySummary.js +23 -28
  140. package/dist/profiles/cache.js +15 -8
  141. package/dist/profiles/export.js +30 -39
  142. package/dist/profiles/finders.js +7 -5
  143. package/dist/profiles/mutations.js +3 -5
  144. package/dist/redis/connection.js +1 -1
  145. package/dist/reports/helpers.js +7 -3
  146. package/dist/roles/mutations.js +20 -21
  147. package/dist/search/finders.js +15 -3
  148. package/dist/search/helpers.js +1 -1
  149. package/dist/sentry/index.js +9 -11
  150. package/dist/seo/index.d.ts +50 -0
  151. package/dist/seo/index.js +145 -0
  152. package/dist/seo/route.d.ts +18 -0
  153. package/dist/seo/route.js +19 -0
  154. package/dist/server/index.d.ts +1 -0
  155. package/dist/server/index.js +16 -11
  156. package/dist/server/status.js +6 -7
  157. package/dist/session/index.js +2 -2
  158. package/dist/stats/finders.js +13 -4
  159. package/dist/stats/helpers.js +4 -1
  160. package/dist/stats/mapping.d.ts +39 -1
  161. package/dist/stats/mapping.js +9 -2
  162. package/dist/stripe/cache.js +5 -6
  163. package/dist/stripe/connection.js +3 -4
  164. package/dist/stripe/helpers.js +15 -20
  165. package/package.json +5 -6
@@ -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);
@@ -39,16 +45,15 @@ const countDistinctActives = async (from, to) => {
39
45
  ) active
40
46
  `);
41
47
  const rows = result.rows;
42
- 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);
43
49
  };
44
50
  /** Earliest day with compiled analytics — used to bound the `all` preset. */
45
51
  const earliestAnalyticsDay = async () => {
46
- var _a;
47
52
  const db = await database();
48
53
  const [row] = await db
49
54
  .select({ day: min(analyticsDailyTotals.day) })
50
55
  .from(analyticsDailyTotals);
51
- return (_a = row === null || row === void 0 ? void 0 : row.day) !== null && _a !== void 0 ? _a : null;
56
+ return row?.day ?? null;
52
57
  };
53
58
  const resolveQueryRange = async (query = {}) => {
54
59
  const range = resolveAnalyticsRange(query);
@@ -57,11 +62,14 @@ const resolveQueryRange = async (query = {}) => {
57
62
  const earliest = await earliestAnalyticsDay();
58
63
  if (!earliest || earliest <= range.from)
59
64
  return range;
60
- 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
+ };
61
69
  };
62
70
  const seriesFromTotals = (days, rows) => {
63
71
  const map = new Map(rows.map((r) => [r.day, r.value]));
64
- 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 }));
65
73
  };
66
74
  const loadTotalsSeries = async (from, to, column) => {
67
75
  const db = await database();
@@ -72,11 +80,10 @@ const loadTotalsSeries = async (from, to, column) => {
72
80
  .from(analyticsDailyTotals)
73
81
  .where(and(gte(analyticsDailyTotals.day, from), lte(analyticsDailyTotals.day, to)))
74
82
  .orderBy(asc(analyticsDailyTotals.day));
75
- 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) })));
76
84
  };
77
85
  const sumColumn = async (from, to, column) => sumSeries(await loadTotalsSeries(from, to, column));
78
86
  const totalMembersAt = async (day) => {
79
- var _a, _b;
80
87
  const db = await database();
81
88
  const end = `${day}T23:59:59.999Z`;
82
89
  const result = await db.execute(sql `
@@ -85,10 +92,9 @@ const totalMembersAt = async (day) => {
85
92
  and created_at <= ${end}
86
93
  `);
87
94
  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);
95
+ return Number(rows[0]?.c ?? 0);
89
96
  };
90
97
  const verifiedMembersAt = async (day) => {
91
- var _a, _b;
92
98
  const db = await database();
93
99
  const end = `${day}T23:59:59.999Z`;
94
100
  const result = await db.execute(sql `
@@ -101,10 +107,9 @@ const verifiedMembersAt = async (day) => {
101
107
  and p.created_at <= ${end}
102
108
  `);
103
109
  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);
110
+ return Number(rows[0]?.c ?? 0);
105
111
  };
106
112
  const unverifiedMembersAt = async (day) => {
107
- var _a, _b;
108
113
  const db = await database();
109
114
  const end = `${day}T23:59:59.999Z`;
110
115
  const result = await db.execute(sql `
@@ -117,10 +122,9 @@ const unverifiedMembersAt = async (day) => {
117
122
  and p.created_at <= ${end}
118
123
  `);
119
124
  const rows = result.rows;
120
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
125
+ return Number(rows[0]?.c ?? 0);
121
126
  };
122
127
  const totalPostsAt = async (day) => {
123
- var _a, _b;
124
128
  const db = await database();
125
129
  const end = `${day}T23:59:59.999Z`;
126
130
  const result = await db.execute(sql `
@@ -130,10 +134,9 @@ const totalPostsAt = async (day) => {
130
134
  and created_at <= ${end}
131
135
  `);
132
136
  const rows = result.rows;
133
- 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);
134
138
  };
135
139
  const latestCompiledAt = async (from, to) => {
136
- var _a, _b;
137
140
  const db = await database();
138
141
  const rows = await db
139
142
  .select({ compiledAt: analyticsDailyTotals.compiledAt })
@@ -141,10 +144,10 @@ const latestCompiledAt = async (from, to) => {
141
144
  .where(and(gte(analyticsDailyTotals.day, from), lte(analyticsDailyTotals.day, to)))
142
145
  .orderBy(desc(analyticsDailyTotals.compiledAt))
143
146
  .limit(1);
144
- 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;
145
148
  };
146
149
  const groupVisibility = (body) => isPublicAnalyticsGroup(body) ? 'public' : 'private';
147
- 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;
148
151
  const enrichGroupRows = async (rows, from, to) => {
149
152
  if (rows.length === 0)
150
153
  return [];
@@ -178,21 +181,17 @@ const enrichGroupRows = async (rows, from, to) => {
178
181
  from groups g
179
182
  where g.id::text in (${sql.join(ids.map((id) => sql `${id}`), sql `, `)})
180
183
  `);
181
- const metaById = new Map(metaResult.rows.map((r) => {
182
- var _a, _b, _c;
183
- return [
184
- r.group_id,
185
- {
186
- members: Number((_a = r.members) !== null && _a !== void 0 ? _a : 0),
187
- growth: Number((_b = r.growth) !== null && _b !== void 0 ? _b : 0),
188
- activeMembers: Number((_c = r.active_members) !== null && _c !== void 0 ? _c : 0),
189
- },
190
- ];
191
- }));
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
+ ]));
192
192
  return rows.map((r) => {
193
- var _a, _b, _c;
194
- const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
195
- const meta = (_b = metaById.get(r.groupId)) !== null && _b !== void 0 ? _b : {
193
+ const body = (r.body ?? {});
194
+ const meta = metaById.get(r.groupId) ?? {
196
195
  members: 0,
197
196
  growth: 0,
198
197
  activeMembers: 0,
@@ -202,7 +201,7 @@ const enrichGroupRows = async (rows, from, to) => {
202
201
  : Math.round(((r.likes + r.comments) / r.uniqueViewers) * 1000) / 10;
203
202
  return {
204
203
  groupId: r.groupId,
205
- handle: (_c = r.handle) !== null && _c !== void 0 ? _c : undefined,
204
+ handle: r.handle ?? undefined,
206
205
  name: groupDisplayName(body, r.handle),
207
206
  posts: r.posts,
208
207
  likes: r.likes,
@@ -239,11 +238,10 @@ const topGroups = async (from, to, limit = 6) => {
239
238
  + coalesce(${sum(analyticsDailyByGroup.comments)}, 0)`))
240
239
  .limit(limit);
241
240
  return enrichGroupRows(rows.map((r) => {
242
- var _a, _b, _c, _d;
243
- const postsCount = Number((_a = r.posts) !== null && _a !== void 0 ? _a : 0);
244
- const likesCount = Number((_b = r.likes) !== null && _b !== void 0 ? _b : 0);
245
- const commentsCount = Number((_c = r.comments) !== null && _c !== void 0 ? _c : 0);
246
- 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);
247
245
  return {
248
246
  groupId: r.groupId,
249
247
  handle: r.handle,
@@ -258,7 +256,6 @@ const topGroups = async (from, to, limit = 6) => {
258
256
  };
259
257
  /** Top groups by new-member joins in range, with bucketed join series. */
260
258
  const groupGrowthOverTime = async (from, to, limit = 6) => {
261
- var _a;
262
259
  const db = await database();
263
260
  const start = `${from}T00:00:00.000Z`;
264
261
  const end = `${to}T23:59:59.999Z`;
@@ -279,12 +276,11 @@ const groupGrowthOverTime = async (from, to, limit = 6) => {
279
276
  `);
280
277
  const topRows = topResult.rows;
281
278
  const series = topRows.map((r, i) => {
282
- var _a, _b;
283
- const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
279
+ const body = (r.body ?? {});
284
280
  return {
285
281
  key: `g${i}`,
286
282
  groupId: r.group_id,
287
- 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),
288
284
  };
289
285
  });
290
286
  if (series.length === 0) {
@@ -308,17 +304,16 @@ const groupGrowthOverTime = async (from, to, limit = 6) => {
308
304
  const key = idToKey.get(row.group_id);
309
305
  if (!key)
310
306
  continue;
311
- 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));
312
308
  }
313
309
  const { buckets } = selectChartBuckets(from, to);
314
310
  const overTime = buckets.map((bucket) => {
315
- var _a;
316
311
  const values = {};
317
312
  for (const s of series)
318
313
  values[s.key] = 0;
319
314
  for (const day of eachUtcDay(bucket.from, bucket.to)) {
320
315
  for (const s of series) {
321
- 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;
322
317
  }
323
318
  }
324
319
  return { day: bucket.key, label: bucket.label, values };
@@ -340,6 +335,7 @@ const loadPostsByTypeDaily = async (from, to) => {
340
335
  when type = 'question' then 'poll'
341
336
  when type = 'article' then 'article'
342
337
  when type = 'event' then 'event'
338
+ when type = 'resource' then 'resource'
343
339
  else 'note'
344
340
  end as kind,
345
341
  count(*)::int as c
@@ -351,17 +347,13 @@ const loadPostsByTypeDaily = async (from, to) => {
351
347
  group by 1, 2
352
348
  order by 1
353
349
  `);
354
- return result.rows.map((r) => {
355
- var _a;
356
- return ({
357
- day: r.day,
358
- kind: r.kind,
359
- count: Number((_a = r.c) !== null && _a !== void 0 ? _a : 0),
360
- });
361
- });
350
+ return result.rows.map((r) => ({
351
+ day: r.day,
352
+ kind: r.kind,
353
+ count: Number(r.c ?? 0),
354
+ }));
362
355
  };
363
356
  const totalGroupsAt = async (day) => {
364
- var _a, _b;
365
357
  const db = await database();
366
358
  const end = `${day}T23:59:59.999Z`;
367
359
  const result = await db.execute(sql `
@@ -369,7 +361,7 @@ const totalGroupsAt = async (day) => {
369
361
  where deleted_at is null and created_at <= ${end}
370
362
  `);
371
363
  const rows = result.rows;
372
- 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);
373
365
  };
374
366
  const topMembers = async (from, to, limit = 10) => {
375
367
  const db = await database();
@@ -427,19 +419,16 @@ const topMembers = async (from, to, limit = 10) => {
427
419
  join profiles p on p.id::text = s.profile_id
428
420
  where p.created_at is not null
429
421
  `);
430
- return result.rows.map((r) => {
431
- var _a, _b, _c, _d, _e, _f;
432
- return ({
433
- profileId: r.profile_id,
434
- handle: (_a = r.handle) !== null && _a !== void 0 ? _a : r.profile_id.slice(0, 8),
435
- 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,
436
- role: r.role,
437
- joinedAt: typeof r.created_at === 'string'
438
- ? r.created_at
439
- : new Date(r.created_at).toISOString(),
440
- contributions: Number((_f = r.contributions) !== null && _f !== void 0 ? _f : 0),
441
- });
442
- });
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
+ }));
443
432
  };
444
433
  /**
445
434
  * Top posts must not expose DM content or private-group posts (snippets +
@@ -475,25 +464,26 @@ const topPostsByViews = async (from, to, limit = 10) => {
475
464
  .orderBy(desc(sum(analyticsPostViewsDaily.uniqueViewers)))
476
465
  .limit(limit);
477
466
  return rows.map((r) => {
478
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
479
- const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
480
- 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 ?? '';
481
469
  const postType = r.type === 'event' && body.jam != null
482
470
  ? 'jam'
483
471
  : r.type === 'question'
484
472
  ? 'poll'
485
- : ((_g = r.type) !== null && _g !== void 0 ? _g : 'note');
486
- 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 ?? {});
487
477
  return {
488
478
  postId: r.postId,
489
479
  snippet: typeof content === 'string'
490
480
  ? content.slice(0, 120) || undefined
491
481
  : undefined,
492
- authorHandle: (_j = r.handle) !== null && _j !== void 0 ? _j : undefined,
493
- 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,
494
484
  postType,
495
- uniqueViewers: Number((_m = r.uniqueViewers) !== null && _m !== void 0 ? _m : 0),
496
- viewEvents: Number((_o = r.viewEvents) !== null && _o !== void 0 ? _o : 0),
485
+ uniqueViewers: Number(r.uniqueViewers ?? 0),
486
+ viewEvents: Number(r.viewEvents ?? 0),
497
487
  };
498
488
  });
499
489
  };
@@ -511,7 +501,6 @@ export const getAnalyticsOverview = async (query = {}) => {
511
501
  // Unique people in the window — summing daily rollups would count a
512
502
  // member once per day they were active.
513
503
  return withCache('overview-v7', range.from, range.to, async () => {
514
- var _a, _b;
515
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([
516
505
  loadTotalsSeries(range.from, range.to, 'activeMembers'),
517
506
  loadTotalsSeries(range.from, range.to, 'posts'),
@@ -546,12 +535,11 @@ export const getAnalyticsOverview = async (query = {}) => {
546
535
  ? row.kind
547
536
  : 'note';
548
537
  typeTotals[kind] += row.count;
549
- const dayMap = (_a = dailyByType.get(row.day)) !== null && _a !== void 0 ? _a : {};
550
- 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;
551
540
  dailyByType.set(row.day, dayMap);
552
541
  }
553
542
  const postsOverTime = buckets.map((bucket) => {
554
- var _a;
555
543
  const point = {
556
544
  day: bucket.key,
557
545
  label: bucket.label,
@@ -560,13 +548,14 @@ export const getAnalyticsOverview = async (query = {}) => {
560
548
  note: 0,
561
549
  poll: 0,
562
550
  event: 0,
551
+ resource: 0,
563
552
  };
564
553
  for (const day of eachUtcDay(bucket.from, bucket.to)) {
565
554
  const dayMap = dailyByType.get(day);
566
555
  if (!dayMap)
567
556
  continue;
568
557
  for (const key of POST_TYPE_KEYS) {
569
- point[key] += (_a = dayMap[key]) !== null && _a !== void 0 ? _a : 0;
558
+ point[key] += dayMap[key] ?? 0;
570
559
  }
571
560
  }
572
561
  return point;
@@ -577,8 +566,7 @@ export const getAnalyticsOverview = async (query = {}) => {
577
566
  }));
578
567
  const activeUsersSeries = aggregateSeriesIntoBuckets(activeMembersSeries, buckets);
579
568
  const engagementRateSeries = postsSeries.map((p, i) => {
580
- var _a, _b, _c, _d;
581
- 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);
582
570
  const postCount = p.value;
583
571
  return {
584
572
  day: p.day,
@@ -588,7 +576,7 @@ export const getAnalyticsOverview = async (query = {}) => {
588
576
  };
589
577
  });
590
578
  return {
591
- range: Object.assign(Object.assign({}, range), { compiledAt }),
579
+ range: { ...range, compiledAt },
592
580
  metrics: {
593
581
  totalPosts: metricCard('totalPosts', totalPosts, prevPosts, postsSeries),
594
582
  allTimePosts: metricCard('allTimePosts', allTimePosts, prevAllTimePosts),
@@ -644,25 +632,19 @@ export const getAnalyticsGrowth = async (query = {}) => {
644
632
  const dauMau = mau === 0 ? 0 : Math.round((dau / mau) * 1000) / 10;
645
633
  const prevDauMau = prevMau === 0 ? 0 : Math.round((prevDau / prevMau) * 1000) / 10;
646
634
  const byDay = new Map(newMembersSeries.map((p) => [p.day, p.value]));
647
- const signupsByDay = eachUtcDay(range.from, range.to).map((day) => {
648
- var _a;
649
- return ({
650
- day,
651
- value: (_a = byDay.get(day)) !== null && _a !== void 0 ? _a : 0,
652
- });
653
- });
654
- const recentSignups = recentRows.rows.map((r) => {
655
- var _a;
656
- return ({
657
- profileId: String(r.id),
658
- handle: r.handle,
659
- displayName: (_a = r.body) === null || _a === void 0 ? void 0 : _a.displayName,
660
- joinedAt: r.created_at,
661
- channel: r.channel,
662
- });
663
- });
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
+ }));
664
646
  return {
665
- range: Object.assign(Object.assign({}, range), { compiledAt }),
647
+ range: { ...range, compiledAt },
666
648
  metrics: {
667
649
  newSignups: metricCard('newSignups', newSignups, prevNew, newMembersSeries),
668
650
  dau: metricCard('dau', dau, prevDau, activeMembersSeries),
@@ -702,20 +684,17 @@ export const getAnalyticsEngagement = async (query = {}) => {
702
684
  const bookmarksByBucket = aggregateSeriesIntoBuckets(bookmarksSeries, buckets);
703
685
  const dmsByBucket = aggregateSeriesIntoBuckets(dmsSeries, buckets);
704
686
  const impressionsByPeriod = aggregateSeriesIntoBuckets(impressionsSeries, buckets);
705
- const engagementOverTime = buckets.map((bucket, i) => {
706
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
707
- return ({
708
- day: bucket.key,
709
- label: bucket.label,
710
- likes: (_b = (_a = likesByBucket[i]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0,
711
- comments: (_d = (_c = commentsByBucket[i]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0,
712
- reposts: (_f = (_e = repostsByBucket[i]) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0,
713
- bookmarks: (_h = (_g = bookmarksByBucket[i]) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0,
714
- dms: (_k = (_j = dmsByBucket[i]) === null || _j === void 0 ? void 0 : _j.value) !== null && _k !== void 0 ? _k : 0,
715
- });
716
- });
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
+ }));
717
696
  return {
718
- range: Object.assign(Object.assign({}, range), { compiledAt }),
697
+ range: { ...range, compiledAt },
719
698
  metrics: {
720
699
  likes: metricCard('likes', sumSeries(likesSeries), prevLikes, likesSeries),
721
700
  comments: metricCard('comments', sumSeries(commentsSeries), prevComments, commentsSeries),
@@ -748,24 +727,21 @@ export const getAnalyticsRetention = async (query = {}) => {
748
727
  const avg = (key) => {
749
728
  if (rates.length === 0)
750
729
  return 0;
751
- 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) *
752
731
  10) / 10);
753
732
  };
754
733
  return {
755
- range: Object.assign(Object.assign({}, range), { compiledAt }),
734
+ range: { ...range, compiledAt },
756
735
  metrics: {
757
736
  day1: metricCard('day1', avg('1'), 0),
758
737
  day7: metricCard('day7', avg('7'), 0),
759
738
  day30: metricCard('day30', avg('30'), 0),
760
739
  },
761
- cohorts: cohortRows.map((c) => {
762
- var _a;
763
- return ({
764
- cohortWeek: c.cohortWeek,
765
- cohortSize: c.cohortSize,
766
- rates: ((_a = c.rates) !== null && _a !== void 0 ? _a : {}),
767
- });
768
- }),
740
+ cohorts: cohortRows.map((c) => ({
741
+ cohortWeek: c.cohortWeek,
742
+ cohortSize: c.cohortSize,
743
+ rates: (c.rates ?? {}),
744
+ })),
769
745
  retentionByGroup: groups,
770
746
  };
771
747
  });
@@ -773,23 +749,28 @@ export const getAnalyticsRetention = async (query = {}) => {
773
749
  export const exportAnalyticsCsv = async (query = {}) => {
774
750
  const overview = await getAnalyticsOverview(query);
775
751
  const lines = [
776
- 'bucket,label,active_members,posts,jams,articles,notes,polls,events',
752
+ 'bucket,label,active_members,posts,jams,articles,notes,polls,events,resources',
777
753
  ...overview.activeUsersSeries.map((p, i) => {
778
- var _a, _b, _c, _d, _e;
779
754
  const posts = overview.postsOverTime[i];
780
755
  const postTotal = posts
781
- ? 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
782
762
  : 0;
783
763
  return [
784
764
  p.day,
785
765
  p.label,
786
766
  p.value,
787
767
  postTotal,
788
- (_a = posts === null || posts === void 0 ? void 0 : posts.jam) !== null && _a !== void 0 ? _a : 0,
789
- (_b = posts === null || posts === void 0 ? void 0 : posts.article) !== null && _b !== void 0 ? _b : 0,
790
- (_c = posts === null || posts === void 0 ? void 0 : posts.note) !== null && _c !== void 0 ? _c : 0,
791
- (_d = posts === null || posts === void 0 ? void 0 : posts.poll) !== null && _d !== void 0 ? _d : 0,
792
- (_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,
793
774
  ].join(',');
794
775
  }),
795
776
  ];
@@ -92,9 +92,10 @@ export declare const buildAnalyticsBoardReport: (query?: AnalyticsDateQuery) =>
92
92
  note: number;
93
93
  poll: number;
94
94
  event: number;
95
+ resource: number;
95
96
  }[];
96
97
  postTypes: {
97
- type: "poll" | "note" | "event" | "article" | "jam";
98
+ type: "resource" | "poll" | "note" | "event" | "article" | "jam";
98
99
  count: number;
99
100
  }[];
100
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();
@@ -6,17 +6,16 @@ const DEFAULT_SETTINGS = {
6
6
  recipients: [],
7
7
  };
8
8
  export const getAnalyticsReportSettings = async () => {
9
- var _a, _b, _c, _d;
10
9
  const db = await database();
11
10
  const rows = await db
12
11
  .select()
13
12
  .from(analyticsSettings)
14
13
  .where(eq(analyticsSettings.id, 'default'))
15
14
  .limit(1);
16
- const body = ((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {});
15
+ const body = (rows[0]?.body ?? {});
17
16
  return {
18
- enabled: (_c = body.enabled) !== null && _c !== void 0 ? _c : DEFAULT_SETTINGS.enabled,
19
- recipients: (_d = body.recipients) !== null && _d !== void 0 ? _d : DEFAULT_SETTINGS.recipients,
17
+ enabled: body.enabled ?? DEFAULT_SETTINGS.enabled,
18
+ recipients: body.recipients ?? DEFAULT_SETTINGS.recipients,
20
19
  };
21
20
  };
22
21
  export const setAnalyticsReportSettings = async (settings) => {