@openpeepshq/core 0.1.32 → 0.1.33

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.
Files changed (136) hide show
  1. package/dist/accessTokens/helpers.d.ts +2 -2
  2. package/dist/accessTokens/tokens.js +14 -7
  3. package/dist/accounts/mutations.d.ts +2 -2
  4. package/dist/analytics/cache.js +12 -7
  5. package/dist/analytics/pdfReport.d.ts +1 -0
  6. package/dist/analytics/pdfReport.js +5 -4
  7. package/dist/analytics/privacy.d.ts +18 -0
  8. package/dist/analytics/privacy.js +10 -0
  9. package/dist/analytics/read.js +24 -11
  10. package/dist/analytics/report.d.ts +1 -1
  11. package/dist/analytics/report.js +9 -2
  12. package/dist/backups/index.js +6 -3
  13. package/dist/backups/metadata.d.ts +7 -0
  14. package/dist/config/defaults/community.js +0 -6
  15. package/dist/config/defaults/db.d.ts +0 -2
  16. package/dist/config/defaults/db.js +0 -2
  17. package/dist/config/index.d.ts +10 -9
  18. package/dist/db/helpers.d.ts +6 -28
  19. package/dist/db/helpers.js +19 -149
  20. package/dist/db/index.d.ts +2 -0
  21. package/dist/db/index.js +4 -0
  22. package/dist/db/init.js +3 -2
  23. package/dist/db/migration/detect.d.ts +0 -3
  24. package/dist/db/migration/detect.js +0 -54
  25. package/dist/db/migration/importCollections.d.ts +1 -1
  26. package/dist/db/migration/importCollections.js +22 -6
  27. package/dist/db/migration/shared.d.ts +0 -4
  28. package/dist/db/migration/shared.js +0 -7
  29. package/dist/db/migration/transform.d.ts +2 -0
  30. package/dist/db/migration/transform.js +23 -0
  31. package/dist/db/pg/client.js +4 -0
  32. package/dist/db/pg/filters/edges.d.ts +1 -1
  33. package/dist/db/pg/filters/edges.js +1 -1
  34. package/dist/db/pg/filters/posts.d.ts +1 -0
  35. package/dist/db/pg/filters/posts.js +11 -1
  36. package/dist/db/pg/map/filters.js +5 -0
  37. package/dist/db/pg/map/relations.d.ts +1 -1
  38. package/dist/db/pg/map/relations.js +89 -41
  39. package/dist/db/pg/migrate.d.ts +23 -0
  40. package/dist/db/pg/migrate.js +87 -1
  41. package/dist/db/pg/schema/documents.d.ts +143 -0
  42. package/dist/db/pg/schema/documents.js +22 -1
  43. package/dist/db/pg/schema/edges.d.ts +1 -0
  44. package/dist/db/pg/schema/edges.js +2 -1
  45. package/dist/db/pg/schema/index.d.ts +143 -0
  46. package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
  47. package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
  48. package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
  49. package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
  50. package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
  51. package/dist/db/pg/sql/meta/_journal.json +21 -0
  52. package/dist/db/replaceOrigin.js +6 -0
  53. package/dist/db/types.d.ts +0 -4
  54. package/dist/events/index.d.ts +2 -1
  55. package/dist/events/index.js +54 -33
  56. package/dist/groups/finders.d.ts +2 -2
  57. package/dist/groups/helpers.d.ts +6 -6
  58. package/dist/groups/mapping.d.ts +4 -4
  59. package/dist/groups/mapping.js +2 -2
  60. package/dist/groups/mutations.js +1 -1
  61. package/dist/inviteLinks/helpers.d.ts +4 -4
  62. package/dist/jams/cache.d.ts +1 -1
  63. package/dist/jams/cache.js +2 -1
  64. package/dist/jams/finders.d.ts +2 -1
  65. package/dist/jams/finders.js +18 -7
  66. package/dist/jams/helpers.d.ts +4 -0
  67. package/dist/jams/index.d.ts +4 -3
  68. package/dist/jams/index.js +20 -13
  69. package/dist/jams/livekit.d.ts +46 -8
  70. package/dist/jams/livekit.js +103 -21
  71. package/dist/jams/mapping.d.ts +14 -4
  72. package/dist/jams/mutations.d.ts +2 -0
  73. package/dist/jams/rtmp.d.ts +5 -0
  74. package/dist/jams/rtmp.js +8 -0
  75. package/dist/jams/token.d.ts +3 -3
  76. package/dist/jams/token.js +15 -12
  77. package/dist/jams/waitingRoom.d.ts +6 -6
  78. package/dist/jams/waitingRoom.js +24 -23
  79. package/dist/migration/index.d.ts +4 -0
  80. package/dist/migration/index.js +4 -0
  81. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
  82. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
  83. package/dist/notifications/helpers.js +6 -2
  84. package/dist/notifications/push.js +11 -4
  85. package/dist/plugins/helpers.d.ts +1 -0
  86. package/dist/plugins/helpers.js +1 -8
  87. package/dist/plugins/index.d.ts +5 -0
  88. package/dist/plugins/index.js +41 -4
  89. package/dist/plugins/install.d.ts +20 -0
  90. package/dist/plugins/install.js +223 -0
  91. package/dist/plugins/state.d.ts +4 -0
  92. package/dist/plugins/state.js +29 -0
  93. package/dist/posts/eventAgenda.d.ts +165 -0
  94. package/dist/posts/eventAgenda.js +120 -0
  95. package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
  96. package/dist/posts/eventOccurrenceJobs.js +23 -0
  97. package/dist/posts/eventOccurrences.d.ts +4 -0
  98. package/dist/posts/eventOccurrences.js +40 -0
  99. package/dist/posts/finders.d.ts +32 -8
  100. package/dist/posts/finders.js +27 -45
  101. package/dist/posts/helpers/filters.js +1 -1
  102. package/dist/posts/helpers/index.d.ts +102 -16
  103. package/dist/posts/helpers/index.js +33 -20
  104. package/dist/posts/index.d.ts +3 -0
  105. package/dist/posts/index.js +3 -0
  106. package/dist/posts/mapping.d.ts +275 -0
  107. package/dist/posts/mapping.js +37 -3
  108. package/dist/posts/mutations.d.ts +1 -1
  109. package/dist/posts/mutations.js +29 -18
  110. package/dist/posts/rsvpConfirmationEmail.js +2 -1
  111. package/dist/posts/unseenCounts.d.ts +2 -0
  112. package/dist/posts/unseenCounts.js +25 -8
  113. package/dist/profiles/cache.d.ts +3 -1
  114. package/dist/profiles/cache.js +9 -1
  115. package/dist/profiles/helpers.d.ts +5 -5
  116. package/dist/profiles/index.d.ts +1 -1
  117. package/dist/profiles/index.js +1 -1
  118. package/dist/profiles/mapping.d.ts +5 -5
  119. package/dist/profiles/mutations.js +12 -14
  120. package/dist/pushSubscriptions/helpers.d.ts +2 -2
  121. package/dist/pushSubscriptions/mutations.js +13 -1
  122. package/dist/reports/helpers.d.ts +6 -6
  123. package/dist/roles/defaults.js +1 -0
  124. package/dist/server/index.d.ts +7 -7
  125. package/dist/server/index.js +15 -8
  126. package/dist/stats/finders.d.ts +1692 -142
  127. package/dist/stats/mapping.d.ts +21 -0
  128. package/package.json +4 -9
  129. package/dist/db/arango.d.ts +0 -2
  130. package/dist/db/arango.js +0 -110
  131. package/dist/db/migration/autoMigrate.d.ts +0 -2
  132. package/dist/db/migration/autoMigrate.js +0 -111
  133. package/dist/db/migration/cli.d.ts +0 -1
  134. package/dist/db/migration/cli.js +0 -56
  135. package/dist/db/migration/exportArango.d.ts +0 -4
  136. package/dist/db/migration/exportArango.js +0 -80
@@ -1,3 +1,4 @@
1
+ import { jamRoomName } from '@openpeepshq/common/lib';
1
2
  import { config } from '../config/index.js';
2
3
  import { DataPacket_Kind, EgressClient, EncodedFileOutput, EncodedFileType, EncodingOptionsPreset, RoomServiceClient, } from 'livekit-server-sdk';
3
4
  import { connectRecording } from './helpers.js';
@@ -5,12 +6,13 @@ import { allpeepDb } from '../db/index.js';
5
6
  import { serverRootUrl } from '../server/index.js';
6
7
  import { uuidv7 } from 'uuidv7';
7
8
  import { createJamEvent, updateJamRecording } from './mutations.js';
8
- import { findActiveRecording } from './finders.js';
9
+ import { findActiveRecording, findActiveRtmpStream } from './finders.js';
9
10
  import { cancelRecordingAutoStop, scheduleRecordingAutoStop } from './jobs.js';
10
11
  import { jamRecordingUploadSecret } from './recordingUploadAuth.js';
11
12
  import { createSignedServiceToken } from '../accessTokens/tokens.js';
12
13
  import { unprocessableRequest } from '../errors/index.js';
13
14
  import { logger } from '../log/index.js';
15
+ import { rtmpStreamOutput, rtmpWebEgressOptions } from './rtmp.js';
14
16
  const encoder = new TextEncoder();
15
17
  const log = logger('app:jams:livekit');
16
18
  /** Seconds a new room stays open before anyone joins. */
@@ -36,7 +38,7 @@ export const listParticipantIds = async (jamId) => {
36
38
  const getJamEgressToken = async (jamId) => createSignedServiceToken({
37
39
  scopes: [
38
40
  {
39
- resource: { type: 'jam', id: jamId },
41
+ resource: { type: 'jams', id: jamId },
40
42
  },
41
43
  ],
42
44
  name: 'jam-egress',
@@ -61,20 +63,24 @@ const assertEgressCanReachRecordingHost = async (recordingUrl) => {
61
63
  }
62
64
  };
63
65
  /**
64
- * Relative path for the observer view (full jam UI). Used both for human
65
- * moderator observer links and as the page LiveKit web egress records.
66
+ * Relative path for the observer view (full jam UI). Used for human
67
+ * moderator observer links, jam recording web egress, and RTMP web egress.
66
68
  */
67
- export const getJamObserverPath = async (jamId) => {
69
+ export const getJamObserverPath = async (jamId, recurrenceId) => {
68
70
  const jamEgressToken = await getJamEgressToken(jamId);
69
- return `/events/${jamId}/jam?observer=true&token=${jamEgressToken}`;
71
+ const occurrence = recurrenceId
72
+ ? `&occurrence=${encodeURIComponent(recurrenceId)}`
73
+ : '';
74
+ return `/events/${jamId}/jam?observer=true&token=${jamEgressToken}${occurrence}`;
70
75
  };
71
- export const getJamRecordingUrl = async (jamId) => `${await serverRootUrl()}${await getJamObserverPath(jamId)}`;
76
+ export const getJamRecordingUrl = async (jamId, recurrenceId) => `${await serverRootUrl()}${await getJamObserverPath(jamId, recurrenceId)}`;
72
77
  const getEgressClient = async () => {
73
78
  const { url, apiKey, apiSecret } = (await config()).jams.livekit;
74
79
  return new EgressClient(url, apiKey, apiSecret);
75
80
  };
76
- export const startRecording = async (profile, jamPost) => {
81
+ export const startRecording = async (profile, jamPost, recurrenceId) => {
77
82
  const jamId = jamPost.id;
83
+ const roomName = jamRoomName(jamPost.id, recurrenceId);
78
84
  const recordingId = uuidv7();
79
85
  // Clear any recording left `active` by a previous failed egress so the new
80
86
  // one is the sole active recording for this jam.
@@ -91,7 +97,7 @@ export const startRecording = async (profile, jamPost) => {
91
97
  const persistedRecordingId = recording.id;
92
98
  const egressClient = await getEgressClient();
93
99
  const outputFilename = `${persistedRecordingId}.mp4`;
94
- const recordingUrl = await getJamRecordingUrl(jamId);
100
+ const recordingUrl = await getJamRecordingUrl(jamId, recurrenceId);
95
101
  await assertEgressCanReachRecordingHost(recordingUrl);
96
102
  const uploadSecret = await jamRecordingUploadSecret(persistedRecordingId);
97
103
  const egressInfo = await egressClient.startWebEgress(recordingUrl, new EncodedFileOutput({
@@ -120,12 +126,80 @@ export const startRecording = async (profile, jamPost) => {
120
126
  jamId,
121
127
  type: 'recordStart',
122
128
  profileId: profile.id,
129
+ recurrenceId,
123
130
  });
124
- await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamId, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
131
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(roomName, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
125
132
  // BullMQ delayed job survives API/worker restarts (unlike setTimeout).
126
133
  await scheduleRecordingAutoStop(jamId, persistedRecordingId);
127
134
  return recording;
128
135
  };
136
+ const assertLivekitConfigured = async () => {
137
+ const { url, apiKey, apiSecret } = (await config()).jams.livekit;
138
+ if (!url || !apiKey || !apiSecret) {
139
+ throw unprocessableRequest({ errorKey: 'error.jamsUnavailable' });
140
+ }
141
+ };
142
+ const assertJamRoomOpen = async (jamId) => {
143
+ const rs = await roomService();
144
+ if (rs === undefined) {
145
+ throw unprocessableRequest({ errorKey: 'error.jamsUnavailable' });
146
+ }
147
+ const rooms = await rs.listRooms([jamId]);
148
+ if (rooms.length !== 1) {
149
+ throw unprocessableRequest({ errorKey: 'error.jamNotOpen' });
150
+ }
151
+ };
152
+ const emitJamEvent = async (jamId, jamEvent) => {
153
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamId, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
154
+ };
155
+ export const startRtmpStream = async (profile, jamPost, rtmpUrl, destinationHost) => {
156
+ await assertLivekitConfigured();
157
+ await assertJamRoomOpen(jamPost.id);
158
+ await stopRtmpStream(jamPost);
159
+ const jamId = jamPost.id;
160
+ const recordingId = uuidv7();
161
+ let recording = (await allpeepDb().then(({ db }) => connectRecording(db, profile, jamPost, {
162
+ id: recordingId,
163
+ status: 'requested',
164
+ kind: 'rtmp',
165
+ destinationHost,
166
+ })));
167
+ const persistedRecordingId = recording.id;
168
+ const observerUrl = await getJamRecordingUrl(jamId);
169
+ await assertEgressCanReachRecordingHost(observerUrl);
170
+ const egressClient = await getEgressClient();
171
+ const egressInfo = await egressClient.startWebEgress(observerUrl, rtmpStreamOutput(rtmpUrl), rtmpWebEgressOptions);
172
+ recording = (await updateJamRecording(persistedRecordingId, {
173
+ egressId: egressInfo.egressId,
174
+ status: 'active',
175
+ }));
176
+ const jamEvent = await createJamEvent({
177
+ id: uuidv7(),
178
+ jamId,
179
+ type: 'streamStart',
180
+ profileId: profile.id,
181
+ });
182
+ await emitJamEvent(jamId, jamEvent);
183
+ return recording;
184
+ };
185
+ export const stopRtmpStream = async (jamPost) => {
186
+ const stream = await findActiveRtmpStream(jamPost);
187
+ if (!stream) {
188
+ return undefined;
189
+ }
190
+ if (stream.egressId) {
191
+ void stopEgress(stream.egressId);
192
+ }
193
+ await updateJamRecording(stream.id, { status: 'completed' });
194
+ const jamEvent = await createJamEvent({
195
+ id: uuidv7(),
196
+ jamId: jamPost.id,
197
+ type: 'streamStop',
198
+ profileId: stream.profile.id,
199
+ });
200
+ await emitJamEvent(jamPost.id, jamEvent);
201
+ return Object.assign(Object.assign({}, stream), { status: 'completed' });
202
+ };
129
203
  export const stopEgress = async (egressId) => {
130
204
  const egressClient = await getEgressClient();
131
205
  try {
@@ -136,7 +210,7 @@ export const stopEgress = async (egressId) => {
136
210
  // stop action should not fail because of that.
137
211
  }
138
212
  };
139
- export const stopRecording = async (jamPost) => {
213
+ export const stopRecording = async (jamPost, recurrenceId) => {
140
214
  const jamRecording = await findActiveRecording(jamPost);
141
215
  if (!jamRecording) {
142
216
  return undefined;
@@ -154,27 +228,34 @@ export const stopRecording = async (jamPost) => {
154
228
  jamId: jamPost.id,
155
229
  type: 'recordStop',
156
230
  profileId: jamRecording.profile.id,
231
+ recurrenceId,
157
232
  });
158
- await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamPost.id, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
233
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamRoomName(jamPost.id, recurrenceId), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
159
234
  return jamRecording;
160
235
  };
161
236
  /**
162
237
  * Stops leftover egress and deletes a LiveKit room that has no human
163
238
  * participants (egress-only / orphan rooms). Safe to call repeatedly.
164
239
  */
165
- export const reclaimOrphanJamRoom = async (jam) => {
240
+ export const reclaimOrphanJamRoom = async (jam, roomName = jam.id) => {
166
241
  try {
167
242
  await stopRecording(jam);
168
243
  }
169
244
  catch (e) {
170
245
  log.warn(`Failed to stop recording while reclaiming jam ${jam.id}: ${e.message}`);
171
246
  }
247
+ try {
248
+ await stopRtmpStream(jam);
249
+ }
250
+ catch (e) {
251
+ log.warn(`Failed to stop RTMP stream while reclaiming jam ${jam.id}: ${e.message}`);
252
+ }
172
253
  try {
173
254
  const rs = await roomService();
174
- await (rs === null || rs === void 0 ? void 0 : rs.deleteRoom(jam.id));
255
+ await (rs === null || rs === void 0 ? void 0 : rs.deleteRoom(roomName));
175
256
  }
176
257
  catch (e) {
177
- log.warn(`Failed to delete orphan jam room ${jam.id}: ${e.message}`);
258
+ log.warn(`Failed to delete orphan jam room ${roomName}: ${e.message}`);
178
259
  }
179
260
  };
180
261
  export const finishRecording = async (jamRecording) => {
@@ -184,10 +265,11 @@ export const finishRecording = async (jamRecording) => {
184
265
  type: 'recordStop',
185
266
  profileId: jamRecording.profile.id,
186
267
  });
187
- await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamRecording.post.id, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
268
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamRoomName(jamRecording.post.id), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
188
269
  };
189
- export const jamState = async (jam, hideParticipants) => {
270
+ export const jamState = async (jam, hideParticipants, recurrenceId) => {
190
271
  const rs = await roomService();
272
+ const roomName = jamRoomName(jam.id, recurrenceId);
191
273
  if (rs === undefined) {
192
274
  return {
193
275
  participants: [],
@@ -195,19 +277,19 @@ export const jamState = async (jam, hideParticipants) => {
195
277
  };
196
278
  }
197
279
  const room = await rs
198
- .listRooms([jam.id])
199
- .then((rooms) => rooms.find((r) => r.name === jam.id));
280
+ .listRooms([roomName])
281
+ .then((rooms) => rooms.find((r) => r.name === roomName));
200
282
  if (!room) {
201
283
  return {
202
284
  participants: [],
203
285
  active: false,
204
286
  };
205
287
  }
206
- const participants = await listParticipantIds(jam.id);
288
+ const participants = await listParticipantIds(roomName);
207
289
  if (participants.length === 0) {
208
290
  // Room exists only for egress ghosts / empty leftovers — reclaim so it
209
291
  // stops appearing under Live jams.
210
- void reclaimOrphanJamRoom(jam);
292
+ void reclaimOrphanJamRoom(jam, roomName);
211
293
  return {
212
294
  participants: [],
213
295
  active: false,
@@ -7,38 +7,44 @@ type EdgeMetadata = {
7
7
  export declare const jamEventsMapping: import("../db/pg/map").Mapping<{
8
8
  id: string;
9
9
  jamId: string;
10
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
10
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
11
11
  profileId: string;
12
12
  content?: string | undefined;
13
13
  reaction?: "👍" | undefined;
14
+ recurrenceId?: string | undefined;
14
15
  }, JamEvent, JamEvent>;
15
16
  export declare const jamSessionStartsMapping: import("../db/pg/map").Mapping<{
16
17
  id: string;
17
18
  jamId: string;
18
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
19
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
19
20
  profileId: string;
20
21
  content?: string | undefined;
21
22
  reaction?: "👍" | undefined;
23
+ recurrenceId?: string | undefined;
22
24
  }, JamEvent, JamEvent>;
23
25
  export declare const jamSessionClosesMapping: import("../db/pg/map").Mapping<{
24
26
  id: string;
25
27
  jamId: string;
26
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
28
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
27
29
  profileId: string;
28
30
  content?: string | undefined;
29
31
  reaction?: "👍" | undefined;
32
+ recurrenceId?: string | undefined;
30
33
  }, JamEvent, JamEvent>;
31
34
  export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
32
35
  id: string;
33
36
  jamId: string;
34
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
37
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
35
38
  profileId: string;
36
39
  content?: string | undefined;
37
40
  reaction?: "👍" | undefined;
41
+ recurrenceId?: string | undefined;
38
42
  }, JamEvent, JamEvent>;
39
43
  export declare const jamRecordingRelation: RelationWithMapping<PostWithMeta, JamRecording>;
40
44
  export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
41
45
  status: "active" | "completed" | "failed" | "requested";
46
+ kind?: "file" | "rtmp" | undefined;
47
+ destinationHost?: string | undefined;
42
48
  egressId?: string | undefined;
43
49
  attachment?: {
44
50
  type: string;
@@ -71,6 +77,8 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
71
77
  deletedAt?: string | null | undefined;
72
78
  } & {
73
79
  status: "active" | "completed" | "failed" | "requested";
80
+ kind?: "file" | "rtmp" | undefined;
81
+ destinationHost?: string | undefined;
74
82
  egressId?: string | undefined;
75
83
  attachment?: {
76
84
  type: string;
@@ -105,6 +113,8 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
105
113
  deletedAt?: string | null | undefined;
106
114
  } & {
107
115
  status: "active" | "completed" | "failed" | "requested";
116
+ kind?: "file" | "rtmp" | undefined;
117
+ destinationHost?: string | undefined;
108
118
  egressId?: string | undefined;
109
119
  attachment?: {
110
120
  type: string;
@@ -6,6 +6,8 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
6
6
  deletedAt?: string | null | undefined;
7
7
  } & {
8
8
  status: "active" | "completed" | "failed" | "requested";
9
+ kind?: "file" | "rtmp" | undefined;
10
+ destinationHost?: string | undefined;
9
11
  egressId?: string | undefined;
10
12
  attachment?: {
11
13
  type: string;
@@ -0,0 +1,5 @@
1
+ import { EncodingOptionsPreset, StreamOutput } from 'livekit-server-sdk';
2
+ export declare const rtmpStreamOutput: (rtmpUrl: string) => StreamOutput;
3
+ export declare const rtmpWebEgressOptions: {
4
+ readonly encodingOptions: EncodingOptionsPreset.H264_1080P_30;
5
+ };
@@ -0,0 +1,8 @@
1
+ import { EncodingOptionsPreset, StreamOutput, StreamProtocol, } from 'livekit-server-sdk';
2
+ export const rtmpStreamOutput = (rtmpUrl) => new StreamOutput({
3
+ protocol: StreamProtocol.RTMP,
4
+ urls: [rtmpUrl],
5
+ });
6
+ export const rtmpWebEgressOptions = {
7
+ encodingOptions: EncodingOptionsPreset.H264_1080P_30,
8
+ };
@@ -1,4 +1,4 @@
1
1
  import { PostWithMeta, PublicProfile } from '@openpeepshq/common/types';
2
- export declare const assertJamRsvpAllowed: (event: PostWithMeta, profile: PublicProfile) => void;
3
- export declare const createJamEgressToken: (event: PostWithMeta) => Promise<string>;
4
- export declare const createJamToken: (event: PostWithMeta, profile: PublicProfile, external?: boolean) => Promise<string>;
2
+ export declare const assertJamRsvpAllowed: (event: PostWithMeta, profile: PublicProfile, recurrenceId?: string) => void;
3
+ export declare const createJamEgressToken: (event: PostWithMeta, recurrenceId?: string) => Promise<string>;
4
+ export declare const createJamToken: (event: PostWithMeta, profile: PublicProfile, external?: boolean, recurrenceId?: string) => Promise<string>;
@@ -1,5 +1,5 @@
1
1
  import { publicProfileSchema, } from '@openpeepshq/common/types';
2
- import { canModerateJam, countYesRsvps, getEffectiveRsvp, } from '@openpeepshq/common/lib';
2
+ import { canModerateJam, countYesRsvps, getEffectiveRsvp, jamRoomName, } 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';
@@ -19,7 +19,7 @@ const calculateSources = (jam, profile) => {
19
19
  }
20
20
  return sources;
21
21
  };
22
- export const assertJamRsvpAllowed = (event, profile) => {
22
+ export const assertJamRsvpAllowed = (event, profile, recurrenceId) => {
23
23
  var _a, _b;
24
24
  const eventData = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? event.data : undefined;
25
25
  if (!(eventData === null || eventData === void 0 ? void 0 : eventData.maxAttendees)) {
@@ -28,17 +28,18 @@ export const assertJamRsvpAllowed = (event, profile) => {
28
28
  if (canModerateJam(profile, event)) {
29
29
  return;
30
30
  }
31
- if (((_b = getEffectiveRsvp(event, profile.id)) === null || _b === void 0 ? void 0 : _b.response) === 'yes') {
31
+ if (((_b = getEffectiveRsvp(event, profile.id, recurrenceId)) === null || _b === void 0 ? void 0 : _b.response) === 'yes') {
32
32
  return;
33
33
  }
34
- if (countYesRsvps(event) >= eventData.maxAttendees) {
34
+ if (countYesRsvps(event, recurrenceId) >= eventData.maxAttendees) {
35
35
  throw forbidden({ errorKey: 'error.eventAtCapacity' });
36
36
  }
37
37
  throw forbidden({ errorKey: 'error.jamRsvpRequired' });
38
38
  };
39
- export const createJamEgressToken = async (event) => {
39
+ export const createJamEgressToken = async (event, recurrenceId) => {
40
40
  var _a, _b;
41
41
  const jamId = event.id;
42
+ const roomName = jamRoomName(event.id, recurrenceId);
42
43
  const jam = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.jam);
43
44
  if (!jam) {
44
45
  throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
@@ -51,7 +52,7 @@ export const createJamEgressToken = async (event) => {
51
52
  }),
52
53
  });
53
54
  accessToken.addGrant({
54
- room: jamId,
55
+ room: roomName,
55
56
  hidden: true,
56
57
  roomJoin: true,
57
58
  roomRecord: true,
@@ -59,21 +60,22 @@ export const createJamEgressToken = async (event) => {
59
60
  });
60
61
  return accessToken.toJwt();
61
62
  };
62
- export const createJamToken = async (event, profile, external = false) => {
63
+ export const createJamToken = async (event, profile, external = false, recurrenceId) => {
63
64
  var _a, _b, _c;
64
65
  if (!profile.id)
65
66
  throw authNeeded({ errorKey: 'error.profileRequired' });
66
67
  const jamId = event.id;
68
+ const roomName = jamRoomName(event.id, recurrenceId);
67
69
  const jam = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.jam);
68
70
  if (!jam) {
69
71
  throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
70
72
  }
71
- assertJamRsvpAllowed(event, profile);
73
+ assertJamRsvpAllowed(event, profile, recurrenceId);
72
74
  const rs = await roomService();
73
75
  if (rs === undefined) {
74
- throw forbidden({ errorKey: 'error.jamNotOpen' });
76
+ throw forbidden({ errorKey: 'error.jamsUnavailable' });
75
77
  }
76
- const rooms = await rs.listRooms([jamId]);
78
+ const rooms = await rs.listRooms([roomName]);
77
79
  const jamOpen = rooms.length === 1;
78
80
  if (!jamOpen && !(jam === null || jam === void 0 ? void 0 : jam.moderators.includes(profile.id))) {
79
81
  throw forbidden({ errorKey: 'error.jamNotOpen' });
@@ -84,7 +86,7 @@ export const createJamToken = async (event, profile, external = false) => {
84
86
  if (instanceDomain) {
85
87
  try {
86
88
  await rs.createRoom({
87
- name: jamId,
89
+ name: roomName,
88
90
  metadata: JSON.stringify({ instanceDomain }),
89
91
  emptyTimeout: JAM_ROOM_EMPTY_TIMEOUT_SEC,
90
92
  departureTimeout: JAM_ROOM_DEPARTURE_TIMEOUT_SEC,
@@ -99,6 +101,7 @@ export const createJamToken = async (event, profile, external = false) => {
99
101
  jamId,
100
102
  type: 'start',
101
103
  profileId: profile.id,
104
+ recurrenceId,
102
105
  });
103
106
  }
104
107
  const { apiKey, apiSecret } = (await config()).jams.livekit;
@@ -112,7 +115,7 @@ export const createJamToken = async (event, profile, external = false) => {
112
115
  }),
113
116
  });
114
117
  accessToken.addGrant({
115
- room: jamId,
118
+ room: roomName,
116
119
  roomJoin: true,
117
120
  roomAdmin: jam === null || jam === void 0 ? void 0 : jam.moderators.includes(profile.id),
118
121
  roomRecord: jam === null || jam === void 0 ? void 0 : jam.moderators.includes(profile.id),
@@ -1,7 +1,7 @@
1
1
  import { type PublicProfile, type PostWithMeta } from '@openpeepshq/common/types';
2
- export declare const isAdmittedToJam: (event: PostWithMeta, profileId: string) => Promise<boolean>;
3
- export declare const clearJamAdmittance: (event: PostWithMeta) => Promise<void>;
4
- export declare const currentWaitingRoomWatch: (jamEvent: PostWithMeta, onChange: (waitingRoom: Record<string, PublicProfile>) => void | Promise<void>) => Promise<() => Promise<void>>;
5
- export declare const admittanceWatch: (jamEvent: PostWithMeta, profileId: string, onToken: (token: string) => Promise<void> | void) => Promise<() => Promise<void>>;
6
- export declare const joinWaitingRoom: (event: PostWithMeta, profile: PublicProfile) => Promise<void>;
7
- export declare const acceptFromWaitingRoom: (event: PostWithMeta, profileId: string) => Promise<undefined>;
2
+ export declare const isAdmittedToJam: (event: PostWithMeta, profileId: string, recurrenceId?: string) => Promise<boolean>;
3
+ export declare const clearJamAdmittance: (event: PostWithMeta, recurrenceId?: string) => Promise<void>;
4
+ export declare const currentWaitingRoomWatch: (jamEvent: PostWithMeta, onChange: (waitingRoom: Record<string, PublicProfile>) => void | Promise<void>, recurrenceId?: string) => Promise<() => Promise<void>>;
5
+ export declare const admittanceWatch: (jamEvent: PostWithMeta, profileId: string, onToken: (token: string) => Promise<void> | void, recurrenceId?: string) => Promise<() => Promise<void>>;
6
+ export declare const joinWaitingRoom: (event: PostWithMeta, profile: PublicProfile, recurrenceId?: string) => Promise<void>;
7
+ export declare const acceptFromWaitingRoom: (event: PostWithMeta, profileId: string, recurrenceId?: string) => Promise<undefined>;
@@ -1,12 +1,13 @@
1
+ import { jamRoomName } from '@openpeepshq/common/lib';
1
2
  import { publicProfileSchema, } from '@openpeepshq/common/types';
2
3
  import { assertJamRsvpAllowed, createJamToken } from './token.js';
3
4
  import { disconnect, getConnection, getSharedConnection, } from '../redis/connection.js';
4
- const waitingRoomKey = (event) => `jams:waiting-room:${event.id}`;
5
- const admittanceKey = (event) => `jams:admitted:${event.id}`;
5
+ const waitingRoomKey = (event, recurrenceId) => `jams:waiting-room:${jamRoomName(event.id, recurrenceId)}`;
6
+ const admittanceKey = (event, recurrenceId) => `jams:admitted:${jamRoomName(event.id, recurrenceId)}`;
6
7
  /** Keep admissions around for the length of a long jam / mobile backgrounding. */
7
8
  const ADMITTANCE_TTL_SEC = 12 * 60 * 60;
8
- const currentWaitingRoom = (event) => getSharedConnection()
9
- .then((conn) => conn.hGetAll(waitingRoomKey(event)))
9
+ const currentWaitingRoom = (event, recurrenceId) => getSharedConnection()
10
+ .then((conn) => conn.hGetAll(waitingRoomKey(event, recurrenceId)))
10
11
  .then((wrRaw) => Object.entries(wrRaw))
11
12
  .then((entries) => entries.filter((e) => e[0] && e[1]))
12
13
  .then((entries) => entries.map(([key, value]) => [
@@ -14,25 +15,25 @@ const currentWaitingRoom = (event) => getSharedConnection()
14
15
  publicProfileSchema.partial().parse(JSON.parse(value)),
15
16
  ]))
16
17
  .then((entries) => Object.fromEntries(entries));
17
- const currentAdmittance = (event) => getSharedConnection().then((conn) => conn.hGetAll(admittanceKey(event)));
18
- export const isAdmittedToJam = async (event, profileId) => {
18
+ const currentAdmittance = (event, recurrenceId) => getSharedConnection().then((conn) => conn.hGetAll(admittanceKey(event, recurrenceId)));
19
+ export const isAdmittedToJam = async (event, profileId, recurrenceId) => {
19
20
  const conn = await getSharedConnection();
20
- return Boolean(await conn.hExists(admittanceKey(event), profileId));
21
+ return Boolean(await conn.hExists(admittanceKey(event, recurrenceId), profileId));
21
22
  };
22
- export const clearJamAdmittance = async (event) => {
23
- await getSharedConnection().then((conn) => conn.del(admittanceKey(event)));
23
+ export const clearJamAdmittance = async (event, recurrenceId) => {
24
+ await getSharedConnection().then((conn) => conn.del(admittanceKey(event, recurrenceId)));
24
25
  };
25
- export const currentWaitingRoomWatch = (jamEvent, onChange) => currentWaitingRoom(jamEvent)
26
+ export const currentWaitingRoomWatch = (jamEvent, onChange, recurrenceId) => currentWaitingRoom(jamEvent, recurrenceId)
26
27
  .then(onChange)
27
28
  .then(() => getConnection())
28
29
  .then((conn) => conn
29
- .subscribe(`__keyspace@0__:${waitingRoomKey(jamEvent)}`, (event) => {
30
+ .subscribe(`__keyspace@0__:${waitingRoomKey(jamEvent, recurrenceId)}`, (event) => {
30
31
  if (['hset', 'hdel'].includes(event)) {
31
- currentWaitingRoom(jamEvent).then(onChange);
32
+ currentWaitingRoom(jamEvent, recurrenceId).then(onChange);
32
33
  }
33
34
  })
34
35
  .then(() => () => disconnect(conn)));
35
- export const admittanceWatch = (jamEvent, profileId, onToken) => currentAdmittance(jamEvent)
36
+ export const admittanceWatch = (jamEvent, profileId, onToken, recurrenceId) => currentAdmittance(jamEvent, recurrenceId)
36
37
  .then((admittance) => {
37
38
  if (admittance[profileId]) {
38
39
  return onToken(admittance[profileId]);
@@ -40,9 +41,9 @@ export const admittanceWatch = (jamEvent, profileId, onToken) => currentAdmittan
40
41
  })
41
42
  .then(() => getConnection())
42
43
  .then((conn) => conn
43
- .subscribe(`__keyspace@0__:${admittanceKey(jamEvent)}`, async (event) => {
44
+ .subscribe(`__keyspace@0__:${admittanceKey(jamEvent, recurrenceId)}`, async (event) => {
44
45
  if ('hset' === event) {
45
- const token = await getSharedConnection().then((c) => c.hGet(admittanceKey(jamEvent), profileId));
46
+ const token = await getSharedConnection().then((c) => c.hGet(admittanceKey(jamEvent, recurrenceId), profileId));
46
47
  if (token) {
47
48
  await disconnect(conn);
48
49
  return onToken(token);
@@ -50,20 +51,20 @@ export const admittanceWatch = (jamEvent, profileId, onToken) => currentAdmittan
50
51
  }
51
52
  })
52
53
  .then(() => async () => {
53
- await getSharedConnection().then((c) => c.hDel(waitingRoomKey(jamEvent), profileId));
54
+ await getSharedConnection().then((c) => c.hDel(waitingRoomKey(jamEvent, recurrenceId), profileId));
54
55
  await disconnect(conn);
55
56
  }));
56
- export const joinWaitingRoom = async (event, profile) => {
57
- assertJamRsvpAllowed(event, profile);
57
+ export const joinWaitingRoom = async (event, profile, recurrenceId) => {
58
+ assertJamRsvpAllowed(event, profile, recurrenceId);
58
59
  const conn = await getSharedConnection();
59
- const wrKey = waitingRoomKey(event);
60
+ const wrKey = waitingRoomKey(event, recurrenceId);
60
61
  // Do not clear admittance here — once admitted, the guest may reconnect
61
62
  // (mobile idle / tab freeze) without a second moderator approval.
62
63
  await conn.hSet(wrKey, { [profile.id]: JSON.stringify(profile) });
63
64
  };
64
- export const acceptFromWaitingRoom = async (event, profileId) => {
65
+ export const acceptFromWaitingRoom = async (event, profileId, recurrenceId) => {
65
66
  const conn = await getSharedConnection();
66
- const wrKey = waitingRoomKey(event);
67
+ const wrKey = waitingRoomKey(event, recurrenceId);
67
68
  const profile = await publicProfileSchema
68
69
  .parseAsync(JSON.parse((await conn.hGet(wrKey, profileId)) || 'undefined'))
69
70
  .catch(() => undefined);
@@ -71,9 +72,9 @@ export const acceptFromWaitingRoom = async (event, profileId) => {
71
72
  if (!event || !profile) {
72
73
  return undefined;
73
74
  }
74
- const aKey = admittanceKey(event);
75
+ const aKey = admittanceKey(event, recurrenceId);
75
76
  await conn.hSet(aKey, {
76
- [profile.id]: await createJamToken(event, profile),
77
+ [profile.id]: await createJamToken(event, profile, false, recurrenceId),
77
78
  });
78
79
  await conn.expire(aKey, ADMITTANCE_TTL_SEC);
79
80
  };
@@ -0,0 +1,4 @@
1
+ export { importPostgres } from '../db/migration/importPostgres';
2
+ export { validateMigration } from '../db/migration/validate';
3
+ export { collectionInfos } from '../db/pg/collections';
4
+ export { collectionFilePath, collectionsDir, exportDirFromEnv, sortedChecksum, writeManifest, type MigrationManifest, } from '../db/migration/shared';
@@ -0,0 +1,4 @@
1
+ export { importPostgres } from '../db/migration/importPostgres.js';
2
+ export { validateMigration } from '../db/migration/validate.js';
3
+ export { collectionInfos } from '../db/pg/collections.js';
4
+ export { collectionFilePath, collectionsDir, exportDirFromEnv, sortedChecksum, writeManifest, } from '../db/migration/shared.js';
@@ -8,7 +8,9 @@ export default {
8
8
  event: 'groupMemberJoined',
9
9
  eventHandler: async (...args) => {
10
10
  const [group, profile] = args;
11
- for (const groupAdmin of await listGroupMembers(group).then((members) => members.filter((m) => { var _a; return (_a = m.roles) === null || _a === void 0 ? void 0 : _a.includes('admin'); }).map((m) => m.profile))) {
11
+ for (const groupAdmin of await listGroupMembers(group).then((members) => members
12
+ .filter((m) => { var _a, _b; return ((_a = m.roles) === null || _a === void 0 ? void 0 : _a.includes('owner')) || ((_b = m.roles) === null || _b === void 0 ? void 0 : _b.includes('admin')); })
13
+ .map((m) => m.profile))) {
12
14
  await maybeCreateNotification(groupAdmin, {
13
15
  type: 'groupMemberJoined',
14
16
  fromProfileId: profile.id,
@@ -8,7 +8,9 @@ export default {
8
8
  event: 'groupMemberLeft',
9
9
  eventHandler: async (...args) => {
10
10
  const [group, profile] = args;
11
- for (const groupAdmin of await listGroupMembers(group).then((members) => members.filter((m) => { var _a; return (_a = m.roles) === null || _a === void 0 ? void 0 : _a.includes('admin'); }).map((m) => m.profile))) {
11
+ for (const groupAdmin of await listGroupMembers(group).then((members) => members
12
+ .filter((m) => { var _a, _b; return ((_a = m.roles) === null || _a === void 0 ? void 0 : _a.includes('owner')) || ((_b = m.roles) === null || _b === void 0 ? void 0 : _b.includes('admin')); })
13
+ .map((m) => m.profile))) {
12
14
  await maybeCreateNotification(groupAdmin, {
13
15
  type: 'groupMemberLeft',
14
16
  fromProfileId: profile.id,
@@ -14,8 +14,12 @@ export const notificationSettings = (profileSettings, type) => {
14
14
  };
15
15
  export const expandNotification = async (notification) => {
16
16
  var _a, _b;
17
- const intermediateNotification = Object.assign(Object.assign({}, notification), { senderProfile: notification.fromProfileId
18
- ? anonymizeProfileIfDeleted(await getProfile(notification.fromProfileId))
17
+ const intermediateNotification = Object.assign(Object.assign({}, notification), {
18
+ // Include soft-deleted senders so anonymizeProfileIfDeleted can tombstone
19
+ // them; otherwise fromProfileId resolves to undefined and the UI falls
20
+ // back to an uninterpolated "{{profileName}} …" string.
21
+ senderProfile: notification.fromProfileId
22
+ ? anonymizeProfileIfDeleted(await getProfile(notification.fromProfileId, true))
19
23
  : undefined, post: notification.post
20
24
  ? await transformPost(notification.post)
21
25
  : undefined, recipientProfile: (await getProfile(notification.profileId)) });
@@ -1,3 +1,4 @@
1
+ import { getUniqueBy, pushSubscriptionDeliveryKey, } from '@openpeepshq/common/lib';
1
2
  import { communityConfig, config } from '../config/index.js';
2
3
  import webPush from 'web-push';
3
4
  import { logger } from '../log/index.js';
@@ -178,10 +179,16 @@ export const doPush = async (notification, notificationStats, account, jobLog) =
178
179
  notificationStats,
179
180
  };
180
181
  const subscriptions = await listPushSubscriptionsByAccount(account);
181
- const webSubscriptions = subscriptions.filter((sub) => sub.type === 'web');
182
- const webhookSubscriptions = subscriptions.filter((sub) => sub.type === 'webhook');
183
- const apnSubscriptions = subscriptions.filter((sub) => sub.type === 'apn');
184
- const fcmSubscriptions = subscriptions.filter((sub) => sub.type === 'fcm');
182
+ const uniqueSubscriptions = getUniqueBy(subscriptions, pushSubscriptionDeliveryKey);
183
+ const duplicateSubscriptions = subscriptions.filter((subscription) => !uniqueSubscriptions.some((unique) => unique.id === subscription.id));
184
+ if (duplicateSubscriptions.length > 0) {
185
+ await logStep(jobLog, log, `Removing ${duplicateSubscriptions.length} duplicate push subscription(s) for account ${account.id}`);
186
+ await Promise.all(duplicateSubscriptions.map((subscription) => deletePushSubscription(subscription.id).catch((error) => logFailure(jobLog, log, `failed to remove duplicate subscription ${subscription.id}`, error))));
187
+ }
188
+ const webSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'web');
189
+ const webhookSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'webhook');
190
+ const apnSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'apn');
191
+ const fcmSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'fcm');
185
192
  await logStep(jobLog, log, `Delivering push "${notification.title}" to account ${account.id} (${account.email}); ` +
186
193
  `subscriptions: web=${webSubscriptions.length} webhook=${webhookSubscriptions.length} ` +
187
194
  `apn=${apnSubscriptions.length} fcm=${fcmSubscriptions.length}`);
@@ -1,4 +1,5 @@
1
1
  import { PackageJson } from 'type-fest';
2
+ export declare const isPluginEnabled: (info: PackageJson) => boolean;
2
3
  type PluginInfo = [string, PackageJson, string];
3
4
  export declare const sortByDependencies: (pluginInfos: PluginInfo[]) => PluginInfo[];
4
5
  export declare const enumeratePluginInfos: (pluginsPath: string) => Promise<PluginInfo[]>;