@openpeepshq/core 0.29.0 → 0.31.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/analytics/compile.js +15 -7
- package/dist/analytics/jamMetrics.d.ts +47 -0
- package/dist/analytics/jamMetrics.js +93 -0
- package/dist/analytics/pdfReport.js +40 -1
- package/dist/analytics/read.js +68 -5
- package/dist/analytics/report.d.ts +75 -0
- package/dist/analytics/report.js +1 -0
- package/dist/db/pg/map/registry.js +11 -1
- package/dist/db/pg/schema/analytics.d.ts +68 -0
- package/dist/db/pg/schema/analytics.js +10 -0
- package/dist/db/pg/schema/documents.d.ts +17 -0
- package/dist/db/pg/schema/documents.js +10 -1
- package/dist/db/pg/schema/index.d.ts +85 -0
- package/dist/db/pg/sql/0021_jam_occurrence_recurrence_id.sql +10 -0
- package/dist/db/pg/sql/meta/0021_snapshot.json +4718 -0
- package/dist/db/pg/sql/meta/0022_snapshot.json +56 -1
- package/dist/db/pg/sql/meta/_journal.json +7 -0
- package/dist/events/index.d.ts +17 -0
- package/dist/events/index.js +50 -1
- package/dist/federation/actors.d.ts +17 -0
- package/dist/federation/actors.js +22 -1
- package/dist/federation/identity.d.ts +2 -0
- package/dist/federation/identity.js +2 -0
- package/dist/federation/index.d.ts +1 -1
- package/dist/federation/index.js +1 -1
- package/dist/federation/notes.d.ts +18 -0
- package/dist/federation/notes.js +11 -0
- package/dist/jams/export.d.ts +17 -4
- package/dist/jams/export.js +36 -6
- package/dist/jams/finders.js +5 -1
- package/dist/jams/index.js +3 -0
- package/dist/jams/livekit.d.ts +18 -3
- package/dist/jams/livekit.js +37 -5
- package/dist/jams/mapping.d.ts +0 -27
- package/dist/jams/mapping.js +0 -15
- package/dist/jams/token.js +14 -6
- package/dist/notifications/defaultNotifications/mention/index.js +9 -3
- package/dist/posts/helpers/index.d.ts +5 -0
- package/dist/posts/helpers/index.js +30 -4
- package/dist/posts/mutations.js +3 -0
- package/dist/stats/finders.js +34 -7
- package/package.json +4 -4
package/dist/jams/mapping.d.ts
CHANGED
|
@@ -13,33 +13,6 @@ export declare const jamEventsMapping: import("../db/pg/map").Mapping<{
|
|
|
13
13
|
reaction?: string | undefined;
|
|
14
14
|
recurrenceId?: string | undefined;
|
|
15
15
|
}, JamEvent, JamEvent>;
|
|
16
|
-
export declare const jamSessionStartsMapping: import("../db/pg/map").Mapping<{
|
|
17
|
-
id: string;
|
|
18
|
-
jamId: string;
|
|
19
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
20
|
-
profileId: string;
|
|
21
|
-
content?: string | undefined;
|
|
22
|
-
reaction?: string | undefined;
|
|
23
|
-
recurrenceId?: string | undefined;
|
|
24
|
-
}, JamEvent, JamEvent>;
|
|
25
|
-
export declare const jamSessionClosesMapping: import("../db/pg/map").Mapping<{
|
|
26
|
-
id: string;
|
|
27
|
-
jamId: string;
|
|
28
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
29
|
-
profileId: string;
|
|
30
|
-
content?: string | undefined;
|
|
31
|
-
reaction?: string | undefined;
|
|
32
|
-
recurrenceId?: string | undefined;
|
|
33
|
-
}, JamEvent, JamEvent>;
|
|
34
|
-
export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
|
|
35
|
-
id: string;
|
|
36
|
-
jamId: string;
|
|
37
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
38
|
-
profileId: string;
|
|
39
|
-
content?: string | undefined;
|
|
40
|
-
reaction?: string | undefined;
|
|
41
|
-
recurrenceId?: string | undefined;
|
|
42
|
-
}, JamEvent, JamEvent>;
|
|
43
16
|
export declare const jamRecordingRelation: RelationWithMapping<PostWithMeta, JamRecording>;
|
|
44
17
|
export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
45
18
|
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
package/dist/jams/mapping.js
CHANGED
|
@@ -3,21 +3,6 @@ import { collectionInfos } from '../db/index.js';
|
|
|
3
3
|
export const jamEventsMapping = map({
|
|
4
4
|
collection: collectionInfos.jamEventsCollection.name,
|
|
5
5
|
});
|
|
6
|
-
export const jamSessionStartsMapping = jamEventsMapping.filter({
|
|
7
|
-
matches: {
|
|
8
|
-
type: 'start',
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
export const jamSessionClosesMapping = jamEventsMapping.filter({
|
|
12
|
-
matches: {
|
|
13
|
-
type: 'close',
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
export const jamParticipantsMapping = jamEventsMapping.filter({
|
|
17
|
-
matches: {
|
|
18
|
-
type: 'join',
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
6
|
export const jamRecordingRelation = {
|
|
22
7
|
alias: 'profile',
|
|
23
8
|
edgeCollection: 'jamRecordings',
|
package/dist/jams/token.js
CHANGED
|
@@ -64,6 +64,14 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
64
64
|
const jamId = event.id;
|
|
65
65
|
const roomName = jamRoomName(event.id, recurrenceId);
|
|
66
66
|
const jam = event.data?.type === 'event' && event.data?.jam;
|
|
67
|
+
const eventData = event.data?.type === 'event' ? event.data : undefined;
|
|
68
|
+
// Recurring jams resolve the occurrence from the event schedule so a
|
|
69
|
+
// re-opened occurrence is stamped with that occurrence (not whatever the
|
|
70
|
+
// query param carried); one-off jams have no schedule, so the raw param —
|
|
71
|
+
// the room key — stands in.
|
|
72
|
+
const startedOccurrenceId = eventData && eventData.recurrence
|
|
73
|
+
? occurrenceForJamStart(eventData, { recurrenceId })?.recurrenceId
|
|
74
|
+
: recurrenceId;
|
|
67
75
|
if (!jam) {
|
|
68
76
|
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
69
77
|
}
|
|
@@ -111,7 +119,7 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
111
119
|
jamId,
|
|
112
120
|
type: 'start',
|
|
113
121
|
profileId: profile.id,
|
|
114
|
-
recurrenceId,
|
|
122
|
+
recurrenceId: startedOccurrenceId,
|
|
115
123
|
});
|
|
116
124
|
}
|
|
117
125
|
const { apiKey, apiSecret } = (await config()).jams.livekit;
|
|
@@ -136,11 +144,11 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
136
144
|
canUpdateOwnMetadata: true,
|
|
137
145
|
});
|
|
138
146
|
if (!jamOpen) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
hub.emit('jamStarted', profile, event, startedOccurrenceId);
|
|
147
|
+
// The same resolved occurrence the persisted start row carries. The one
|
|
148
|
+
// difference: a one-off jam's raw room key is not an occurrence, so the
|
|
149
|
+
// notification omits it for those (a recurring jam's resolution is the
|
|
150
|
+
// identical value the start event was stamped with).
|
|
151
|
+
hub.emit('jamStarted', profile, event, eventData?.recurrence ? startedOccurrenceId : undefined);
|
|
144
152
|
}
|
|
145
153
|
return accessToken.toJwt();
|
|
146
154
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { notificationAll, } from '@openpeepshq/common/types';
|
|
2
|
-
import {
|
|
2
|
+
import { extractFederatedMentionTokens } from '@openpeepshq/core/posts';
|
|
3
3
|
import { findPost } from '@openpeepshq/core/posts';
|
|
4
4
|
import { findProfile, findProfileByHandle } from '@openpeepshq/core/profiles';
|
|
5
|
+
import { findProfileByHandleAndDomain } from '@openpeepshq/core/federation';
|
|
5
6
|
import { maybeCreateNotification } from '@openpeepshq/core/notifications';
|
|
6
7
|
import { getProfileAvatar, profileName } from '@openpeepshq/common/lib';
|
|
7
8
|
import { communityConfig } from '../../../config/index.js';
|
|
@@ -15,8 +16,13 @@ const getMentionedProfiles = async (post) => {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
if (byId.size === 0) {
|
|
18
|
-
for (const
|
|
19
|
-
const
|
|
19
|
+
for (const token of extractFederatedMentionTokens(post.data?.content)) {
|
|
20
|
+
const [handle, domain] = token.includes('@')
|
|
21
|
+
? token.split('@')
|
|
22
|
+
: [token, undefined];
|
|
23
|
+
const profile = domain
|
|
24
|
+
? await findProfileByHandleAndDomain(handle, domain)
|
|
25
|
+
: await findProfileByHandle(handle);
|
|
20
26
|
if (profile) {
|
|
21
27
|
byId.set(profile.id, profile);
|
|
22
28
|
}
|
|
@@ -10,6 +10,11 @@ export declare const isLocal: (post: PostWithMeta) => boolean;
|
|
|
10
10
|
export * from './filters';
|
|
11
11
|
export declare const extractHashtags: (data: PostDataUnion) => string[];
|
|
12
12
|
export declare const extractMentionHandles: (text?: string) => string[];
|
|
13
|
+
/**
|
|
14
|
+
* Every mention token in the text: local `@handle` plus remote
|
|
15
|
+
* `handle@domain` (domain lowercased).
|
|
16
|
+
*/
|
|
17
|
+
export declare const extractFederatedMentionTokens: (text?: string) => string[];
|
|
13
18
|
export declare const resolveMentionsForPost: (data: PostDataUnion) => Promise<MentionWithPublicProfile[]>;
|
|
14
19
|
export declare const entryConnector: (db: import("../../db").PgDb, from: Profile, to: Post, data?: ({
|
|
15
20
|
type: "create";
|
|
@@ -5,7 +5,8 @@ import { composeFilters, connectionFinder, connector, disconnector, filterAndTra
|
|
|
5
5
|
import { allpeepDb, collectionInfos } from '../../db/index.js';
|
|
6
6
|
import { capabilitiesConfig } from '../../config/index.js';
|
|
7
7
|
import { canReadPost } from './filters.js';
|
|
8
|
-
import { currentReactionsFromEntries, isBlockedPair, isReactionHistoryEntry, isReactionType, matchMentionHandles, normalizePostDataFromDb, toHiddenPost, tombstoneProfileWithMetaIfDeleted, } from '@openpeepshq/common/lib';
|
|
8
|
+
import { currentReactionsFromEntries, isBlockedPair, isReactionHistoryEntry, isReactionType, matchFederatedMentionTokens, matchMentionHandles, normalizePostDataFromDb, toHiddenPost, tombstoneProfileWithMetaIfDeleted, } from '@openpeepshq/common/lib';
|
|
9
|
+
import { findProfileByHandleAndDomain } from '../../federation/profiles.js';
|
|
9
10
|
import { EMBEDDED_REPOSTS_LIMIT } from '../mapping.js';
|
|
10
11
|
import { loadThreadPreviewReplies } from '../threadPreview.js';
|
|
11
12
|
export const isDirect = (post) => post.visibility === 'direct';
|
|
@@ -28,12 +29,37 @@ export const extractHashtags = (data) => {
|
|
|
28
29
|
return [...new Set([...fromContent, ...fromTags])];
|
|
29
30
|
};
|
|
30
31
|
export const extractMentionHandles = (text) => matchMentionHandles(text);
|
|
32
|
+
/**
|
|
33
|
+
* Every mention token in the text: local `@handle` plus remote
|
|
34
|
+
* `handle@domain` (domain lowercased).
|
|
35
|
+
*/
|
|
36
|
+
export const extractFederatedMentionTokens = (text) => matchFederatedMentionTokens(text);
|
|
31
37
|
export const resolveMentionsForPost = async (data) => {
|
|
32
38
|
const byProfileId = new Map();
|
|
33
|
-
for (const
|
|
34
|
-
const
|
|
39
|
+
for (const token of extractFederatedMentionTokens(data.content)) {
|
|
40
|
+
const [handle, domain] = token.includes('@')
|
|
41
|
+
? token.split('@')
|
|
42
|
+
: [token, undefined];
|
|
43
|
+
// Local remains the fast path; a remote `handle@domain` token resolves
|
|
44
|
+
// through the federated finder first, then falls back to a local profile
|
|
45
|
+
// with the same handle (keeps behavior for ambiguous local handles).
|
|
46
|
+
// Fallback side effect: when the federated finder misses and a *local*
|
|
47
|
+
// profile matches, the stored `MentionData.text` keeps the `@domain`
|
|
48
|
+
// suffix (`@bob@mastodon.social` against local bob). Consumers of
|
|
49
|
+
// `MentionData.text` must therefore handle both the bare local-handle
|
|
50
|
+
// shape and the `handle@domain` shape for the same profile.
|
|
51
|
+
const profile = domain
|
|
52
|
+
? ((await findProfileByHandleAndDomain(handle, domain)) ??
|
|
53
|
+
(await findProfileByHandle(handle)))
|
|
54
|
+
: await findProfileByHandle(handle);
|
|
35
55
|
if (profile) {
|
|
36
|
-
|
|
56
|
+
// Handles are case-insensitive identity keys, so the stored mention text
|
|
57
|
+
// is normalised to lowercase on both branches (remote tokens are already
|
|
58
|
+
// lowercased at extraction) to keep `MentionData.text` a consistent shape.
|
|
59
|
+
byProfileId.set(profile.id, {
|
|
60
|
+
profile,
|
|
61
|
+
text: `@${handle.toLowerCase()}${domain ? `@${domain}` : ''}`,
|
|
62
|
+
});
|
|
37
63
|
}
|
|
38
64
|
}
|
|
39
65
|
return [...byProfileId.values()];
|
package/dist/posts/mutations.js
CHANGED
|
@@ -316,6 +316,9 @@ export const deletePost = async (post, profile) => {
|
|
|
316
316
|
if (post.type === 'question') {
|
|
317
317
|
await cancelPollEnd(post.id);
|
|
318
318
|
}
|
|
319
|
+
// Fires after the post row is gone from the DB, so federation handlers
|
|
320
|
+
// cannot re-load the note and must rely on the pre-delete `post.uri`.
|
|
321
|
+
hub.emit('postDeleted', post);
|
|
319
322
|
return postsMapping.find(db, post.id);
|
|
320
323
|
};
|
|
321
324
|
export const validatePollVote = (post, data) => {
|
package/dist/stats/finders.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { publicProfileWithActivityScoreSchema, publicPostWithActivityScoreSchema, } from '@openpeepshq/common/types';
|
|
2
2
|
import { sub } from 'date-fns';
|
|
3
|
+
import { sql } from 'drizzle-orm';
|
|
3
4
|
import { hostResources } from '../server/status.js';
|
|
4
5
|
import { baseProfilesMapping } from '../profiles/index.js';
|
|
5
6
|
import { allpeepDb } from '../db/index.js';
|
|
6
7
|
import { postsMapping, postsWithReplyCountMapping, postsWithReplyToCountMapping, transformPost, } from '../posts/index.js';
|
|
7
8
|
import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping, repostsMapping, } from './mapping.js';
|
|
8
9
|
import { compileStatsWithAll, createdAtFilter } from './helpers.js';
|
|
9
|
-
import { jamParticipantsMapping, jamSessionStartsMapping, } from '../jams/mapping.js';
|
|
10
10
|
import { edgeFilters, postFilters, profileFilters } from '../db/pg/filters/index.js';
|
|
11
11
|
import { sorts } from '../db/pg/queries/index.js';
|
|
12
12
|
import { entries, follows, repost } from '../db/pg/schema/edges.js';
|
|
@@ -69,13 +69,40 @@ export const serverCounts = async () => allpeepDb().then(async ({ db }) => {
|
|
|
69
69
|
rsvps,
|
|
70
70
|
};
|
|
71
71
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
// Distinct (post, occurrence): a recurring series counts N sessions, not 1.
|
|
73
|
+
// The time bounds come from the shared createdAtFilter so day/week/month
|
|
74
|
+
// windows behave like every other stat.
|
|
75
|
+
const jamSessionStarts = (db, start, end) => {
|
|
76
|
+
const bounds = createdAtFilter(jamEvents, start, end);
|
|
77
|
+
return db
|
|
78
|
+
.select({
|
|
79
|
+
value: sql `count(distinct (post_id, coalesce(recurrence_id, '')))::int`,
|
|
80
|
+
})
|
|
81
|
+
.from(jamEvents)
|
|
82
|
+
.where(bounds
|
|
83
|
+
? sql `deleted_at is null and body->>'type' = 'start' and ${bounds.where}`
|
|
84
|
+
: sql `deleted_at is null and body->>'type' = 'start'`)
|
|
85
|
+
.then((rows) => Number(rows[0]?.value ?? 0));
|
|
86
|
+
};
|
|
75
87
|
export const jamSessionsStats = () => compileStatsWithAll(jamSessionStarts);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
// Distinct profiles who joined: reconnects/tabs no longer inflate the count.
|
|
89
|
+
// Joins profiles to count only live local profiles — guests and deleted
|
|
90
|
+
// profiles are excluded, matching the analytics dashboard's computeJamStats
|
|
91
|
+
// so both admin surfaces show the same number for the same window.
|
|
92
|
+
const jamParticipants = (db, start, end) => {
|
|
93
|
+
const bounds = createdAtFilter(jamEvents, start, end);
|
|
94
|
+
const scope = sql `jam_events.deleted_at is null
|
|
95
|
+
and jam_events.body->>'type' = 'join'
|
|
96
|
+
and profiles.type = 'local' and profiles.deleted_at is null`;
|
|
97
|
+
return db
|
|
98
|
+
.select({
|
|
99
|
+
value: sql `count(distinct jam_events.body->>'profileId')::int`,
|
|
100
|
+
})
|
|
101
|
+
.from(jamEvents)
|
|
102
|
+
.innerJoin(profiles, sql `${profiles.id}::text = ${jamEvents.body}->>'profileId'`)
|
|
103
|
+
.where(bounds ? sql `${scope} and ${bounds.where}` : scope)
|
|
104
|
+
.then((rows) => Number(rows[0]?.value ?? 0));
|
|
105
|
+
};
|
|
79
106
|
export const jamParticipantsStats = () => compileStatsWithAll(jamParticipants);
|
|
80
107
|
const topPosts = (db, start) => postsWithActivityScoreMapping
|
|
81
108
|
.filter(createdAtFilter(posts, start))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"@openpeepshq/common": "0.31.0",
|
|
41
40
|
"@openpeepshq/fetch-client": "^0.3.0",
|
|
42
|
-
"@openpeepshq/
|
|
43
|
-
"@openpeepshq/geocoder": "^0.1.2"
|
|
41
|
+
"@openpeepshq/common": "0.33.0",
|
|
42
|
+
"@openpeepshq/geocoder": "^0.1.2",
|
|
43
|
+
"@openpeepshq/i18n": "^0.33.0"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|