@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.
- 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 +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- 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 +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- 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 +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- 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.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- 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/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- 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/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- 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 +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
- 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.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- 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 +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +82 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- 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 +19 -0
- package/dist/server/index.js +31 -14
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- 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 -7
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
|
@@ -14,19 +14,18 @@ export const isServiceAccessToken = (token) => {
|
|
|
14
14
|
const parsed = authorizationSchema.safeParse(payload);
|
|
15
15
|
return parsed.success && !!parsed.data.identities.service;
|
|
16
16
|
}
|
|
17
|
-
catch
|
|
17
|
+
catch {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
const withCachedOwnerAndScopes = async (token) => {
|
|
22
|
-
|
|
23
|
-
const ownerId = (_a = token.ownedBy) === null || _a === void 0 ? void 0 : _a.id;
|
|
22
|
+
const ownerId = token.ownedBy?.id;
|
|
24
23
|
const scopes = parseScopesFromJwt(token.signedToken);
|
|
25
24
|
if (!ownerId) {
|
|
26
|
-
return
|
|
25
|
+
return { ...token, ownedBy: undefined, scopes };
|
|
27
26
|
}
|
|
28
27
|
const owner = await getProfile(ownerId);
|
|
29
|
-
return
|
|
28
|
+
return { ...token, ownedBy: owner, scopes };
|
|
30
29
|
};
|
|
31
30
|
export const findAccessToken = (id) => allpeepDb().then(({ db }) => accessTokensMapping
|
|
32
31
|
.find(db, id)
|
|
@@ -40,4 +39,4 @@ export const listAccessTokensForProfile = (profile) => allpeepDb().then(async ({
|
|
|
40
39
|
.all(db)
|
|
41
40
|
.then((tokens) => Promise.all(tokens.map(withCachedOwnerAndScopes))));
|
|
42
41
|
export const listServiceAccessTokens = () => listAccessTokens().then((tokens) => tokens.filter(isServiceAccessToken));
|
|
43
|
-
export const isRevoked = async (id) =>
|
|
42
|
+
export const isRevoked = async (id) => (await isMaybeRevoked(id)) && !!(await findAccessToken(id))?.revokedAt;
|
|
@@ -5,7 +5,7 @@ import { uuidv7 } from 'uuidv7';
|
|
|
5
5
|
import { addToBloomFilter } from './revokations.js';
|
|
6
6
|
export const createAccessToken = (profile, data) => allpeepDb().then(async ({ db }) => {
|
|
7
7
|
const id = uuidv7();
|
|
8
|
-
const accessToken = await accessTokensMapping.create(db,
|
|
8
|
+
const accessToken = await accessTokensMapping.create(db, { ...data, id });
|
|
9
9
|
if (profile) {
|
|
10
10
|
await profileAccessTokenConnector(db, profile, accessToken);
|
|
11
11
|
}
|
|
@@ -8,8 +8,7 @@ import { createAccessToken, revokeAccessToken } from './mutations.js';
|
|
|
8
8
|
export const verifySignedAccessToken = (token) => jwtUtil()
|
|
9
9
|
.then((jwt) => jwt.verify(token))
|
|
10
10
|
.then(async (result) => {
|
|
11
|
-
|
|
12
|
-
if (!((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.jti)) {
|
|
11
|
+
if (!result?.payload?.jti) {
|
|
13
12
|
return undefined;
|
|
14
13
|
}
|
|
15
14
|
const id = result.payload.jti;
|
|
@@ -19,7 +18,6 @@ export const verifySignedAccessToken = (token) => jwtUtil()
|
|
|
19
18
|
return result.payload;
|
|
20
19
|
});
|
|
21
20
|
export const createSignedAccessToken = async ({ profile, authorization, name, description, expirationTime, }) => {
|
|
22
|
-
var _a;
|
|
23
21
|
const id = uuidv7();
|
|
24
22
|
const jwt = await jwtUtil();
|
|
25
23
|
const signedToken = await jwt.sign({
|
|
@@ -28,7 +26,7 @@ export const createSignedAccessToken = async ({ profile, authorization, name, de
|
|
|
28
26
|
id,
|
|
29
27
|
});
|
|
30
28
|
const result = await jwt.verify(signedToken);
|
|
31
|
-
if (!
|
|
29
|
+
if (!result?.payload?.exp) {
|
|
32
30
|
throw new Error('Failed to verify signed token');
|
|
33
31
|
}
|
|
34
32
|
const expiresAt = new Date(result.payload.exp * 1000).toISOString();
|
|
@@ -42,8 +40,8 @@ export const createSignedAccessToken = async ({ profile, authorization, name, de
|
|
|
42
40
|
export const createSignedProfileAccessToken = async ({ profile, account, name, description, scopes = [{ scopeLevel: 'admin', resource: { type: '*', id: '*' } }], expirationTime = '1y', }) => {
|
|
43
41
|
const authorization = {
|
|
44
42
|
identities: {
|
|
45
|
-
profile: profile
|
|
46
|
-
account: account
|
|
43
|
+
profile: profile?.id,
|
|
44
|
+
account: account?.id,
|
|
47
45
|
},
|
|
48
46
|
scopes,
|
|
49
47
|
};
|
|
@@ -67,8 +65,7 @@ export const createSignedServiceToken = async ({ scopes, name, description, expi
|
|
|
67
65
|
expirationTime,
|
|
68
66
|
});
|
|
69
67
|
export const createSignedGuestPass = async (profile, expirationTime = '1d') => {
|
|
70
|
-
|
|
71
|
-
if (!((_a = profile.guestData) === null || _a === void 0 ? void 0 : _a.resource)) {
|
|
68
|
+
if (!profile.guestData?.resource) {
|
|
72
69
|
throw new Error('Guest pass requires a resource');
|
|
73
70
|
}
|
|
74
71
|
const resource = profile.guestData.resource;
|
|
@@ -122,8 +119,8 @@ export const createSignedDbToken = (profile) => createSignedAccessToken({
|
|
|
122
119
|
export const refreshSignedAccessToken = async (token) => {
|
|
123
120
|
const jwt = await jwtUtil();
|
|
124
121
|
const verified = await jwt.verify(token);
|
|
125
|
-
const rawPayload = verified
|
|
126
|
-
if (!
|
|
122
|
+
const rawPayload = verified?.payload;
|
|
123
|
+
if (!rawPayload?.jti || typeof rawPayload.jti !== 'string') {
|
|
127
124
|
return undefined;
|
|
128
125
|
}
|
|
129
126
|
const jti = rawPayload.jti;
|
|
@@ -138,7 +135,7 @@ export const refreshSignedAccessToken = async (token) => {
|
|
|
138
135
|
}
|
|
139
136
|
const authorization = authParsed.data;
|
|
140
137
|
const existing = await findAccessToken(jti);
|
|
141
|
-
if (!
|
|
138
|
+
if (!existing?.signedToken || existing.revokedAt) {
|
|
142
139
|
return undefined;
|
|
143
140
|
}
|
|
144
141
|
if (authorization.identities.profile) {
|
package/dist/accounts/helpers.js
CHANGED
|
@@ -5,7 +5,7 @@ import { logger } from '../log/index.js';
|
|
|
5
5
|
import { getProfiles } from '../profiles/cache.js';
|
|
6
6
|
import { uuidv7 } from 'uuidv7';
|
|
7
7
|
export const log = logger('core:accounts');
|
|
8
|
-
export const normalizeEmailAddress = (email) => email
|
|
8
|
+
export const normalizeEmailAddress = (email) => email?.toLowerCase();
|
|
9
9
|
export const createEmailValidationToken = async (account) => {
|
|
10
10
|
return jwtUtil().then((jwt) => jwt.sign({
|
|
11
11
|
payload: { email: account.email },
|
|
@@ -33,4 +33,8 @@ export const sendEmailValidationMail = async (account) => {
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
export const expandAccount = async (account) => account
|
|
36
|
-
?
|
|
36
|
+
? {
|
|
37
|
+
...account,
|
|
38
|
+
profiles: await getProfiles(account.profiles.map((p) => p.id)),
|
|
39
|
+
}
|
|
40
|
+
: undefined;
|
|
@@ -10,6 +10,8 @@ import { assignRole, unassignRole } from '../profiles/mutations.js';
|
|
|
10
10
|
import { hash } from 'bcrypt';
|
|
11
11
|
import { profilesMapping } from '../profiles/mapping.js';
|
|
12
12
|
import { assertProfileCapacity } from '../profiles/capacity.js';
|
|
13
|
+
import { localActorScalars } from '../federation/identity.js';
|
|
14
|
+
import { uuidv7 } from 'uuidv7';
|
|
13
15
|
import { findRoleByKey } from '../roles/index.js';
|
|
14
16
|
import { log, normalizeEmailAddress, sendEmailValidationMail, sendWelcomeEmail, } from './helpers.js';
|
|
15
17
|
import { findAccountByEmail } from './finders.js';
|
|
@@ -19,6 +21,26 @@ import { conflict } from '../errors/index.js';
|
|
|
19
21
|
import { connector } from '../db/helpers.js';
|
|
20
22
|
import { hub } from '../events/index.js';
|
|
21
23
|
import { deletePushSubscription, listPushSubscriptionsByAccount, } from '../pushSubscriptions/index.js';
|
|
24
|
+
const applyCommunityRoleChanges = async (profile, changes) => {
|
|
25
|
+
for (const roleKey of changes.add) {
|
|
26
|
+
const role = await findRoleByKey(roleKey);
|
|
27
|
+
if (role) {
|
|
28
|
+
await assignRole(profile, role);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
log.error(`Role ${roleKey} missing`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const roleKey of changes.remove) {
|
|
35
|
+
const role = await findRoleByKey(roleKey);
|
|
36
|
+
if (role) {
|
|
37
|
+
await unassignRole(profile, role);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
log.error(`Role ${roleKey} missing`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
22
44
|
export const createAccount = async (accountCreationData) => {
|
|
23
45
|
const { db } = await allpeepDb();
|
|
24
46
|
const coreConfig = await config();
|
|
@@ -57,15 +79,19 @@ export const createAccount = async (accountCreationData) => {
|
|
|
57
79
|
let profile;
|
|
58
80
|
if (accountCreationData.profile) {
|
|
59
81
|
await assertProfileCapacity();
|
|
60
|
-
const { handle, displayName, avatar } = accountCreationData.profile;
|
|
82
|
+
const { handle, displayName, avatar, bot } = accountCreationData.profile;
|
|
83
|
+
const profileId = uuidv7();
|
|
61
84
|
profile = await profilesMapping.create(db, {
|
|
85
|
+
id: profileId,
|
|
62
86
|
handle,
|
|
63
87
|
displayName,
|
|
64
88
|
avatar,
|
|
89
|
+
...(bot === true ? { bot: true } : {}),
|
|
65
90
|
activityPub: {
|
|
66
91
|
domain: coreConfig.activityPub.defaultDomain,
|
|
67
92
|
},
|
|
68
93
|
type: 'local',
|
|
94
|
+
...localActorScalars(profileId, coreConfig.activityPub.defaultDomain),
|
|
69
95
|
});
|
|
70
96
|
if (firstAccount && profile) {
|
|
71
97
|
const ownerRole = await findRoleByKey('owner');
|
|
@@ -78,15 +104,11 @@ export const createAccount = async (accountCreationData) => {
|
|
|
78
104
|
}
|
|
79
105
|
else {
|
|
80
106
|
await hub.emit('profileCreated', profile);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
log.error(`Role ${roleKey} missing`);
|
|
89
|
-
}
|
|
107
|
+
await applyCommunityRoleChanges(profile, communityConf.roles.onRegistration);
|
|
108
|
+
// Authorized/SSO creates skip the validation email, so apply the
|
|
109
|
+
// same promotion humans get after confirming.
|
|
110
|
+
if (emailValidated) {
|
|
111
|
+
await applyCommunityRoleChanges(profile, communityConf.roles.onEmailValidation);
|
|
90
112
|
}
|
|
91
113
|
}
|
|
92
114
|
if (inviteCode) {
|
|
@@ -112,9 +134,8 @@ export const createAccount = async (accountCreationData) => {
|
|
|
112
134
|
return { account, profile };
|
|
113
135
|
};
|
|
114
136
|
export const updateAccount = async (accountData) => {
|
|
115
|
-
var _a;
|
|
116
137
|
const { db } = await allpeepDb();
|
|
117
|
-
if (!
|
|
138
|
+
if (!accountData?.account?.id) {
|
|
118
139
|
throw new Error('Account ID is missing');
|
|
119
140
|
}
|
|
120
141
|
const previousEmail = accountData.account.email;
|
|
@@ -163,36 +184,18 @@ export const sendResetPasswordEmail = async (account) => {
|
|
|
163
184
|
}));
|
|
164
185
|
};
|
|
165
186
|
export const validateEmail = async (token) => {
|
|
166
|
-
var _a;
|
|
167
187
|
const communityConf = await communityConfig();
|
|
168
188
|
const jwt = await jwtUtil();
|
|
169
189
|
const { db } = await allpeepDb();
|
|
170
190
|
try {
|
|
171
191
|
const validatedToken = await jwt.verify(token);
|
|
172
|
-
const email =
|
|
173
|
-
const account = await findAccountByEmail(email
|
|
192
|
+
const email = validatedToken?.payload?.email;
|
|
193
|
+
const account = await findAccountByEmail(email ?? '');
|
|
174
194
|
if (account) {
|
|
175
195
|
await accountsMapping.update(db, account.id, { emailValidated: true });
|
|
176
196
|
await accountsCache.del(account.id);
|
|
177
197
|
await accountsCache.del(account.email);
|
|
178
|
-
|
|
179
|
-
const role = await findRoleByKey(roleKey);
|
|
180
|
-
if (role) {
|
|
181
|
-
await assignRole(account.profiles[0], role);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
log.error(`Role ${roleKey} missing`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
for (const roleKey of communityConf.roles.onEmailValidation.remove) {
|
|
188
|
-
const role = await findRoleByKey(roleKey);
|
|
189
|
-
if (role) {
|
|
190
|
-
await unassignRole(account.profiles[0], role);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
log.error(`Role ${roleKey} missing`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
198
|
+
await applyCommunityRoleChanges(account.profiles[0], communityConf.roles.onEmailValidation);
|
|
196
199
|
return true;
|
|
197
200
|
}
|
|
198
201
|
}
|
package/dist/analytics/cache.js
CHANGED
|
@@ -11,17 +11,17 @@ export const getAnalyticsCache = async (key) => {
|
|
|
11
11
|
return undefined;
|
|
12
12
|
return JSON.parse(raw);
|
|
13
13
|
}
|
|
14
|
-
catch
|
|
14
|
+
catch {
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
export const setAnalyticsCache = async (key, value, opts) => {
|
|
19
19
|
try {
|
|
20
20
|
const redis = await getSharedConnection();
|
|
21
|
-
const ttl =
|
|
21
|
+
const ttl = opts?.includesToday ? OPEN_DAY_TTL_SEC : CLOSED_RANGE_TTL_SEC;
|
|
22
22
|
await redis.set(key, JSON.stringify(value), { EX: ttl });
|
|
23
23
|
}
|
|
24
|
-
catch
|
|
24
|
+
catch {
|
|
25
25
|
// Overview still returns; Redis must not 500 the request.
|
|
26
26
|
}
|
|
27
27
|
};
|
package/dist/analytics/clicks.js
CHANGED
|
@@ -6,7 +6,7 @@ import { analyticsDailyClicks } from '../db/pg/schema/analytics.js';
|
|
|
6
6
|
import { resolveAnalyticsRange } from './dateRange.js';
|
|
7
7
|
const log = logger('app:analytics:clicks');
|
|
8
8
|
export const MAX_CLICK_TARGET_LENGTH = 512;
|
|
9
|
-
export const MAX_DISTINCT_CLICK_TARGETS_PER_DAY =
|
|
9
|
+
export const MAX_DISTINCT_CLICK_TARGETS_PER_DAY = 5_000;
|
|
10
10
|
export const TOP_CLICKS_LIMIT = 25;
|
|
11
11
|
const SKIP_PAGE_PREFIXES = [
|
|
12
12
|
'/admin',
|
|
@@ -41,7 +41,7 @@ export const normalizePageTarget = (raw) => {
|
|
|
41
41
|
pathname = new URL(trimmed, 'https://openpeeps.invalid').pathname || '/';
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
catch
|
|
44
|
+
catch {
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
if (!pathname.startsWith('/'))
|
|
@@ -67,7 +67,7 @@ export const normalizeLinkTarget = (raw) => {
|
|
|
67
67
|
const path = url.pathname || '/';
|
|
68
68
|
return truncateCheck(`${url.protocol}//${host}${port}${path}`);
|
|
69
69
|
}
|
|
70
|
-
catch
|
|
70
|
+
catch {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
@@ -80,7 +80,6 @@ export const normalizeClickEvent = (event) => {
|
|
|
80
80
|
return target ? { kind: 'link', target } : null;
|
|
81
81
|
};
|
|
82
82
|
export const tallyNormalizedClicks = (events) => {
|
|
83
|
-
var _a;
|
|
84
83
|
const counts = new Map();
|
|
85
84
|
const tallies = new Map();
|
|
86
85
|
for (const event of events) {
|
|
@@ -89,16 +88,13 @@ export const tallyNormalizedClicks = (events) => {
|
|
|
89
88
|
continue;
|
|
90
89
|
const key = `${normalized.kind}\0${normalized.target}`;
|
|
91
90
|
counts.set(key, normalized);
|
|
92
|
-
tallies.set(key, (
|
|
91
|
+
tallies.set(key, (tallies.get(key) ?? 0) + 1);
|
|
93
92
|
}
|
|
94
|
-
return [...counts.entries()].map(([key, { kind, target }]) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
clicks: (_a = tallies.get(key)) !== null && _a !== void 0 ? _a : 0,
|
|
100
|
-
});
|
|
101
|
-
});
|
|
93
|
+
return [...counts.entries()].map(([key, { kind, target }]) => ({
|
|
94
|
+
kind,
|
|
95
|
+
target,
|
|
96
|
+
clicks: tallies.get(key) ?? 0,
|
|
97
|
+
}));
|
|
102
98
|
};
|
|
103
99
|
const incrementExisting = async (day, kind, target, clicks) => {
|
|
104
100
|
const db = await database();
|
|
@@ -124,13 +120,12 @@ const upsertClick = async (day, kind, target, clicks) => {
|
|
|
124
120
|
});
|
|
125
121
|
};
|
|
126
122
|
const distinctTargetCount = async (day) => {
|
|
127
|
-
var _a, _b;
|
|
128
123
|
const db = await database();
|
|
129
124
|
const rows = await db
|
|
130
125
|
.select({ n: count() })
|
|
131
126
|
.from(analyticsDailyClicks)
|
|
132
127
|
.where(eq(analyticsDailyClicks.day, day));
|
|
133
|
-
return Number(
|
|
128
|
+
return Number(rows[0]?.n ?? 0);
|
|
134
129
|
};
|
|
135
130
|
/** Live increment. Does not accept or persist a profile id. */
|
|
136
131
|
export const recordClickEvents = async (events) => {
|
|
@@ -165,13 +160,10 @@ const topClicks = async (from, to, kind) => {
|
|
|
165
160
|
.groupBy(analyticsDailyClicks.target)
|
|
166
161
|
.orderBy(desc(sum(analyticsDailyClicks.clicks)))
|
|
167
162
|
.limit(TOP_CLICKS_LIMIT);
|
|
168
|
-
return rows.map((row) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
clicks: Number((_a = row.clicks) !== null && _a !== void 0 ? _a : 0),
|
|
173
|
-
});
|
|
174
|
-
});
|
|
163
|
+
return rows.map((row) => ({
|
|
164
|
+
target: row.target,
|
|
165
|
+
clicks: Number(row.clicks ?? 0),
|
|
166
|
+
}));
|
|
175
167
|
};
|
|
176
168
|
export const getAnalyticsClicks = async (query = {}) => {
|
|
177
169
|
const range = resolveAnalyticsRange(query);
|
|
@@ -13,10 +13,9 @@ const dayBounds = (day) => {
|
|
|
13
13
|
return { start, end };
|
|
14
14
|
};
|
|
15
15
|
const countScalar = async (db, query) => {
|
|
16
|
-
var _a, _b;
|
|
17
16
|
const result = await db.execute(query);
|
|
18
17
|
const rows = result.rows;
|
|
19
|
-
return Number(
|
|
18
|
+
return Number(rows[0]?.c ?? 0);
|
|
20
19
|
};
|
|
21
20
|
export const compileAnalyticsDay = async (day) => {
|
|
22
21
|
const db = await database();
|
|
@@ -24,14 +23,16 @@ export const compileAnalyticsDay = async (day) => {
|
|
|
24
23
|
const now = new Date().toISOString();
|
|
25
24
|
const newMembers = await countScalar(db, sql `select count(*)::int as c from profiles
|
|
26
25
|
where deleted_at is null
|
|
26
|
+
and type = 'local'
|
|
27
27
|
and created_at >= ${start} and created_at < ${end}`);
|
|
28
28
|
const posts = await countScalar(db, sql `select count(*)::int as c from posts
|
|
29
29
|
where deleted_at is null and visibility <> 'direct'
|
|
30
30
|
and created_at >= ${start} and created_at < ${end}`);
|
|
31
31
|
const replies = await countScalar(db, sql `select count(*)::int as c from reply_to
|
|
32
32
|
where created_at >= ${start} and created_at < ${end}`);
|
|
33
|
-
const likes = await countScalar(db, sql `select count(*)::int as c from
|
|
34
|
-
where
|
|
33
|
+
const likes = await countScalar(db, sql `select count(*)::int as c from entries
|
|
34
|
+
where body->>'type' = 'reaction'
|
|
35
|
+
and created_at >= ${start} and created_at < ${end}`);
|
|
35
36
|
const reposts = await countScalar(db, sql `select count(*)::int as c from repost
|
|
36
37
|
where created_at >= ${start} and created_at < ${end}`);
|
|
37
38
|
const bookmarks = await countScalar(db, sql `select count(*)::int as c from bookmarks
|
|
@@ -55,8 +56,9 @@ export const compileAnalyticsDay = async (day) => {
|
|
|
55
56
|
where deleted_at is null
|
|
56
57
|
and created_at >= ${start} and created_at < ${end}
|
|
57
58
|
union
|
|
58
|
-
select from_id from
|
|
59
|
-
where
|
|
59
|
+
select from_id from entries
|
|
60
|
+
where body->>'type' in ('reaction', 'unreaction')
|
|
61
|
+
and created_at >= ${start} and created_at < ${end}
|
|
60
62
|
union
|
|
61
63
|
select from_id from repost
|
|
62
64
|
where created_at >= ${start} and created_at < ${end}
|
|
@@ -129,10 +131,11 @@ export const compileAnalyticsDay = async (day) => {
|
|
|
129
131
|
update analytics_daily_by_group g
|
|
130
132
|
set
|
|
131
133
|
likes = coalesce((
|
|
132
|
-
select count(*)::int from
|
|
133
|
-
join post_groups pg on pg.from_id =
|
|
134
|
+
select count(*)::int from entries e
|
|
135
|
+
join post_groups pg on pg.from_id = e.to_id
|
|
134
136
|
where pg.to_id = g.group_id
|
|
135
|
-
and
|
|
137
|
+
and e.body->>'type' = 'reaction'
|
|
138
|
+
and e.created_at >= ${start} and e.created_at < ${end}
|
|
136
139
|
), 0),
|
|
137
140
|
comments = coalesce((
|
|
138
141
|
select count(*)::int from reply_to rt
|
|
@@ -164,8 +167,9 @@ export const compileAnalyticsDay = async (day) => {
|
|
|
164
167
|
select created_at from posts
|
|
165
168
|
where deleted_at is null and created_at >= ${start} and created_at < ${end}
|
|
166
169
|
union all
|
|
167
|
-
select created_at from
|
|
168
|
-
where
|
|
170
|
+
select created_at from entries
|
|
171
|
+
where body->>'type' in ('reaction', 'unreaction')
|
|
172
|
+
and created_at >= ${start} and created_at < ${end}
|
|
169
173
|
union all
|
|
170
174
|
select created_at from reply_to
|
|
171
175
|
where created_at >= ${start} and created_at < ${end}
|
|
@@ -243,7 +247,8 @@ export const compileRetentionCohorts = async () => {
|
|
|
243
247
|
from (
|
|
244
248
|
select creator_id as profile_id, created_at from posts where deleted_at is null
|
|
245
249
|
union all
|
|
246
|
-
select from_id, created_at from
|
|
250
|
+
select from_id, created_at from entries
|
|
251
|
+
where body->>'type' in ('reaction', 'unreaction')
|
|
247
252
|
union all
|
|
248
253
|
select from_id, created_at from reply_to
|
|
249
254
|
union all
|
|
@@ -18,8 +18,7 @@ const presetBounds = (preset, now) => {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
export const resolveAnalyticsRange = (query = {}, now = new Date()) => {
|
|
21
|
-
|
|
22
|
-
const preset = (_a = query.preset) !== null && _a !== void 0 ? _a : (!query.from && !query.to ? '30d' : undefined);
|
|
21
|
+
const preset = query.preset ?? (!query.from && !query.to ? '30d' : undefined);
|
|
23
22
|
let fromDate;
|
|
24
23
|
let toDate;
|
|
25
24
|
if (query.from && query.to) {
|
|
@@ -27,7 +26,7 @@ export const resolveAnalyticsRange = (query = {}, now = new Date()) => {
|
|
|
27
26
|
toDate = startOfDay(parseISO(query.to));
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
const bounds = presetBounds(preset
|
|
29
|
+
const bounds = presetBounds(preset ?? '30d', now);
|
|
31
30
|
fromDate = bounds.from;
|
|
32
31
|
toDate = bounds.to;
|
|
33
32
|
}
|
|
@@ -166,10 +165,9 @@ export const selectChartBuckets = (from, to) => {
|
|
|
166
165
|
export const aggregateSeriesIntoBuckets = (series, buckets) => {
|
|
167
166
|
const byDay = new Map(series.map((p) => [p.day, p.value]));
|
|
168
167
|
return buckets.map((bucket) => {
|
|
169
|
-
var _a;
|
|
170
168
|
let value = 0;
|
|
171
169
|
for (const day of eachUtcDay(bucket.from, bucket.to)) {
|
|
172
|
-
value +=
|
|
170
|
+
value += byDay.get(day) ?? 0;
|
|
173
171
|
}
|
|
174
172
|
return { day: bucket.key, label: bucket.label, value };
|
|
175
173
|
});
|
package/dist/analytics/jobs.js
CHANGED
|
@@ -44,11 +44,10 @@ const [analyticsCompileQueue, analyticsCompileWorker] = queueAndWorker(ANALYTICS
|
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
46
|
const maybeEnqueueInitialBackfill = async () => {
|
|
47
|
-
var _a;
|
|
48
47
|
const db = await database();
|
|
49
48
|
const result = await db.execute(sql `select exists(select 1 from analytics_daily_totals limit 1) as has_rows`);
|
|
50
49
|
const rows = result.rows;
|
|
51
|
-
if (
|
|
50
|
+
if (rows[0]?.has_rows)
|
|
52
51
|
return;
|
|
53
52
|
const queue = analyticsCompileQueue();
|
|
54
53
|
const existing = await queue.getJob(INITIAL_BACKFILL_JOB_ID);
|
|
@@ -72,8 +71,8 @@ export const ensureAnalyticsSchedules = async () => {
|
|
|
72
71
|
};
|
|
73
72
|
export const enqueueAnalyticsBackfill = async (from, to) => {
|
|
74
73
|
const defaults = defaultBackfillRange();
|
|
75
|
-
const start = from
|
|
76
|
-
const end = to
|
|
74
|
+
const start = from ?? defaults.from;
|
|
75
|
+
const end = to ?? defaults.to;
|
|
77
76
|
const job = await analyticsCompileQueue().add('backfill', {
|
|
78
77
|
type: 'backfill',
|
|
79
78
|
from: start,
|