@openpeepshq/core 0.1.34 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +13 -8
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +1 -2
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +116 -135
- package/dist/analytics/report.d.ts +2 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +13 -16
- package/dist/backups/metadata.js +1 -1
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/community.js +1 -0
- package/dist/config/defaults/core.js +13 -8
- package/dist/config/defaults/logs.d.ts +4 -0
- package/dist/config/defaults/logs.js +5 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +9 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.js +15 -5
- package/dist/db/migration/importCollections.js +15 -18
- package/dist/db/migration/shared.js +15 -35
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +2 -0
- package/dist/db/pg/filters/posts.js +3 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +8 -8
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +56 -21
- package/dist/db/pg/map/registry.js +87 -50
- package/dist/db/pg/map/relations.js +67 -63
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.js +2 -3
- package/dist/db/pg/queries/activity.js +2 -2
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/schema/documents.js +119 -18
- package/dist/db/pg/schema/edges.js +7 -1
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/_journal.json +8 -1
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +7 -4
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.js +1 -2
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.js +2 -2
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.js +5 -7
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +6 -4
- package/dist/jams/health.js +15 -11
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.js +2 -2
- package/dist/jams/jobs.js +1 -2
- package/dist/jams/livekit.d.ts +2 -2
- package/dist/jams/livekit.js +8 -8
- package/dist/jams/mapping.d.ts +10 -10
- package/dist/jams/mutations.d.ts +2 -2
- package/dist/jams/recording.js +1 -1
- package/dist/jams/token.js +13 -17
- package/dist/jobs/index.js +7 -6
- package/dist/jobs/jobDetail.js +5 -6
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.js +14 -29
- package/dist/log/retention.d.ts +9 -0
- package/dist/log/retention.js +83 -0
- package/dist/log/retentionJobs.d.ts +17 -0
- package/dist/log/retentionJobs.js +50 -0
- package/dist/media/index.js +127 -4
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +7 -4
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/mediaAttachments/mapping.d.ts +1 -1
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/jamModerator/index.js +27 -20
- package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +9 -10
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
- package/dist/notifications/eventIcsAttachment.d.ts +6 -0
- package/dist/notifications/eventIcsAttachment.js +32 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.d.ts +11 -1
- package/dist/notifications/helpers.js +38 -9
- package/dist/notifications/jobs.js +16 -7
- package/dist/notifications/mutations.js +13 -2
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +2 -3
- package/dist/plugins/install.js +31 -17
- package/dist/plugins/pluginAuth.js +3 -4
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +1 -1
- package/dist/posts/activity.js +2 -3
- package/dist/posts/contextClosure.js +1 -2
- package/dist/posts/conversationQueries.js +2 -4
- package/dist/posts/eventAgenda.js +12 -7
- package/dist/posts/eventOccurrences.js +2 -2
- package/dist/posts/finders.d.ts +46 -6
- package/dist/posts/finders.js +21 -9
- package/dist/posts/helpers/filters.js +2 -3
- package/dist/posts/helpers/index.d.ts +170 -18
- package/dist/posts/helpers/index.js +43 -27
- package/dist/posts/mapping.d.ts +616 -84
- package/dist/posts/mapping.js +60 -18
- package/dist/posts/mutations.d.ts +85 -9
- package/dist/posts/mutations.js +47 -34
- package/dist/posts/pollEnd.js +3 -6
- package/dist/posts/rsvpConfirmationEmail.js +18 -8
- package/dist/posts/threadPreview.js +1 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +1 -2
- package/dist/profileSettings/mapping.d.ts +1 -0
- package/dist/profiles/activitySummary.js +23 -28
- package/dist/profiles/cache.js +15 -8
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.js +7 -5
- package/dist/profiles/mapping.d.ts +10 -10
- package/dist/profiles/mutations.js +3 -5
- package/dist/redis/connection.js +1 -1
- package/dist/reports/helpers.js +7 -3
- package/dist/reports/mapping.d.ts +1 -1
- package/dist/roles/mutations.js +20 -21
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +16 -11
- package/dist/server/status.js +6 -7
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.js +13 -4
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +43 -5
- package/dist/stats/mapping.js +9 -2
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -6
- package/LICENSE +0 -674
package/dist/analytics/read.js
CHANGED
|
@@ -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 = [
|
|
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(
|
|
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
|
|
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
|
|
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) =>
|
|
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) =>
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
147
|
+
return rows[0]?.compiledAt ?? null;
|
|
145
148
|
};
|
|
146
149
|
const groupVisibility = (body) => isPublicAnalyticsGroup(body) ? 'public' : 'private';
|
|
147
|
-
const groupDisplayName = (body, handle) =>
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
r.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
194
|
-
const
|
|
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:
|
|
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
|
-
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
const
|
|
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
|
-
|
|
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:
|
|
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(
|
|
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] +=
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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(
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
479
|
-
const
|
|
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
|
-
:
|
|
486
|
-
|
|
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:
|
|
493
|
-
authorDisplayName:
|
|
482
|
+
authorHandle: r.handle ?? undefined,
|
|
483
|
+
authorDisplayName: profileBody.displayName ?? profileBody.name ?? undefined,
|
|
494
484
|
postType,
|
|
495
|
-
uniqueViewers: Number(
|
|
496
|
-
viewEvents: Number(
|
|
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 =
|
|
550
|
-
dayMap[kind] = (
|
|
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] +=
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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:
|
|
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
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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:
|
|
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) =>
|
|
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:
|
|
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
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
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 +
|
|
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
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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: "
|
|
98
|
+
type: "resource" | "note" | "event" | "article" | "poll" | "jam";
|
|
98
99
|
count: number;
|
|
99
100
|
}[];
|
|
100
101
|
activeUsersSeries: {
|
package/dist/analytics/report.js
CHANGED
|
@@ -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 =
|
|
123
|
-
const to =
|
|
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 = (
|
|
15
|
+
const body = (rows[0]?.body ?? {});
|
|
17
16
|
return {
|
|
18
|
-
enabled:
|
|
19
|
-
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) => {
|