@openpeepshq/core 0.1.35 → 0.2.1
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/accounts/mutations.js +9 -0
- package/dist/analytics/report.d.ts +1 -1
- package/dist/config/defaults/logs.d.ts +4 -0
- package/dist/config/defaults/logs.js +5 -0
- package/dist/config/index.d.ts +3 -328
- package/dist/db/explorer/index.d.ts +1 -1
- package/dist/db/explorer/index.js +1 -1
- package/dist/db/pg/filters/posts.js +1 -1
- package/dist/db/pg/map/registry.js +3 -2
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/jams/export.d.ts +2 -0
- package/dist/jams/export.js +5 -0
- package/dist/jams/finders.d.ts +1 -0
- package/dist/jams/finders.js +1 -0
- package/dist/jams/health.d.ts +23 -0
- package/dist/jams/health.js +79 -7
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/index.d.ts +1 -1
- package/dist/jams/index.js +10 -3
- package/dist/jams/livekit.d.ts +2 -2
- package/dist/jams/mapping.d.ts +10 -10
- package/dist/jams/mutations.d.ts +2 -2
- package/dist/jams/token.js +6 -2
- package/dist/jams/waitingRoom.js +3 -1
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.js +1 -0
- 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/garbageCollection.d.ts +109 -0
- package/dist/media/garbageCollection.js +603 -0
- package/dist/media/garbageCollectionJobs.d.ts +14 -0
- package/dist/media/garbageCollectionJobs.js +55 -0
- package/dist/media/index.d.ts +2 -0
- package/dist/media/index.js +91 -12
- package/dist/media/streaming.d.ts +2 -0
- package/dist/media/streaming.js +8 -0
- package/dist/mediaAttachments/mapping.d.ts +1 -1
- package/dist/notifications/defaultNotifications/index.js +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +25 -16
- package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +1 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.js +61 -13
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +3 -3
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
- package/dist/notifications/defaultNotifications/waitlistOffer/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/waitlistOffer/index.js +40 -0
- package/dist/notifications/eventIcsAttachment.d.ts +6 -0
- package/dist/notifications/eventIcsAttachment.js +32 -0
- package/dist/notifications/helpers.d.ts +11 -1
- package/dist/notifications/helpers.js +26 -0
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/jobs.js +6 -0
- package/dist/notifications/mutations.js +9 -1
- package/dist/plugins/pluginAuth.js +1 -0
- package/dist/posts/activity.d.ts +1 -1
- package/dist/posts/activity.js +1 -1
- package/dist/posts/conversationQueries.d.ts +31 -0
- package/dist/posts/conversationQueries.js +150 -24
- package/dist/posts/eventAgenda.js +4 -2
- package/dist/posts/finders.d.ts +15 -6
- package/dist/posts/finders.js +23 -3
- package/dist/posts/helpers/index.d.ts +34 -26
- package/dist/posts/helpers/index.js +6 -0
- package/dist/posts/index.d.ts +3 -1
- package/dist/posts/index.js +3 -1
- package/dist/posts/mapping.d.ts +112 -98
- package/dist/posts/mutations.d.ts +24 -18
- package/dist/posts/mutations.js +222 -72
- package/dist/posts/rsvpExport.d.ts +47 -0
- package/dist/posts/rsvpExport.js +178 -0
- package/dist/posts/unseenCounts.d.ts +6 -0
- package/dist/posts/unseenCounts.js +51 -1
- package/dist/posts/waitlist.d.ts +13 -0
- package/dist/posts/waitlist.js +75 -0
- package/dist/posts/waitlistOfferJobs.d.ts +10 -0
- package/dist/posts/waitlistOfferJobs.js +91 -0
- package/dist/profileSettings/mapping.d.ts +1 -0
- package/dist/profiles/index.js +6 -1
- package/dist/profiles/mapping.d.ts +10 -10
- package/dist/reports/mapping.d.ts +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/stats/mapping.d.ts +7 -6
- package/dist/stripe/connection.js +1 -1
- package/dist/stripe/helpers.js +7 -3
- package/package.json +11 -10
package/dist/jams/health.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createCache } from 'cache-manager';
|
|
2
|
+
import { livekitDiagnosisSchema, } from '@openpeepshq/common/types';
|
|
3
|
+
import { config } from '../config/index.js';
|
|
2
4
|
import { logger } from '../log/index.js';
|
|
3
5
|
import { roomService } from './livekit.js';
|
|
4
6
|
const log = logger('app:jams:livekit');
|
|
@@ -23,28 +25,98 @@ const withTimeout = (promise, timeoutMs) => new Promise((resolve, reject) => {
|
|
|
23
25
|
reject(err);
|
|
24
26
|
});
|
|
25
27
|
});
|
|
28
|
+
const errorMessage = (e) => e instanceof Error && e.message ? e.message : 'LiveKit health check failed';
|
|
29
|
+
/** Drop credential material if a client library echoes it in an error. */
|
|
30
|
+
export const redactSecrets = (message, secrets) => secrets.reduce((text, secret) => {
|
|
31
|
+
if (!secret || secret.length < 8)
|
|
32
|
+
return text;
|
|
33
|
+
return text.split(secret).join('[redacted]');
|
|
34
|
+
}, message);
|
|
26
35
|
/**
|
|
27
36
|
* True when a LiveKit RoomService call succeeds within maxAttempts. Retries so a
|
|
28
37
|
* single transient failure does not disable jams for a full /server/info bucket.
|
|
29
38
|
* Credentials in config are not enough — invalid keys fail on first RPC.
|
|
30
39
|
*/
|
|
31
|
-
export const
|
|
40
|
+
export const probeLivekitConnectionResult = async (listRooms, timeoutMs = LIVEKIT_HEALTH_TIMEOUT_MS, maxAttempts = LIVEKIT_HEALTH_MAX_ATTEMPTS) => {
|
|
41
|
+
let lastError = 'LiveKit health check failed';
|
|
32
42
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
33
43
|
try {
|
|
34
44
|
await withTimeout(listRooms(), timeoutMs);
|
|
35
|
-
return true;
|
|
45
|
+
return { ok: true };
|
|
36
46
|
}
|
|
37
47
|
catch (e) {
|
|
38
|
-
|
|
48
|
+
lastError = errorMessage(e);
|
|
49
|
+
log.warn(`LiveKit health check failed (attempt ${attempt}/${maxAttempts}): ${lastError}`);
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
|
-
return false;
|
|
52
|
+
return { ok: false, error: lastError };
|
|
42
53
|
};
|
|
54
|
+
export const probeLivekitConnection = async (listRooms, timeoutMs = LIVEKIT_HEALTH_TIMEOUT_MS, maxAttempts = LIVEKIT_HEALTH_MAX_ATTEMPTS) => (await probeLivekitConnectionResult(listRooms, timeoutMs, maxAttempts)).ok;
|
|
43
55
|
/** Cached LiveKit reachability. False when unset, unauthorized, or unreachable. */
|
|
44
56
|
export const isLivekitConnected = () => livekitHealthCache.wrap(LIVEKIT_HEALTH_CACHE_KEY, async () => {
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
try {
|
|
58
|
+
const rs = await roomService();
|
|
59
|
+
if (rs === undefined) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return probeLivekitConnection(() => rs.listRooms([LIVEKIT_HEALTH_ROOM]));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
log.warn(`LiveKit health check failed: ${errorMessage(e)}`);
|
|
47
66
|
return false;
|
|
48
67
|
}
|
|
49
|
-
return probeLivekitConnection(() => rs.listRooms([LIVEKIT_HEALTH_ROOM]));
|
|
50
68
|
});
|
|
69
|
+
/** Checklist the admin diagnosis page renders. Secrets never leave this shape. */
|
|
70
|
+
export const buildLivekitDiagnosis = (input) => {
|
|
71
|
+
const configured = Boolean(input.url) && input.hasApiKey && input.hasApiSecret;
|
|
72
|
+
return {
|
|
73
|
+
connected: configured && input.reachable,
|
|
74
|
+
recordingEnabled: input.recordingEnabled,
|
|
75
|
+
...(input.url ? { url: input.url } : {}),
|
|
76
|
+
...(configured && !input.reachable && input.error
|
|
77
|
+
? { error: input.error }
|
|
78
|
+
: {}),
|
|
79
|
+
checks: [
|
|
80
|
+
{ id: 'url', ok: Boolean(input.url) },
|
|
81
|
+
{ id: 'apiKey', ok: input.hasApiKey },
|
|
82
|
+
{ id: 'apiSecret', ok: input.hasApiSecret },
|
|
83
|
+
{ id: 'reachable', ok: configured && input.reachable },
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Fresh LiveKit check for admins. Bypasses the short health cache so Refresh
|
|
89
|
+
* reports the current credentials and the last probe error.
|
|
90
|
+
*/
|
|
91
|
+
export const diagnoseLivekit = async () => {
|
|
92
|
+
const { url, apiKey, apiSecret, recordingEnabled } = (await config()).jams
|
|
93
|
+
.livekit;
|
|
94
|
+
const base = {
|
|
95
|
+
url,
|
|
96
|
+
hasApiKey: Boolean(apiKey),
|
|
97
|
+
hasApiSecret: Boolean(apiSecret),
|
|
98
|
+
recordingEnabled: !!recordingEnabled,
|
|
99
|
+
};
|
|
100
|
+
// Only probe when all credentials are present: a partial config can't tell
|
|
101
|
+
// "missing secret" apart from "auth rejected" and would surface errors that
|
|
102
|
+
// don't reflect the real problem.
|
|
103
|
+
let reachable = false;
|
|
104
|
+
let error;
|
|
105
|
+
if (url && apiKey && apiSecret) {
|
|
106
|
+
try {
|
|
107
|
+
const rs = await roomService();
|
|
108
|
+
if (rs) {
|
|
109
|
+
const probe = await probeLivekitConnectionResult(() => rs.listRooms([LIVEKIT_HEALTH_ROOM]));
|
|
110
|
+
reachable = probe.ok;
|
|
111
|
+
error = probe.error
|
|
112
|
+
? redactSecrets(probe.error, [apiKey, apiSecret])
|
|
113
|
+
: undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
error = redactSecrets(errorMessage(e), [apiKey, apiSecret]);
|
|
118
|
+
log.warn(`LiveKit diagnosis failed: ${error}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return livekitDiagnosisSchema.parse(buildLivekitDiagnosis({ ...base, reachable, error }));
|
|
122
|
+
};
|
package/dist/jams/helpers.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare const connectRecording: (db: import("../db").PgDb, from: ProfileW
|
|
|
24
24
|
updatedAt: string;
|
|
25
25
|
description?: string | undefined;
|
|
26
26
|
blurhash?: string | undefined;
|
|
27
|
-
status?: "failed" | "
|
|
27
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
28
28
|
error?: string | undefined;
|
|
29
29
|
deletedAt?: string | null | undefined;
|
|
30
30
|
} | undefined;
|
|
@@ -56,7 +56,7 @@ export declare const connectRecording: (db: import("../db").PgDb, from: ProfileW
|
|
|
56
56
|
updatedAt: string;
|
|
57
57
|
description?: string | undefined;
|
|
58
58
|
blurhash?: string | undefined;
|
|
59
|
-
status?: "failed" | "
|
|
59
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
60
60
|
error?: string | undefined;
|
|
61
61
|
deletedAt?: string | null | undefined;
|
|
62
62
|
} | undefined;
|
package/dist/jams/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AuthorizationData, type MuteParticipantRequest, type PostWithMeta, type Profile } from '@openpeepshq/common/types';
|
|
2
2
|
export { createJamToken, createJamEgressToken } from './token';
|
|
3
|
-
export { isLivekitConnected } from './health';
|
|
3
|
+
export { diagnoseLivekit, isLivekitConnected } from './health';
|
|
4
4
|
export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit';
|
|
5
5
|
export { rtmpStreamOutput } from './rtmp';
|
|
6
6
|
export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs';
|
package/dist/jams/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { canReadPost } from '../posts/helpers/index.js';
|
|
|
10
10
|
import { capabilitiesConfig } from '../config/index.js';
|
|
11
11
|
import { logger } from '../log/index.js';
|
|
12
12
|
export { createJamToken, createJamEgressToken } from './token.js';
|
|
13
|
-
export { isLivekitConnected } from './health.js';
|
|
13
|
+
export { diagnoseLivekit, isLivekitConnected } from './health.js';
|
|
14
14
|
export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit.js';
|
|
15
15
|
export { rtmpStreamOutput } from './rtmp.js';
|
|
16
16
|
export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs.js';
|
|
@@ -35,7 +35,14 @@ const reclaimLocalOrphan = (post) => {
|
|
|
35
35
|
* Auth filtering happens in {@link listLiveJams} so the cache is not per-user.
|
|
36
36
|
*/
|
|
37
37
|
const fetchLiveJamPosts = async () => {
|
|
38
|
-
|
|
38
|
+
let rs;
|
|
39
|
+
try {
|
|
40
|
+
rs = await roomService();
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
log.warn(`Failed to reach LiveKit (${e.message}). Admins can diagnose this at /admin/diagnostics/livekit.`);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
39
46
|
if (rs === undefined) {
|
|
40
47
|
return [];
|
|
41
48
|
}
|
|
@@ -48,7 +55,7 @@ const fetchLiveJamPosts = async () => {
|
|
|
48
55
|
]);
|
|
49
56
|
}
|
|
50
57
|
catch (e) {
|
|
51
|
-
log.warn(`Failed to list live jam rooms
|
|
58
|
+
log.warn(`Failed to list live jam rooms (${e.message}). Admins can diagnose this at /admin/diagnostics/livekit.`);
|
|
52
59
|
return [];
|
|
53
60
|
}
|
|
54
61
|
const posts = await Promise.all(rooms.map(async (room) => {
|
package/dist/jams/livekit.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare const stopRtmpStream: (jamPost: PostWithMeta) => Promise<{
|
|
|
51
51
|
updatedAt: string;
|
|
52
52
|
description?: string | undefined;
|
|
53
53
|
blurhash?: string | undefined;
|
|
54
|
-
status?: "failed" | "
|
|
54
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
55
55
|
error?: string | undefined;
|
|
56
56
|
deletedAt?: string | null | undefined;
|
|
57
57
|
} | undefined;
|
|
@@ -88,7 +88,7 @@ export declare const stopRecording: (jamPost: PostWithMeta, recurrenceId?: strin
|
|
|
88
88
|
updatedAt: string;
|
|
89
89
|
description?: string | undefined;
|
|
90
90
|
blurhash?: string | undefined;
|
|
91
|
-
status?: "failed" | "
|
|
91
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
92
92
|
error?: string | undefined;
|
|
93
93
|
deletedAt?: string | null | undefined;
|
|
94
94
|
} | undefined;
|
package/dist/jams/mapping.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type EdgeMetadata = {
|
|
|
7
7
|
export declare const jamEventsMapping: import("../db/pg/map").Mapping<{
|
|
8
8
|
id: string;
|
|
9
9
|
jamId: string;
|
|
10
|
-
type: "
|
|
10
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
11
11
|
profileId: string;
|
|
12
12
|
content?: string | undefined;
|
|
13
13
|
reaction?: "👍" | undefined;
|
|
@@ -16,7 +16,7 @@ export declare const jamEventsMapping: import("../db/pg/map").Mapping<{
|
|
|
16
16
|
export declare const jamSessionStartsMapping: import("../db/pg/map").Mapping<{
|
|
17
17
|
id: string;
|
|
18
18
|
jamId: string;
|
|
19
|
-
type: "
|
|
19
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
20
20
|
profileId: string;
|
|
21
21
|
content?: string | undefined;
|
|
22
22
|
reaction?: "👍" | undefined;
|
|
@@ -25,7 +25,7 @@ export declare const jamSessionStartsMapping: import("../db/pg/map").Mapping<{
|
|
|
25
25
|
export declare const jamSessionClosesMapping: import("../db/pg/map").Mapping<{
|
|
26
26
|
id: string;
|
|
27
27
|
jamId: string;
|
|
28
|
-
type: "
|
|
28
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
29
29
|
profileId: string;
|
|
30
30
|
content?: string | undefined;
|
|
31
31
|
reaction?: "👍" | undefined;
|
|
@@ -34,7 +34,7 @@ export declare const jamSessionClosesMapping: import("../db/pg/map").Mapping<{
|
|
|
34
34
|
export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
|
|
35
35
|
id: string;
|
|
36
36
|
jamId: string;
|
|
37
|
-
type: "
|
|
37
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
38
38
|
profileId: string;
|
|
39
39
|
content?: string | undefined;
|
|
40
40
|
reaction?: "👍" | undefined;
|
|
@@ -42,7 +42,7 @@ export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
|
|
|
42
42
|
}, JamEvent, JamEvent>;
|
|
43
43
|
export declare const jamRecordingRelation: RelationWithMapping<PostWithMeta, JamRecording>;
|
|
44
44
|
export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
45
|
-
status: "
|
|
45
|
+
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
|
46
46
|
kind?: "file" | "rtmp" | undefined;
|
|
47
47
|
destinationHost?: string | undefined;
|
|
48
48
|
egressId?: string | undefined;
|
|
@@ -66,7 +66,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
66
66
|
updatedAt: string;
|
|
67
67
|
description?: string | undefined;
|
|
68
68
|
blurhash?: string | undefined;
|
|
69
|
-
status?: "
|
|
69
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
70
70
|
error?: string | undefined;
|
|
71
71
|
deletedAt?: string | null | undefined;
|
|
72
72
|
} | undefined;
|
|
@@ -76,7 +76,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
76
76
|
updatedAt: string;
|
|
77
77
|
deletedAt?: string | null | undefined;
|
|
78
78
|
} & {
|
|
79
|
-
status: "
|
|
79
|
+
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
|
80
80
|
kind?: "file" | "rtmp" | undefined;
|
|
81
81
|
destinationHost?: string | undefined;
|
|
82
82
|
egressId?: string | undefined;
|
|
@@ -100,7 +100,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
100
100
|
updatedAt: string;
|
|
101
101
|
description?: string | undefined;
|
|
102
102
|
blurhash?: string | undefined;
|
|
103
|
-
status?: "
|
|
103
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
104
104
|
error?: string | undefined;
|
|
105
105
|
deletedAt?: string | null | undefined;
|
|
106
106
|
} | undefined;
|
|
@@ -112,7 +112,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
112
112
|
updatedAt: string;
|
|
113
113
|
deletedAt?: string | null | undefined;
|
|
114
114
|
} & {
|
|
115
|
-
status: "
|
|
115
|
+
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
|
116
116
|
kind?: "file" | "rtmp" | undefined;
|
|
117
117
|
destinationHost?: string | undefined;
|
|
118
118
|
egressId?: string | undefined;
|
|
@@ -136,7 +136,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
136
136
|
updatedAt: string;
|
|
137
137
|
description?: string | undefined;
|
|
138
138
|
blurhash?: string | undefined;
|
|
139
|
-
status?: "
|
|
139
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
140
140
|
error?: string | undefined;
|
|
141
141
|
deletedAt?: string | null | undefined;
|
|
142
142
|
} | undefined;
|
package/dist/jams/mutations.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
|
|
|
5
5
|
updatedAt: string;
|
|
6
6
|
deletedAt?: string | null | undefined;
|
|
7
7
|
} & {
|
|
8
|
-
status: "
|
|
8
|
+
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
|
9
9
|
kind?: "file" | "rtmp" | undefined;
|
|
10
10
|
destinationHost?: string | undefined;
|
|
11
11
|
egressId?: string | undefined;
|
|
@@ -29,7 +29,7 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
|
|
|
29
29
|
updatedAt: string;
|
|
30
30
|
description?: string | undefined;
|
|
31
31
|
blurhash?: string | undefined;
|
|
32
|
-
status?: "
|
|
32
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
33
33
|
error?: string | undefined;
|
|
34
34
|
deletedAt?: string | null | undefined;
|
|
35
35
|
} | undefined;
|
package/dist/jams/token.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { publicProfileSchema, } from '@openpeepshq/common/types';
|
|
2
|
-
import { canModerateJam, countYesRsvps, getEffectiveRsvp, isBlockedPair, jamRoomName, } from '@openpeepshq/common/lib';
|
|
2
|
+
import { canModerateJam, countYesRsvps, getEffectiveRsvp, isBlockedPair, jamRoomName, occurrenceForJamStart, } from '@openpeepshq/common/lib';
|
|
3
3
|
import { authNeeded, forbidden, notFound } from '../errors/index.js';
|
|
4
4
|
import { config } from '../config/index.js';
|
|
5
5
|
import { AccessToken, TrackSource } from 'livekit-server-sdk';
|
|
@@ -133,7 +133,11 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
133
133
|
canUpdateOwnMetadata: true,
|
|
134
134
|
});
|
|
135
135
|
if (!jamOpen) {
|
|
136
|
-
|
|
136
|
+
const eventData = event.data?.type === 'event' ? event.data : undefined;
|
|
137
|
+
const startedOccurrenceId = eventData
|
|
138
|
+
? occurrenceForJamStart(eventData, { recurrenceId })?.recurrenceId
|
|
139
|
+
: undefined;
|
|
140
|
+
hub.emit('jamStarted', profile, event, startedOccurrenceId);
|
|
137
141
|
}
|
|
138
142
|
return accessToken.toJwt();
|
|
139
143
|
};
|
package/dist/jams/waitingRoom.js
CHANGED
|
@@ -12,7 +12,9 @@ const currentWaitingRoom = (event, recurrenceId) => getSharedConnection()
|
|
|
12
12
|
.then((entries) => entries.filter((e) => e[0] && e[1]))
|
|
13
13
|
.then((entries) => entries.map(([key, value]) => [
|
|
14
14
|
key,
|
|
15
|
-
publicProfileSchema
|
|
15
|
+
publicProfileSchema
|
|
16
|
+
.partial()
|
|
17
|
+
.parse(JSON.parse(value)),
|
|
16
18
|
]))
|
|
17
19
|
.then((entries) => Object.fromEntries(entries));
|
|
18
20
|
const currentAdmittance = (event, recurrenceId) => getSharedConnection().then((conn) => conn.hGetAll(admittanceKey(event, recurrenceId)));
|
package/dist/log/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { LoggerFactory } from '@openpeepshq/common/types';
|
|
2
|
+
export { logRetentionQueue, logRetentionWorker, ensureLogRetentionSchedule, LOG_RETENTION_CRON, type LogRetentionJobData, } from './retentionJobs';
|
|
2
3
|
export declare const listLogs: (date?: Date) => Promise<any[]>;
|
|
3
4
|
export declare const logger: LoggerFactory;
|
package/dist/log/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as readline from 'node:readline';
|
|
|
5
5
|
import { formatDate } from 'date-fns/format';
|
|
6
6
|
import safeJsonStringify from 'safe-json-stringify';
|
|
7
7
|
import { default as logsConfig } from '../config/defaults/logs.js';
|
|
8
|
+
export { logRetentionQueue, logRetentionWorker, ensureLogRetentionSchedule, LOG_RETENTION_CRON, } from './retentionJobs.js';
|
|
8
9
|
const createLogDirectory = () => mkdirSync(logsConfig.local.path, { recursive: true });
|
|
9
10
|
const currentFile = (date) => join(logsConfig.local.path, formatDate(date, 'yyyyMMdd') + '.log');
|
|
10
11
|
export const listLogs = async (date = new Date()) => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface LogRetentionResult {
|
|
2
|
+
/** Log files archived to a .zip during this run. */
|
|
3
|
+
zipped: string[];
|
|
4
|
+
/** Files (log and .zip) removed during this run. */
|
|
5
|
+
deleted: string[];
|
|
6
|
+
/** Log files under the zip threshold, or already zipped. */
|
|
7
|
+
untouched: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const cleanOldLogs: (dir: string, zipAfterDays: number, deleteAfterDays: number) => Promise<LogRetentionResult>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
2
|
+
import { readdir, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
import archiver from 'archiver';
|
|
5
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
/** Daily log file as written by the logger, e.g. `20261001.log`. */
|
|
7
|
+
const RAW_LOG_FILE = /^\d{8}\.log$/;
|
|
8
|
+
/** Archive produced by `cleanOldLogs`, e.g. `20261001.log.zip`. */
|
|
9
|
+
const LOG_ZIP_FILE = /^\d{8}\.log\.zip$/;
|
|
10
|
+
const fileExists = async (path) => {
|
|
11
|
+
try {
|
|
12
|
+
await stat(path);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const zipLogFile = (file, zipPath) => new Promise((resolve, reject) => {
|
|
20
|
+
const output = createWriteStream(zipPath);
|
|
21
|
+
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
22
|
+
output.on('close', () => resolve());
|
|
23
|
+
output.on('error', reject);
|
|
24
|
+
archive.on('error', reject);
|
|
25
|
+
archive.on('warning', (err) => {
|
|
26
|
+
if (err.code === 'ENOENT')
|
|
27
|
+
return;
|
|
28
|
+
reject(err);
|
|
29
|
+
});
|
|
30
|
+
archive.pipe(output);
|
|
31
|
+
archive.append(createReadStream(file), { name: basename(file) });
|
|
32
|
+
void archive.finalize();
|
|
33
|
+
});
|
|
34
|
+
export const cleanOldLogs = async (dir, zipAfterDays, deleteAfterDays) => {
|
|
35
|
+
const result = { zipped: [], deleted: [], untouched: 0 };
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
let entries;
|
|
38
|
+
try {
|
|
39
|
+
entries = await readdir(dir);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
// The log directory is created lazily by the logger; nothing to clean.
|
|
43
|
+
if (err.code === 'ENOENT')
|
|
44
|
+
return result;
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const isRawLog = RAW_LOG_FILE.test(entry);
|
|
49
|
+
if (!isRawLog && !LOG_ZIP_FILE.test(entry))
|
|
50
|
+
continue;
|
|
51
|
+
const filePath = join(dir, entry);
|
|
52
|
+
// May already be gone: deleting a raw log also removes its zip.
|
|
53
|
+
if (!(await fileExists(filePath)))
|
|
54
|
+
continue;
|
|
55
|
+
const st = await stat(filePath);
|
|
56
|
+
if (!st.isFile())
|
|
57
|
+
continue;
|
|
58
|
+
if (now - st.mtimeMs > deleteAfterDays * DAY_MS) {
|
|
59
|
+
// Zips share the raw log's lifetime so disk usage actually shrinks.
|
|
60
|
+
await rm(filePath, { force: true });
|
|
61
|
+
result.deleted.push(entry);
|
|
62
|
+
if (isRawLog) {
|
|
63
|
+
const zipPath = `${filePath}.zip`;
|
|
64
|
+
if (await fileExists(zipPath)) {
|
|
65
|
+
await rm(zipPath, { force: true });
|
|
66
|
+
result.deleted.push(`${entry}.zip`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!isRawLog)
|
|
72
|
+
continue;
|
|
73
|
+
if (now - st.mtimeMs > zipAfterDays * DAY_MS &&
|
|
74
|
+
!(await fileExists(`${filePath}.zip`))) {
|
|
75
|
+
await zipLogFile(filePath, `${filePath}.zip`);
|
|
76
|
+
result.zipped.push(entry);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
result.untouched += 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const LOG_RETENTION_CRON = "0 2 * * *";
|
|
2
|
+
export interface LogRetentionJobData {
|
|
3
|
+
/** Override the zip threshold; mostly for testing. */
|
|
4
|
+
zipAfterDays?: number;
|
|
5
|
+
/** Override the delete threshold; mostly for testing. */
|
|
6
|
+
deleteAfterDays?: number;
|
|
7
|
+
/** Override the log directory; mostly for testing. */
|
|
8
|
+
dir?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const logRetentionQueue: () => import("bullmq").Queue, logRetentionWorker: () => import("bullmq").Worker;
|
|
11
|
+
/**
|
|
12
|
+
* Registers (or refreshes) the daily schedule with BullMQ. Safe to call
|
|
13
|
+
* repeatedly — `upsertJobScheduler` is idempotent and overwrites the existing
|
|
14
|
+
* schedule entry under the same id.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ensureLogRetentionSchedule: () => Promise<void>;
|
|
17
|
+
export { logRetentionQueue, logRetentionWorker };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { queueAndWorker } from '../jobs/index.js';
|
|
2
|
+
import { cleanOldLogs } from './retention.js';
|
|
3
|
+
// Cron pattern (UTC): every day at 02:00. Off-peak for most regions and
|
|
4
|
+
// staggered away from the other daily housekeeping (streaming cleanup 03:00,
|
|
5
|
+
// analytics retention 03:30, event occurrences 04:00).
|
|
6
|
+
export const LOG_RETENTION_CRON = '0 2 * * *';
|
|
7
|
+
const SCHEDULER_ID = 'log-retention-daily';
|
|
8
|
+
const JOB_NAME = 'clean';
|
|
9
|
+
const [logRetentionQueue, logRetentionWorker] = queueAndWorker('log-retention', async (job) => {
|
|
10
|
+
// Dynamic imports: the log barrel is among the first modules loaded,
|
|
11
|
+
// and ../config -> ../events -> this barrel, so a static edge would
|
|
12
|
+
// create a load-time import cycle.
|
|
13
|
+
const { logger } = await import('./index.js');
|
|
14
|
+
const { config } = await import('../config/index.js');
|
|
15
|
+
const log = logger('app:log:retention');
|
|
16
|
+
const coreConfig = await config();
|
|
17
|
+
const zipAfterDays = job.data.zipAfterDays ?? coreConfig.logs.retention.zipAfterDays;
|
|
18
|
+
const deleteAfterDays = job.data.deleteAfterDays ?? coreConfig.logs.retention.deleteAfterDays;
|
|
19
|
+
const dir = job.data.dir ?? coreConfig.logs.local.path;
|
|
20
|
+
log.info(`Running log retention (zipAfterDays=${zipAfterDays}, ` +
|
|
21
|
+
`deleteAfterDays=${deleteAfterDays})`);
|
|
22
|
+
const result = await cleanOldLogs(dir, zipAfterDays, deleteAfterDays);
|
|
23
|
+
log.info(`Log retention done: zipped=${result.zipped.length}, ` +
|
|
24
|
+
`deleted=${result.deleted.length}, untouched=${result.untouched}`);
|
|
25
|
+
if (result.zipped.length > 0) {
|
|
26
|
+
log.info(`Zipped logs: ${result.zipped.join(', ')}`);
|
|
27
|
+
}
|
|
28
|
+
if (result.deleted.length > 0) {
|
|
29
|
+
log.info(`Deleted logs: ${result.deleted.join(', ')}`);
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
defaultJobOptions: {
|
|
33
|
+
// We never need more than the most recent runs; keep a small history
|
|
34
|
+
// for debugging and let BullMQ trim the rest.
|
|
35
|
+
removeOnComplete: { count: 10 },
|
|
36
|
+
removeOnFail: { age: 86400 * 14, count: 50 },
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Registers (or refreshes) the daily schedule with BullMQ. Safe to call
|
|
41
|
+
* repeatedly — `upsertJobScheduler` is idempotent and overwrites the existing
|
|
42
|
+
* schedule entry under the same id.
|
|
43
|
+
*/
|
|
44
|
+
export const ensureLogRetentionSchedule = async () => {
|
|
45
|
+
const queue = logRetentionQueue();
|
|
46
|
+
await queue.upsertJobScheduler(SCHEDULER_ID, { pattern: LOG_RETENTION_CRON }, { name: JOB_NAME });
|
|
47
|
+
const { logger } = await import('./index.js');
|
|
48
|
+
logger('app:log:retention').info(`Log retention schedule registered: cron="${LOG_RETENTION_CRON}"`);
|
|
49
|
+
};
|
|
50
|
+
export { logRetentionQueue, logRetentionWorker };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { StoredMediaFile, StoredMediaStatus } from '@openpeepshq/common/types';
|
|
2
|
+
/**
|
|
3
|
+
* How long a file must stay unreferenced before it is deleted. The clock
|
|
4
|
+
* starts the first time a collection run sees the file with no live link, so
|
|
5
|
+
* the run that ships this job only records files — it does not delete them.
|
|
6
|
+
* In-progress uploads (stored, not yet saved onto a post or recording) survive
|
|
7
|
+
* the same window.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MEDIA_GC_GRACE_MS: number;
|
|
10
|
+
/** Type alias for the stream-active check, overridable in tests. */
|
|
11
|
+
export type StreamActiveChecker = (storageId: string, now: number) => Promise<boolean>;
|
|
12
|
+
/** SHA-256 digest, base64url, no padding. */
|
|
13
|
+
export declare const STORAGE_ID_LENGTH = 43;
|
|
14
|
+
/**
|
|
15
|
+
* POSIX regex (no lookahead) shared with the SQL scan. Matches
|
|
16
|
+
* `/storage/allpeep/<id>/<file>` and `/media/streaming/<id>/...`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const STORAGE_URL_SOURCE = "/(?:allpeep|media/streaming)/([A-Za-z0-9_-]{43})(?:[^A-Za-z0-9_-]|$)";
|
|
19
|
+
/**
|
|
20
|
+
* Live content that can embed a media URL. The scan also covers every other
|
|
21
|
+
* public jsonb column, so a new page or plugin table is included without a
|
|
22
|
+
* code change. These are the ones GC refuses to run without.
|
|
23
|
+
*/
|
|
24
|
+
export declare const REFERENCE_TABLES: readonly ["posts", "profiles", "groups", "configs", "jam_recordings"];
|
|
25
|
+
/**
|
|
26
|
+
* Rows that store a media URL but are not a live link:
|
|
27
|
+
* - `media_attachments` is the upload registry. It keeps a copy of every file
|
|
28
|
+
* URL, including files whose post or recording is already gone.
|
|
29
|
+
* - `entries` snapshots the post at create and edit time. After the post is
|
|
30
|
+
* deleted those snapshots are the only remaining copy, so counting them
|
|
31
|
+
* would keep the file forever. The rendered post is the post row itself.
|
|
32
|
+
*/
|
|
33
|
+
export declare const EXCLUDED_REFERENCE_TABLES: readonly ["media_attachments", "entries"];
|
|
34
|
+
export declare const isStorageId: (value: string) => boolean;
|
|
35
|
+
/** Quick existence check for the stored source file (without the HLS dir). */
|
|
36
|
+
export declare const mediaFileExists: (storageId: string) => Promise<boolean>;
|
|
37
|
+
export declare const quoteIdent: (name: string) => string;
|
|
38
|
+
export declare const extractStorageIds: (text: string) => string[];
|
|
39
|
+
export interface JsonbColumn {
|
|
40
|
+
tableName: string;
|
|
41
|
+
columnName: string;
|
|
42
|
+
}
|
|
43
|
+
export declare const buildReferenceScanSql: (columns: JsonbColumn[], tablesWithDeletedAt: ReadonlySet<string>) => string | null;
|
|
44
|
+
export interface SqlExecutor {
|
|
45
|
+
execute: (query: string) => Promise<{
|
|
46
|
+
rows: Record<string, unknown>[];
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
export declare const loadReferencedStorageIds: (executor: SqlExecutor) => Promise<Set<string>>;
|
|
50
|
+
export interface AttachmentBody {
|
|
51
|
+
id: string;
|
|
52
|
+
body: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Attachment rows whose local files are all gone. Rows that still point at a
|
|
56
|
+
* file on disk (referenced, or inside the grace window) stay so an in-progress
|
|
57
|
+
* upload can finish.
|
|
58
|
+
*/
|
|
59
|
+
export declare const danglingMediaAttachmentIds: (rows: AttachmentBody[], filesOnDisk: ReadonlySet<string>) => string[];
|
|
60
|
+
export interface SweepOptions {
|
|
61
|
+
filesDir: string;
|
|
62
|
+
hlsRoot: string;
|
|
63
|
+
statePath: string;
|
|
64
|
+
referencedIds: ReadonlySet<string>;
|
|
65
|
+
now?: number;
|
|
66
|
+
graceMs?: number;
|
|
67
|
+
/** Override the recent-access check (default: Redis-backed). */
|
|
68
|
+
streamActiveChecker?: StreamActiveChecker;
|
|
69
|
+
}
|
|
70
|
+
export interface SweepResult {
|
|
71
|
+
deleted: string[];
|
|
72
|
+
marked: number;
|
|
73
|
+
kept: number;
|
|
74
|
+
skipped: string[];
|
|
75
|
+
remainingIds: string[];
|
|
76
|
+
tempDeleted: number;
|
|
77
|
+
storageMissing: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Delete stored files with no live reference, once they have stayed that way
|
|
81
|
+
* for the grace period. Also drops HLS directories for those files, stale
|
|
82
|
+
* upload temps, and HLS directories whose source file is already gone.
|
|
83
|
+
*/
|
|
84
|
+
export declare const sweepUnreferencedMedia: (options: SweepOptions) => Promise<SweepResult>;
|
|
85
|
+
export declare const deleteMediaAttachmentRows: (ids: string[]) => Promise<number>;
|
|
86
|
+
export interface MediaGarbageCollectionResult extends SweepResult {
|
|
87
|
+
referenced: number;
|
|
88
|
+
attachmentsDeleted: number;
|
|
89
|
+
}
|
|
90
|
+
export declare const collectUnreferencedMedia: (graceMs?: number) => Promise<MediaGarbageCollectionResult>;
|
|
91
|
+
interface ClassifiedMedia {
|
|
92
|
+
status: StoredMediaStatus;
|
|
93
|
+
unreferencedSince: string | null;
|
|
94
|
+
deletesAt: string | null;
|
|
95
|
+
}
|
|
96
|
+
/** How garbage collection treats one file, given the live link set and clock. */
|
|
97
|
+
export declare const classifyMediaFile: (storageId: string, referencedIds: ReadonlySet<string>, unreferencedSinceMs: number | undefined, now: number, graceMs?: number) => ClassifiedMedia;
|
|
98
|
+
export declare const listStoredMedia: () => Promise<{
|
|
99
|
+
files: StoredMediaFile[];
|
|
100
|
+
graceMs: number;
|
|
101
|
+
}>;
|
|
102
|
+
/**
|
|
103
|
+
* Remove one stored file immediately. The garbage-collection clock and
|
|
104
|
+
* dangling attachment rows are cleaned up too. Live links are left in place
|
|
105
|
+
* and will 404. The HLS cache is preserved if the stream was accessed within
|
|
106
|
+
* the recent-access window; it will be reclaimed by the streaming-cleanup cron.
|
|
107
|
+
*/
|
|
108
|
+
export declare const deleteStoredMediaNow: (storageId: string) => Promise<boolean>;
|
|
109
|
+
export {};
|