@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.
- 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/index.d.ts +1 -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 +2 -0
- 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/helpers.js +1 -2
- 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.js +6 -2
- package/dist/jams/index.js +2 -2
- package/dist/jams/jobs.js +1 -2
- package/dist/jams/livekit.js +8 -8
- 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.js +13 -29
- package/dist/media/index.js +50 -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/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 +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 +6 -7
- 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/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -7
- package/dist/notifications/mutations.js +4 -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 +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.js +1 -2
- package/dist/posts/contextClosure.js +1 -2
- package/dist/posts/conversationQueries.js +2 -4
- package/dist/posts/eventAgenda.js +8 -5
- package/dist/posts/eventOccurrences.js +2 -2
- package/dist/posts/finders.d.ts +42 -2
- package/dist/posts/finders.js +21 -9
- package/dist/posts/helpers/filters.js +2 -3
- package/dist/posts/helpers/index.d.ts +152 -0
- package/dist/posts/helpers/index.js +43 -27
- package/dist/posts/mapping.d.ts +546 -14
- package/dist/posts/mapping.js +60 -18
- package/dist/posts/mutations.d.ts +76 -0
- package/dist/posts/mutations.js +46 -31
- 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/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/mutations.js +3 -5
- package/dist/redis/connection.js +1 -1
- package/dist/reports/helpers.js +7 -3
- 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 +39 -1
- 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/dist/jams/health.js
CHANGED
|
@@ -5,7 +5,8 @@ const log = logger('app:jams:livekit');
|
|
|
5
5
|
/** Sentinel room name so the probe authenticates without listing every room. */
|
|
6
6
|
const LIVEKIT_HEALTH_ROOM = '__openpeeps_livekit_health__';
|
|
7
7
|
const LIVEKIT_HEALTH_CACHE_KEY = 'livekit-health';
|
|
8
|
-
export const LIVEKIT_HEALTH_TIMEOUT_MS =
|
|
8
|
+
export const LIVEKIT_HEALTH_TIMEOUT_MS = 5000;
|
|
9
|
+
export const LIVEKIT_HEALTH_MAX_ATTEMPTS = 3;
|
|
9
10
|
const livekitHealthCache = createCache({
|
|
10
11
|
ttl: 20 * 1000,
|
|
11
12
|
refreshThreshold: 5 * 1000,
|
|
@@ -23,18 +24,21 @@ const withTimeout = (promise, timeoutMs) => new Promise((resolve, reject) => {
|
|
|
23
24
|
});
|
|
24
25
|
});
|
|
25
26
|
/**
|
|
26
|
-
* True when a LiveKit RoomService call succeeds
|
|
27
|
-
*
|
|
27
|
+
* True when a LiveKit RoomService call succeeds within maxAttempts. Retries so a
|
|
28
|
+
* single transient failure does not disable jams for a full /server/info bucket.
|
|
29
|
+
* Credentials in config are not enough — invalid keys fail on first RPC.
|
|
28
30
|
*/
|
|
29
|
-
export const probeLivekitConnection = async (listRooms, timeoutMs = LIVEKIT_HEALTH_TIMEOUT_MS) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
export const probeLivekitConnection = async (listRooms, timeoutMs = LIVEKIT_HEALTH_TIMEOUT_MS, maxAttempts = LIVEKIT_HEALTH_MAX_ATTEMPTS) => {
|
|
32
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
33
|
+
try {
|
|
34
|
+
await withTimeout(listRooms(), timeoutMs);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
log.warn(`LiveKit health check failed (attempt ${attempt}/${maxAttempts}): ${e.message}`);
|
|
39
|
+
}
|
|
37
40
|
}
|
|
41
|
+
return false;
|
|
38
42
|
};
|
|
39
43
|
/** Cached LiveKit reachability. False when unset, unauthorized, or unreachable. */
|
|
40
44
|
export const isLivekitConnected = () => livekitHealthCache.wrap(LIVEKIT_HEALTH_CACHE_KEY, async () => {
|
package/dist/jams/helpers.js
CHANGED
|
@@ -5,7 +5,11 @@ import { findProfile } from '../profiles/index.js';
|
|
|
5
5
|
import { findPost } from '../posts/index.js';
|
|
6
6
|
import { config } from '../config/index.js';
|
|
7
7
|
export const connectRecording = connector(collectionInfos.profilesCollection, collectionInfos.postsCollection, collectionInfos.jamRecordingsCollection);
|
|
8
|
-
export const transformJamRecordingData = async (recording) => (
|
|
8
|
+
export const transformJamRecordingData = async (recording) => ({
|
|
9
|
+
...jamRecordingSchema.parse(recording),
|
|
10
|
+
profile: (await findProfile(recording._from.split('/')[1])),
|
|
11
|
+
post: (await findPost(recording._to.split('/')[1])),
|
|
12
|
+
});
|
|
9
13
|
/** Hostname used when stamping LiveKit room metadata (`instanceDomain`). */
|
|
10
14
|
export const localInstanceDomain = async () => {
|
|
11
15
|
const host = (await config()).server.host;
|
|
@@ -23,7 +27,7 @@ export const parseRoomInstanceDomain = (metadata) => {
|
|
|
23
27
|
? parsed.instanceDomain.toLowerCase()
|
|
24
28
|
: undefined;
|
|
25
29
|
}
|
|
26
|
-
catch
|
|
30
|
+
catch {
|
|
27
31
|
return undefined;
|
|
28
32
|
}
|
|
29
33
|
};
|
package/dist/jams/index.js
CHANGED
|
@@ -89,7 +89,7 @@ export const listLiveJams = async (authData) => {
|
|
|
89
89
|
]);
|
|
90
90
|
return posts.filter(canReadPost(config, authData));
|
|
91
91
|
};
|
|
92
|
-
export const findJamEvent = async (id) => findPost(id).then((post) =>
|
|
92
|
+
export const findJamEvent = async (id) => findPost(id).then((post) => post?.data?.type === 'event' && post.data?.jam ? post : undefined);
|
|
93
93
|
export const closeJam = async (profile, jamEvent, recurrenceId) => {
|
|
94
94
|
const rs = await roomService();
|
|
95
95
|
if (rs === undefined) {
|
|
@@ -122,5 +122,5 @@ export const muteParticipant = async (jamId, data, recurrenceId) => {
|
|
|
122
122
|
if (!result) {
|
|
123
123
|
return { success: false };
|
|
124
124
|
}
|
|
125
|
-
return { success: result
|
|
125
|
+
return { success: result?.muted };
|
|
126
126
|
};
|
package/dist/jams/jobs.js
CHANGED
|
@@ -6,12 +6,11 @@ const log = logger('app:jams:jobs');
|
|
|
6
6
|
export const JAM_RECORDING_MAX_DURATION_MS = 2 * 60 * 60 * 1000;
|
|
7
7
|
const recordingStopJobId = (recordingId) => `jam-recording-stop:${recordingId}`;
|
|
8
8
|
const [jamRecordingStopQueue, jamRecordingStopWorker] = queueAndWorker('jam-recording-stop', async (job) => {
|
|
9
|
-
var _a;
|
|
10
9
|
// Dynamic import avoids a load-time cycle with livekit.ts (which schedules
|
|
11
10
|
// this job when a recording starts).
|
|
12
11
|
const { stopRecording } = await import('./livekit.js');
|
|
13
12
|
const jamPost = await findPost(job.data.jamPostId);
|
|
14
|
-
if (!jamPost ||
|
|
13
|
+
if (!jamPost || jamPost.data?.type !== 'event' || !jamPost.data.jam) {
|
|
15
14
|
log.info(`Skipping auto-stop for missing jam ${job.data.jamPostId}`);
|
|
16
15
|
return;
|
|
17
16
|
}
|
package/dist/jams/livekit.js
CHANGED
|
@@ -92,7 +92,7 @@ export const stopEgress = async (egressId) => {
|
|
|
92
92
|
try {
|
|
93
93
|
await egressClient.stopEgress(egressId);
|
|
94
94
|
}
|
|
95
|
-
catch
|
|
95
|
+
catch {
|
|
96
96
|
// LiveKit egress can time out or already be stopped/failed; the user-facing
|
|
97
97
|
// stop action should not fail because of that.
|
|
98
98
|
}
|
|
@@ -151,7 +151,7 @@ export const startRecording = async (profile, jamPost, recurrenceId) => {
|
|
|
151
151
|
profileId: profile.id,
|
|
152
152
|
recurrenceId,
|
|
153
153
|
});
|
|
154
|
-
await roomService().then(async (rs) => rs
|
|
154
|
+
await roomService().then(async (rs) => rs?.sendData(roomName, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
155
155
|
// BullMQ delayed job survives API/worker restarts (unlike setTimeout).
|
|
156
156
|
await scheduleRecordingAutoStop(jamId, persistedRecordingId);
|
|
157
157
|
return recording;
|
|
@@ -173,7 +173,7 @@ const assertJamRoomOpen = async (jamId) => {
|
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
175
|
const emitJamEvent = async (jamId, jamEvent) => {
|
|
176
|
-
await roomService().then(async (rs) => rs
|
|
176
|
+
await roomService().then(async (rs) => rs?.sendData(jamId, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
177
177
|
};
|
|
178
178
|
export const startRtmpStream = async (profile, jamPost, rtmpUrl, destinationHost) => {
|
|
179
179
|
await assertLivekitConfigured();
|
|
@@ -221,7 +221,7 @@ export const stopRtmpStream = async (jamPost) => {
|
|
|
221
221
|
profileId: stream.profile.id,
|
|
222
222
|
});
|
|
223
223
|
await emitJamEvent(jamPost.id, jamEvent);
|
|
224
|
-
return
|
|
224
|
+
return { ...stream, status: 'completed' };
|
|
225
225
|
};
|
|
226
226
|
export const stopRecording = async (jamPost, recurrenceId) => {
|
|
227
227
|
const jamRecording = await findActiveRecording(jamPost);
|
|
@@ -243,9 +243,9 @@ export const stopRecording = async (jamPost, recurrenceId) => {
|
|
|
243
243
|
profileId: jamRecording.profile.id,
|
|
244
244
|
recurrenceId,
|
|
245
245
|
});
|
|
246
|
-
await roomService().then(async (rs) => rs
|
|
246
|
+
await roomService().then(async (rs) => rs?.sendData(jamRoomName(jamPost.id, recurrenceId), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
247
247
|
await finalizeJamRecording(jamRecording.id);
|
|
248
|
-
return
|
|
248
|
+
return { ...jamRecording, status: 'finalizing' };
|
|
249
249
|
};
|
|
250
250
|
/**
|
|
251
251
|
* Stops leftover egress and deletes an egress-only LiveKit room.
|
|
@@ -267,7 +267,7 @@ export const reclaimOrphanJamRoom = async (jam, roomName = jam.id) => {
|
|
|
267
267
|
}
|
|
268
268
|
try {
|
|
269
269
|
const rs = await roomService();
|
|
270
|
-
await
|
|
270
|
+
await rs?.deleteRoom(roomName);
|
|
271
271
|
}
|
|
272
272
|
catch (e) {
|
|
273
273
|
log.warn(`Failed to delete orphan jam room ${roomName}: ${e.message}`);
|
|
@@ -280,7 +280,7 @@ export const finishRecording = async (jamRecording) => {
|
|
|
280
280
|
type: 'recordStop',
|
|
281
281
|
profileId: jamRecording.profile.id,
|
|
282
282
|
});
|
|
283
|
-
await roomService().then(async (rs) => rs
|
|
283
|
+
await roomService().then(async (rs) => rs?.sendData(jamRoomName(jamRecording.post.id), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
284
284
|
};
|
|
285
285
|
export const jamState = async (jam, hideParticipants, recurrenceId) => {
|
|
286
286
|
const inactive = { participants: [], active: false };
|
package/dist/jams/recording.js
CHANGED
|
@@ -81,7 +81,7 @@ export const publishJamRecordingReply = async (eventPost, recordingId) => {
|
|
|
81
81
|
audience: eventPost.audience,
|
|
82
82
|
});
|
|
83
83
|
await updateJamRecording(recordingId, { replyPostId: reply.id });
|
|
84
|
-
return jamRecordingSchema.parse(
|
|
84
|
+
return jamRecordingSchema.parse({ ...recording, replyPostId: reply.id });
|
|
85
85
|
};
|
|
86
86
|
export const deleteJamRecording = async (eventPost, recordingId) => {
|
|
87
87
|
const recording = await findJamRecording(recordingId);
|
package/dist/jams/token.js
CHANGED
|
@@ -10,26 +10,24 @@ import { createJamEvent } from './mutations.js';
|
|
|
10
10
|
import { uuidv7 } from 'uuidv7';
|
|
11
11
|
import { findProfile } from '../profiles/index.js';
|
|
12
12
|
const calculateSources = (jam, profile) => {
|
|
13
|
-
var _a;
|
|
14
13
|
const sources = [TrackSource.MICROPHONE];
|
|
15
14
|
if (jam.videoEnabled) {
|
|
16
15
|
sources.push(TrackSource.CAMERA, TrackSource.SCREEN_SHARE, TrackSource.SCREEN_SHARE_AUDIO);
|
|
17
16
|
}
|
|
18
|
-
if (
|
|
17
|
+
if (jam.presenters?.includes(profile.id)) {
|
|
19
18
|
sources.push(TrackSource.SCREEN_SHARE, TrackSource.SCREEN_SHARE_AUDIO);
|
|
20
19
|
}
|
|
21
20
|
return sources;
|
|
22
21
|
};
|
|
23
22
|
export const assertJamRsvpAllowed = (event, profile, recurrenceId) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!(eventData === null || eventData === void 0 ? void 0 : eventData.maxAttendees)) {
|
|
23
|
+
const eventData = event.data?.type === 'event' ? event.data : undefined;
|
|
24
|
+
if (!eventData?.maxAttendees) {
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
27
|
if (canModerateJam(profile, event)) {
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
|
-
if (
|
|
30
|
+
if (getEffectiveRsvp(event, profile.id, recurrenceId)?.response === 'yes') {
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
35
33
|
if (countYesRsvps(event, recurrenceId) >= eventData.maxAttendees) {
|
|
@@ -38,10 +36,9 @@ export const assertJamRsvpAllowed = (event, profile, recurrenceId) => {
|
|
|
38
36
|
throw forbidden({ errorKey: 'error.jamRsvpRequired' });
|
|
39
37
|
};
|
|
40
38
|
export const createJamEgressToken = async (event, recurrenceId) => {
|
|
41
|
-
var _a, _b;
|
|
42
39
|
const jamId = event.id;
|
|
43
40
|
const roomName = jamRoomName(event.id, recurrenceId);
|
|
44
|
-
const jam =
|
|
41
|
+
const jam = event.data?.type === 'event' && event.data?.jam;
|
|
45
42
|
if (!jam) {
|
|
46
43
|
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
47
44
|
}
|
|
@@ -62,17 +59,16 @@ export const createJamEgressToken = async (event, recurrenceId) => {
|
|
|
62
59
|
return accessToken.toJwt();
|
|
63
60
|
};
|
|
64
61
|
export const createJamToken = async (event, profile, { external = false, recurrenceId, reconnect = false, } = {}) => {
|
|
65
|
-
var _a, _b, _c, _d;
|
|
66
62
|
if (!profile.id)
|
|
67
63
|
throw authNeeded({ errorKey: 'error.profileRequired' });
|
|
68
64
|
const jamId = event.id;
|
|
69
65
|
const roomName = jamRoomName(event.id, recurrenceId);
|
|
70
|
-
const jam =
|
|
66
|
+
const jam = event.data?.type === 'event' && event.data?.jam;
|
|
71
67
|
if (!jam) {
|
|
72
68
|
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
73
69
|
}
|
|
74
70
|
const joiner = await findProfile(profile.id);
|
|
75
|
-
if (joiner && isBlockedPair(joiner,
|
|
71
|
+
if (joiner && isBlockedPair(joiner, event.profile?.id)) {
|
|
76
72
|
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
77
73
|
}
|
|
78
74
|
assertJamRsvpAllowed(event, profile, recurrenceId);
|
|
@@ -84,11 +80,11 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
84
80
|
try {
|
|
85
81
|
rooms = await rs.listRooms([roomName]);
|
|
86
82
|
}
|
|
87
|
-
catch
|
|
83
|
+
catch {
|
|
88
84
|
throw forbidden({ errorKey: 'error.jamsUnavailable' });
|
|
89
85
|
}
|
|
90
86
|
const jamOpen = rooms.length === 1;
|
|
91
|
-
if (!jamOpen && (reconnect || !
|
|
87
|
+
if (!jamOpen && (reconnect || !jam?.moderators.includes(profile.id))) {
|
|
92
88
|
throw forbidden({ errorKey: 'error.jamNotOpen' });
|
|
93
89
|
}
|
|
94
90
|
if (!jamOpen) {
|
|
@@ -103,7 +99,7 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
103
99
|
departureTimeout: JAM_ROOM_DEPARTURE_TIMEOUT_SEC,
|
|
104
100
|
});
|
|
105
101
|
}
|
|
106
|
-
catch
|
|
102
|
+
catch {
|
|
107
103
|
// Concurrent open may have created the room already.
|
|
108
104
|
}
|
|
109
105
|
}
|
|
@@ -128,9 +124,9 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
128
124
|
accessToken.addGrant({
|
|
129
125
|
room: roomName,
|
|
130
126
|
roomJoin: true,
|
|
131
|
-
roomAdmin: jam
|
|
132
|
-
roomRecord: jam
|
|
133
|
-
canPublish:
|
|
127
|
+
roomAdmin: jam?.moderators.includes(profile.id),
|
|
128
|
+
roomRecord: jam?.moderators.includes(profile.id),
|
|
129
|
+
canPublish: jam?.type === 'video-call' || !!jam?.speakers?.includes(profile.id),
|
|
134
130
|
canPublishSources: calculateSources(jam, profile),
|
|
135
131
|
canPublishData: true,
|
|
136
132
|
canSubscribe: true,
|
package/dist/jobs/index.js
CHANGED
|
@@ -18,10 +18,13 @@ export const closeQueues = async () => {
|
|
|
18
18
|
export const queueAndWorker = (queueName, processor, queueOptions) => [
|
|
19
19
|
() => {
|
|
20
20
|
if (!queues[queueName]) {
|
|
21
|
-
const queue = new Queue(queueName,
|
|
21
|
+
const queue = new Queue(queueName, {
|
|
22
|
+
connection,
|
|
23
|
+
...queueOptions,
|
|
24
|
+
});
|
|
22
25
|
queues[queueName] = queue;
|
|
23
26
|
// Clean up existing jobs based on defaultJobOptions retention settings
|
|
24
|
-
const defaultJobOptions = queueOptions
|
|
27
|
+
const defaultJobOptions = queueOptions?.defaultJobOptions;
|
|
25
28
|
if (defaultJobOptions) {
|
|
26
29
|
void (async () => {
|
|
27
30
|
try {
|
|
@@ -57,9 +60,7 @@ export const queueAndWorker = (queueName, processor, queueOptions) => [
|
|
|
57
60
|
metrics: { maxDataPoints: MetricsTime.ONE_WEEK },
|
|
58
61
|
}),
|
|
59
62
|
];
|
|
60
|
-
export const getOrCreateQueue = (queueName) =>
|
|
61
|
-
|
|
62
|
-
return (_a = queues[queueName]) !== null && _a !== void 0 ? _a : (queues[queueName] = new Queue(queueName, { connection }));
|
|
63
|
-
};
|
|
63
|
+
export const getOrCreateQueue = (queueName) => queues[queueName] ??
|
|
64
|
+
(queues[queueName] = new Queue(queueName, { connection }));
|
|
64
65
|
export { getJobDetail } from './jobDetail.js';
|
|
65
66
|
export { jobLogger, logStep, logFailure, formatErrorDetail, } from './jobLog.js';
|
package/dist/jobs/jobDetail.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getOrCreateQueue } from './index.js';
|
|
2
2
|
export const getJobDetail = async (queueName, jobId) => {
|
|
3
|
-
var _a, _b, _c, _d, _e;
|
|
4
3
|
const queue = getOrCreateQueue(queueName);
|
|
5
4
|
const job = await queue.getJob(jobId);
|
|
6
5
|
if (!job || job.id == null) {
|
|
@@ -15,11 +14,11 @@ export const getJobDetail = async (queueName, jobId) => {
|
|
|
15
14
|
id: String(job.id),
|
|
16
15
|
name: job.name,
|
|
17
16
|
state,
|
|
18
|
-
failedReason:
|
|
19
|
-
finishedOn:
|
|
20
|
-
processedOn:
|
|
21
|
-
timestamp:
|
|
22
|
-
data:
|
|
17
|
+
failedReason: job.failedReason ?? null,
|
|
18
|
+
finishedOn: job.finishedOn ?? null,
|
|
19
|
+
processedOn: job.processedOn ?? null,
|
|
20
|
+
timestamp: job.timestamp ?? null,
|
|
21
|
+
data: job.data ?? null,
|
|
23
22
|
logs,
|
|
24
23
|
logCount: count,
|
|
25
24
|
};
|
package/dist/jobs/jobLog.js
CHANGED
|
@@ -6,7 +6,6 @@ export const jobLogger = (job) => (message) => job.log(message).then(() => undef
|
|
|
6
6
|
* `code`) so failed deliveries are diagnosable from the job log alone.
|
|
7
7
|
*/
|
|
8
8
|
export const formatErrorDetail = (error) => {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
if (error instanceof Error) {
|
|
11
10
|
const e = error;
|
|
12
11
|
const parts = [e.message];
|
|
@@ -24,13 +23,13 @@ export const formatErrorDetail = (error) => {
|
|
|
24
23
|
}
|
|
25
24
|
if (error && typeof error === 'object') {
|
|
26
25
|
const e = error;
|
|
27
|
-
const reason =
|
|
26
|
+
const reason = e.reason ?? e.code ?? e.message;
|
|
28
27
|
if (reason != null)
|
|
29
28
|
return String(reason);
|
|
30
29
|
try {
|
|
31
30
|
return JSON.stringify(error);
|
|
32
31
|
}
|
|
33
|
-
catch
|
|
32
|
+
catch {
|
|
34
33
|
return String(error);
|
|
35
34
|
}
|
|
36
35
|
}
|
package/dist/lib/streams.js
CHANGED
|
@@ -1,42 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
6
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
-
};
|
|
8
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
9
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
10
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
11
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
12
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
13
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
14
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
15
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
16
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
17
|
-
function fulfill(value) { resume("next", value); }
|
|
18
|
-
function reject(value) { resume("throw", value); }
|
|
19
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
20
|
-
};
|
|
21
|
-
function nodeStreamToIterator(stream) {
|
|
22
|
-
return __asyncGenerator(this, arguments, function* nodeStreamToIterator_1() {
|
|
23
|
-
var _a, e_1, _b, _c;
|
|
24
|
-
try {
|
|
25
|
-
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
|
|
26
|
-
_c = stream_1_1.value;
|
|
27
|
-
_d = false;
|
|
28
|
-
const chunk = _c;
|
|
29
|
-
yield yield __await(chunk);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
33
|
-
finally {
|
|
34
|
-
try {
|
|
35
|
-
if (!_d && !_a && (_b = stream_1.return)) yield __await(_b.call(stream_1));
|
|
36
|
-
}
|
|
37
|
-
finally { if (e_1) throw e_1.error; }
|
|
38
|
-
}
|
|
39
|
-
});
|
|
1
|
+
async function* nodeStreamToIterator(stream) {
|
|
2
|
+
for await (const chunk of stream) {
|
|
3
|
+
yield chunk;
|
|
4
|
+
}
|
|
40
5
|
}
|
|
41
6
|
function iteratorToStream(iterator) {
|
|
42
7
|
return new ReadableStream({
|
package/dist/log/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
2
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3
|
-
var m = o[Symbol.asyncIterator], i;
|
|
4
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
5
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
6
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
-
};
|
|
8
1
|
import { createReadStream, existsSync, mkdirSync } from 'node:fs';
|
|
9
2
|
import { appendFile } from 'node:fs/promises';
|
|
10
3
|
import { join } from 'node:path';
|
|
@@ -15,7 +8,6 @@ import { default as logsConfig } from '../config/defaults/logs.js';
|
|
|
15
8
|
const createLogDirectory = () => mkdirSync(logsConfig.local.path, { recursive: true });
|
|
16
9
|
const currentFile = (date) => join(logsConfig.local.path, formatDate(date, 'yyyyMMdd') + '.log');
|
|
17
10
|
export const listLogs = async (date = new Date()) => {
|
|
18
|
-
var _a, e_1, _b, _c;
|
|
19
11
|
const filePath = currentFile(date);
|
|
20
12
|
if (!existsSync(filePath)) {
|
|
21
13
|
return [];
|
|
@@ -26,25 +18,13 @@ export const listLogs = async (date = new Date()) => {
|
|
|
26
18
|
crlfDelay: Infinity,
|
|
27
19
|
});
|
|
28
20
|
const lines = [];
|
|
29
|
-
|
|
30
|
-
for (var _d = true, iterator_1 = __asyncValues(iterator), iterator_1_1; iterator_1_1 = await iterator_1.next(), _a = iterator_1_1.done, !_a; _d = true) {
|
|
31
|
-
_c = iterator_1_1.value;
|
|
32
|
-
_d = false;
|
|
33
|
-
const logLine = _c;
|
|
34
|
-
try {
|
|
35
|
-
lines.push(JSON.parse(logLine));
|
|
36
|
-
}
|
|
37
|
-
catch (_e) {
|
|
38
|
-
// skip malformed lines
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
43
|
-
finally {
|
|
21
|
+
for await (const logLine of iterator) {
|
|
44
22
|
try {
|
|
45
|
-
|
|
23
|
+
lines.push(JSON.parse(logLine));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// skip malformed lines
|
|
46
27
|
}
|
|
47
|
-
finally { if (e_1) throw e_1.error; }
|
|
48
28
|
}
|
|
49
29
|
return lines.reverse();
|
|
50
30
|
};
|
|
@@ -62,7 +42,12 @@ const namespaceLogLevels = {};
|
|
|
62
42
|
/** Errors stringify to `{}` unless message/stack are copied onto enumerable keys. */
|
|
63
43
|
const serializeLogArg = (arg) => {
|
|
64
44
|
if (arg instanceof Error) {
|
|
65
|
-
return safeJsonStringify(
|
|
45
|
+
return safeJsonStringify({
|
|
46
|
+
name: arg.name,
|
|
47
|
+
message: arg.message,
|
|
48
|
+
stack: arg.stack,
|
|
49
|
+
...arg,
|
|
50
|
+
});
|
|
66
51
|
}
|
|
67
52
|
if (arg !== null && typeof arg === 'object') {
|
|
68
53
|
return safeJsonStringify(arg);
|
|
@@ -72,12 +57,11 @@ const serializeLogArg = (arg) => {
|
|
|
72
57
|
export const logger = (ns, meta) => {
|
|
73
58
|
createLogDirectory();
|
|
74
59
|
const log = (level, ...args) => {
|
|
75
|
-
|
|
76
|
-
if (logLevels[level] < ((_a = namespaceLogLevels[ns]) !== null && _a !== void 0 ? _a : defaultLogLevel)) {
|
|
60
|
+
if (logLevels[level] < (namespaceLogLevels[ns] ?? defaultLogLevel)) {
|
|
77
61
|
return;
|
|
78
62
|
}
|
|
79
63
|
const date = new Date();
|
|
80
|
-
console.log(`${date.toISOString()} - ${ns} - ${level} | `, ...args, meta
|
|
64
|
+
console.log(`${date.toISOString()} - ${ns} - ${level} | `, ...args, meta ?? '');
|
|
81
65
|
appendFile(currentFile(date), JSON.stringify({
|
|
82
66
|
level,
|
|
83
67
|
message: args.map(serializeLogArg).join(' '),
|
package/dist/media/index.js
CHANGED
|
@@ -107,7 +107,7 @@ export const createPreview = async (inputPath, mimetype, originalName) => {
|
|
|
107
107
|
if (originalName.endsWith('.mkv')) {
|
|
108
108
|
return createVideoPreview(inputPath);
|
|
109
109
|
}
|
|
110
|
-
return
|
|
110
|
+
return createFilePreview(inputPath, mimetype, originalName);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
const createImagePreview = async (inputPath, mimetype) => {
|
|
@@ -125,6 +125,52 @@ const createImagePreview = async (inputPath, mimetype) => {
|
|
|
125
125
|
.toFile(outputPath);
|
|
126
126
|
return { path: outputPath, mimetype: 'image/webp' };
|
|
127
127
|
};
|
|
128
|
+
const escapeXml = (value) => value
|
|
129
|
+
.replace(/&/g, '&')
|
|
130
|
+
.replace(/</g, '<')
|
|
131
|
+
.replace(/>/g, '>')
|
|
132
|
+
.replace(/"/g, '"');
|
|
133
|
+
const createPdfPreview = (inputPath) => {
|
|
134
|
+
const outputPath = join(tmpdir(), `preview-${randomString(16)}.webp`);
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
ffmpeg(inputPath)
|
|
137
|
+
.frames(1)
|
|
138
|
+
.outputOptions(['-c:v libwebp', '-lossless 0', '-q:v 80'])
|
|
139
|
+
.output(outputPath)
|
|
140
|
+
.on('end', () => resolve({ path: outputPath, mimetype: 'image/webp' }))
|
|
141
|
+
.on('error', reject)
|
|
142
|
+
.run();
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const createDocumentCardPreview = async (originalName) => {
|
|
146
|
+
const ext = (path.extname(originalName).replace('.', '') || 'FILE')
|
|
147
|
+
.slice(0, 8)
|
|
148
|
+
.toUpperCase();
|
|
149
|
+
const base = path.parse(originalName).name.slice(0, 28);
|
|
150
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="700" height="700">
|
|
151
|
+
<rect width="700" height="700" fill="#f4f4f5"/>
|
|
152
|
+
<rect x="160" y="80" width="380" height="480" rx="16" fill="#ffffff" stroke="#d4d4d8" stroke-width="4"/>
|
|
153
|
+
<rect x="210" y="140" width="180" height="72" rx="8" fill="#18181b"/>
|
|
154
|
+
<text x="300" y="188" text-anchor="middle" font-family="sans-serif" font-size="28" font-weight="700" fill="#ffffff">${escapeXml(ext)}</text>
|
|
155
|
+
<text x="350" y="420" text-anchor="middle" font-family="sans-serif" font-size="28" fill="#18181b">${escapeXml(base)}</text>
|
|
156
|
+
</svg>`;
|
|
157
|
+
const outputPath = join(tmpdir(), `preview-${randomString(16)}.webp`);
|
|
158
|
+
await sharp(Buffer.from(svg)).webp({ quality: 80 }).toFile(outputPath);
|
|
159
|
+
return { path: outputPath, mimetype: 'image/webp' };
|
|
160
|
+
};
|
|
161
|
+
const createFilePreview = async (inputPath, mimetype, originalName) => {
|
|
162
|
+
const isPdf = mimetype === 'application/pdf' ||
|
|
163
|
+
originalName.toLowerCase().endsWith('.pdf');
|
|
164
|
+
if (isPdf) {
|
|
165
|
+
try {
|
|
166
|
+
return await createPdfPreview(inputPath);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Some ffmpeg builds cannot rasterize PDFs.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return createDocumentCardPreview(originalName);
|
|
173
|
+
};
|
|
128
174
|
const getMediaDuration = (filePath) => new Promise((resolve, reject) => {
|
|
129
175
|
ffmpeg.ffprobe(filePath, (err, metadata) => {
|
|
130
176
|
if (err) {
|
|
@@ -144,14 +190,14 @@ const getMediaDuration = (filePath) => new Promise((resolve, reject) => {
|
|
|
144
190
|
});
|
|
145
191
|
const getVideoStreamInfo = (filePath) => new Promise((resolve, reject) => {
|
|
146
192
|
ffmpeg.ffprobe(filePath, (err, metadata) => {
|
|
147
|
-
var _a;
|
|
148
193
|
if (err) {
|
|
149
194
|
reject(err);
|
|
150
195
|
return;
|
|
151
196
|
}
|
|
152
197
|
const stream = metadata.streams.find((s) => s.codec_type === 'video');
|
|
153
|
-
const duration =
|
|
154
|
-
|
|
198
|
+
const duration = metadata.format.duration ??
|
|
199
|
+
(stream?.duration ? Number(stream.duration) : undefined);
|
|
200
|
+
if (!stream?.width || !stream?.height || !duration) {
|
|
155
201
|
reject(new Error('Could not determine video stream info'));
|
|
156
202
|
return;
|
|
157
203
|
}
|
package/dist/media/jobs.js
CHANGED
|
@@ -42,13 +42,12 @@ export const subscribeToMediaProgress = async (mediaAttachmentId, onMessage) =>
|
|
|
42
42
|
return () => disconnect(conn);
|
|
43
43
|
};
|
|
44
44
|
const [mediaProcessingQueue, mediaProcessingWorker] = queueAndWorker('media-processing', async (job) => {
|
|
45
|
-
var _a;
|
|
46
45
|
const { mediaAttachmentId, fileStorageKey } = job.data;
|
|
47
46
|
const attachment = await findMediaAttachment(mediaAttachmentId);
|
|
48
47
|
if (!attachment) {
|
|
49
48
|
throw new Error(`MediaAttachment ${mediaAttachmentId} not found in worker`);
|
|
50
49
|
}
|
|
51
|
-
const filesize =
|
|
50
|
+
const filesize = attachment.meta.size ?? 0;
|
|
52
51
|
const estimatedDurationMs = await estimateProcessingDuration({
|
|
53
52
|
filetype: attachment.type,
|
|
54
53
|
filesize,
|